Re: [PyKDE] Using SIP to wrap python objects
On Thursday June 12 2003 16: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. Would it be possible to create an object using SIP that I can inherit from and use the SIP api to convert into a CppPointer? Is there another/better way to achieve this? Unless I'm misunderstanding (always a possibility), what you want to do is the reverse of what sip does. Sip binds C++ objects to Python (so that you can use C++ objects in a Python program), and you appear to want to communicate with a Python object from a C++ program. The standard Python API has all of the C functions you need to accomplish this - see the Python/C API Manual that's included in the Python docs. You can find good examples on the web, or Lutz' Programming Python (O'Reilly) has some good example code and documentation (it's out of date, but the Python/C API stuff is still useful for the basics). I didn't find it too difficult to use the standard Python API - it's likely to be easier learning that than learning sip (especially since sip itself is based on the Python API to some extent). I'd estimate a day or two for a good C/C++ programmer for the Python API and longer for sip. It may not be important in your application, but an added benefit is that you'll figure out pretty quickly how to embed the Python interpreter into your app, and can then use Python to script it or develop extensions. Jim ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] Using SIP to wrap python objects
On Friday 13 June 2003 04:21 am, Phil Thompson wrote: On Friday 13 June 2003 12:31 am, 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. What C++ object does it need to look like? It needs to be a QObject, more specifically we want it to inherit from QWidget ...which is why SIP looks like such a good match. Would it be possible to create an object using SIP that I can inherit from and use the SIP api to convert into a CppPointer? If you have a C++ ctor for the object then that's exactly what SIP does, so maybe what you want to do is more complicated than your are implying? So, if I inherit a C++ object from QWidget and write a sip binding, then I'm set. That's what I thought, but what I was hoping for was some way to automatically generate this in between object. Here is what I'm trying to do: Let's say I need to add some slots to QWidget and a couple of methods, I then need to embed this on a dialog box made by someone else in C++. That dialog box needs access to these additional methods and slots. From what I'm seeing in the responses, I would write a C++ class(QMyddrin) that inherits from QWidget and adds these methods. Then my python ocde I would inherit from QMyddrin and it should all work as long as I do the conversion from Py_Object to CppPointer (I forget the call name.) That may be enough becuase I can probably modify some existing python introspection code that I have to spit out the .h, .cpp and .sip files fairly easily. Is there another/better way to achieve this? Phil The address of the PyKDE mailing list has changed. ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.imk.fraunhofer.de/mailman/listinfo/pykde ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] Using SIP to wrap python objects
On Friday 13 June 2003 12:31 am, 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. What C++ object does it need to look like? Would it be possible to create an object using SIP that I can inherit from and use the SIP api to convert into a CppPointer? If you have a C++ ctor for the object then that's exactly what SIP does, so maybe what you want to do is more complicated than your are implying? Is there another/better way to achieve this? Phil The address of the PyKDE mailing list has changed. ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] Using SIP to wrap python objects
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. Would it be possible to create an object using SIP that I can inherit from and use the SIP api to convert into a CppPointer? Is there another/better way to achieve this? 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? ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.imk.fraunhofer.de/mailman/listinfo/pykde