[C++-sig] [boost.python] convert swig-wrapped c++-return values to python with boost.python

Maximilian Matthe Maxi.Matthe at web.de
Thu Jul 17 01:11:02 CEST 2008


I know, this question is somehow often asked, but I did not find the 
solution for my problem.

I managed to implement a simple to_python converter for any wxObject:

template <class Obj>
struct convert_wxObject
	static PyObject* convert(Obj const& o)
		PyObject* arg = wxPyMake_wxObject(const_cast<Obj*>(&o), false);
			throw python_error("Object is not convertible to wxPython!");
		return arg;

This struct works for any wxWidgets object. At least if I want to
pass them from c++ to python.

What does not work is the following:

// c++:
wxWindow* getWindow();

// python:

I get the following error:
Traceback (most recent call last):
   File "test.py", line 31, in testit
TypeError: No Python class registered for C++ class class wxWindow.

How can I tell boost.python to use my conversion above? Practically it 
seems to be the same to me, if I convert a return value from a 
c++-function to python or convert a c++-parameter for a python function. 
Both is converting from c++ to python. so why does that not work?

I appreciate any help :-)

More information about the Cplusplus-sig mailing list