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

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu Jul 17 02:50:15 CEST 2008


That looks interesting...
Do you have a long list of boost::python::to_python_converter<> instantiations?
Ralf




----- Original Message ----
From: Maximilian Matthe <Maxi.Matthe at web.de>
To: c++-sig at python.org
Sent: Wednesday, July 16, 2008 4:11:02 PM
Subject: [C++-sig] [boost.python] convert swig-wrapped c++-return values to python with boost.python

Hello!

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);
        if(!arg)
            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:
getWindow().Hide()

I get the following error:
Traceback (most recent call last):
   File "test.py", line 31, in testit
     getWindow().Hide()
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 :-)
Max

_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig




More information about the Cplusplus-sig mailing list