[PyKDE] Panel applets with PyKDE/Python
jbublitz at nwinternet.com
Tue Aug 19 03:11:01 BST 2003
On Monday August 18 2003 16:06, Roland Schulz wrote:
> do you think the same would work for Custom Widgets in
I just looked at Qt Designer quickly and I'm not real familiar
with it. I think what you're asking is "Would it be possible to
create a custom widget in Python and have Qt Designer handle it
properly?" , or am I missing the point?
Assuming that's what you're asking, the code would be different -
this is very panel applet specific - but the basic approach
should be the same. I'm also assuming that the "plugin.h" stuff
in the custom widget section of the Qt Designer manual is
methods that Qt Desinger calls that reside in the custom widget.
If that's also correct, then my guess is you'd have to do the
same thing that PyKDE would do for panel applets, but once for
For panel applets, kicker finds a .desktop file in its directory
and from there gets the name of the panel applet .so lib to
load. PyKDE will substitute a single .so that loads any Python
panel applet (so it needs a mod to KDE/kicker to pass in the
name of the script being requested - this is really easy to do).
Here's the part that I think is similar to Qt Designer: when
kicker loads the lib for the applet, it looks for a function:
KPanelApplet *init (QWidget *parent, QString& configFile);
(PyKDE's .so lib wants to see a script name in configFile, which
doesn't happen right now).
A C++ applet's init would construct a KPanelApplet subclass that
does whatever the applet's supposed to do and return a pointer
to the subclass to kicker. Instead of that, PyKDE's init:
1. Loads the Python interpreter (from another linked .so lib)
2. Converts the QWidget and QString to PyObjects (using sip
conversion functions from PyQt)
3. Loads the Python script into the interpreter
4. Calls a Python version of "init" in the script loaded (passes
the args that kicker sent to init)., which then uses Python to
construct the applet and returns a PyObject to the C++ init
5. Converts (using sip again and PyKDE) the PyObject returned to
a C++ KPanelApplet * and returns it to kicker.
It's taken more lines to describe it than to code it. Basically,
you'd need to do the same thing with Qt Designer for each method
(again if I understand it correctly after a quick look).
Somebody who understands Qt plugins might have a better
In fewer words, you need to provide a wrapper for the entire
interface, and embed Python into it.
The two hard parts are:
1. Converting objects between C++ and Python domains -
sip/PyQt/PyKDE make this easy.
2. Loading and comminicating with the Python interpreter - I
built a lib that makes this easy too.
The problem with releasing this that the panel applet part is
easier if tightly integrated into PyKDE, but I don't want to do
that until KDE/kicker supports it. It's a lot of picky details
to get this to build and link automatically (and that's true
whether it's part of PyKDE or not). The python lib part is
pretty stand-alone (it's independent of sip/PyKDE) - it's in
C++, it has a complete set of unit tests (yay!) and I threw
together a C wrapper (with it's own set of tests) in about 15
minutes while waiting for FedEx to call for my pickup. If
someone wants to see that, I can throw together some docs and
tar it up. The only thing I don't know is if it's thread safe (I
know NOTHING about threads).
> Am Montag, 18. August 2003 07:26 schrieb Jim Bublitz:
> > I've been promising to do something with this for quite a
> > while and finally got to it.
> > I spent some time this weekend playing around with the
> > possibility of writing panel applets for KDE (kicker) in
> > Python using PyKDE. David Boddie has made some preliminary
> > code available which I stole from shamelessly and with
> > mostly a little reorganization got it somewhat working.
More information about the PyQt