[PyQt] Python callback in SIP

Phil Thompson phil at riverbankcomputing.com
Fri Jun 12 15:45:53 BST 2009


On Fri, 12 Jun 2009 16:38:45 +0200, MD <marco.dinacci at gmail.com> wrote:
> Phil,
> 
>> So why are you now using .sip files? I though you were embedding in a
C++
>> application, not generating a Python module.
> 
> Well I guess I didn't explain myself very clearly...I'm sorry.
> I'm wrapping a C++ library in order to generate a Python module. When
> using the C++ library, a developer can subclass A (which is an
> interface) and override the foo method, then another object of another
> class will automaticall call foo on the overridden object.
> The idea with the Python bindings is that the developer create a
> Python class extending from the wrapped A class, create a foo method
> and then the C++ code automatically call it.

Understood.

> In order for this to work
> I have to subclass A in C++ (let's call it B) and in its foo method
> somehow call the "equivalent" python foo method. Then I'll wrap B with
> SIP and I'll extend it in Python.

No you don't. SIP does all of that for you - otherwise it would be pretty
useless as a C++ wrapper generator. Just provide a .sip file for your A
class and you shouldn't need any %MethodCode.

> I don't know if this is the best approach but it's what I've used when
> wrapping the library using the Python C API and Cython. I'm now trying
> to wrap it with SIP in order to compare the various wrapping
> technologies, but for now SIP is the one that is causing me more
> headaches.
> 
> I hope it's clear, it's not so easy to explain it :)

Phil


More information about the PyQt mailing list