[PyQt] Embed PyQt scripting in PyQt app‏

Adrien Tétar adri-from-59 at hotmail.fr
Sun Oct 18 18:10:23 BST 2015


Hi all,


I have added scripting support to my application by using the Python primitives compile() and exec() on code passed by the user, and I selectively hand a couple of my app intrinsics that are to be mutated in the global variables passed to exec() – so far so good.
Now, I would like to be able to run the event loop on the script as if it were the top-level window. Currently if you spawn a parent-less QWidget window in that embedded scripting engine, it will just close immediately. How to make it work as a top-level script?

Right now what I am doing is passing a reference to the parent window in the global variables of the executed script so users have to use that as parent widget, but I would like to run scripts that are made to run as top-level.

I considered spawning a separate thread but scripts mutate app data that wasn't made to be thread-safe, so it's not exactly what I want to resort to... any idea? how to make a scripting engine that runs the event loop as top-level?

The application in question is TruFont (a font editor), by the way: http://trufont.github.io/

My scripting facility is here: https://github.com/trufont/trufont/blob/master/Lib/defconQt/scriptingWindow.py

Thanks,


Adrien Tétar  		 	   		  


More information about the PyQt mailing list