[PyKDE] KFilePlugins, using Python from C++ code and vice versa
Joachim Werner
joe at novell.com
Tue Sep 5 17:56:23 BST 2006
Hi Jim,
Am Freitag, 1. September 2006 00:18 schrieb Jim Bublitz:
[...]
> > So the question is how I can do that with PyKDE. Do I have to write a
> > wrapper dynamic library in C++ that calls my Python code? If yes, how?
> > (An example would be fine.)
> Yes, you have to create a .so and a .la file. You can fake the .la file,
> but it has to exist or KDE won't find the .so.
> Basically, your .so (in C++ of course) needs to load the Python
> interpreter, then use Python C API calls to load your script into the
> interpreter, and then invoke the entry point of the script to create the
> KDE object in Python... Finally, pass the pointer for Python-created KDE
> object back to the .so and from there back to the loader code that loaded
> the .so in the first place.
>
> You can pass pointers to Qt/KDE objects between C++ and Python as integers
> and use sip.wrapinstance() and sip.unwrapinstance() (in sip docs) to
> convert them back and forth.
>
> It's actually very little C++ code, and sometimes it actually works :)
>
> It usually works, but you may run into problems calling back into the
> Python created stuff from KDE when your new object is actually running.
> I've had that problem trying to create Control Center modules, but
> apparently Simon Edwards hasn't. You might want to look at his
> pykdeextension stuff (sorry, don't have URL handy), because it has to do
> what you're asking about.
>
> I have example code somewhere, but it's written in terms of other libraries
> and wouldn't be very useful.
As I've written in my reply to David, I was quite successful with his
ThumbCreator code. It has examples for building the .so and .la file. I was
able to build my own thumbnail creator. This is actually quite simple because
all a thumbnail creator does is take a QImage reference and some additional
parameters like the image path and then use QImage's loadFromData() method to
write the image.
My next step will be looking into the actual KFilePlugin stuff. If I get it
right, a KFilePlugin can optionally provide a thumbnail that is then used by
the generic thumb creator. So I wouldn't need to have two separate "remote
plugins".
Cheers
Joachim
--
Joachim Werner <joe at suse.de>
Project Manager Contracts, Migration, SDK
Novell, Linux R&D Nuernberg
More information about the PyQt
mailing list