summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-06-13 13:56:28 (GMT)
committerGuido van Rossum <guido@python.org>1998-06-13 13:56:28 (GMT)
commitad4db17552b631bc94a47d75d6de2934f328cc7d (patch)
treef0bc0dbced82408586357005dce8735e18e1d7d0 /Modules
parentd458faadc303cef6fd07b9e22bfa9e08456426cf (diff)
downloadcpython-ad4db17552b631bc94a47d75d6de2934f328cc7d.zip
cpython-ad4db17552b631bc94a47d75d6de2934f328cc7d.tar.gz
cpython-ad4db17552b631bc94a47d75d6de2934f328cc7d.tar.bz2
Fixed the EventHook() code so that it also works on Windows, sort of.
(The "sort of" is because it uses kbhit() to detect that the user starts typing, and then no events are processed until they hit return.) Also fixed a nasty locking bug: EventHook() is called without the Tcl lock set, so it can't use the ENTER_PYTHON and LEAVE_PYTHON macros, which manipulate both the Python and the Tcl lock. I now only acquire and release the Python lock. (Haven't tested this on Unix yet...)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_tkinter.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 1c2c793..70d571b 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -121,6 +121,11 @@ PERFORMANCE OF THIS SOFTWARE.
#endif /* HAVE_CREATEFILEHANDLER */
+#ifdef MS_WINDOWS
+#include <conio.h>
+#define WAIT_FOR_STDIN
+#endif
+
#ifdef WITH_THREAD
/* The threading situation is complicated. Tcl is not thread-safe, except for
@@ -1822,6 +1827,7 @@ static PyMethodDef moduleMethods[] =
static int stdin_ready = 0;
+#ifndef MS_WINDOWS
static void
MyFileProc(clientData, mask)
void *clientData;
@@ -1829,22 +1835,34 @@ MyFileProc(clientData, mask)
{
stdin_ready = 1;
}
+#endif
static PyThreadState *event_tstate = NULL;
static int
EventHook()
{
+#ifndef MS_WINDOWS
FHANDLE tfile;
-
- ENTER_PYTHON(event_tstate)
- tfile = MAKEFHANDLE(fileno(stdin));
+#endif
+ if (PyThreadState_Swap(NULL) != NULL)
+ Py_FatalError("EventHook with non-NULL tstate\n");
+ PyEval_RestoreThread(event_tstate);
stdin_ready = 0;
+ errorInCmd = 0;
+#ifndef MS_WINDOWS
+ tfile = MAKEFHANDLE(fileno(stdin));
Tcl_CreateFileHandler(tfile, TCL_READABLE, MyFileProc, NULL);
+#endif
while (!errorInCmd && !stdin_ready) {
int result;
-
-#ifdef WITH_THREAD
+#ifdef MS_WINDOWS
+ if (_kbhit()) {
+ stdin_ready = 1;
+ break;
+ }
+#endif
+#if defined(WITH_THREAD) || defined(MS_WINDOWS)
ENTER_TCL
result = Tcl_DoOneEvent(TCL_DONT_WAIT);
release_lock(tcl_lock);
@@ -1858,14 +1876,16 @@ EventHook()
if (result < 0)
break;
}
+#ifndef MS_WINDOWS
Tcl_DeleteFileHandler(tfile);
+#endif
if (errorInCmd) {
errorInCmd = 0;
PyErr_Restore(excInCmd, valInCmd, trbInCmd);
excInCmd = valInCmd = trbInCmd = NULL;
PyErr_Print();
}
- LEAVE_PYTHON
+ PyEval_SaveThread();
return 0;
}