[PyKDE] Using SIP to wrap python objects
Rob Knapp
myddrin at myddrin.com
Thu Jul 3 17:09:01 BST 2003
On Thu June 12 2003 09:05 pm, Frederick Polgardy Jr wrote:
> On Thursday 12 June 2003 18:31, Rob Knapp wrote:
> > I've found myself in a position where I need to present a python object
> > to a C++ object, and it needs to look like a C++ object. The target
> > application knows nothing of python.
> >
[snip]
>
> Why not write what's called (in "Patterns" speak) an Adaptor class: one
> which provides its own interface, and keeps track of the Python objects it
> needs to use internally. What kind of interface is the target application
> expecting?
>
Almost a month later (I got pulled off onto other things) I'm back at this and
have concluded that an out and out adapter class (rather that inheritance) is
the way to go as you suggested. I've written a nice little script that auto
generates my classes, and just generally seems to make life good. :)
Just generally, things go too confusing attempting this other ways.
I've run into a snag though:
When my python widget sends a signal, I need to pass this on to the
application that contains my C++ object. It looks like sipConnectRx is the
function I need, but when it requires a PyObject for both the transmitter and
receiver, so I need to get a SIP wrapper for my wrapper class.
The following code doesn't seem to work, even though this inherits from
QWidget sipThisObject is always null.
PyObject * sipThisObject;
sipThisObject = sipGetThisWrapper( this, qtQWidget);
sipConnectRx(objPyWidget, "SomePythonSignal", sipThisObject,
"slot_OnSomePythonSignal")
Legend:
objPyWidget the custom python widget being wrapped
qtQWidget is the python class QWidget retrieved from the qt module
slot_OnSomePythonSignal is a slot on my c++ wrapper object
Is there some other api call I should be using, or am I missing some piece
that needs to make this work?
More information about the PyQt
mailing list