Run Debian graphing calculator from Gambas3

Post

Posted
Rating:
#1 (In Topic #1111)
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 Hello everyone

I need to run the Debian (Gnome) graphing calculator from a command in Gambas3, how do I do it?

Note: in my terminal I put: gnome-calculator (and it launches it)

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#2
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 Thank you all anyway. The solution is: Shell "gnome-calculator"

Now I don't know if it is possible to present the calculator in the center of the screen

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
I cannot test but maybe try this ..

Code (gambas)

  1.  
  2. Shell "gnome-calculator"
  3.  
  4. Wait 1 ' give it a second to open.
  5.  
  6. Application.ActiveWindow.Center()
  7.  
  8.  

If Center() does not work maybe this…

Code (gambas)

  1.  
  2. Shell "gnome-calculator"
  3.  
  4. Wait 1 ' give it a second to open.
  5.  
  6. With Application.ActiveWindow
  7.   .Move((Screen.W - .W) / 2, (Screen.H - .H) / 2)
  8.  
  9.  
  10.  

I have found Application.ActiveWindow can point to external applications.
Could be worth a try.

Otherwise gb.desktop.x11 could probably do it using Desktop.FindWindow()
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
vuott is in the usergroup ‘Regular’
:? …and if we didn't want to use "Shell" (we also need to activate the Components "gb.desktop" and "gb.desktop.x11"):

Code (gambas)

  1. Public Sub Button1_Click()
  2.  
  3.   Dim dw As DesktopWindow
  4.  
  5. ' Run the graphing calculator:
  6.   df.Run(System.Find("gnome-calculator"))
  7.  
  8. ' Provides for centering the calculator window:
  9.   Repeat
  10.     Wait 0.01
  11.   Until Desktop.FindWindow(Null, Null, "gnome-calculator").Count > 0
  12.  
  13.   dw = New DesktopWindow(Desktop.FindWindow(Null, Null, "gnome-calculator")[0])
  14.  
  15.   dw.Move((Screen.W - dw.W) / 2, (Screen.H - dw.H) / 2)
  16.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#5
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
I am sincerely happy to greet you. I hope they are well.

Bruce Steers:
I appreciate your code and help but it doesn't work. I think "Application" is for local code or to manage Gambas3 windows and not external ones. But what do I know, you are a God of Olympus. :)

vuott:
Your code seemed more coherent to me for my case. But it doesn't work, if you look at your code you will see that you only have to change one line of site and everything will work perfectly fine. And so I have done it and it works fine. But I'm missing something because when I want to close the program it tells me an error and it doesn't close the Gambas3 program because of the line I moved. The error is "out of limits"

Code (gambas)

  1.    Dim dw As DesktopWindow
  2.    
  3.    ' Run the graphing calculator:
  4.    df.Run(System.Find("gnome-calculator"))
  5.    
  6.    dw = New DesktopWindow(Desktop.FindWindow(Null, Null, "gnome-calculator")[0])  ' Moved line and line with "Out of limits" error when closing the application
  7.    
  8.    ' Provides for centering the calculator window:
  9.    Repeat
  10.       Wait 0.01
  11.    Until Desktop.FindWindow(Null, Null, "gnome-calculator").Count > 0
  12.    
  13.    dw.Move((Screen.W - dw.W) / 2, (Screen.H - dw.H) / 2)  
  14.  

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
vuott is in the usergroup ‘Regular’
My code, like BruceSteers', attempts to address the two needs you posed in the beginning of this post: launching the "gnome-calculator" program and centering its window within the Desktop.
I wanted to solve the first problem by avoiding using the "Shell " command (to whose use I am particularly opposed, except in special cases that are difficult to solve otherwise).
The first command line in my code effectively addresses both your need (starting "gnome-calculator") and mine (avoiding the use of "Shell ").

The second part of your request can only be satisfied if "gnome-calculator" window is present on the Desktop, since its position will have to be managed to center it.
To wait for the "gnome-calculator" window to appear, our friend, BruceSteers, rightly placed a "Wait." The showing of the window, however, may - for various reasons - take less or more time than BruceSteers set. So I wanted to make it wait the proper and strictly necessary time, that is, until the actual appearance of the "gnome-calculator" window. To achieve this, I found it efficient to use a loop, from which one will exit only when the "Desktop.FindWindow()" Method has located the "gnome-calculator" window.
That is why that same command line cannot logically be placed before the loop (which - I remind you - is intended to replace the "Wait" of our very good friend BruceSteers: my loop is intended to achieve in essence the same end as the "Wait").

In fact, if I move that command line before the loop, as you did, I get an "out of limits" error. This is understandable, since - beyond the speed of one's pc - in the logic of the code, in order to move the "gnome-calculator" window, one must absolutely wait for its show. In fact, in my code the Object (variable "dw") of the Class "DesktopWindow" is a "handle " that can manage a window "really present" on the Desktop.

Regarding closing the program, you are probably referring to "gnome-calculator."
Since the Method "df.Run()" returns a variable of type "Process ", you could try "killing" the process of "gnome-calculator" with the Method ".Kill", which you can call from that variable, of type "Global", by clicking - for example - on a "Button".

Code (gambas)

  1.  
  2.  
  3. Public Sub Button1_Click()
  4.  
  5. ' Run the graphing calculator:
  6.   pr = df.Run(System.Find("gnome-calculator"))
  7.  
  8.   ...etc...etc....
  9.  
  10.  
  11. Public Sub Button2_Click()
  12.  
  13.   pr.Kill
  14.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top
1 guest and 0 members have just viewed this.