SWIG -- Passing python proxy class instance to python callback

Discussion in 'Python' started by Jeff, May 2, 2005.

  1. Jeff

    Jeff Guest

    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
     
    Jeff, May 2, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus von Ehr

    SWIG callback problem on win32

    Markus von Ehr, May 18, 2004, in forum: Python
    Replies:
    1
    Views:
    445
    Markus von Ehr
    May 18, 2004
  2. Bit Byte
    Replies:
    3
    Views:
    653
    Bit Byte
    Mar 5, 2007
  3. HalloUlrich
    Replies:
    0
    Views:
    995
    HalloUlrich
    Apr 12, 2007
  4. HalloUlrich
    Replies:
    1
    Views:
    1,442
    migger
    May 4, 2011
  5. Keith Sabine
    Replies:
    0
    Views:
    592
    Keith Sabine
    Jun 6, 2008
Loading...

Share This Page