[PyKDE] KFilePlugins, using Python from C++ code and vice versa

Joachim Werner joe at novell.com
Tue Sep 5 17:49:35 BST 2006


Am Donnerstag, 31. August 2006 23:35 schrieb David Boddie:
> On Thu Aug 31 12:59:20 MEST 2006, Joachim Werner wrote:
> > quite a while ago I asked if anybody had working examples of KFilePlugins
> > written in Python, but I got no answer. I guess the reason was that there
> > are no such examples.
>
> Probably.
>
> > So let me rephrase the problem:
> >
> > What I want to do is prototype a metadata pluging for KDE that can fetch
> > file metadata from a server instead of reading the files.
>
> Or you could just write it in Python rather than merely prototyping it. ;-)

If all the heavy lifting is done outside the Python glue code, this may be a 
real option. OTOH what I am trying to do is relatively easy to port to C/C++ 
by somebody who knows how. The two reasons why I'm going for PyKDE here is 
that

a) I have not much clue about C++ myself

b) It is so much faster to develop if you don't have to go through a compile 
cycle every time you change something.

> > KFilePlugins are available in PyKDE, but the missing piece for me is how
> > to register them. Usually, KFilePlugins are referenced by name in a
> > .desktop file, and the matching dynamic library is loaded when needed.
>
> Yes, lots of plugins in KDE need a shared library, a libtool library file
> (with a .la suffix), and a desktop file.
>
> > 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.)
>
> Unfortunately, the answer is yes. Fortunately, this has been done many
> times by people reading this list, just for different types of plugins to
> the one you want.
>
> The most established set of tools and libraries for doing similar things is
> Simon Edwards' PyKDE Extensions package:
>
>   http://www.simonzone.com/software/pykdeextensions/
>
> As far as I can tell, the plugin will need a factory function more like the
> one for Control Centre modules than the one for kioslaves, so you should
> probably find the code for that in the above package and start with that.
>
> If you get stuck, I can probably send you something to help you get
> started, but it won't use the standard DistUtils infrastructure like the
> PyKDE Extensions do.

I actually had quite some success over the weekend with this stuff you have 
put on your website:

http://www.boddie.org.uk/david/Projects/Python/KDE/Software/thumbcreators-2005-09-19.tar.gz

I have a working Thumb Creator now that gets the thumbnail from a remote 
server via XML-RPC.

I am expecting the KFilePlugin to work very similar to the ThumbCreator stuff.

BTW: My experience was that this kind of stuff is relatively hard to debug. I 
had to ask your KDE guys for the tip to start kinit in a console window, so I 
see the output of the plugin.

And the actual problem turned out to be that your setup.py install is not 
x86-64-clean and installed into the 32bit tree. ;-)

After copying the stuff to the right place things worked.

I'll check Simon's stuff, too. I might need the kioslave template anyway.

That said, is there the slightest chance that KDE 4 gets plugin interfaces 
that accept plain Python (or Ruby or whatever) code without needing to wrap 
it into a C++ stub DLL?

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