Run Debian graphing calculator from Gambas3

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
User avatar
gambafeliz
Posts: 141
Joined: Friday 2nd September 2022 7:50pm
Location: I live in the same city as Picasso

Run Debian graphing calculator from Gambas3

Post by gambafeliz »

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. :)
User avatar
gambafeliz
Posts: 141
Joined: Friday 2nd September 2022 7:50pm
Location: I live in the same city as Picasso

Re: Run Debian graphing calculator from Gambas3

Post by gambafeliz »

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. :)
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Run Debian graphing calculator from Gambas3

Post by BruceSteers »

I cannot test but maybe try this ..


Shell "gnome-calculator"

Wait 1 ' give it a second to open.

Application.ActiveWindow.Center()



If Center() does not work maybe this...


Shell "gnome-calculator"

Wait 1 ' give it a second to open.

With Application.ActiveWindow
  .Move((Screen.W - .W) / 2, (Screen.H - .H) / 2)

End With



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()
If at first you don't succeed , try doing something differently.
BruceS
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Run Debian graphing calculator from Gambas3

Post by vuott »

:? ...and if we didn't want to use "Shell" (we also need to activate the Components "gb.desktop" and "gb.desktop.x11"):
Public Sub Button1_Click()
  
  Dim df As New DesktopFile(Null)
  Dim dw As DesktopWindow

' Run the graphing calculator:
  df.Run(System.Find("gnome-calculator"))

' Provides for centering the calculator window:
  Repeat 
    Wait 0.01
  Until Desktop.FindWindow(Null, Null, "gnome-calculator").Count > 0
  
  dw = New DesktopWindow(Desktop.FindWindow(Null, Null, "gnome-calculator")[0])

  dw.Move((Screen.W - dw.W) / 2, (Screen.H - dw.H) / 2)
  
End
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
gambafeliz
Posts: 141
Joined: Friday 2nd September 2022 7:50pm
Location: I live in the same city as Picasso

Re: Run Debian graphing calculator from Gambas3

Post by gambafeliz »

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"
   Dim df As New DesktopFile(Null)
   Dim dw As DesktopWindow
   
   ' Run the graphing calculator:
   df.Run(System.Find("gnome-calculator"))
   
   dw = New DesktopWindow(Desktop.FindWindow(Null, Null, "gnome-calculator")[0])  ' Moved line and line with "Out of limits" error when closing the application
   
   ' Provides for centering the calculator window:
   Repeat 
      Wait 0.01
   Until Desktop.FindWindow(Null, Null, "gnome-calculator").Count > 0
   
   dw.Move((Screen.W - dw.W) / 2, (Screen.H - dw.H) / 2)   
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Run Debian graphing calculator from Gambas3

Post by vuott »

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".

Private pr As Process


Public Sub Button1_Click()

' Run the graphing calculator:
  pr = df.Run(System.Find("gnome-calculator"))

  ...etc...etc....

End

Public Sub Button2_Click()

  pr.Kill

End
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
Post Reply