SWIG -- Passing python proxy class instance to python callback

Discussion in 'Python' started by Keith Sabine, Jun 6, 2008.

  1. Keith Sabine

    Keith Sabine Guest

    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
    Keith Sabine, Jun 6, 2008
    #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:
    411
    Markus von Ehr
    May 18, 2004
  2. Jeff
    Replies:
    0
    Views:
    723
  3. Bit Byte
    Replies:
    3
    Views:
    638
    Bit Byte
    Mar 5, 2007
  4. HalloUlrich
    Replies:
    0
    Views:
    939
    HalloUlrich
    Apr 12, 2007
  5. HalloUlrich
    Replies:
    1
    Views:
    1,331
    migger
    May 4, 2011
Loading...

Share This Page