[PyKDE] Re: Using SIP to call Python from C++
James Emerton
ephelon at gmail.com
Thu May 19 22:32:58 BST 2005
I am in the process of instrumenting a large C++ API with hooks that
allow plugins to handle specific events. This is simply a
sophistication of the snippet that I sent you.
The principle is to create an abstract base class in C++ and implement
the concrete class in Python. You need to handle the instantiation of
the Python object, and pass the object back to a C++ method that
expects a pointer to the abstract interface.
The method you use to obtain the abstract interface pointer is highly
dependant on the architecture of your application.
ie: TLookupTable is a class I wrote to replace QTable with a version
more suited to displaying large read-only datasets. All data is
provided by an interface called TLookupDataSource. Both of these
classes have been wrapped with SIP, no special tricks are required.
To use data provided from Python, I subclass TLookupDataSource, and
implement the required methods. The code then creates an instance of
TLookupTable, or obtains a reference to an existing TLookupTable and
calls setDataSource(), passing in the reference to the data source
object.
You really should be able to implement this with the information I
have already provided.
James
On 5/19/05, Niac Neb <niacneb at yahoo.com> wrote:
> James,
>
> I'm assuming you don't have an example of calling
> Python from C++. Your previous post indicated you'd
> done this numerous times. The code snippet pretty
> much left me hanging.
>
> The folks at Riverbank indicated that SIP didn't even
> facilitate this capability.
>
> Perhaps more tutorials/WIKI will evolve as SIP becomes
> mature. I'll look forward to it. For now, the
> Boost.Python community seems more responsive to posts.
> I guess that's due to a larger user base.
>
> Thanks anyways,
> Niac
More information about the PyQt
mailing list