Call backs

Anand K Raydu anand at easi.soft.net
Wed Jun 16 09:51:55 EDT 2004


Hi all,

I have some problems with callback mechanisms,
I have embedded python into my application and want to customize my 
application through python.
It is great with respect to calling the my APIS .
Now i have a situation where one of my API calls dialog box , and upon 
clicking the dialog box buttons i am invoking python callback.
most of the time callback is failing. unfortunately there is no error 
message is also generated.

following is the way i am sending the callback to python & calling it 
from c.

main python code:

class myClass:
   def __init__(self,value):
       self.value = value
   def Execute(self):
       import myapis
       myapis.activateDialogBox()
       myapis.setCallBack(self.myCallBack)
      myapis.EventLoop()        # this an infinate loop which just gets 
all gui events & dispatches like any gui event loop
    
   def myCallBack(self):
        import myapis
        myapis.doSomeThing()
      

my  C code to get the callback

PyObject *setCallBack(PyObject *self, PyObject *args) {

    PyObject *command;
    int  retvalue =0;

    if (!PyArg_ParseTuple(args, "O:setCallBack", &command))
        return NULL;

    Py_XDECREF(command);
    glbCallback = command;  //  a global python variable
}
at the time of invocation of the API i have following code

void invokeCallBack()
 if( glbCallback == NULL ) return 0 ;
   
    PyObject *arglist;
    PyObject *result;

    PyGILState_STATE state = PyGILState_Ensure();
    arglist = Py_BuildValue("(i)", buttonValue);
    result = PyEval_CallObject(glbCallback , arglist);
// The result some times in NULL indicating failure,
// I noticed that if i imort my module in the python callback it is 
happening.
/
    Py_XDECREF(arglist);
    Py_XDECREF(result);
    PyGILState_Release(state);
}

Can some one please suggest a better way of dealing it.
i want really a robust mechanism for callbacks.
Thanks & Best Regards,
Anand






More information about the Python-list mailing list