FreeCAD Hangs When Called from Python
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: FreeCAD Hangs When Called from Python
Any idea ? Or can you maybe give a hint where to search for relevant information to solve this issue?
Re: FreeCAD Hangs When Called from Python
Not necessarily.So if I understood it correctly, it is required to perform .exec_loop() in order to get the gui properly running.
Many years ago the Qt team published an interesting slide about event loop integration (unfortunately it's not available any more). Anyway, the main points were:
* The application process delivers native events to Qt. On Windows and macOS this is always the case while on X11 the application must support GLib
* The plugin needs to ensure that the Qt event loop runs
** X11: If GLib is supported by the application, then this works automatically. Otherwise this is unlikely to work.
** macOS: Application needs to call an event-handler callback that does event translation and sends posted QEvents.
** Windows: Register a callback with the system to call QCoreApplication::sendPostedEvents
In the past I used Unity on Ubuntu and when entering showMainWindow() the GUI came up and I could work with it. Only modal dialogs didn't work because the disappeared immediately. Now I am on XFCE and there I have to call exec_loop. Alternatively I can use FreeCADGui.updateGui() in a while-loop.
On Windows a callback function must be registered as we did here: https://github.com/FreeCAD/FreeCAD/blob ... y.cpp#L105
Spyder is based on Qt, right? Does it use the same Qt version as FreeCAD or is it different? In the latter case this may lead to problems.In my case (IDE: Spyder, ipython, FreeCAD python 3 built) this results in a responsive FreeCAD gui. However, it also blocks the interpreter
According to https://stackoverflow.com/questions/105 ... p-with-qts it should be possible to call processEvents instead of starting the QApplication's event loop. With our Python binding you can do this with FreeCADGui.updateGui() which means that instead of
Code: Select all
FreeCADGui.exec_loop()
Code: Select all
while True: FreeCADGui.updateGui()
It you enter t1.isAlive() then it says the thread has stopped.But unfortunately it seems like if I run .exec_loop() within a separate thread, the gui doesn't respond (window pops up, but no content, similar to not running .exec_loop()):
Since you mentioned ipython you can give this a try, too: http://ipython.readthedocs.io/en/stable ... loops.html