Run a function of an instantiated qt-macro from command line
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Run a function of an instantiated qt-macro from command line
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.
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.
- 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
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.
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.
Re: Run a function of an instantiated qt-macro from command line
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)
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)
- 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
You can simply reload your module after modifying your source
import GMSHMesh
reload(GMSHMesh)
import GMSHMesh
reload(GMSHMesh)
Re: Run a function of an instantiated qt-macro from command line
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
Think to go with wrapper function, although it is tedious. (Gonna post the results here, if nothing comes better than it)
Tia
- 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
Do not understand what you want.teobo wrote:hm somebody know how one could set the editboxes that ways,
Do you want to open a dialog or preset the parameters of an object?
Re: Run a function of an instantiated qt-macro from command line
Excuse me.microelly2 wrote:Do not understand what you want.teobo wrote:hm somebody know how one could set the editboxes that ways,
Do you want to open a dialog or preset the parameters of an object?
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
Re: Run a function of an instantiated qt-macro from command line
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:
Nothing happens .. What can I do?
Tia
lets say I have got the gui of the above gmsh macro. There is an editbox:
I would like to change its contents, so I write a functions:self.le_cmd_line_opt = QtGui.QLineEdit(self)
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")
Tia
- 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
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")
Re: Run a function of an instantiated qt-macro from command line
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
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