annotate Modules/tclNotify.c @ 16798:258dcafe2d0b legacy-trunk

Gustavo Niemeyer <niemeyer@conectiva.com>: Fixed recno support (keys are integers rather than strings). Work around DB bug that cause stdin to be closed by rnopen() when the DB file needed to exist but did not (no longer segfaults). This closes SF tracker patch #403445. Also wrapped some long lines and added whitespace around operators -- FLD.
author Fred Drake <fdrake@acm.org>
date Tue, 27 Feb 2001 18:56:46 +0000
parents 8a063423e0b7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6343
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 * This is a modified version of tclNotify.c from Sun's Tcl 8.0
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 * distribution. The purpose of the modification is to provide an
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 * interface to the internals of the notifier that make it possible to
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 * write safe multi-threaded Python programs that use Tkinter.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 * Original comments follow. The file license.terms from the Tcl 8.0
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 * distribution is contained in this directory, as required.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 * tclNotify.c --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 * This file implements the generic portion of the Tcl notifier.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 * The notifier is lowest-level part of the event system. It
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 * manages an event queue that holds Tcl_Event structures. The
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 * platform specific portion of the notifier is defined in the
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 * tcl*Notify.c files in each platform directory.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 * See the file "license.terms" for information on usage and redistribution
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 * SCCS: @(#) tclNotify.c 1.15 97/06/18 17:14:04
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #include "tclInt.h"
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 #include "tclPort.h"
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 * The following static indicates whether this module has been initialized.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 static int initialized = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 * For each event source (created with Tcl_CreateEventSource) there
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 * is a structure of the following type:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 typedef struct EventSource {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 Tcl_EventSetupProc *setupProc;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 Tcl_EventCheckProc *checkProc;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 ClientData clientData;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 struct EventSource *nextPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 } EventSource;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 * The following structure keeps track of the state of the notifier.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 * The first three elements keep track of the event queue. In addition to
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 * the first (next to be serviced) and last events in the queue, we keep
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 * track of a "marker" event. This provides a simple priority mechanism
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 * whereby events can be inserted at the front of the queue but behind all
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 * other high-priority events already in the queue (this is used for things
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 * like a sequence of Enter and Leave events generated during a grab in
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 * Tk).
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 static struct {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 Tcl_Event *firstEventPtr; /* First pending event, or NULL if none. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 Tcl_Event *lastEventPtr; /* Last pending event, or NULL if none. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 Tcl_Event *markerEventPtr; /* Last high-priority event in queue, or
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 * NULL if none. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 int serviceMode; /* One of TCL_SERVICE_NONE or
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 * TCL_SERVICE_ALL. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 int blockTimeSet; /* 0 means there is no maximum block
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 * time: block forever. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 Tcl_Time blockTime; /* If blockTimeSet is 1, gives the
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 * maximum elapsed time for the next block. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 int inTraversal; /* 1 if Tcl_SetMaxBlockTime is being
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 * called during an event source traversal. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 EventSource *firstEventSourcePtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 /* Pointer to first event source in
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 * global list of event sources. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 } notifier;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
77
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 * Declarations for functions used in this file.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 static void InitNotifier _ANSI_ARGS_((void));
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 static void NotifierExitHandler _ANSI_ARGS_((ClientData clientData));
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 * InitNotifier --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 * This routine is called to initialize the notifier module.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 * None.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 * Side effects:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 * Creates an exit handler and initializes static data.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 static void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
103 InitNotifier(void)
6343
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 initialized = 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 memset(&notifier, 0, sizeof(notifier));
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 notifier.serviceMode = TCL_SERVICE_NONE;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 Tcl_CreateExitHandler(NotifierExitHandler, NULL);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 * NotifierExitHandler --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 * This routine is called during Tcl finalization.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 * None.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 * Side effects:
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 6343
diff changeset
122 * Clears the notifier initialization flag.
6343
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 static void
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 NotifierExitHandler(clientData)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 ClientData clientData; /* Not used. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 initialized = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
133
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 * Tcl_CreateEventSource --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 * This procedure is invoked to create a new source of events.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 * The source is identified by a procedure that gets invoked
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 * during Tcl_DoOneEvent to check for events on that source
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 * and queue them.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 * None.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 * Side effects:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 * SetupProc and checkProc will be invoked each time that Tcl_DoOneEvent
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 * runs out of things to do. SetupProc will be invoked before
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 * Tcl_DoOneEvent calls select or whatever else it uses to wait
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 * for events. SetupProc typically calls functions like Tcl_WatchFile
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 * or Tcl_SetMaxBlockTime to indicate what to wait for.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 * CheckProc is called after select or whatever operation was actually
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 * used to wait. It figures out whether anything interesting actually
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 * happened (e.g. by calling Tcl_FileReady), and then calls
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 * Tcl_QueueEvent to queue any events that are ready.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 * Each of these procedures is passed two arguments, e.g.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 * (*checkProc)(ClientData clientData, int flags));
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 * ClientData is the same as the clientData argument here, and flags
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 * is a combination of things like TCL_FILE_EVENTS that indicates
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 * what events are of interest: setupProc and checkProc use flags
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 * to figure out whether their events are relevant or not.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 void
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 Tcl_CreateEventSource(setupProc, checkProc, clientData)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 Tcl_EventSetupProc *setupProc; /* Procedure to invoke to figure out
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 * what to wait for. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 Tcl_EventCheckProc *checkProc; /* Procedure to call after waiting
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 * to see what happened. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 ClientData clientData; /* One-word argument to pass to
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 * setupProc and checkProc. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 EventSource *sourcePtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
180
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 if (!initialized) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 InitNotifier();
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
184
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 sourcePtr = (EventSource *) ckalloc(sizeof(EventSource));
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 sourcePtr->setupProc = setupProc;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 sourcePtr->checkProc = checkProc;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 sourcePtr->clientData = clientData;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 sourcePtr->nextPtr = notifier.firstEventSourcePtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 notifier.firstEventSourcePtr = sourcePtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 * Tcl_DeleteEventSource --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 * This procedure is invoked to delete the source of events
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 * given by proc and clientData.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 * None.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 * Side effects:
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 6343
diff changeset
205 * The given event source is canceled, so its procedure will
6343
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 * never again be called. If no such source exists, nothing
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 * happens.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
211
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 void
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 Tcl_DeleteEventSource(setupProc, checkProc, clientData)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 Tcl_EventSetupProc *setupProc; /* Procedure to invoke to figure out
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 * what to wait for. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 Tcl_EventCheckProc *checkProc; /* Procedure to call after waiting
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 * to see what happened. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 ClientData clientData; /* One-word argument to pass to
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 * setupProc and checkProc. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 EventSource *sourcePtr, *prevPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
222
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 for (sourcePtr = notifier.firstEventSourcePtr, prevPtr = NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 sourcePtr != NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 prevPtr = sourcePtr, sourcePtr = sourcePtr->nextPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 if ((sourcePtr->setupProc != setupProc)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 || (sourcePtr->checkProc != checkProc)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 || (sourcePtr->clientData != clientData)) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 continue;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 if (prevPtr == NULL) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 notifier.firstEventSourcePtr = sourcePtr->nextPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 } else {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 prevPtr->nextPtr = sourcePtr->nextPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 ckfree((char *) sourcePtr);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 return;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
240
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 * Tcl_QueueEvent --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 * Insert an event into the Tk event queue at one of three
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 * positions: the head, the tail, or before a floating marker.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 * Events inserted before the marker will be processed in
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 * first-in-first-out order, but before any events inserted at
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 * the tail of the queue. Events inserted at the head of the
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 * queue will be processed in last-in-first-out order.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 * None.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 * Side effects:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 * None.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
261
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 void
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 Tcl_QueueEvent(evPtr, position)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 Tcl_Event* evPtr; /* Event to add to queue. The storage
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 * space must have been allocated the caller
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 * with malloc (ckalloc), and it becomes
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 * the property of the event queue. It
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 * will be freed after the event has been
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 * handled. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 Tcl_QueuePosition position; /* One of TCL_QUEUE_TAIL, TCL_QUEUE_HEAD,
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 * TCL_QUEUE_MARK. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 if (!initialized) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 InitNotifier();
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
276
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 if (position == TCL_QUEUE_TAIL) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
279 * Append the event on the end of the queue.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
281
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 evPtr->nextPtr = NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 if (notifier.firstEventPtr == NULL) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 notifier.firstEventPtr = evPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 } else {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 notifier.lastEventPtr->nextPtr = evPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 notifier.lastEventPtr = evPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 } else if (position == TCL_QUEUE_HEAD) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 * Push the event on the head of the queue.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
293
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
294 evPtr->nextPtr = notifier.firstEventPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 if (notifier.firstEventPtr == NULL) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 notifier.lastEventPtr = evPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 notifier.firstEventPtr = evPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 } else if (position == TCL_QUEUE_MARK) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 * Insert the event after the current marker event and advance
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 * the marker to the new event.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
304
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 if (notifier.markerEventPtr == NULL) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 evPtr->nextPtr = notifier.firstEventPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 notifier.firstEventPtr = evPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
308 } else {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 evPtr->nextPtr = notifier.markerEventPtr->nextPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 notifier.markerEventPtr->nextPtr = evPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 notifier.markerEventPtr = evPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 if (evPtr->nextPtr == NULL) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 notifier.lastEventPtr = evPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
318
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 * Tcl_DeleteEvents --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 * Calls a procedure for each event in the queue and deletes those
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 * for which the procedure returns 1. Events for which the
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 * procedure returns 0 are left in the queue.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 * None.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 * Side effects:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 * Potentially removes one or more events from the event queue.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
336
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 void
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 Tcl_DeleteEvents(proc, clientData)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 Tcl_EventDeleteProc *proc; /* The procedure to call. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 ClientData clientData; /* type-specific data. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 Tcl_Event *evPtr, *prevPtr, *hold;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
343
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 if (!initialized) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 InitNotifier();
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
347
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 for (prevPtr = (Tcl_Event *) NULL, evPtr = notifier.firstEventPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 evPtr != (Tcl_Event *) NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 ) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 if ((*proc) (evPtr, clientData) == 1) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 if (notifier.firstEventPtr == evPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 notifier.firstEventPtr = evPtr->nextPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 if (evPtr->nextPtr == (Tcl_Event *) NULL) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 notifier.lastEventPtr = (Tcl_Event *) NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 } else {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 prevPtr->nextPtr = evPtr->nextPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 hold = evPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 evPtr = evPtr->nextPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 ckfree((char *) hold);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 } else {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 prevPtr = evPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 evPtr = evPtr->nextPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
369
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 * Tcl_ServiceEvent --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 * Process one event from the event queue, or invoke an
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 * asynchronous event handler.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 * The return value is 1 if the procedure actually found an event
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 * to process. If no processing occurred, then 0 is returned.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 * Side effects:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 * Invokes all of the event handlers for the highest priority
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 * event in the event queue. May collapse some events into a
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 * single event or discard stale events.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
388 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
389
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 int
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 Tcl_ServiceEvent(flags)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 int flags; /* Indicates what events should be processed.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 * May be any combination of TCL_WINDOW_EVENTS
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 * TCL_FILE_EVENTS, TCL_TIMER_EVENTS, or other
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 * flags defined elsewhere. Events not
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 * matching this will be skipped for processing
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 * later. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 Tcl_Event *evPtr, *prevPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 Tcl_EventProc *proc;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
401
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 if (!initialized) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
403 InitNotifier();
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
405
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
407 * Asynchronous event handlers are considered to be the highest
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
408 * priority events, and so must be invoked before we process events
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 * on the event queue.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
410 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
411
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
412 if (Tcl_AsyncReady()) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 (void) Tcl_AsyncInvoke((Tcl_Interp *) NULL, 0);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
414 return 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
415 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
416
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 * No event flags is equivalent to TCL_ALL_EVENTS.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
419 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
420
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
421 if ((flags & TCL_ALL_EVENTS) == 0) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 flags |= TCL_ALL_EVENTS;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
424
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 * Loop through all the events in the queue until we find one
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 * that can actually be handled.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
429
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
430 for (evPtr = notifier.firstEventPtr; evPtr != NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 evPtr = evPtr->nextPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
433 * Call the handler for the event. If it actually handles the
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 * event then free the storage for the event. There are two
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 * tricky things here, but stemming from the fact that the event
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
436 * code may be re-entered while servicing the event:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 * 1. Set the "proc" field to NULL. This is a signal to ourselves
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
439 * that we shouldn't reexecute the handler if the event loop
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
440 * is re-entered.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 * 2. When freeing the event, must search the queue again from the
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
442 * front to find it. This is because the event queue could
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 * change almost arbitrarily while handling the event, so we
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 * can't depend on pointers found now still being valid when
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
445 * the handler returns.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
446 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
447
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 proc = evPtr->proc;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 evPtr->proc = NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
450 if ((proc != NULL) && (*proc)(evPtr, flags)) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
451 if (notifier.firstEventPtr == evPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
452 notifier.firstEventPtr = evPtr->nextPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
453 if (evPtr->nextPtr == NULL) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
454 notifier.lastEventPtr = NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
455 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
456 if (notifier.markerEventPtr == evPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
457 notifier.markerEventPtr = NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
458 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 } else {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
460 for (prevPtr = notifier.firstEventPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
461 prevPtr->nextPtr != evPtr; prevPtr = prevPtr->nextPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
462 /* Empty loop body. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
463 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
464 prevPtr->nextPtr = evPtr->nextPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
465 if (evPtr->nextPtr == NULL) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
466 notifier.lastEventPtr = prevPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
467 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
468 if (notifier.markerEventPtr == evPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
469 notifier.markerEventPtr = prevPtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
470 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
471 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
472 ckfree((char *) evPtr);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
473 return 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
474 } else {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
475 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
476 * The event wasn't actually handled, so we have to restore
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
477 * the proc field to allow the event to be attempted again.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
478 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
479
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
480 evPtr->proc = proc;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
481 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
482
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
483 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
484 * The handler for this event asked to defer it. Just go on to
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
485 * the next event.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
486 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
487
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
488 continue;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
489 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
490 return 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
491 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
492
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
493 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
494 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
495 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
496 * Tcl_GetServiceMode --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
497 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
498 * This routine returns the current service mode of the notifier.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
499 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
500 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
501 * Returns either TCL_SERVICE_ALL or TCL_SERVICE_NONE.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
502 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
503 * Side effects:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
504 * None.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
505 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
506 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
507 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
508
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
509 int
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
510 Tcl_GetServiceMode(void)
6343
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
511 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
512 if (!initialized) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
513 InitNotifier();
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
514 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
515
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
516 return notifier.serviceMode;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
517 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
518
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
519 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
520 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
521 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
522 * Tcl_SetServiceMode --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
523 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
524 * This routine sets the current service mode of the notifier.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
525 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
526 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
527 * Returns the previous service mode.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
528 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
529 * Side effects:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
530 * None.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
531 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
532 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
533 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
534
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
535 int
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
536 Tcl_SetServiceMode(mode)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
537 int mode; /* New service mode: TCL_SERVICE_ALL or
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
538 * TCL_SERVICE_NONE */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
539 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
540 int oldMode;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
541
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
542 if (!initialized) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
543 InitNotifier();
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
544 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
545
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
546 oldMode = notifier.serviceMode;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
547 notifier.serviceMode = mode;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
548 return oldMode;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
549 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
550
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
551 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
552 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
553 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
554 * Tcl_SetMaxBlockTime --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
555 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
556 * This procedure is invoked by event sources to tell the notifier
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
557 * how long it may block the next time it blocks. The timePtr
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
558 * argument gives a maximum time; the actual time may be less if
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
559 * some other event source requested a smaller time.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
560 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
561 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
562 * None.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
563 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
564 * Side effects:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
565 * May reduce the length of the next sleep in the notifier.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
566 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
567 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
568 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
569
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
570 void
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
571 Tcl_SetMaxBlockTime(timePtr)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
572 Tcl_Time *timePtr; /* Specifies a maximum elapsed time for
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
573 * the next blocking operation in the
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
574 * event notifier. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
575 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
576 if (!initialized) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
577 InitNotifier();
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
578 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
579
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
580 if (!notifier.blockTimeSet || (timePtr->sec < notifier.blockTime.sec)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
581 || ((timePtr->sec == notifier.blockTime.sec)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
582 && (timePtr->usec < notifier.blockTime.usec))) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
583 notifier.blockTime = *timePtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
584 notifier.blockTimeSet = 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
585 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
586
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
587 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
588 * If we are called outside an event source traversal, set the
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
589 * timeout immediately.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
590 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
591
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
592 if (!notifier.inTraversal) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
593 if (notifier.blockTimeSet) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
594 Tcl_SetTimer(&notifier.blockTime);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
595 } else {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
596 Tcl_SetTimer(NULL);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
597 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
598 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
599 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
600
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
601 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
602 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
603 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
604 * Tcl_DoOneEvent --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
605 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
606 * Process a single event of some sort. If there's no work to
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
607 * do, wait for an event to occur, then process it.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
608 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
609 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
610 * The return value is 1 if the procedure actually found an event
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
611 * to process. If no processing occurred, then 0 is returned (this
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
612 * can happen if the TCL_DONT_WAIT flag is set or if there are no
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
613 * event handlers to wait for in the set specified by flags).
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
614 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
615 * Side effects:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
616 * May delay execution of process while waiting for an event,
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
617 * unless TCL_DONT_WAIT is set in the flags argument. Event
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
618 * sources are invoked to check for and queue events. Event
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
619 * handlers may produce arbitrary side effects.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
620 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
621 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
622 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
623
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
624 int
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
625 Tcl_DoOneEvent(flags)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
626 int flags; /* Miscellaneous flag values: may be any
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
627 * combination of TCL_DONT_WAIT,
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
628 * TCL_WINDOW_EVENTS, TCL_FILE_EVENTS,
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
629 * TCL_TIMER_EVENTS, TCL_IDLE_EVENTS, or
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
630 * others defined by event sources. */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
631 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
632 int result = 0, oldMode;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
633 EventSource *sourcePtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
634 Tcl_Time *timePtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
635
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
636 if (!initialized) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
637 InitNotifier();
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
638 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
639
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
640 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
641 * The first thing we do is to service any asynchronous event
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
642 * handlers.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
643 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
644
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
645 if (Tcl_AsyncReady()) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
646 (void) Tcl_AsyncInvoke((Tcl_Interp *) NULL, 0);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
647 return 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
648 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
649
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
650 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
651 * No event flags is equivalent to TCL_ALL_EVENTS.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
652 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
653
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
654 if ((flags & TCL_ALL_EVENTS) == 0) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
655 flags |= TCL_ALL_EVENTS;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
656 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
657
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
658 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
659 * Set the service mode to none so notifier event routines won't
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
660 * try to service events recursively.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
661 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
662
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
663 oldMode = notifier.serviceMode;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
664 notifier.serviceMode = TCL_SERVICE_NONE;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
665
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
666 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
667 * The core of this procedure is an infinite loop, even though
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
668 * we only service one event. The reason for this is that we
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
669 * may be processing events that don't do anything inside of Tcl.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
670 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
671
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
672 while (1) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
673
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
674 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
675 * If idle events are the only things to service, skip the
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
676 * main part of the loop and go directly to handle idle
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
677 * events (i.e. don't wait even if TCL_DONT_WAIT isn't set).
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
678 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
679
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
680 if ((flags & TCL_ALL_EVENTS) == TCL_IDLE_EVENTS) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
681 flags = TCL_IDLE_EVENTS|TCL_DONT_WAIT;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
682 goto idleEvents;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
683 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
684
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
685 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
686 * Ask Tcl to service a queued event, if there are any.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
687 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
688
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
689 if (Tcl_ServiceEvent(flags)) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
690 result = 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
691 break;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
692 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
693
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
694 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
695 * If TCL_DONT_WAIT is set, be sure to poll rather than
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
696 * blocking, otherwise reset the block time to infinity.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
697 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
698
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
699 if (flags & TCL_DONT_WAIT) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
700 notifier.blockTime.sec = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
701 notifier.blockTime.usec = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
702 notifier.blockTimeSet = 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
703 } else {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
704 notifier.blockTimeSet = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
705 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
706
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
707 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
708 * Set up all the event sources for new events. This will
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
709 * cause the block time to be updated if necessary.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
710 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
711
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
712 notifier.inTraversal = 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
713 for (sourcePtr = notifier.firstEventSourcePtr; sourcePtr != NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
714 sourcePtr = sourcePtr->nextPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
715 if (sourcePtr->setupProc) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
716 (sourcePtr->setupProc)(sourcePtr->clientData, flags);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
717 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
718 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
719 notifier.inTraversal = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
720
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
721 if ((flags & TCL_DONT_WAIT) || notifier.blockTimeSet) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
722 timePtr = &notifier.blockTime;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
723 } else {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
724 timePtr = NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
725 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
726
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
727 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
728 * Wait for a new event or a timeout. If Tcl_WaitForEvent
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
729 * returns -1, we should abort Tcl_DoOneEvent.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
730 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
731
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
732 result = Tcl_WaitForEvent(timePtr);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
733 if (result < 0) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
734 result = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
735 break;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
736 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
737
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
738 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
739 * Check all the event sources for new events.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
740 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
741
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
742 for (sourcePtr = notifier.firstEventSourcePtr; sourcePtr != NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
743 sourcePtr = sourcePtr->nextPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
744 if (sourcePtr->checkProc) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
745 (sourcePtr->checkProc)(sourcePtr->clientData, flags);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
746 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
747 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
748
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
749 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
750 * Check for events queued by the notifier or event sources.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
751 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
752
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
753 if (Tcl_ServiceEvent(flags)) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
754 result = 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
755 break;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
756 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
757
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
758 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
759 * We've tried everything at this point, but nobody we know
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
760 * about had anything to do. Check for idle events. If none,
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
761 * either quit or go back to the top and try again.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
762 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
763
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
764 idleEvents:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
765 if (flags & TCL_IDLE_EVENTS) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
766 if (TclServiceIdle()) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
767 result = 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
768 break;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
769 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
770 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
771 if (flags & TCL_DONT_WAIT) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
772 break;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
773 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
774 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
775
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
776 notifier.serviceMode = oldMode;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
777 return result;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
778 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
779
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
780 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
781 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
782 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
783 * Tcl_ServiceAll --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
784 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
785 * This routine checks all of the event sources, processes
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
786 * events that are on the Tcl event queue, and then calls the
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
787 * any idle handlers. Platform specific notifier callbacks that
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
788 * generate events should call this routine before returning to
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
789 * the system in order to ensure that Tcl gets a chance to
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
790 * process the new events.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
791 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
792 * Results:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
793 * Returns 1 if an event or idle handler was invoked, else 0.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
794 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
795 * Side effects:
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
796 * Anything that an event or idle handler may do.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
797 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
798 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
799 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
800
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
801 int
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
802 Tcl_ServiceAll(void)
6343
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
803 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
804 int result = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
805 EventSource *sourcePtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
806
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
807 if (!initialized) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
808 InitNotifier();
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
809 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
810
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
811 if (notifier.serviceMode == TCL_SERVICE_NONE) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
812 return result;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
813 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
814
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
815 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
816 * We need to turn off event servicing like we to in Tcl_DoOneEvent,
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
817 * to avoid recursive calls.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
818 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
819
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
820 notifier.serviceMode = TCL_SERVICE_NONE;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
821
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
822 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
823 * Check async handlers first.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
824 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
825
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
826 if (Tcl_AsyncReady()) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
827 (void) Tcl_AsyncInvoke((Tcl_Interp *) NULL, 0);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
828 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
829
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
830 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
831 * Make a single pass through all event sources, queued events,
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
832 * and idle handlers. Note that we wait to update the notifier
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
833 * timer until the end so we can avoid multiple changes.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
834 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
835
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
836 notifier.inTraversal = 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
837 notifier.blockTimeSet = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
838
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
839 for (sourcePtr = notifier.firstEventSourcePtr; sourcePtr != NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
840 sourcePtr = sourcePtr->nextPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
841 if (sourcePtr->setupProc) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
842 (sourcePtr->setupProc)(sourcePtr->clientData, TCL_ALL_EVENTS);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
843 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
844 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
845 for (sourcePtr = notifier.firstEventSourcePtr; sourcePtr != NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
846 sourcePtr = sourcePtr->nextPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
847 if (sourcePtr->checkProc) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
848 (sourcePtr->checkProc)(sourcePtr->clientData, TCL_ALL_EVENTS);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
849 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
850 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
851
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
852 while (Tcl_ServiceEvent(0)) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
853 result = 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
854 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
855 if (TclServiceIdle()) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
856 result = 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
857 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
858
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
859 if (!notifier.blockTimeSet) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
860 Tcl_SetTimer(NULL);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
861 } else {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
862 Tcl_SetTimer(&notifier.blockTime);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
863 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
864 notifier.inTraversal = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
865 notifier.serviceMode = TCL_SERVICE_ALL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
866 return result;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
867 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
868
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
869 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
870 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
871 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
872 * PyTcl_WaitUntilEvent --
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
873 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
874 * New function to wait until a Tcl event is ready without
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
875 * actually handling the event. This is different than
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
876 * TclWaitForEvent(): that function doesn't call the event
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
877 * check routines, which is necessary for our purpose.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
878 * We also can't use Tcl_DoOneEvent(TCL_DONT_WAIT), since that
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
879 * does too much: it handles the event. We want the *handling*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
880 * of the event to be done with the Python lock held, but the
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
881 * *waiting* with the lock released.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
882 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
883 * Since the event administration is not exported, our only
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
884 * choice is to use a modified copy of the file tclNotify.c,
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
885 * containing this additional function that makes the desired
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
886 * functionality available. It is mostly a stripped down version
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
887 * of the code in Tcl_DoOneEvent().
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
888 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
889 * This requires that you link with a static version of the Tcl
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
890 * library. On Windows/Mac, a custom compilation of Tcl may be
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
891 * required (I haven't tried this yet).
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
892 *
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
893 *----------------------------------------------------------------------
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
894 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
895
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
896 int
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
897 PyTcl_WaitUntilEvent(void)
6343
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
898 {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
899 int flags = TCL_ALL_EVENTS;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
900 int result = 0, oldMode;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
901 EventSource *sourcePtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
902 Tcl_Time *timePtr;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
903
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
904 if (!initialized) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
905 InitNotifier();
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
906 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
907
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
908 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
909 * The first thing we do is to service any asynchronous event
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
910 * handlers.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
911 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
912
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
913 if (Tcl_AsyncReady())
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
914 return 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
915
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
916 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
917 * Set the service mode to none so notifier event routines won't
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
918 * try to service events recursively.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
919 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
920
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
921 oldMode = notifier.serviceMode;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
922 notifier.serviceMode = TCL_SERVICE_NONE;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
923
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
924 notifier.blockTimeSet = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
925
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
926 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
927 * Set up all the event sources for new events. This will
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
928 * cause the block time to be updated if necessary.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
929 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
930
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
931 notifier.inTraversal = 1;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
932 for (sourcePtr = notifier.firstEventSourcePtr; sourcePtr != NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
933 sourcePtr = sourcePtr->nextPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
934 if (sourcePtr->setupProc) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
935 (sourcePtr->setupProc)(sourcePtr->clientData, flags);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
936 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
937 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
938 notifier.inTraversal = 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
939
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
940 timePtr = NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
941
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
942 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
943 * Wait for a new event or a timeout. If Tcl_WaitForEvent
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
944 * returns -1, we should abort Tcl_DoOneEvent.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
945 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
946
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
947 result = Tcl_WaitForEvent(timePtr);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
948 if (result < 0)
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
949 return 0;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
950
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
951 /*
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
952 * Check all the event sources for new events.
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
953 */
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
954
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
955 for (sourcePtr = notifier.firstEventSourcePtr; sourcePtr != NULL;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
956 sourcePtr = sourcePtr->nextPtr) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
957 if (sourcePtr->checkProc) {
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
958 (sourcePtr->checkProc)(sourcePtr->clientData, flags);
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
959 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
960 }
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
961
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
962 notifier.serviceMode = oldMode;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
963 return result;
689de613ea1c Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
diff changeset
964 }