Run a function of an instantiated qt-macro from command line

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
teobo
Posts: 410
Joined: Fri Feb 21, 2014 11:23 am

Run a function of an instantiated qt-macro from command line

Post by teobo »

Hi,
given I have got a typical macro for fc such as this: http://www.freecadweb.org/wiki/index.ph ... Macro_GMSH
Code here: https://github.com/psicofil/Macros_Free ... sh.FCMacro

Can one and if yes, how can one call best (for testing purposes) lets say the method() of the ok-Button (proceed(self)) from Python console?
Tia
Ps: Would be glad even if i could run the proceed() methode anyhow without user interaction (for example from the init routines). Maybe there is tutorial for it? Thanks for a hint, too.
Last edited by teobo on Wed Dec 16, 2015 11:50 am, edited 1 time in total.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Run a function of a instantiated qt-macro from command line

Post by microelly2 »

t=MeshGmsh()
t.proceed()

When I have the Gui up I use sometimes this trick:

....
#somehwehre in your code
t=MeshGmsh()
FreeCAD.myWidget=t
....

and then I can access from python console using the global Symbol FreeCAD

FreeCAD.myWidget.proceed()

In this case the call can use the parameter values from your open dialog.
User avatar
teobo
Posts: 410
Joined: Fri Feb 21, 2014 11:23 am

Re: Run a function of an instantiated qt-macro from command line

Post by teobo »

Super- Cool!
Thanks for these two methods for accessing the qt gui. t=MeshGmsh() was the missing link.
For sake of completeness I post my snippet (re)start from console here. Starting the macro from console (having renamed the file in .py)
(no tested)

GMSHMesh.MeshGmsh.close(GMSHMesh.d)
del sys.modules["GMSHMesh"]
import GMSHMesh
GMSHMesh.MeshGmsh.proceed(GMSHMesh.t)
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Run a function of an instantiated qt-macro from command line

Post by microelly2 »

You can simply reload your module after modifying your source

import GMSHMesh
reload(GMSHMesh)
User avatar
teobo
Posts: 410
Joined: Fri Feb 21, 2014 11:23 am

Re: Run a function of an instantiated qt-macro from command line

Post by teobo »

hm somebody know how one could set the editboxes that ways, Does not function here.
Think to go with wrapper function, although it is tedious. (Gonna post the results here, if nothing comes better than it)
Tia
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Run a function of an instantiated qt-macro from command line

Post by microelly2 »

teobo wrote:hm somebody know how one could set the editboxes that ways,
Do not understand what you want. :?
Do you want to open a dialog or preset the parameters of an object?
User avatar
teobo
Posts: 410
Joined: Fri Feb 21, 2014 11:23 am

Re: Run a function of an instantiated qt-macro from command line

Post by teobo »

microelly2 wrote:
teobo wrote:hm somebody know how one could set the editboxes that ways,
Do not understand what you want. :?
Do you want to open a dialog or preset the parameters of an object?
Excuse me.
I just want to set the editbox parameter (property) -dynamically- from the console or somewhere else from outside the qt-class, just as it did with its functions.(methods)
Eg. I decide to set the editbox contents to "2" for testing porpose and then trigger a test process. - But I cannot _set_ it..
Tia
User avatar
teobo
Posts: 410
Joined: Fri Feb 21, 2014 11:23 am

Re: Run a function of an instantiated qt-macro from command line

Post by teobo »

This problem "change qt editbox contents" resulted difficult in the end:
lets say I have got the gui of the above gmsh macro. There is an editbox:
self.le_cmd_line_opt = QtGui.QLineEdit(self)
I would like to change its contents, so I write a functions:

Code: Select all

def set_le_cmd_line_opt_mesh(self,line="5"):
	print line
	self.le_cmd_line_opt_mesh.setText(line)
	return
#from command line or program
t.set_le_cmd_line_opt_mesh("line")
Nothing happens .. What can I do?
Tia
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Run a function of an instantiated qt-macro from command line

Post by microelly2 »

This works for me without extra update

Code: Select all

le_cmd_line_opt = QtGui.QLineEdit()
le_cmd_line_opt.show()
le_cmd_line_opt.setText("huhu")
le_cmd_line_opt.setText("huha")
User avatar
teobo
Posts: 410
Joined: Fri Feb 21, 2014 11:23 am

Re: Run a function of an instantiated qt-macro from command line

Post by teobo »

Thanks for the answer,

suppose that you are in the init method of the class:
def initUI(self):

Here I can change, too. But in other place or times I can not.
Am I right?
How would be for example a call from the console:

>>> t.le_cmd_line_opt_mesh.setText("hehe")
>>> FreeCAD.myWidget.le_cmd_line_opt_mesh.setText("hehe")
>>> FreeCAD.myWidget.le_cmd_line_opt_mesh.update()
gives no effect?

How can one somehow change after the init-routine has passed, keeps still the question.
tia
Post Reply