[PyKDE] sip, was: newest Version

Phil Thompson phil at riverbankcomputing.co.uk
Sat Nov 1 13:21:01 GMT 2003


On Saturday 01 November 2003 8:37 am, Roland Schulz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hey,
>
> On Saturday 01 November 2003 00:25, you wrote:
> > On Friday 31 October 2003 9:49 pm, Roland Schulz wrote:
> > > -----BEGIN PGP SIGNED MESSAGE-----
> > > Hash: SHA1
> > >
> > > Hey,
> > >
> > > trying to change the sip layer makes great advancement. Overwriting the
> > > className function already makes the Preview working!! Overwriting
> > > metaObject also makes signals, slots and propterties (partly) working!!
> > > So I think this will work.
> >
> > How have you "overwritten" the className function?
>
> Adding it to sipqtQWidget.h by hand. See the attached file.
>
> > > What I did for className is that I added to sipqtQWidget.h:
> > > virtual const char *className() const {return "FileChooser";}
> > >
> > >
> > > How should I do this in qwidget.sip? How can I get the classname (of
> > > course harding it is only for testing)? Calling className from Python
> > > space gives the correct result, so this should be doable. How can I
> > > access variables defined in the Python claass? Is there a way to tell
> > > sip to add this className method to all classes?
> >
> > Use the /AutoGen/ option to automatically generate methods, but I'm not
> > convinced this is going to help.
>
> What does this /AutoGen/ function?

Having seen what you've done, /AutoGen/ isn't designed for what you want to 
do. It needs a SIP change to generate the calls.

> > Remind me how Designer calls the factory
> > function to create the widget.
>
> designer creates an object PyQWidgetPlugin from the library and calls the
> create method. Create uses pythonize to call the createWidget method in the
> Python class.

I agree with Jim in that I can't see why adding these functions here is any 
different to using a proxy. In the end you are going to need to introspect 
the Python object to return the correct class name and meta-object anyway. 
(However I am coming round to thinking the proxy approach is worse as a more 
general solution.)

I think what you need to do next is to come up with 2 functions that can go 
into the SIP module/library that can be called from SIP generated code (or a 
proxy) like this...

class sipQFoo : public QFoo
{
public:
    const char *className() const
    {
        return sipGetClassNameForCpp(sipPyThis);
    }

    QMetaObject *metaObject() const
    {
        static QMetaObject *metaObj = 0;

        if (!metaObj)
            metaObj = sipGetMetaObjectForCpp(sipPyThis);

        return metaObj;
    }

    ...normal ctors...

In fact sipGetClassNameForCpp() is fairly simple...

const char *sipGetClassNameForCpp(sipThisType *sipThis)
{
    PyObject *nmo;

    if (sipThis == NULL || (nm = sipClassName((PyObject *)sipThis)) == NULL)
        return "Unknown class";

    const char *nm = PyString_AsString(nmo);
    Py_DECREF(nmo);

    return nm;
}

You can do the other one. :)

Phil




More information about the PyQt mailing list