diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1997-06-20 16:19:38 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1997-06-20 16:19:38 (GMT) |
commit | 883765eb71e1cf684a71fb805cf2f87b1c9c9ccd (patch) | |
tree | 028897ac43056a75d4a7208001a0d2bae33c513a | |
parent | 3757523f1e5cc70dbd26fa6ccb8a8a0f421201a0 (diff) | |
download | cpython-883765eb71e1cf684a71fb805cf2f87b1c9c9ccd.zip cpython-883765eb71e1cf684a71fb805cf2f87b1c9c9ccd.tar.gz cpython-883765eb71e1cf684a71fb805cf2f87b1c9c9ccd.tar.bz2 |
added SetEventHandler
-rw-r--r-- | Mac/Modules/macosmodule.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/Mac/Modules/macosmodule.c b/Mac/Modules/macosmodule.c index 6dd6de4..dc16243 100644 --- a/Mac/Modules/macosmodule.c +++ b/Mac/Modules/macosmodule.c @@ -499,27 +499,39 @@ MacOS_EnableAppswitch(PyObject *self, PyObject *args) return Py_BuildValue("i", old); } +static char setevh_doc[] = "Set python event handler to be called in mainloop"; + +static PyObject * +MacOS_SetEventHandler(self, args) + PyObject *self; + PyObject *args; +{ + PyObject *evh = NULL; + + if (!PyArg_ParseTuple(args, "|O", &evh)) + return NULL; + if (evh == Py_None) + evh = NULL; + if ( evh && !PyCallable_Check(evh) ) { + PyErr_SetString(PyExc_ValueError, "SetEventHandler argument must be callable"); + return NULL; + } + if ( !PyMac_SetEventHandler(evh) ) + return NULL; + Py_INCREF(Py_None); + return Py_None; +} + static char handleev_doc[] = "Pass event to other interested parties like sioux"; static PyObject * MacOS_HandleEvent(PyObject *self, PyObject *args) { EventRecord ev; - static int inhere; - /* - ** With HandleEvent and SetEventHandler we have a chance of recursive - ** calls. We check that here (for lack of a better place) - */ - if ( inhere ) { - PyErr_SetString(PyExc_RuntimeError, "Recursive call to MacOS.HandleEvent"); - return NULL; - } if (!PyArg_ParseTuple(args, "O&", PyMac_GetEventRecord, &ev)) return NULL; - inhere = 1; - PyMac_HandleEvent(&ev, 1); - inhere = 0; + PyMac_HandleEventIntern(&ev); Py_INCREF(Py_None); return Py_None; } @@ -658,6 +670,7 @@ static PyMethodDef MacOS_Methods[] = { #endif {"SchedParams", MacOS_SchedParams, 1, schedparams_doc}, {"EnableAppswitch", MacOS_EnableAppswitch, 1, appswitch_doc}, + {"SetEventHandler", MacOS_SetEventHandler, 1, setevh_doc}, {"HandleEvent", MacOS_HandleEvent, 1, handleev_doc}, {"GetErrorString", MacOS_GetErrorString, 1, geterr_doc}, {"openrf", MacOS_openrf, 1, openrf_doc}, |