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. Advertisements

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. Sridhar R
    Replies:
    14
    Views:
    1,760
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    Feb 10, 2004
  2. Markus von Ehr

    SWIG callback problem on win32

    Markus von Ehr, May 18, 2004, in forum: Python
    Replies:
    1
    Views:
    536
    Markus von Ehr
    May 18, 2004
  3. Bit Byte
    Replies:
    3
    Views:
    767
    Bit Byte
    Mar 5, 2007
  4. HalloUlrich
    Replies:
    0
    Views:
    1,213
    HalloUlrich
    Apr 12, 2007
  5. HalloUlrich
    Replies:
    1
    Views:
    1,927
    migger
    May 4, 2011
  6. Keith Sabine
    Replies:
    0
    Views:
    707
    Keith Sabine
    Jun 6, 2008
  7. Martin P. Hellwig
    Replies:
    1
    Views:
    502
    Martin P. Hellwig
    Mar 26, 2010
  8. Lyes Amazouz
    Replies:
    2
    Views:
    384
    Lyes Amazouz
    Aug 20, 2008
Loading...