@@ -499,27 +499,39 @@ MacOS_EnableAppswitch(PyObject *self, PyObject *args)
499499 return Py_BuildValue ("i" , old );
500500}
501501
502+ static char setevh_doc [] = "Set python event handler to be called in mainloop" ;
503+
504+ static PyObject *
505+ MacOS_SetEventHandler (self , args )
506+ PyObject * self ;
507+ PyObject * args ;
508+ {
509+ PyObject * evh = NULL ;
510+
511+ if (!PyArg_ParseTuple (args , "|O" , & evh ))
512+ return NULL ;
513+ if (evh == Py_None )
514+ evh = NULL ;
515+ if ( evh && !PyCallable_Check (evh ) ) {
516+ PyErr_SetString (PyExc_ValueError , "SetEventHandler argument must be callable" );
517+ return NULL ;
518+ }
519+ if ( !PyMac_SetEventHandler (evh ) )
520+ return NULL ;
521+ Py_INCREF (Py_None );
522+ return Py_None ;
523+ }
524+
502525static char handleev_doc [] = "Pass event to other interested parties like sioux" ;
503526
504527static PyObject *
505528MacOS_HandleEvent (PyObject * self , PyObject * args )
506529{
507530 EventRecord ev ;
508- static int inhere ;
509531
510- /*
511- ** With HandleEvent and SetEventHandler we have a chance of recursive
512- ** calls. We check that here (for lack of a better place)
513- */
514- if ( inhere ) {
515- PyErr_SetString (PyExc_RuntimeError , "Recursive call to MacOS.HandleEvent" );
516- return NULL ;
517- }
518532 if (!PyArg_ParseTuple (args , "O&" , PyMac_GetEventRecord , & ev ))
519533 return NULL ;
520- inhere = 1 ;
521- PyMac_HandleEvent (& ev , 1 );
522- inhere = 0 ;
534+ PyMac_HandleEventIntern (& ev );
523535 Py_INCREF (Py_None );
524536 return Py_None ;
525537}
@@ -658,6 +670,7 @@ static PyMethodDef MacOS_Methods[] = {
658670#endif
659671 {"SchedParams" , MacOS_SchedParams , 1 , schedparams_doc },
660672 {"EnableAppswitch" , MacOS_EnableAppswitch , 1 , appswitch_doc },
673+ {"SetEventHandler" , MacOS_SetEventHandler , 1 , setevh_doc },
661674 {"HandleEvent" , MacOS_HandleEvent , 1 , handleev_doc },
662675 {"GetErrorString" , MacOS_GetErrorString , 1 , geterr_doc },
663676 {"openrf" , MacOS_openrf , 1 , openrf_doc },
0 commit comments