[C++-sig] boost.python class inheritance

Florian Delizy florian.delizy at unfreeze.net
Thu Apr 26 10:34:17 CEST 2007

Roman Yakovenko wrote:
> On 4/26/07, DELIZY Florian <fdelizy at unfreeze.net> wrote:
>> Hi,
>> I am using boost.python and wxPython together and I am experiencing some
>> troubles getting both interacting.
>> wxPython (www.wxpython.org) is a SWIG wrapped GUI C++ extension for
> python.
>> My problem is I want to expose a class using boost.python class_
>> template to python but this class is derived from a wx C++ class, to be
>> more precise, say I have this code :
>> class MyFrame : public wxFrame
>> {
>>     public:
>>           void SomeOperations( ... );
>>           ...
>> };
>> the class wxFrame is a C++ wx class already exposed to python using SWIG
>> as wx.wxFrame, how do I expose the class MyFrame, informing python that
>> MyFrame is derived from wxFrame using boost.python ?
>> is there a way to do such things ?
> Basically what you want is to expose your class and say that one of 
> its base
> classes is defined in Python.
well, not exactly, I want to expose a C++ class using python, given the 
fact that this C++ class is derived (in C++) from another C++ class 
itself exposed in python using SWIG...

so basically I want to export this existing C++ inheritance link into 
python, but I don't want to rewrite all wxPython using boost.python 
(quite an intensive job I think).

How does boost.python create this inheritance link (internally) ? I was 
thinking of something like retrieving a class descriptor from 
python/swig/wxPython and feeding it to boost.python class_ template ... 
(ok I could read the whole boost.python code for that ... but I don't 
know yet what to loof for ...)

> Right now, Boost.Python does not provide this
> functionality. In some cases it is possible to create work-around to the
> problem, but I am not sure about your use-case. 
I understand Python -> C++ inheritance is something tricky, but I am 
speaking about symetric C++->C++/Python->Python inheritance ... I 
thought it would work that way, would it ?

> Take a look on next link
> http://www.language-binding.net/pyplusplus/troubleshooting_guide/exceptions/exceptions.html- 
> it contains solution to similar problem.
I read it thanks, but that method does not apply
> P.S. Python-Ogre project, exposed using Boost.Python, makes an 
> extensive use
> of wxPython. May be they have some knowledge or "ready" solution for you.
all I found about it is wxPython + wxOgre usage (all together), but no 
integration between the two libs ...

More information about the Cplusplus-sig mailing list