Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > SWIG -- Passing python proxy class instance to python callback

Reply
Thread Tools

SWIG -- Passing python proxy class instance to python callback

 
 
Keith Sabine
Guest
Posts: n/a
 
      06-06-2008
Hi

Did you ever find a solution to this? I am having the exact same problem...

- Keith

I'm trying to pass a proxy class instance (SWIG generated) of CClass,
to a python callback function from C++. The proxy class instance of
CClass is created from a pointer to the C++ class CClass.

Using the code below, I receive the error message:

"AttributeError: 'PySwigObject' object has no attribute 'GetName'"


The python callback function is being passed in through the clientdata
pointer, and the CClass *class pointer is what's being converted to an
instance of the SWIG proxy class and passed to the python callback
function as an argument.

static void PythonCallBack(CClass *class,void *clientdata)
{
PyObject *func, *arglist,*obj;
PyObject *result;

func = (PyObject *) clientdata; // Get Python function
obj = SWIG_NewPointerObj((void*) cmd, SWIGTYPE_p_CSCSICommand, 1);
//create instance of python proxy class from c++ pointer

arglist=Py_BuildValue("(O)",*obj); //convert to tuple
result = PyEval_CallObject(func,arglist); // Call Python

Py_XDECREF(result);
return;
}

Any input would greatly appreciated. Thanks,
Jeff


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SWIG CallBack from C++ into Java-Class HalloUlrich Java 1 05-04-2011 12:46 PM
SWIG CallBack from C++ into Java-Class HalloUlrich Java 0 04-12-2007 02:55 PM
Derived class passing callback to base class Bit Byte C++ 3 03-05-2007 12:48 PM
SWIG -- Passing python proxy class instance to python callback Jeff Python 0 05-02-2005 02:55 PM
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. DJ Dev ASP .Net 3 02-08-2004 04:19 PM



Advertisments