Call backs

Discussion in 'Python' started by Anand K Raydu, Jun 16, 2004.

  1. 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
    Anand K Raydu, Jun 16, 2004
    #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. Mark S.

    Post Backs

    Mark S., Aug 13, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    783
    George Ter-Saakov
    Aug 13, 2003
  2. Robin Becker

    extension call backs and the GIL

    Robin Becker, Sep 29, 2003, in forum: Python
    Replies:
    6
    Views:
    327
    Robin Becker
    Sep 29, 2003
  3. Stefan Ram
    Replies:
    6
    Views:
    362
  4. Nick Keighley

    passing data to Tkinter call backs

    Nick Keighley, Jun 9, 2010, in forum: Python
    Replies:
    6
    Views:
    394
    rantingrick
    Jun 9, 2010
  5. Edward Rutherford

    Call Backs

    Edward Rutherford, Feb 15, 2012, in forum: C Programming
    Replies:
    8
    Views:
    266
    Willem
    Feb 17, 2012
Loading...

Share This Page