[PyKDE] Re: Kcontrol modules.

David Boddie david at boddie.org.uk
Thu Jul 10 20:40:00 BST 2003


On Thursday 10 July 2003 07:29, Jim Bublitz wrote:

> On Wednesday July 9 2003 15:20, David Boddie wrote:

> > Any ideas on what I'm doing wrong would be good at this point.
>
> sipMapSelfToThis returns sipThisType*, which is a ptr to a
> struct. You probably want sipThisType->cppPtr (at least it is in
> 3.5 - its in siplib/siplib.c). Alternatively, it's a little
> simpler to use:
>
> KPanelApplet *sipForceConvertTo_KPanelApplet (
>    PyObject  *,int *)

That's helpful, thanks.

I've since been on a detour, wrapping the KPanelApplet methods manually, but
then I discovered sipConvertToCpp which I'm using in the following manner:

            int iserrp;
            PyClassObject *class_obj;
            PyObject *base_objs, *base_class;
            
            class_obj = ((PyInstanceObject*)pInstance)->in_class;
            
            base_objs = ((PyClassObject*)class_obj)->cl_bases;
            
            base_class = PyTuple_GetItem(base_objs, 0);
            
            panel_applet = (KPanelApplet*)sipConvertToCpp(
                pInstance, base_class, &iserrp
                );

The result of this class hacking is a space for an applet on the panel and
a handle for it (but this happens even when the Pythen part of it has
crashed). With the manual method, I managed to get an applet to open an About
dialog but this is taking longer with the above approach.

> eg:
>
> #include <sipkdeuiKPanelApplet.h>
>
> int isErr = 0;
> panel_applet = sipForceConvertTo_KPanelApplet (pyObj, &isErr);
>
> if (isErr) {
> <handle error>
> }

Yes, I'll need to handle isErr. Thanks for the reminder!

> and link to libkdeui (in site-packages).

I'll have to work on the dependencies a bit. At the moment I'm linking the
library against all the PyKDE modules. Still, the resulting shared library
is only 123K, although I dread to think how large the sum of all the other
components is.

> You might not be this far along, but will your method allow
> someone to choose one of several panel applets written in Python
> using the same .so file for each? In other words, does each
> applet require a .so file, or is there a common .so file and
> users just write applets strictly in Python?

At the moment, the build script hardwires the module name and path into the
library but I think that there's scope for the use of an applet handler which
dispatches the appropriate Python module based on the contents of the
"configFile" parameter passed to the "init" function in the shared library
(DSO, as they appear to be referred to in the KDE examples).

For example, a test applet I have is called in this manner:

   init(None, "libtestapplet_9vmslmsnnuootgrnc8t_rc", "testapplet")

where the third parameter is the name of the applet (hardwired at the moment)
so, in the scheme you outline, it might be something generic like
"pythonapplet". The second parameter may be generated by the calling
application based on the .desktop file or the name of the DSO so it might
be worth parsing to find the name of the necessary module. We'll see.

I'll work on it a bit more today and try to upload something in time for
the weekend.

All the best,

David




More information about the PyQt mailing list