[PyKDE] SIP and SWIG communication
Phil Thompson
phil at riverbankcomputing.co.uk
Sun Jun 8 12:12:01 BST 2003
On Sunday 08 June 2003 10:09 am, Alexandre Courbot wrote:
> Hello everybody,
>
> I'd like to write some graphical editors for a C++ game library using PyQt.
> This library is wrapped using SWIG, and dispose of a backend system for
> graphical output (which means I can easily add a Qt backend using QPixmaps
> for images of all sort if needed).
>
> In this context, I'd like to be able to draw game elements in a PyQt
> application. The best (at least, fastest to me) solution I can think of
> would be to write a Qt backend and to make the game elements draw
> themselves on a QPaintDevice using bitBlt.
>
> But this involves that soon or later, I will have pass the QPixmap of an
> image to be drawn from my SWIG-wrapped lib to PyQt. Also, I'll have to give
> the destination QPaintDevice that will come from PyQt to some of my own
> functions. Take the example of an animation editor: I'll want to have the
> images drawn in a list (passing them from SWIG to PyQt), but when it will
> come to animate it, I'll rather give the destination QPaintDevice to the
> animation's blit function so it can itself choose which frame to draw
> there.
>
> So all the problem is to convert Qt objects from my SWIG wrapper to valid
> PyQt objects and vice-versa. Obviously, both wrappers doesn't wrap things
> the same way. But maybe I can do something by manipulating raw pointers:
> SWIG objects contain a 'this' member that contains the raw address of the
> C++ object. SWIG also has construction classes that allow the construction
> of a SWIG object from a raw pointer. If SIP has the same capabilities, then
> some instance passing between the two should be possible. Is something like
> this possible? 'sipThis' members of SIP objects look like something similar
> to 'this' in SWIG. Which type is it? Can I easily get the C++ object's
> pointer from it? I haven't found anything related to SIP objects creations
> from pointers - is there something for that?
>
> I'm also open to your comments about this SWIG-SIP translation, and how
> safe it is (especially regarding C++ objects ownership - again, I know of a
> way to deal this with SWIG, but know only very few about SIP). Maybe also
> there is an easier way to do what I want, without such conversions - I
> don't know Qt and PyQt well, so I may have missed something obvious.
>
> Thanks for your time and advices,
> Alex.
sipThis is the internal (to SIP) Python object that contains the real C++
pointer. It doesn't exist in SIP v4.
The C++ SIP API provides you with all the functionality you need - but this is
not exposed at the Python level, so you may need a C++ glue layer.
The other alternative, of course, is to re-wrap the library using SIP. How big
is the library? Is there a URL for it?
Phil
More information about the PyQt
mailing list