[PyKDE] Embedding PyQt apps in non-PyQt python programs
Jeremy Sanders
jeremy at jeremysanders.net
Sun May 8 16:10:36 BST 2005
Hi -
I've written a module other PyQt users may find useful. It embeds my PyQt
based plotting package, Veusz, in non-PyQt python apps. The non-PyQt
code can communicate with the PyQt code as if there wasn't an event
loop. It exposes Veusz's scripting language as methods of an object.
http://cvs.gna.org/viewcvs/veusz/veusz/embed.py?rev=HEAD&content-type=text/vnd.viewcvs-markup
It works by starting PyQt in a second python thread. A new instance of the
class creates a new PyQt window. When a method is called, __getattr__ is
used to "wrap" the method which is passed to the PyQt thread. It does this
by writing a character to a pipe. The PyQt QApplication uses
QSocketNotifier to catch the character, read the method and its arguments
from a variable and call it. Return values or exceptions are passed back
to the primary thread (with the help of another pipe for synchronisation).
Any exceptions are rethrown in the primary thread, or values are returned
from the method wrapper.
It all seems to work pretty well, except that __del__ never appears to be
called on the wrapper instances. Presumably something is keeping a
reference to the objects, but I haven't tracked it down yet...
Jeremy
--
Jeremy Sanders <jeremy at jeremysanders.net>
http://www.jeremysanders.net/ Cambridge, UK
Public Key Server PGP Key ID: E1AAE053
More information about the PyQt
mailing list