diff options
Diffstat (limited to 'ivycpy.i')
-rw-r--r-- | ivycpy.i | 90 |
1 files changed, 62 insertions, 28 deletions
@@ -50,6 +50,8 @@ typedef struct { typedef enum { IvyApplicationConnected, IvyApplicationDisconnected } IvyApplicationEvent; +typedef enum { IvyAddBind, IvyRemoveBind } IvyBindEvent; + typedef struct _timer *TimerId; /* a voir si a laisser ici */ @@ -288,9 +290,6 @@ pytkIvyApplicationCallback(IvyClientPtr app, void *user_data, PyTuple_SetItem(arglist,1,eventobj); result = PyEval_CallObject(func,arglist); - if(PyErr_Occurred()){ - PyErr_Print(); - } Py_DECREF(arglist); } @@ -323,11 +322,61 @@ pyIvyApplicationCallback(IvyClientPtr app, void *user_data, PyTuple_SetItem(arglist,1,eventobj); result = PyEval_CallObject(func,arglist); - if(PyErr_Occurred()){ - PyErr_Print(); - } Py_DECREF(arglist); } + +static void +pyIvyBindCallback(IvyClientPtr app, void *user_data, + int id, char* regexp, IvyBindEvent event) +{ + PyObject *func, *arglist; + PyObject *result, *eventobj, *idobj, *regexpobj; + PyObject *resultobj; + static void *descr = 0; +#ifdef __DEBUG__ + printf("-pyIvyBindCallback\n"); +#endif + func = (PyObject *) user_data; + /* cette verif est inutile ; elle a deja ete faite lors de + l'enregistrement du callback */ + if (!PyCallable_Check(func)) { + PyErr_SetString(PyExc_TypeError, "Need a callable object!"); + return ; + }; + /* user_data->func ; */ + /* la signature python doit etre proc(n) elle ne retourne rien */ + descr = SWIG_TypeQuery("IvyClientPtr"); + resultobj = SWIG_NewPointerObj((void *) app, descr, 0); + + idobj = Py_BuildValue("i", (int) id); + regexpobj=PyString_FromString(regexp); + eventobj = Py_BuildValue("i", (int) event); + arglist = PyTuple_New(4); + + PyTuple_SetItem(arglist,0,resultobj); + PyTuple_SetItem(arglist,1,idobj); + PyTuple_SetItem(arglist,2,regexpobj); + PyTuple_SetItem(arglist,3,eventobj); + + result = PyEval_CallObject(func,arglist); + Py_DECREF(arglist); +} + +static void +pyIvySetBindCallback(PyObject *PyFunc) /* void *user_data, */ +{ + + IvySetBindCallback(pyIvyBindCallback, (void *) PyFunc); + Py_INCREF(PyFunc); +} + +static void +pyIvyDelBindCallback() /* void *user_data, */ +{ + + IvyDelBindCallback(); +} + static void pytkIvyDieCallback(IvyClientPtr app, void *user_data, int id) { @@ -360,9 +409,6 @@ pytkIvyDieCallback(IvyClientPtr app, void *user_data, int id) PyTuple_SetItem(arglist,1,idobj); result = PyEval_CallObject(func,arglist); - if(PyErr_Occurred()){ - PyErr_Print(); - } Py_DECREF(arglist); } @@ -396,9 +442,6 @@ pyIvyDieCallback(IvyClientPtr app, void *user_data, int id) PyTuple_SetItem(arglist,1,idobj); result = PyEval_CallObject(func,arglist); - if(PyErr_Occurred()){ - PyErr_Print(); - } Py_DECREF(arglist); } @@ -442,9 +485,6 @@ pytkMsgCallback( IvyClientPtr app, void *user_data, int argc, char **argv ) Py_DECREF(arglist); */ result = PyEval_CallObject(func, pyargv) ; - if(PyErr_Occurred()){ - PyErr_Print(); - } Py_DECREF(pyargv); } @@ -495,9 +535,6 @@ pyMsgCallback( IvyClientPtr app, void *user_data, int argc, char **argv ) to the Python call back */ result = PyEval_CallObject(func, pyargv) ; - if(PyErr_Occurred()){ - PyErr_Print(); - } Py_DECREF(pyargv); /*Py_DECREF(resultobj);*/ } @@ -534,10 +571,8 @@ pytkMsgDirectCallback( IvyClientPtr app, void *user_data, int id, char *msg ) PyTuple_SetItem(arglist,1,PyString_FromString(msg)); result = PyEval_CallObject(func,arglist); - if(PyErr_Occurred()){ - PyErr_Print(); - } Py_DECREF(arglist); + Py_DECREF(resultobj); } static void @@ -569,10 +604,8 @@ pyMsgDirectCallback( IvyClientPtr app, void *user_data, int id, char *msg ) PyTuple_SetItem(arglist,1,PyString_FromString(msg)); result = PyEval_CallObject(func,arglist); - if(PyErr_Occurred()){ - PyErr_Print(); - } Py_DECREF(arglist); + Py_DECREF(resultobj); } /* facade to IvyBindMsg avoiding vararg problem */ @@ -610,7 +643,6 @@ pyIvyUnBindMsg (int binding_id) MsgRcvPtr rcvid ; rcvid = getRcvMsg(binding_id) ; if (rcvid != NULL) { - printf("-IvyUnbindMsg %x \n" , (int) rcvid) ; IvyUnbindMsg(rcvid); delRcvMsg(binding_id); }; @@ -730,7 +762,6 @@ pyIvyTimerModify( int timerid, int time ) TimerId timer ; timer = getIvyTimer(timerid); if (timer != NULL) { - printf("-modifying timer %x \n", (int) timer); TimerModify(timer, (long) time); } } @@ -740,7 +771,6 @@ pyIvyTimerRemove( int timerid) TimerId timer ; timer = getIvyTimer(timerid); if (timer != NULL) { - printf("-removing timer %x \n", (int) timer); TimerRemove(timer); delIvyTimer(timerid); } @@ -958,7 +988,6 @@ pyIvyInit( IvyInit(AppName,ready, pytkIvyApplicationCallback, (void *) PyFuncOnCx, pytkIvyDieCallback, (void *) PyFuncOnDie); - printf("-pyIvyInit after IvyInit Tk\n"); } else { IvyInit(AppName,ready, @@ -1107,6 +1136,11 @@ pyIvyTimerModify( int timerid, int time ); void pyIvyTimerRemove( int timerid); +static void +pyIvySetBindCallback(PyObject *PyFunc); +static void +pyIvyDelBindCallback(); + // for emacs // Local Variables: // mode: C |