Daniel Calvelo wrote:
Hi all,
Sorry for the keywordish subject line, but it's a bit long to put simply.
I'm trying to port the Thuban geographic data viewer (thuban.intevation.de)
from 2.4 to 2.5. The wxPython part is not a major hassle, even without using
wxversion.Now, there is a piece of the code where C++ is used for speed. It must
interoperate very closely with a Python-side created wxDC. Specifically, a
wxMemoryDC is created in Python, and it is passed to a C++ function to be
drawn on.In 2.4, the following works:
- take the 'this' property of the PyObject*,
- extract the hex part after the _, before the _p
- convert that to an address
- cast it to the appropriate type
And there you have the C++ object corresponding to the Python one.
That is definitly *not* the way to do it. Instead:
#include <wx/wxPython/wxPython.h>
wxMemoryDC* dc;
if (! wxPyConvertSwigPtr(pyobject,
(void**)&dc, wxT("wxMemoryDC")) {
// handle the error...
}
// use the DC...
Here are the docs and prototype for the function:
// Extract a pointer to the wrapped C++ object from a Python proxy object.
// Ensures that the proxy object is of the specified (or derived) type. If
// not able to perform the conversion then a Python exception is set and the
// error should be handled properly in the caller. Returns True on success.
bool wxPyConvertSwigPtr(PyObject* obj, void **ptr,
const wxChar* className);
ยทยทยท
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!