Guido van Rossum | 845547d | 1996-06-26 18:26:04 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright (C) 1994 Steen Lumholt. |
| 3 | Copyright 1994-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 4 | The Netherlands. |
| 5 | |
| 6 | All Rights Reserved |
| 7 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 8 | Permission to use, copy, modify, and distribute this software and its |
| 9 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | 845547d | 1996-06-26 18:26:04 +0000 | [diff] [blame] | 10 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 11 | both that copyright notice and this permission notice appear in |
Guido van Rossum | 845547d | 1996-06-26 18:26:04 +0000 | [diff] [blame] | 12 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 13 | Centrum or CWI or Corporation for National Research Initiatives or |
| 14 | CNRI not be used in advertising or publicity pertaining to |
| 15 | distribution of the software without specific, written prior |
| 16 | permission. |
Guido van Rossum | 845547d | 1996-06-26 18:26:04 +0000 | [diff] [blame] | 17 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 18 | While CWI is the initial source for this software, a modified version |
| 19 | is made available by the Corporation for National Research Initiatives |
| 20 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 21 | |
| 22 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 23 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 24 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 25 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 26 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 27 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 28 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 29 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | 845547d | 1996-06-26 18:26:04 +0000 | [diff] [blame] | 30 | |
| 31 | ******************************************************************/ |
| 32 | |
| 33 | /* _tkinter.c -- Interface to libtk.a and libtcl.a. */ |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 34 | |
Guido van Rossum | 7ffa761 | 1996-08-13 21:10:16 +0000 | [diff] [blame] | 35 | /* TCL/TK VERSION INFO: |
| 36 | |
| 37 | Unix: |
Guido van Rossum | 496f8f6 | 1997-07-19 19:57:42 +0000 | [diff] [blame] | 38 | Tcl/Tk 8.0 (even alpha or beta) or 7.6/4.2 are recommended. |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 39 | Versions 7.5/4.1 are the earliest versions still supported. |
| 40 | Versions 7.4/4.0 or Tk 3.x are no longer supported. |
Guido van Rossum | 7ffa761 | 1996-08-13 21:10:16 +0000 | [diff] [blame] | 41 | |
| 42 | Mac and Windows: |
Guido van Rossum | 496f8f6 | 1997-07-19 19:57:42 +0000 | [diff] [blame] | 43 | Use Tcl 8.0 if available (even alpha or beta). |
| 44 | The oldest usable version is 4.1p1/7.5p1. |
| 45 | |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 46 | XXX Further speed-up ideas, involving Tcl 8.0 features: |
| 47 | |
| 48 | - In Tcl_Call(), create Tcl objects from the arguments, possibly using |
| 49 | intelligent mappings between Python objects and Tcl objects (e.g. ints, |
| 50 | floats and Tcl window pointers could be handled specially). |
| 51 | |
| 52 | - Register a new Tcl type, "Python callable", which can be called more |
| 53 | efficiently and passed to Tcl_EvalObj() directly (if this is possible). |
| 54 | |
Guido van Rossum | 7ffa761 | 1996-08-13 21:10:16 +0000 | [diff] [blame] | 55 | */ |
| 56 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 57 | |
Guido van Rossum | 9722ad8 | 1995-09-22 23:49:28 +0000 | [diff] [blame] | 58 | #include "Python.h" |
Guido van Rossum | 97867b2 | 1996-08-08 19:09:53 +0000 | [diff] [blame] | 59 | #include <ctype.h> |
Guido van Rossum | 9722ad8 | 1995-09-22 23:49:28 +0000 | [diff] [blame] | 60 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 61 | #ifdef WITH_THREAD |
Guido van Rossum | 49b5606 | 1998-10-01 20:42:43 +0000 | [diff] [blame] | 62 | #include "pythread.h" |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 63 | #endif |
| 64 | |
Guido van Rossum | 2a5119b | 1998-05-29 01:28:40 +0000 | [diff] [blame] | 65 | #ifdef MS_WINDOWS |
| 66 | #include <windows.h> |
| 67 | #endif |
| 68 | |
Guido van Rossum | bf0dc9f | 1996-08-20 20:49:56 +0000 | [diff] [blame] | 69 | #ifdef macintosh |
| 70 | #define MAC_TCL |
Guido van Rossum | 290283b | 1997-06-02 22:16:43 +0000 | [diff] [blame] | 71 | #include "myselect.h" |
Guido van Rossum | bf0dc9f | 1996-08-20 20:49:56 +0000 | [diff] [blame] | 72 | #endif |
| 73 | |
Guido van Rossum | 49b5606 | 1998-10-01 20:42:43 +0000 | [diff] [blame] | 74 | #ifdef PYOS_OS2 |
| 75 | #include "myselect.h" |
| 76 | #endif |
| 77 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 78 | #include <tcl.h> |
| 79 | #include <tk.h> |
| 80 | |
Guido van Rossum | 3e819a7 | 1997-08-01 19:29:02 +0000 | [diff] [blame] | 81 | #define TKMAJORMINOR (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) |
| 82 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 83 | #if TKMAJORMINOR < 4001 |
| 84 | #error "Tk 4.0 or 3.x are not supported -- use 4.1 or higher" |
| 85 | #endif |
| 86 | |
Guido van Rossum | 0d2390c | 1997-08-14 19:57:07 +0000 | [diff] [blame] | 87 | #if TKMAJORMINOR >= 8000 && defined(macintosh) |
| 88 | /* Sigh, we have to include this to get at the tcl qd pointer */ |
| 89 | #include <tkMac.h> |
Guido van Rossum | 2ea1c94 | 1998-04-28 16:12:43 +0000 | [diff] [blame] | 90 | /* And this one we need to clear the menu bar */ |
| 91 | #include <Menus.h> |
Guido van Rossum | 0d2390c | 1997-08-14 19:57:07 +0000 | [diff] [blame] | 92 | #endif |
| 93 | |
Guido van Rossum | b010544 | 1997-10-08 15:25:37 +0000 | [diff] [blame] | 94 | #if TKMAJORMINOR < 8000 || !defined(MS_WINDOWS) |
Guido van Rossum | 0d2390c | 1997-08-14 19:57:07 +0000 | [diff] [blame] | 95 | #define HAVE_CREATEFILEHANDLER |
| 96 | #endif |
| 97 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 98 | #ifdef HAVE_CREATEFILEHANDLER |
| 99 | |
| 100 | /* Tcl_CreateFileHandler() changed several times; these macros deal with the |
| 101 | messiness. In Tcl 8.0 and later, it is not available on Windows (and on |
| 102 | Unix, only because Jack added it back); when available on Windows, it only |
| 103 | applies to sockets. */ |
| 104 | |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 105 | #ifdef MS_WINDOWS |
| 106 | #define FHANDLETYPE TCL_WIN_SOCKET |
| 107 | #else |
| 108 | #define FHANDLETYPE TCL_UNIX_FD |
| 109 | #endif |
| 110 | |
| 111 | #if TKMAJORMINOR < 8000 |
| 112 | #define FHANDLE Tcl_File |
| 113 | #define MAKEFHANDLE(fd) Tcl_GetFile((ClientData)(fd), FHANDLETYPE) |
| 114 | #else |
| 115 | #define FHANDLE int |
| 116 | #define MAKEFHANDLE(fd) (fd) |
| 117 | #endif |
| 118 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 119 | /* If Tcl can wait for a Unix file descriptor, define the EventHook() routine |
| 120 | which uses this to handle Tcl events while the user is typing commands. */ |
| 121 | |
| 122 | #if FHANDLETYPE == TCL_UNIX_FD |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 123 | #define WAIT_FOR_STDIN |
| 124 | #endif |
| 125 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 126 | #endif /* HAVE_CREATEFILEHANDLER */ |
| 127 | |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 128 | #ifdef MS_WINDOWS |
| 129 | #include <conio.h> |
| 130 | #define WAIT_FOR_STDIN |
| 131 | #endif |
| 132 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 133 | #ifdef WITH_THREAD |
| 134 | |
| 135 | /* The threading situation is complicated. Tcl is not thread-safe, except for |
| 136 | Tcl 8.1, which will probably remain in alpha status for another 6 months |
| 137 | (and the README says that Tk will probably remain thread-unsafe forever). |
| 138 | So we need to use a lock around all uses of Tcl. Previously, the Python |
| 139 | interpreter lock was used for this. However, this causes problems when |
| 140 | other Python threads need to run while Tcl is blocked waiting for events. |
| 141 | |
| 142 | To solve this problem, a separate lock for Tcl is introduced. Holding it |
| 143 | is incompatible with holding Python's interpreter lock. The following four |
| 144 | macros manipulate both locks together. |
| 145 | |
| 146 | ENTER_TCL and LEAVE_TCL are brackets, just like Py_BEGIN_ALLOW_THREADS and |
| 147 | Py_END_ALLOW_THREADS. They should be used whenever a call into Tcl is made |
| 148 | that could call an event handler, or otherwise affect the state of a Tcl |
| 149 | interpreter. These assume that the surrounding code has the Python |
| 150 | interpreter lock; inside the brackets, the Python interpreter lock has been |
| 151 | released and the lock for Tcl has been acquired. |
| 152 | |
Guido van Rossum | 5e97783 | 1998-06-15 14:03:52 +0000 | [diff] [blame] | 153 | Sometimes, it is necessary to have both the Python lock and the Tcl lock. |
| 154 | (For example, when transferring data from the Tcl interpreter result to a |
| 155 | Python string object.) This can be done by using different macros to close |
| 156 | the ENTER_TCL block: ENTER_OVERLAP reacquires the Python lock (and restores |
| 157 | the thread state) but doesn't release the Tcl lock; LEAVE_OVERLAP_TCL |
| 158 | releases the Tcl lock. |
| 159 | |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 160 | By contrast, ENTER_PYTHON and LEAVE_PYTHON are used in Tcl event |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 161 | handlers when the handler needs to use Python. Such event handlers are |
| 162 | entered while the lock for Tcl is held; the event handler presumably needs |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 163 | to use Python. ENTER_PYTHON releases the lock for Tcl and acquires |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 164 | the Python interpreter lock, restoring the appropriate thread state, and |
| 165 | LEAVE_PYTHON releases the Python interpreter lock and re-acquires the lock |
| 166 | for Tcl. It is okay for ENTER_TCL/LEAVE_TCL pairs to be contained inside |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 167 | the code between ENTER_PYTHON and LEAVE_PYTHON. |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 168 | |
| 169 | These locks expand to several statements and brackets; they should not be |
| 170 | used in branches of if statements and the like. |
| 171 | |
| 172 | */ |
| 173 | |
| 174 | static type_lock tcl_lock = 0; |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 175 | static PyThreadState *tcl_tstate = NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 176 | |
| 177 | #define ENTER_TCL \ |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 178 | { PyThreadState *tstate = PyThreadState_Get(); Py_BEGIN_ALLOW_THREADS \ |
| 179 | acquire_lock(tcl_lock, 1); tcl_tstate = tstate; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 180 | |
| 181 | #define LEAVE_TCL \ |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 182 | tcl_tstate = NULL; release_lock(tcl_lock); Py_END_ALLOW_THREADS} |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 183 | |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 184 | #define ENTER_OVERLAP \ |
| 185 | Py_END_ALLOW_THREADS |
| 186 | |
| 187 | #define LEAVE_OVERLAP_TCL \ |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 188 | tcl_tstate = NULL; release_lock(tcl_lock); } |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 189 | |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 190 | #define ENTER_PYTHON \ |
| 191 | { PyThreadState *tstate = tcl_tstate; tcl_tstate = NULL; \ |
| 192 | release_lock(tcl_lock); PyEval_RestoreThread((tstate)); } |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 193 | |
| 194 | #define LEAVE_PYTHON \ |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 195 | { PyThreadState *tstate = PyEval_SaveThread(); \ |
| 196 | acquire_lock(tcl_lock, 1); tcl_tstate = tstate; } |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 197 | |
| 198 | #else |
| 199 | |
| 200 | #define ENTER_TCL |
| 201 | #define LEAVE_TCL |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 202 | #define ENTER_OVERLAP |
| 203 | #define LEAVE_OVERLAP_TCL |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 204 | #define ENTER_PYTHON |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 205 | #define LEAVE_PYTHON |
| 206 | |
| 207 | #endif |
| 208 | |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 209 | #ifdef macintosh |
| 210 | |
| 211 | /* |
| 212 | ** Additional cruft needed by Tcl/Tk on the Mac. |
Guido van Rossum | 97867b2 | 1996-08-08 19:09:53 +0000 | [diff] [blame] | 213 | ** This is for Tcl 7.5 and Tk 4.1 (patch release 1). |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 214 | */ |
| 215 | |
Guido van Rossum | 7ffa761 | 1996-08-13 21:10:16 +0000 | [diff] [blame] | 216 | /* ckfree() expects a char* */ |
Guido van Rossum | 97867b2 | 1996-08-08 19:09:53 +0000 | [diff] [blame] | 217 | #define FREECAST (char *) |
| 218 | |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 219 | #include <Events.h> /* For EventRecord */ |
| 220 | |
| 221 | typedef int (*TclMacConvertEventPtr) Py_PROTO((EventRecord *eventPtr)); |
Guido van Rossum | 0d2390c | 1997-08-14 19:57:07 +0000 | [diff] [blame] | 222 | /* They changed the name... */ |
| 223 | #if TKMAJORMINOR < 8000 |
| 224 | #define Tcl_MacSetEventProc TclMacSetEventProc |
| 225 | #endif |
| 226 | void Tcl_MacSetEventProc Py_PROTO((TclMacConvertEventPtr procPtr)); |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 227 | int TkMacConvertEvent Py_PROTO((EventRecord *eventPtr)); |
| 228 | |
| 229 | staticforward int PyMacConvertEvent Py_PROTO((EventRecord *eventPtr)); |
| 230 | |
Guido van Rossum | 2ea1c94 | 1998-04-28 16:12:43 +0000 | [diff] [blame] | 231 | #if defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__) |
| 232 | #pragma import on |
| 233 | #endif |
| 234 | |
| 235 | #include <SIOUX.h> |
| 236 | extern int SIOUXIsAppWindow(WindowPtr); |
| 237 | |
| 238 | #if defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__) |
| 239 | #pragma import reset |
| 240 | #endif |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 241 | #endif /* macintosh */ |
| 242 | |
Guido van Rossum | 97867b2 | 1996-08-08 19:09:53 +0000 | [diff] [blame] | 243 | #ifndef FREECAST |
Guido van Rossum | 7ffa761 | 1996-08-13 21:10:16 +0000 | [diff] [blame] | 244 | #define FREECAST (char *) |
Guido van Rossum | 97867b2 | 1996-08-08 19:09:53 +0000 | [diff] [blame] | 245 | #endif |
| 246 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 247 | /**** Tkapp Object Declaration ****/ |
| 248 | |
| 249 | staticforward PyTypeObject Tkapp_Type; |
| 250 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 251 | typedef struct { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 252 | PyObject_HEAD |
| 253 | Tcl_Interp *interp; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 254 | } TkappObject; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 255 | |
| 256 | #define Tkapp_Check(v) ((v)->ob_type == &Tkapp_Type) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 257 | #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) |
| 258 | #define Tkapp_Result(v) (((TkappObject *) (v))->interp->result) |
| 259 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 260 | #define DEBUG_REFCNT(v) (printf("DEBUG: id=%p, refcnt=%i\n", \ |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 261 | (void *) v, ((PyObject *) v)->ob_refcnt)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 262 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 263 | |
| 264 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 265 | /**** Error Handling ****/ |
| 266 | |
| 267 | static PyObject *Tkinter_TclError; |
Guido van Rossum | d308e2b | 1994-07-07 09:25:12 +0000 | [diff] [blame] | 268 | static int quitMainLoop = 0; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 269 | static int errorInCmd = 0; |
| 270 | static PyObject *excInCmd; |
| 271 | static PyObject *valInCmd; |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 272 | static PyObject *trbInCmd; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 273 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 274 | |
| 275 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 276 | static PyObject * |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 277 | Tkinter_Error(v) |
| 278 | PyObject *v; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 279 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 280 | PyErr_SetString(Tkinter_TclError, Tkapp_Result(v)); |
| 281 | return NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 284 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 285 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 286 | /**** Utils ****/ |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 287 | |
| 288 | #ifdef WITH_THREAD |
Guido van Rossum | 2a5119b | 1998-05-29 01:28:40 +0000 | [diff] [blame] | 289 | #ifndef MS_WINDOWS |
Guido van Rossum | 541f241 | 1998-08-13 13:29:22 +0000 | [diff] [blame] | 290 | #include "mytime.h" |
| 291 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 292 | /* Millisecond sleep() for Unix platforms. */ |
| 293 | |
| 294 | static void |
| 295 | Sleep(milli) |
| 296 | int milli; |
| 297 | { |
| 298 | /* XXX Too bad if you don't have select(). */ |
| 299 | struct timeval t; |
| 300 | double frac; |
| 301 | t.tv_sec = milli/1000; |
| 302 | t.tv_usec = (milli%1000) * 1000; |
| 303 | select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t); |
| 304 | } |
Guido van Rossum | 2a5119b | 1998-05-29 01:28:40 +0000 | [diff] [blame] | 305 | #endif /* MS_WINDOWS */ |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 306 | #endif /* WITH_THREAD */ |
| 307 | |
| 308 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 309 | static char * |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 310 | AsString(value, tmp) |
| 311 | PyObject *value; |
| 312 | PyObject *tmp; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 313 | { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 314 | if (PyString_Check(value)) |
| 315 | return PyString_AsString(value); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 316 | else { |
| 317 | PyObject *v = PyObject_Str(value); |
| 318 | PyList_Append(tmp, v); |
| 319 | Py_DECREF(v); |
| 320 | return PyString_AsString(v); |
| 321 | } |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 324 | |
| 325 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 326 | #define ARGSZ 64 |
| 327 | |
| 328 | static char * |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 329 | Merge(args) |
| 330 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 331 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 332 | PyObject *tmp = NULL; |
| 333 | char *argvStore[ARGSZ]; |
| 334 | char **argv = NULL; |
| 335 | int fvStore[ARGSZ]; |
| 336 | int *fv = NULL; |
| 337 | int argc = 0, i; |
| 338 | char *res = NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 339 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 340 | if (!(tmp = PyList_New(0))) |
| 341 | return NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 342 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 343 | argv = argvStore; |
| 344 | fv = fvStore; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 345 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 346 | if (args == NULL) |
| 347 | argc = 0; |
| 348 | |
| 349 | else if (!PyTuple_Check(args)) { |
| 350 | argc = 1; |
| 351 | fv[0] = 0; |
| 352 | argv[0] = AsString(args, tmp); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 353 | } |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 354 | else { |
| 355 | argc = PyTuple_Size(args); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 356 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 357 | if (argc > ARGSZ) { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 358 | argv = (char **)ckalloc(argc * sizeof(char *)); |
| 359 | fv = (int *)ckalloc(argc * sizeof(int)); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 360 | if (argv == NULL || fv == NULL) { |
| 361 | PyErr_NoMemory(); |
| 362 | goto finally; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | for (i = 0; i < argc; i++) { |
| 367 | PyObject *v = PyTuple_GetItem(args, i); |
| 368 | if (PyTuple_Check(v)) { |
| 369 | fv[i] = 1; |
| 370 | if (!(argv[i] = Merge(v))) |
| 371 | goto finally; |
| 372 | } |
| 373 | else if (v == Py_None) { |
| 374 | argc = i; |
| 375 | break; |
| 376 | } |
| 377 | else { |
| 378 | fv[i] = 0; |
| 379 | argv[i] = AsString(v, tmp); |
| 380 | } |
| 381 | } |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 382 | } |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 383 | res = Tcl_Merge(argc, argv); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 384 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 385 | finally: |
| 386 | for (i = 0; i < argc; i++) |
| 387 | if (fv[i]) { |
| 388 | ckfree(argv[i]); |
| 389 | } |
| 390 | if (argv != argvStore) |
| 391 | ckfree(FREECAST argv); |
| 392 | if (fv != fvStore) |
| 393 | ckfree(FREECAST fv); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 394 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 395 | Py_DECREF(tmp); |
| 396 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 399 | |
| 400 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 401 | static PyObject * |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 402 | Split(list) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 403 | char *list; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 404 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 405 | int argc; |
| 406 | char **argv; |
| 407 | PyObject *v; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 408 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 409 | if (list == NULL) { |
| 410 | Py_INCREF(Py_None); |
| 411 | return Py_None; |
| 412 | } |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 413 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 414 | if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 415 | /* Not a list. |
| 416 | * Could be a quoted string containing funnies, e.g. {"}. |
| 417 | * Return the string itself. |
| 418 | */ |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 419 | return PyString_FromString(list); |
| 420 | } |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 421 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 422 | if (argc == 0) |
| 423 | v = PyString_FromString(""); |
| 424 | else if (argc == 1) |
| 425 | v = PyString_FromString(argv[0]); |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 426 | else if ((v = PyTuple_New(argc)) != NULL) { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 427 | int i; |
| 428 | PyObject *w; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 429 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 430 | for (i = 0; i < argc; i++) { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 431 | if ((w = Split(argv[i])) == NULL) { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 432 | Py_DECREF(v); |
| 433 | v = NULL; |
| 434 | break; |
| 435 | } |
| 436 | PyTuple_SetItem(v, i, w); |
| 437 | } |
| 438 | } |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 439 | Tcl_Free(FREECAST argv); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 440 | return v; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 443 | |
| 444 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 445 | /**** Tkapp Object ****/ |
| 446 | |
| 447 | #ifndef WITH_APPINIT |
| 448 | int |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 449 | Tcl_AppInit(interp) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 450 | Tcl_Interp *interp; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 451 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 452 | Tk_Window main; |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 453 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 454 | main = Tk_MainWindow(interp); |
| 455 | if (Tcl_Init(interp) == TCL_ERROR) { |
Guido van Rossum | b41addf | 1998-05-12 15:02:41 +0000 | [diff] [blame] | 456 | PySys_WriteStderr("Tcl_Init error: %s\n", interp->result); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 457 | return TCL_ERROR; |
| 458 | } |
| 459 | if (Tk_Init(interp) == TCL_ERROR) { |
Guido van Rossum | b41addf | 1998-05-12 15:02:41 +0000 | [diff] [blame] | 460 | PySys_WriteStderr("Tk_Init error: %s\n", interp->result); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 461 | return TCL_ERROR; |
| 462 | } |
| 463 | return TCL_OK; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 464 | } |
| 465 | #endif /* !WITH_APPINIT */ |
| 466 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 467 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 468 | |
| 469 | |
| 470 | /* Initialize the Tk application; see the `main' function in |
| 471 | * `tkMain.c'. |
| 472 | */ |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 473 | |
| 474 | static void EnableEventHook(); /* Forward */ |
| 475 | static void DisableEventHook(); /* Forward */ |
| 476 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 477 | static TkappObject * |
| 478 | Tkapp_New(screenName, baseName, className, interactive) |
| 479 | char *screenName; |
| 480 | char *baseName; |
| 481 | char *className; |
| 482 | int interactive; |
| 483 | { |
| 484 | TkappObject *v; |
| 485 | char *argv0; |
| 486 | |
| 487 | v = PyObject_NEW(TkappObject, &Tkapp_Type); |
| 488 | if (v == NULL) |
| 489 | return NULL; |
| 490 | |
| 491 | v->interp = Tcl_CreateInterp(); |
Guido van Rossum | dfd428d | 1996-02-25 04:46:40 +0000 | [diff] [blame] | 492 | |
Guido van Rossum | 2ea1c94 | 1998-04-28 16:12:43 +0000 | [diff] [blame] | 493 | #if defined(macintosh) && TKMAJORMINOR >= 8000 |
| 494 | /* This seems to be needed since Tk 8.0 */ |
| 495 | ClearMenuBar(); |
| 496 | TkMacInitMenus(v->interp); |
| 497 | #endif |
Guido van Rossum | 1c0d315 | 1998-02-19 21:28:49 +0000 | [diff] [blame] | 498 | /* Delete the 'exit' command, which can screw things up */ |
| 499 | Tcl_DeleteCommand(v->interp, "exit"); |
| 500 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 501 | if (screenName != NULL) |
| 502 | Tcl_SetVar2(v->interp, "env", "DISPLAY", |
| 503 | screenName, TCL_GLOBAL_ONLY); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 504 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 505 | if (interactive) |
| 506 | Tcl_SetVar(v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); |
| 507 | else |
| 508 | Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 509 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 510 | /* This is used to get the application class for Tk 4.1 and up */ |
| 511 | argv0 = (char*)ckalloc(strlen(className) + 1); |
| 512 | if (!argv0) { |
| 513 | PyErr_NoMemory(); |
| 514 | Py_DECREF(v); |
| 515 | return NULL; |
| 516 | } |
Guido van Rossum | 97867b2 | 1996-08-08 19:09:53 +0000 | [diff] [blame] | 517 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 518 | strcpy(argv0, className); |
Guido van Rossum | 730806d | 1998-04-10 22:27:42 +0000 | [diff] [blame] | 519 | if (isupper((int)(argv0[0]))) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 520 | argv0[0] = tolower(argv0[0]); |
| 521 | Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY); |
| 522 | ckfree(argv0); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 523 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 524 | if (Tcl_AppInit(v->interp) != TCL_OK) |
Guido van Rossum | c821d1e | 1998-07-07 22:25:47 +0000 | [diff] [blame] | 525 | return (TkappObject *)Tkinter_Error((PyObject *)v); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 526 | |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 527 | EnableEventHook(); |
| 528 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 529 | return v; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 532 | |
| 533 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 534 | /** Tcl Eval **/ |
| 535 | |
| 536 | static PyObject * |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 537 | Tkapp_Call(self, args) |
| 538 | PyObject *self; |
| 539 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 540 | { |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 541 | /* This is copied from Merge() */ |
| 542 | PyObject *tmp = NULL; |
| 543 | char *argvStore[ARGSZ]; |
| 544 | char **argv = NULL; |
| 545 | int fvStore[ARGSZ]; |
| 546 | int *fv = NULL; |
| 547 | int argc = 0, i; |
| 548 | PyObject *res = NULL; /* except this has a different type */ |
| 549 | Tcl_CmdInfo info; /* and this is added */ |
| 550 | Tcl_Interp *interp = Tkapp_Interp(self); /* and this too */ |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 551 | |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 552 | if (!(tmp = PyList_New(0))) |
| 553 | return NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 554 | |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 555 | argv = argvStore; |
| 556 | fv = fvStore; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 557 | |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 558 | if (args == NULL) |
| 559 | argc = 0; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 560 | |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 561 | else if (!PyTuple_Check(args)) { |
| 562 | argc = 1; |
| 563 | fv[0] = 0; |
| 564 | argv[0] = AsString(args, tmp); |
| 565 | } |
| 566 | else { |
| 567 | argc = PyTuple_Size(args); |
| 568 | |
| 569 | if (argc > ARGSZ) { |
| 570 | argv = (char **)ckalloc(argc * sizeof(char *)); |
| 571 | fv = (int *)ckalloc(argc * sizeof(int)); |
| 572 | if (argv == NULL || fv == NULL) { |
| 573 | PyErr_NoMemory(); |
| 574 | goto finally; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | for (i = 0; i < argc; i++) { |
| 579 | PyObject *v = PyTuple_GetItem(args, i); |
| 580 | if (PyTuple_Check(v)) { |
| 581 | fv[i] = 1; |
| 582 | if (!(argv[i] = Merge(v))) |
| 583 | goto finally; |
| 584 | } |
| 585 | else if (v == Py_None) { |
| 586 | argc = i; |
| 587 | break; |
| 588 | } |
| 589 | else { |
| 590 | fv[i] = 0; |
| 591 | argv[i] = AsString(v, tmp); |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | /* End code copied from Merge() */ |
| 596 | |
| 597 | /* All this to avoid a call to Tcl_Merge() and the corresponding call |
| 598 | to Tcl_SplitList() inside Tcl_Eval()... It can save a bundle! */ |
| 599 | if (Py_VerboseFlag >= 2) { |
| 600 | for (i = 0; i < argc; i++) |
Guido van Rossum | b41addf | 1998-05-12 15:02:41 +0000 | [diff] [blame] | 601 | PySys_WriteStderr("%s ", argv[i]); |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 602 | } |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 603 | ENTER_TCL |
| 604 | info.proc = NULL; |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 605 | if (argc < 1 || |
| 606 | !Tcl_GetCommandInfo(interp, argv[0], &info) || |
| 607 | info.proc == NULL) |
| 608 | { |
| 609 | char *cmd; |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 610 | cmd = Tcl_Merge(argc, argv); |
| 611 | i = Tcl_Eval(interp, cmd); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 612 | ckfree(cmd); |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 613 | } |
| 614 | else { |
| 615 | Tcl_ResetResult(interp); |
| 616 | i = (*info.proc)(info.clientData, interp, argc, argv); |
| 617 | } |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 618 | ENTER_OVERLAP |
| 619 | if (info.proc == NULL && Py_VerboseFlag >= 2) |
| 620 | PySys_WriteStderr("... use TclEval "); |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 621 | if (i == TCL_ERROR) { |
| 622 | if (Py_VerboseFlag >= 2) |
Guido van Rossum | b41addf | 1998-05-12 15:02:41 +0000 | [diff] [blame] | 623 | PySys_WriteStderr("... error: '%s'\n", |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 624 | interp->result); |
| 625 | Tkinter_Error(self); |
| 626 | } |
| 627 | else { |
| 628 | if (Py_VerboseFlag >= 2) |
Guido van Rossum | b41addf | 1998-05-12 15:02:41 +0000 | [diff] [blame] | 629 | PySys_WriteStderr("-> '%s'\n", interp->result); |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 630 | res = PyString_FromString(interp->result); |
| 631 | } |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 632 | LEAVE_OVERLAP_TCL |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 633 | |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 634 | /* Copied from Merge() again */ |
| 635 | finally: |
| 636 | for (i = 0; i < argc; i++) |
| 637 | if (fv[i]) { |
| 638 | ckfree(argv[i]); |
| 639 | } |
| 640 | if (argv != argvStore) |
| 641 | ckfree(FREECAST argv); |
| 642 | if (fv != fvStore) |
| 643 | ckfree(FREECAST fv); |
| 644 | |
| 645 | Py_DECREF(tmp); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 646 | return res; |
| 647 | } |
| 648 | |
| 649 | |
| 650 | static PyObject * |
| 651 | Tkapp_GlobalCall(self, args) |
| 652 | PyObject *self; |
| 653 | PyObject *args; |
| 654 | { |
Guido van Rossum | 212643f | 1998-04-29 16:22:14 +0000 | [diff] [blame] | 655 | /* Could do the same here as for Tkapp_Call(), but this is not used |
| 656 | much, so I can't be bothered. Unfortunately Tcl doesn't export a |
| 657 | way for the user to do what all its Global* variants do (save and |
| 658 | reset the scope pointer, call the local version, restore the saved |
| 659 | scope pointer). */ |
| 660 | |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 661 | char *cmd; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 662 | PyObject *res = NULL; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 663 | |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 664 | cmd = Merge(args); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 665 | if (!cmd) |
| 666 | PyErr_SetString(Tkinter_TclError, "merge failed"); |
| 667 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 668 | else { |
| 669 | int err; |
| 670 | ENTER_TCL |
| 671 | err = Tcl_GlobalEval(Tkapp_Interp(self), cmd); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 672 | ENTER_OVERLAP |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 673 | if (err == TCL_ERROR) |
| 674 | res = Tkinter_Error(self); |
| 675 | else |
| 676 | res = PyString_FromString(Tkapp_Result(self)); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 677 | LEAVE_OVERLAP_TCL |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 678 | } |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 679 | |
| 680 | if (cmd) |
| 681 | ckfree(cmd); |
| 682 | |
| 683 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | static PyObject * |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 687 | Tkapp_Eval(self, args) |
| 688 | PyObject *self; |
| 689 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 690 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 691 | char *script; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 692 | PyObject *res = NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 693 | int err; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 694 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 695 | if (!PyArg_ParseTuple(args, "s", &script)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 696 | return NULL; |
| 697 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 698 | ENTER_TCL |
| 699 | err = Tcl_Eval(Tkapp_Interp(self), script); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 700 | ENTER_OVERLAP |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 701 | if (err == TCL_ERROR) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 702 | res = Tkinter_Error(self); |
| 703 | else |
| 704 | res = PyString_FromString(Tkapp_Result(self)); |
| 705 | LEAVE_OVERLAP_TCL |
| 706 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | static PyObject * |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 710 | Tkapp_GlobalEval(self, args) |
| 711 | PyObject *self; |
| 712 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 713 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 714 | char *script; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 715 | PyObject *res = NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 716 | int err; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 717 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 718 | if (!PyArg_ParseTuple(args, "s", &script)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 719 | return NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 720 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 721 | ENTER_TCL |
| 722 | err = Tcl_GlobalEval(Tkapp_Interp(self), script); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 723 | ENTER_OVERLAP |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 724 | if (err == TCL_ERROR) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 725 | res = Tkinter_Error(self); |
| 726 | else |
| 727 | res = PyString_FromString(Tkapp_Result(self)); |
| 728 | LEAVE_OVERLAP_TCL |
| 729 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 733 | Tkapp_EvalFile(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 734 | PyObject *self; |
| 735 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 736 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 737 | char *fileName; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 738 | PyObject *res = NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 739 | int err; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 740 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 741 | if (!PyArg_ParseTuple(args, "s", &fileName)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 742 | return NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 743 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 744 | ENTER_TCL |
| 745 | err = Tcl_EvalFile(Tkapp_Interp(self), fileName); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 746 | ENTER_OVERLAP |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 747 | if (err == TCL_ERROR) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 748 | res = Tkinter_Error(self); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 749 | |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 750 | else |
| 751 | res = PyString_FromString(Tkapp_Result(self)); |
| 752 | LEAVE_OVERLAP_TCL |
| 753 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | static PyObject * |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 757 | Tkapp_Record(self, args) |
| 758 | PyObject *self; |
| 759 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 760 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 761 | char *script; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 762 | PyObject *res = NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 763 | int err; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 764 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 765 | if (!PyArg_ParseTuple(args, "s", &script)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 766 | return NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 767 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 768 | ENTER_TCL |
| 769 | err = Tcl_RecordAndEval(Tkapp_Interp(self), script, TCL_NO_EVAL); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 770 | ENTER_OVERLAP |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 771 | if (err == TCL_ERROR) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 772 | res = Tkinter_Error(self); |
| 773 | else |
| 774 | res = PyString_FromString(Tkapp_Result(self)); |
| 775 | LEAVE_OVERLAP_TCL |
| 776 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | static PyObject * |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 780 | Tkapp_AddErrorInfo(self, args) |
| 781 | PyObject *self; |
| 782 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 783 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 784 | char *msg; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 785 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 786 | if (!PyArg_ParseTuple(args, "s", &msg)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 787 | return NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 788 | ENTER_TCL |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 789 | Tcl_AddErrorInfo(Tkapp_Interp(self), msg); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 790 | LEAVE_TCL |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 791 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 792 | Py_INCREF(Py_None); |
| 793 | return Py_None; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 794 | } |
| 795 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 796 | |
| 797 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 798 | /** Tcl Variable **/ |
| 799 | |
| 800 | static PyObject * |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 801 | SetVar(self, args, flags) |
| 802 | PyObject *self; |
| 803 | PyObject *args; |
| 804 | int flags; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 805 | { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 806 | char *name1, *name2, *ok, *s; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 807 | PyObject *newValue; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 808 | PyObject *tmp; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 809 | |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 810 | tmp = PyList_New(0); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 811 | if (!tmp) |
| 812 | return NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 813 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 814 | if (PyArg_ParseTuple(args, "sO", &name1, &newValue)) { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 815 | /* XXX Merge? */ |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 816 | s = AsString(newValue, tmp); |
| 817 | ENTER_TCL |
| 818 | ok = Tcl_SetVar(Tkapp_Interp(self), name1, s, flags); |
| 819 | LEAVE_TCL |
| 820 | } |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 821 | else { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 822 | PyErr_Clear(); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 823 | if (PyArg_ParseTuple(args, "ssO", &name1, &name2, &newValue)) { |
| 824 | s = AsString (newValue, tmp); |
| 825 | ENTER_TCL |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 826 | ok = Tcl_SetVar2(Tkapp_Interp(self), name1, name2, |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 827 | s, flags); |
| 828 | LEAVE_TCL |
| 829 | } |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 830 | else { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 831 | Py_DECREF(tmp); |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 832 | return NULL; |
| 833 | } |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 834 | } |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 835 | Py_DECREF(tmp); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 836 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 837 | if (!ok) |
| 838 | return Tkinter_Error(self); |
| 839 | |
| 840 | Py_INCREF(Py_None); |
| 841 | return Py_None; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 845 | Tkapp_SetVar(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 846 | PyObject *self; |
| 847 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 848 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 849 | return SetVar(self, args, TCL_LEAVE_ERR_MSG); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 853 | Tkapp_GlobalSetVar(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 854 | PyObject *self; |
| 855 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 856 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 857 | return SetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 858 | } |
| 859 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 860 | |
| 861 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 862 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 863 | GetVar(self, args, flags) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 864 | PyObject *self; |
| 865 | PyObject *args; |
| 866 | int flags; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 867 | { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 868 | char *name1, *name2=NULL, *s; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 869 | PyObject *res = NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 870 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 871 | if (!PyArg_ParseTuple(args, "s|s", &name1, &name2)) |
| 872 | return NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 873 | ENTER_TCL |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 874 | if (name2 == NULL) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 875 | s = Tcl_GetVar(Tkapp_Interp(self), name1, flags); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 876 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 877 | else |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 878 | s = Tcl_GetVar2(Tkapp_Interp(self), name1, name2, flags); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 879 | ENTER_OVERLAP |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 880 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 881 | if (s == NULL) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 882 | res = Tkinter_Error(self); |
| 883 | else |
| 884 | res = PyString_FromString(s); |
| 885 | LEAVE_OVERLAP_TCL |
| 886 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 890 | Tkapp_GetVar(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 891 | PyObject *self; |
| 892 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 893 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 894 | return GetVar(self, args, TCL_LEAVE_ERR_MSG); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 898 | Tkapp_GlobalGetVar(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 899 | PyObject *self; |
| 900 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 901 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 902 | return GetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 905 | |
| 906 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 907 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 908 | UnsetVar(self, args, flags) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 909 | PyObject *self; |
| 910 | PyObject *args; |
| 911 | int flags; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 912 | { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 913 | char *name1, *name2=NULL; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 914 | PyObject *res = NULL; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 915 | int code; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 916 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 917 | if (!PyArg_ParseTuple(args, "s|s", &name1, &name2)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 918 | return NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 919 | ENTER_TCL |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 920 | if (name2 == NULL) |
| 921 | code = Tcl_UnsetVar(Tkapp_Interp(self), name1, flags); |
| 922 | |
| 923 | else |
| 924 | code = Tcl_UnsetVar2(Tkapp_Interp(self), name1, name2, flags); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 925 | ENTER_OVERLAP |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 926 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 927 | if (code == TCL_ERROR) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 928 | res = Tkinter_Error(self); |
| 929 | else { |
| 930 | Py_INCREF(Py_None); |
| 931 | res = Py_None; |
| 932 | } |
| 933 | LEAVE_OVERLAP_TCL |
| 934 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 938 | Tkapp_UnsetVar(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 939 | PyObject *self; |
| 940 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 941 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 942 | return UnsetVar(self, args, TCL_LEAVE_ERR_MSG); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 946 | Tkapp_GlobalUnsetVar(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 947 | PyObject *self; |
| 948 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 949 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 950 | return UnsetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 953 | |
| 954 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 955 | /** Tcl to Python **/ |
| 956 | |
| 957 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 958 | Tkapp_GetInt(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 959 | PyObject *self; |
| 960 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 961 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 962 | char *s; |
| 963 | int v; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 964 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 965 | if (!PyArg_ParseTuple(args, "s", &s)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 966 | return NULL; |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 967 | if (Tcl_GetInt(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 968 | return Tkinter_Error(self); |
| 969 | return Py_BuildValue("i", v); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 973 | Tkapp_GetDouble(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 974 | PyObject *self; |
| 975 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 976 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 977 | char *s; |
| 978 | double v; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 979 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 980 | if (!PyArg_ParseTuple(args, "s", &s)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 981 | return NULL; |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 982 | if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 983 | return Tkinter_Error(self); |
| 984 | return Py_BuildValue("d", v); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 988 | Tkapp_GetBoolean(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 989 | PyObject *self; |
| 990 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 991 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 992 | char *s; |
| 993 | int v; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 994 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 995 | if (!PyArg_ParseTuple(args, "s", &s)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 996 | return NULL; |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 997 | if (Tcl_GetBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
| 998 | return Tkinter_Error(self); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 999 | return Py_BuildValue("i", v); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1003 | Tkapp_ExprString(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1004 | PyObject *self; |
| 1005 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1006 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1007 | char *s; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1008 | PyObject *res = NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1009 | int retval; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1010 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1011 | if (!PyArg_ParseTuple(args, "s", &s)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1012 | return NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1013 | ENTER_TCL |
| 1014 | retval = Tcl_ExprString(Tkapp_Interp(self), s); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1015 | ENTER_OVERLAP |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1016 | if (retval == TCL_ERROR) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1017 | res = Tkinter_Error(self); |
| 1018 | else |
| 1019 | res = Py_BuildValue("s", Tkapp_Result(self)); |
| 1020 | LEAVE_OVERLAP_TCL |
| 1021 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1025 | Tkapp_ExprLong(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1026 | PyObject *self; |
| 1027 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1028 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1029 | char *s; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1030 | PyObject *res = NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1031 | int retval; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1032 | long v; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1033 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1034 | if (!PyArg_ParseTuple(args, "s", &s)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1035 | return NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1036 | ENTER_TCL |
| 1037 | retval = Tcl_ExprLong(Tkapp_Interp(self), s, &v); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1038 | ENTER_OVERLAP |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1039 | if (retval == TCL_ERROR) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1040 | res = Tkinter_Error(self); |
| 1041 | else |
| 1042 | res = Py_BuildValue("l", v); |
| 1043 | LEAVE_OVERLAP_TCL |
| 1044 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1048 | Tkapp_ExprDouble(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1049 | PyObject *self; |
| 1050 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1051 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1052 | char *s; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1053 | PyObject *res = NULL; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1054 | double v; |
Guido van Rossum | 52fa3a6 | 1997-02-14 22:59:58 +0000 | [diff] [blame] | 1055 | int retval; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1056 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1057 | if (!PyArg_ParseTuple(args, "s", &s)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1058 | return NULL; |
Guido van Rossum | 52fa3a6 | 1997-02-14 22:59:58 +0000 | [diff] [blame] | 1059 | PyFPE_START_PROTECT("Tkapp_ExprDouble", return 0) |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1060 | ENTER_TCL |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1061 | retval = Tcl_ExprDouble(Tkapp_Interp(self), s, &v); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1062 | ENTER_OVERLAP |
Guido van Rossum | 45b8391 | 1997-03-14 04:32:50 +0000 | [diff] [blame] | 1063 | PyFPE_END_PROTECT(retval) |
Guido van Rossum | 52fa3a6 | 1997-02-14 22:59:58 +0000 | [diff] [blame] | 1064 | if (retval == TCL_ERROR) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1065 | res = Tkinter_Error(self); |
| 1066 | else |
| 1067 | res = Py_BuildValue("d", v); |
| 1068 | LEAVE_OVERLAP_TCL |
| 1069 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1073 | Tkapp_ExprBoolean(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1074 | PyObject *self; |
| 1075 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1076 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1077 | char *s; |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1078 | PyObject *res = NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1079 | int retval; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1080 | int v; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1081 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1082 | if (!PyArg_ParseTuple(args, "s", &s)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1083 | return NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1084 | ENTER_TCL |
| 1085 | retval = Tcl_ExprBoolean(Tkapp_Interp(self), s, &v); |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1086 | ENTER_OVERLAP |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1087 | if (retval == TCL_ERROR) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1088 | res = Tkinter_Error(self); |
| 1089 | else |
| 1090 | res = Py_BuildValue("i", v); |
| 1091 | LEAVE_OVERLAP_TCL |
| 1092 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1095 | |
| 1096 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1097 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1098 | Tkapp_SplitList(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1099 | PyObject *self; |
| 1100 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1101 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1102 | char *list; |
| 1103 | int argc; |
| 1104 | char **argv; |
| 1105 | PyObject *v; |
| 1106 | int i; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1107 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1108 | if (!PyArg_ParseTuple(args, "s", &list)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1109 | return NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1110 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1111 | if (Tcl_SplitList(Tkapp_Interp(self), list, &argc, &argv) == TCL_ERROR) |
| 1112 | return Tkinter_Error(self); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1113 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1114 | if (!(v = PyTuple_New(argc))) |
| 1115 | return NULL; |
| 1116 | |
| 1117 | for (i = 0; i < argc; i++) { |
| 1118 | PyObject *s = PyString_FromString(argv[i]); |
| 1119 | if (!s || PyTuple_SetItem(v, i, s)) { |
| 1120 | Py_DECREF(v); |
| 1121 | v = NULL; |
| 1122 | goto finally; |
| 1123 | } |
| 1124 | } |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1125 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1126 | finally: |
| 1127 | ckfree(FREECAST argv); |
| 1128 | return v; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1132 | Tkapp_Split(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1133 | PyObject *self; |
| 1134 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1135 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1136 | char *list; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1137 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1138 | if (!PyArg_ParseTuple(args, "s", &list)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1139 | return NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1140 | return Split(list); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1144 | Tkapp_Merge(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1145 | PyObject *self; |
| 1146 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1147 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1148 | char *s = Merge(args); |
| 1149 | PyObject *res = NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1150 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1151 | if (s) { |
| 1152 | res = PyString_FromString(s); |
| 1153 | ckfree(s); |
| 1154 | } |
| 1155 | else |
| 1156 | PyErr_SetString(Tkinter_TclError, "merge failed"); |
| 1157 | |
| 1158 | return res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1161 | |
| 1162 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1163 | /** Tcl Command **/ |
| 1164 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1165 | /* Client data struct */ |
| 1166 | typedef struct { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1167 | PyObject *self; |
| 1168 | PyObject *func; |
| 1169 | } PythonCmd_ClientData; |
| 1170 | |
| 1171 | static int |
| 1172 | PythonCmd_Error(interp) |
| 1173 | Tcl_Interp *interp; |
| 1174 | { |
| 1175 | errorInCmd = 1; |
| 1176 | PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); |
| 1177 | LEAVE_PYTHON |
| 1178 | return TCL_ERROR; |
| 1179 | } |
| 1180 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1181 | /* This is the Tcl command that acts as a wrapper for Python |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1182 | * function or method. |
| 1183 | */ |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1184 | static int |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1185 | PythonCmd(clientData, interp, argc, argv) |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1186 | ClientData clientData; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1187 | Tcl_Interp *interp; |
| 1188 | int argc; |
| 1189 | char *argv[]; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1190 | { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1191 | PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1192 | PyObject *self, *func, *arg, *res, *tmp; |
| 1193 | int i; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1194 | |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 1195 | ENTER_PYTHON |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1196 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1197 | /* TBD: no error checking here since we know, via the |
| 1198 | * Tkapp_CreateCommand() that the client data is a two-tuple |
| 1199 | */ |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1200 | self = data->self; |
| 1201 | func = data->func; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1202 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1203 | /* Create argument list (argv1, ..., argvN) */ |
| 1204 | if (!(arg = PyTuple_New(argc - 1))) |
| 1205 | return PythonCmd_Error(interp); |
Guido van Rossum | d308e2b | 1994-07-07 09:25:12 +0000 | [diff] [blame] | 1206 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1207 | for (i = 0; i < (argc - 1); i++) { |
| 1208 | PyObject *s = PyString_FromString(argv[i + 1]); |
| 1209 | if (!s || PyTuple_SetItem(arg, i, s)) { |
| 1210 | Py_DECREF(arg); |
Guido van Rossum | f766e23 | 1998-06-19 04:28:10 +0000 | [diff] [blame] | 1211 | return PythonCmd_Error(interp); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | res = PyEval_CallObject(func, arg); |
| 1215 | Py_DECREF(arg); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1216 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1217 | if (res == NULL) |
| 1218 | return PythonCmd_Error(interp); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1219 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1220 | if (!(tmp = PyList_New(0))) { |
| 1221 | Py_DECREF(res); |
| 1222 | return PythonCmd_Error(interp); |
| 1223 | } |
| 1224 | |
| 1225 | Tcl_SetResult(Tkapp_Interp(self), AsString(res, tmp), TCL_VOLATILE); |
| 1226 | Py_DECREF(res); |
| 1227 | Py_DECREF(tmp); |
| 1228 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1229 | LEAVE_PYTHON |
| 1230 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1231 | return TCL_OK; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | static void |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1235 | PythonCmdDelete(clientData) |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1236 | ClientData clientData; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1237 | { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1238 | PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData; |
| 1239 | |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 1240 | ENTER_PYTHON |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1241 | Py_XDECREF(data->self); |
| 1242 | Py_XDECREF(data->func); |
| 1243 | PyMem_DEL(data); |
| 1244 | LEAVE_PYTHON |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1247 | |
| 1248 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1249 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1250 | Tkapp_CreateCommand(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1251 | PyObject *self; |
| 1252 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1253 | { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1254 | PythonCmd_ClientData *data; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1255 | char *cmdName; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1256 | PyObject *func; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1257 | Tcl_Command err; |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1258 | |
| 1259 | if (!PyArg_ParseTuple(args, "sO", &cmdName, &func)) |
| 1260 | return NULL; |
| 1261 | if (!PyCallable_Check(func)) { |
| 1262 | PyErr_SetString(PyExc_TypeError, "command not callable"); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1263 | return NULL; |
| 1264 | } |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1265 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1266 | data = PyMem_NEW(PythonCmd_ClientData, 1); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1267 | if (!data) |
| 1268 | return NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1269 | Py_XINCREF(self); |
| 1270 | Py_XINCREF(func); |
| 1271 | data->self = self; |
| 1272 | data->func = func; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1273 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1274 | ENTER_TCL |
| 1275 | err = Tcl_CreateCommand(Tkapp_Interp(self), cmdName, PythonCmd, |
| 1276 | (ClientData)data, PythonCmdDelete); |
| 1277 | LEAVE_TCL |
| 1278 | if (err == NULL) { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1279 | PyErr_SetString(Tkinter_TclError, "can't create Tcl command"); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1280 | PyMem_DEL(data); |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1281 | return NULL; |
| 1282 | } |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1283 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1284 | Py_INCREF(Py_None); |
| 1285 | return Py_None; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1288 | |
| 1289 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1290 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1291 | Tkapp_DeleteCommand(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1292 | PyObject *self; |
| 1293 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1294 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1295 | char *cmdName; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1296 | int err; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1297 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1298 | if (!PyArg_ParseTuple(args, "s", &cmdName)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1299 | return NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1300 | ENTER_TCL |
| 1301 | err = Tcl_DeleteCommand(Tkapp_Interp(self), cmdName); |
| 1302 | LEAVE_TCL |
| 1303 | if (err == -1) { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1304 | PyErr_SetString(Tkinter_TclError, "can't delete Tcl command"); |
| 1305 | return NULL; |
| 1306 | } |
| 1307 | Py_INCREF(Py_None); |
| 1308 | return Py_None; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1311 | |
| 1312 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1313 | #ifdef HAVE_CREATEFILEHANDLER |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1314 | /** File Handler **/ |
| 1315 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1316 | typedef struct _fhcdata { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1317 | PyObject *func; |
| 1318 | PyObject *file; |
| 1319 | int id; |
| 1320 | struct _fhcdata *next; |
| 1321 | } FileHandler_ClientData; |
| 1322 | |
| 1323 | static FileHandler_ClientData *HeadFHCD; |
| 1324 | |
| 1325 | static FileHandler_ClientData * |
| 1326 | NewFHCD(func, file, id) |
| 1327 | PyObject *func; |
| 1328 | PyObject *file; |
| 1329 | int id; |
| 1330 | { |
| 1331 | FileHandler_ClientData *p; |
| 1332 | p = PyMem_NEW(FileHandler_ClientData, 1); |
| 1333 | if (p != NULL) { |
| 1334 | Py_XINCREF(func); |
| 1335 | Py_XINCREF(file); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1336 | p->func = func; |
| 1337 | p->file = file; |
| 1338 | p->id = id; |
| 1339 | p->next = HeadFHCD; |
| 1340 | HeadFHCD = p; |
| 1341 | } |
| 1342 | return p; |
| 1343 | } |
| 1344 | |
| 1345 | static void |
| 1346 | DeleteFHCD(id) |
| 1347 | int id; |
| 1348 | { |
| 1349 | FileHandler_ClientData *p, **pp; |
| 1350 | |
| 1351 | pp = &HeadFHCD; |
| 1352 | while ((p = *pp) != NULL) { |
| 1353 | if (p->id == id) { |
| 1354 | *pp = p->next; |
| 1355 | Py_XDECREF(p->func); |
| 1356 | Py_XDECREF(p->file); |
| 1357 | PyMem_DEL(p); |
| 1358 | } |
| 1359 | else |
| 1360 | pp = &p->next; |
| 1361 | } |
| 1362 | } |
| 1363 | |
Guido van Rossum | a597dde | 1995-01-10 20:56:29 +0000 | [diff] [blame] | 1364 | static void |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1365 | FileHandler(clientData, mask) |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1366 | ClientData clientData; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1367 | int mask; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1368 | { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1369 | FileHandler_ClientData *data = (FileHandler_ClientData *)clientData; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1370 | PyObject *func, *file, *arg, *res; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1371 | |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 1372 | ENTER_PYTHON |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1373 | func = data->func; |
| 1374 | file = data->file; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1375 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1376 | arg = Py_BuildValue("(Oi)", file, (long) mask); |
| 1377 | res = PyEval_CallObject(func, arg); |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1378 | Py_DECREF(arg); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1379 | |
| 1380 | if (res == NULL) { |
| 1381 | errorInCmd = 1; |
| 1382 | PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); |
| 1383 | } |
| 1384 | Py_XDECREF(res); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1385 | LEAVE_PYTHON |
Guido van Rossum | 9bb4fd6 | 1994-08-09 14:15:19 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | static int |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1389 | GetFileNo(file) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1390 | /* Either an int >= 0 or an object with a |
| 1391 | *.fileno() method that returns an int >= 0 |
| 1392 | */ |
| 1393 | PyObject *file; |
Guido van Rossum | 9bb4fd6 | 1994-08-09 14:15:19 +0000 | [diff] [blame] | 1394 | { |
Guido van Rossum | a597dde | 1995-01-10 20:56:29 +0000 | [diff] [blame] | 1395 | PyObject *meth, *args, *res; |
Guido van Rossum | 9bb4fd6 | 1994-08-09 14:15:19 +0000 | [diff] [blame] | 1396 | int id; |
| 1397 | if (PyInt_Check(file)) { |
| 1398 | id = PyInt_AsLong(file); |
| 1399 | if (id < 0) |
| 1400 | PyErr_SetString(PyExc_ValueError, "invalid file id"); |
| 1401 | return id; |
| 1402 | } |
Guido van Rossum | 9bb4fd6 | 1994-08-09 14:15:19 +0000 | [diff] [blame] | 1403 | args = PyTuple_New(0); |
| 1404 | if (args == NULL) |
| 1405 | return -1; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1406 | |
| 1407 | meth = PyObject_GetAttrString(file, "fileno"); |
| 1408 | if (meth == NULL) { |
| 1409 | Py_DECREF(args); |
| 1410 | return -1; |
| 1411 | } |
| 1412 | |
Guido van Rossum | 9bb4fd6 | 1994-08-09 14:15:19 +0000 | [diff] [blame] | 1413 | res = PyEval_CallObject(meth, args); |
| 1414 | Py_DECREF(args); |
| 1415 | Py_DECREF(meth); |
| 1416 | if (res == NULL) |
| 1417 | return -1; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1418 | |
Guido van Rossum | 9bb4fd6 | 1994-08-09 14:15:19 +0000 | [diff] [blame] | 1419 | if (PyInt_Check(res)) |
| 1420 | id = PyInt_AsLong(res); |
| 1421 | else |
| 1422 | id = -1; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1423 | |
Guido van Rossum | 9bb4fd6 | 1994-08-09 14:15:19 +0000 | [diff] [blame] | 1424 | if (id < 0) |
| 1425 | PyErr_SetString(PyExc_ValueError, |
| 1426 | "invalid fileno() return value"); |
| 1427 | Py_DECREF(res); |
| 1428 | return id; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1432 | Tkapp_CreateFileHandler(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1433 | PyObject *self; |
| 1434 | PyObject *args; /* Is (file, mask, func) */ |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1435 | { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1436 | FileHandler_ClientData *data; |
| 1437 | PyObject *file, *func; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1438 | int mask, id; |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1439 | FHANDLE tfile; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1440 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1441 | if (!PyArg_ParseTuple(args, "OiO", &file, &mask, &func)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1442 | return NULL; |
| 1443 | id = GetFileNo(file); |
| 1444 | if (id < 0) |
| 1445 | return NULL; |
| 1446 | if (!PyCallable_Check(func)) { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1447 | PyErr_SetString(PyExc_TypeError, "bad argument list"); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1448 | return NULL; |
| 1449 | } |
| 1450 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1451 | data = NewFHCD(func, file, id); |
| 1452 | if (data == NULL) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1453 | return NULL; |
| 1454 | |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1455 | tfile = MAKEFHANDLE(id); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1456 | /* Ought to check for null Tcl_File object... */ |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1457 | ENTER_TCL |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1458 | Tcl_CreateFileHandler(tfile, mask, FileHandler, (ClientData) data); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1459 | LEAVE_TCL |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1460 | Py_INCREF(Py_None); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1461 | return Py_None; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1465 | Tkapp_DeleteFileHandler(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1466 | PyObject *self; |
| 1467 | PyObject *args; /* Args: file */ |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1468 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1469 | PyObject *file; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1470 | FileHandler_ClientData *data; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1471 | int id; |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1472 | FHANDLE tfile; |
Guido van Rossum | 6878436 | 1996-05-16 17:17:31 +0000 | [diff] [blame] | 1473 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1474 | if (!PyArg_ParseTuple(args, "O", &file)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1475 | return NULL; |
| 1476 | id = GetFileNo(file); |
| 1477 | if (id < 0) |
| 1478 | return NULL; |
| 1479 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1480 | DeleteFHCD(id); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1481 | |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1482 | tfile = MAKEFHANDLE(id); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1483 | /* Ought to check for null Tcl_File object... */ |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1484 | ENTER_TCL |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1485 | Tcl_DeleteFileHandler(tfile); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1486 | LEAVE_TCL |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1487 | Py_INCREF(Py_None); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1488 | return Py_None; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1489 | } |
Guido van Rossum | 0d2390c | 1997-08-14 19:57:07 +0000 | [diff] [blame] | 1490 | #endif /* HAVE_CREATEFILEHANDLER */ |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1491 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1492 | |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1493 | /**** Tktt Object (timer token) ****/ |
| 1494 | |
| 1495 | staticforward PyTypeObject Tktt_Type; |
| 1496 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1497 | typedef struct { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1498 | PyObject_HEAD |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1499 | Tcl_TimerToken token; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1500 | PyObject *func; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1501 | } TkttObject; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1502 | |
| 1503 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1504 | Tktt_DeleteTimerHandler(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1505 | PyObject *self; |
| 1506 | PyObject *args; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1507 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1508 | TkttObject *v = (TkttObject *)self; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1509 | PyObject *func = v->func; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1510 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1511 | if (!PyArg_ParseTuple(args, "")) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1512 | return NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1513 | if (v->token != NULL) { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1514 | Tcl_DeleteTimerHandler(v->token); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1515 | v->token = NULL; |
| 1516 | } |
| 1517 | if (func != NULL) { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1518 | v->func = NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1519 | Py_DECREF(func); |
| 1520 | Py_DECREF(v); /* See Tktt_New() */ |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1521 | } |
| 1522 | Py_INCREF(Py_None); |
| 1523 | return Py_None; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | static PyMethodDef Tktt_methods[] = |
| 1527 | { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1528 | {"deletetimerhandler", Tktt_DeleteTimerHandler, 1}, |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1529 | {NULL, NULL} |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1530 | }; |
| 1531 | |
| 1532 | static TkttObject * |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1533 | Tktt_New(func) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1534 | PyObject *func; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1535 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1536 | TkttObject *v; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1537 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1538 | v = PyObject_NEW(TkttObject, &Tktt_Type); |
| 1539 | if (v == NULL) |
| 1540 | return NULL; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1541 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1542 | Py_INCREF(func); |
| 1543 | v->token = NULL; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1544 | v->func = func; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1545 | |
| 1546 | /* Extra reference, deleted when called or when handler is deleted */ |
| 1547 | Py_INCREF(v); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1548 | return v; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | static void |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1552 | Tktt_Dealloc(self) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1553 | PyObject *self; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1554 | { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1555 | TkttObject *v = (TkttObject *)self; |
| 1556 | PyObject *func = v->func; |
| 1557 | |
| 1558 | Py_XDECREF(func); |
| 1559 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1560 | PyMem_DEL(self); |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
Guido van Rossum | 597ac20 | 1998-05-12 14:36:19 +0000 | [diff] [blame] | 1563 | static PyObject * |
| 1564 | Tktt_Repr(self) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1565 | PyObject *self; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1566 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1567 | TkttObject *v = (TkttObject *)self; |
Guido van Rossum | 597ac20 | 1998-05-12 14:36:19 +0000 | [diff] [blame] | 1568 | char buf[100]; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1569 | |
Guido van Rossum | 597ac20 | 1998-05-12 14:36:19 +0000 | [diff] [blame] | 1570 | sprintf(buf, "<tktimertoken at 0x%lx%s>", (long)v, |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1571 | v->func == NULL ? ", handler deleted" : ""); |
Guido van Rossum | 597ac20 | 1998-05-12 14:36:19 +0000 | [diff] [blame] | 1572 | return PyString_FromString(buf); |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1576 | Tktt_GetAttr(self, name) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1577 | PyObject *self; |
| 1578 | char *name; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1579 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1580 | return Py_FindMethod(Tktt_methods, self, name); |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | static PyTypeObject Tktt_Type = |
| 1584 | { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1585 | PyObject_HEAD_INIT(NULL) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1586 | 0, /*ob_size */ |
| 1587 | "tktimertoken", /*tp_name */ |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1588 | sizeof(TkttObject), /*tp_basicsize */ |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1589 | 0, /*tp_itemsize */ |
| 1590 | Tktt_Dealloc, /*tp_dealloc */ |
Guido van Rossum | 597ac20 | 1998-05-12 14:36:19 +0000 | [diff] [blame] | 1591 | 0, /*tp_print */ |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1592 | Tktt_GetAttr, /*tp_getattr */ |
| 1593 | 0, /*tp_setattr */ |
| 1594 | 0, /*tp_compare */ |
Guido van Rossum | 597ac20 | 1998-05-12 14:36:19 +0000 | [diff] [blame] | 1595 | Tktt_Repr, /*tp_repr */ |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1596 | 0, /*tp_as_number */ |
| 1597 | 0, /*tp_as_sequence */ |
| 1598 | 0, /*tp_as_mapping */ |
| 1599 | 0, /*tp_hash */ |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1600 | }; |
| 1601 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1602 | |
| 1603 | |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1604 | /** Timer Handler **/ |
| 1605 | |
| 1606 | static void |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1607 | TimerHandler(clientData) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1608 | ClientData clientData; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1609 | { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1610 | TkttObject *v = (TkttObject *)clientData; |
| 1611 | PyObject *func = v->func; |
| 1612 | PyObject *res; |
| 1613 | |
| 1614 | if (func == NULL) |
| 1615 | return; |
| 1616 | |
| 1617 | v->func = NULL; |
| 1618 | |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 1619 | ENTER_PYTHON |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1620 | |
| 1621 | res = PyEval_CallObject(func, NULL); |
| 1622 | Py_DECREF(func); |
| 1623 | Py_DECREF(v); /* See Tktt_New() */ |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1624 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1625 | if (res == NULL) { |
| 1626 | errorInCmd = 1; |
| 1627 | PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); |
| 1628 | } |
| 1629 | else |
| 1630 | Py_DECREF(res); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1631 | |
| 1632 | LEAVE_PYTHON |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1636 | Tkapp_CreateTimerHandler(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1637 | PyObject *self; |
| 1638 | PyObject *args; /* Is (milliseconds, func) */ |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1639 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1640 | int milliseconds; |
| 1641 | PyObject *func; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1642 | TkttObject *v; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1643 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1644 | if (!PyArg_ParseTuple(args, "iO", &milliseconds, &func)) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1645 | return NULL; |
| 1646 | if (!PyCallable_Check(func)) { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1647 | PyErr_SetString(PyExc_TypeError, "bad argument list"); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1648 | return NULL; |
| 1649 | } |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1650 | v = Tktt_New(func); |
| 1651 | v->token = Tcl_CreateTimerHandler(milliseconds, TimerHandler, |
| 1652 | (ClientData)v); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1653 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1654 | return (PyObject *) v; |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1657 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1658 | /** Event Loop **/ |
| 1659 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1660 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1661 | Tkapp_MainLoop(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1662 | PyObject *self; |
| 1663 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1664 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1665 | int threshold = 0; |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 1666 | #ifdef WITH_THREAD |
| 1667 | PyThreadState *tstate = PyThreadState_Get(); |
| 1668 | #endif |
Guido van Rossum | f34cadd | 1994-11-10 22:50:21 +0000 | [diff] [blame] | 1669 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1670 | if (!PyArg_ParseTuple(args, "|i", &threshold)) |
| 1671 | return NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1672 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1673 | quitMainLoop = 0; |
| 1674 | while (Tk_GetNumMainWindows() > threshold && |
| 1675 | !quitMainLoop && |
| 1676 | !errorInCmd) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1677 | { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1678 | int result; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1679 | |
| 1680 | #ifdef WITH_THREAD |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1681 | Py_BEGIN_ALLOW_THREADS |
| 1682 | acquire_lock(tcl_lock, 1); |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 1683 | tcl_tstate = tstate; |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1684 | result = Tcl_DoOneEvent(TCL_DONT_WAIT); |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 1685 | tcl_tstate = NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1686 | release_lock(tcl_lock); |
| 1687 | if (result == 0) |
| 1688 | Sleep(20); |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1689 | Py_END_ALLOW_THREADS |
Guido van Rossum | 5b02078 | 1997-08-19 01:00:50 +0000 | [diff] [blame] | 1690 | #else |
| 1691 | result = Tcl_DoOneEvent(0); |
| 1692 | #endif |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1693 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1694 | if (PyErr_CheckSignals() != 0) |
| 1695 | return NULL; |
| 1696 | if (result < 0) |
| 1697 | break; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1698 | } |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1699 | quitMainLoop = 0; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1700 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1701 | if (errorInCmd) { |
| 1702 | errorInCmd = 0; |
| 1703 | PyErr_Restore(excInCmd, valInCmd, trbInCmd); |
| 1704 | excInCmd = valInCmd = trbInCmd = NULL; |
| 1705 | return NULL; |
| 1706 | } |
| 1707 | Py_INCREF(Py_None); |
| 1708 | return Py_None; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1712 | Tkapp_DoOneEvent(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1713 | PyObject *self; |
| 1714 | PyObject *args; |
Guido van Rossum | 062cfb0 | 1995-01-10 17:42:51 +0000 | [diff] [blame] | 1715 | { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1716 | int flags = 0; |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1717 | int rv; |
Guido van Rossum | 062cfb0 | 1995-01-10 17:42:51 +0000 | [diff] [blame] | 1718 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1719 | if (!PyArg_ParseTuple(args, "|i", &flags)) |
| 1720 | return NULL; |
| 1721 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1722 | ENTER_TCL |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1723 | rv = Tcl_DoOneEvent(flags); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1724 | LEAVE_TCL |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1725 | return Py_BuildValue("i", rv); |
Guido van Rossum | 062cfb0 | 1995-01-10 17:42:51 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1729 | Tkapp_Quit(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1730 | PyObject *self; |
| 1731 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1732 | { |
| 1733 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1734 | if (!PyArg_ParseTuple(args, "")) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1735 | return NULL; |
| 1736 | |
| 1737 | quitMainLoop = 1; |
| 1738 | Py_INCREF(Py_None); |
| 1739 | return Py_None; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
Guido van Rossum | 9d1b7ae | 1998-04-29 16:17:01 +0000 | [diff] [blame] | 1742 | static PyObject * |
| 1743 | Tkapp_InterpAddr(self, args) |
| 1744 | PyObject *self; |
| 1745 | PyObject *args; |
| 1746 | { |
| 1747 | |
| 1748 | if (!PyArg_ParseTuple(args, "")) |
| 1749 | return NULL; |
| 1750 | |
| 1751 | return PyInt_FromLong((long)Tkapp_Interp(self)); |
| 1752 | } |
| 1753 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1754 | |
| 1755 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1756 | /**** Tkapp Method List ****/ |
| 1757 | |
| 1758 | static PyMethodDef Tkapp_methods[] = |
| 1759 | { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1760 | {"call", Tkapp_Call, 0}, |
| 1761 | {"globalcall", Tkapp_GlobalCall, 0}, |
| 1762 | {"eval", Tkapp_Eval, 1}, |
| 1763 | {"globaleval", Tkapp_GlobalEval, 1}, |
| 1764 | {"evalfile", Tkapp_EvalFile, 1}, |
| 1765 | {"record", Tkapp_Record, 1}, |
| 1766 | {"adderrorinfo", Tkapp_AddErrorInfo, 1}, |
| 1767 | {"setvar", Tkapp_SetVar, 1}, |
| 1768 | {"globalsetvar", Tkapp_GlobalSetVar, 1}, |
| 1769 | {"getvar", Tkapp_GetVar, 1}, |
| 1770 | {"globalgetvar", Tkapp_GlobalGetVar, 1}, |
| 1771 | {"unsetvar", Tkapp_UnsetVar, 1}, |
| 1772 | {"globalunsetvar", Tkapp_GlobalUnsetVar, 1}, |
| 1773 | {"getint", Tkapp_GetInt, 1}, |
| 1774 | {"getdouble", Tkapp_GetDouble, 1}, |
| 1775 | {"getboolean", Tkapp_GetBoolean, 1}, |
| 1776 | {"exprstring", Tkapp_ExprString, 1}, |
| 1777 | {"exprlong", Tkapp_ExprLong, 1}, |
| 1778 | {"exprdouble", Tkapp_ExprDouble, 1}, |
| 1779 | {"exprboolean", Tkapp_ExprBoolean, 1}, |
| 1780 | {"splitlist", Tkapp_SplitList, 1}, |
| 1781 | {"split", Tkapp_Split, 1}, |
| 1782 | {"merge", Tkapp_Merge, 0}, |
| 1783 | {"createcommand", Tkapp_CreateCommand, 1}, |
| 1784 | {"deletecommand", Tkapp_DeleteCommand, 1}, |
Guido van Rossum | 0d2390c | 1997-08-14 19:57:07 +0000 | [diff] [blame] | 1785 | #ifdef HAVE_CREATEFILEHANDLER |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1786 | {"createfilehandler", Tkapp_CreateFileHandler, 1}, |
| 1787 | {"deletefilehandler", Tkapp_DeleteFileHandler, 1}, |
Guido van Rossum | 02c0467 | 1997-08-07 00:12:22 +0000 | [diff] [blame] | 1788 | #endif |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1789 | {"createtimerhandler", Tkapp_CreateTimerHandler, 1}, |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1790 | {"mainloop", Tkapp_MainLoop, 1}, |
| 1791 | {"dooneevent", Tkapp_DoOneEvent, 1}, |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1792 | {"quit", Tkapp_Quit, 1}, |
Guido van Rossum | 9d1b7ae | 1998-04-29 16:17:01 +0000 | [diff] [blame] | 1793 | {"interpaddr", Tkapp_InterpAddr, 1}, |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1794 | {NULL, NULL} |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1795 | }; |
| 1796 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1797 | |
| 1798 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1799 | /**** Tkapp Type Methods ****/ |
| 1800 | |
| 1801 | static void |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1802 | Tkapp_Dealloc(self) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1803 | PyObject *self; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1804 | { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1805 | ENTER_TCL |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1806 | Tcl_DeleteInterp(Tkapp_Interp(self)); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1807 | LEAVE_TCL |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1808 | PyMem_DEL(self); |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1809 | DisableEventHook(); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1813 | Tkapp_GetAttr(self, name) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1814 | PyObject *self; |
| 1815 | char *name; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1816 | { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1817 | return Py_FindMethod(Tkapp_methods, self, name); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | static PyTypeObject Tkapp_Type = |
| 1821 | { |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1822 | PyObject_HEAD_INIT(NULL) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1823 | 0, /*ob_size */ |
| 1824 | "tkapp", /*tp_name */ |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1825 | sizeof(TkappObject), /*tp_basicsize */ |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1826 | 0, /*tp_itemsize */ |
| 1827 | Tkapp_Dealloc, /*tp_dealloc */ |
| 1828 | 0, /*tp_print */ |
| 1829 | Tkapp_GetAttr, /*tp_getattr */ |
| 1830 | 0, /*tp_setattr */ |
| 1831 | 0, /*tp_compare */ |
| 1832 | 0, /*tp_repr */ |
| 1833 | 0, /*tp_as_number */ |
| 1834 | 0, /*tp_as_sequence */ |
| 1835 | 0, /*tp_as_mapping */ |
| 1836 | 0, /*tp_hash */ |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1837 | }; |
| 1838 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1839 | |
| 1840 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1841 | /**** Tkinter Module ****/ |
| 1842 | |
| 1843 | static PyObject * |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1844 | Tkinter_Create(self, args) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1845 | PyObject *self; |
| 1846 | PyObject *args; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1847 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1848 | char *screenName = NULL; |
| 1849 | char *baseName = NULL; |
| 1850 | char *className = NULL; |
| 1851 | int interactive = 0; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1852 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1853 | baseName = strrchr(Py_GetProgramName(), '/'); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1854 | if (baseName != NULL) |
| 1855 | baseName++; |
| 1856 | else |
| 1857 | baseName = Py_GetProgramName(); |
| 1858 | className = "Tk"; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1859 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1860 | if (!PyArg_ParseTuple(args, "|zssi", |
| 1861 | &screenName, &baseName, &className, |
| 1862 | &interactive)) |
| 1863 | return NULL; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1864 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1865 | return (PyObject *) Tkapp_New(screenName, baseName, className, |
| 1866 | interactive); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | static PyMethodDef moduleMethods[] = |
| 1870 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1871 | {"create", Tkinter_Create, 1}, |
Guido van Rossum | 0d2390c | 1997-08-14 19:57:07 +0000 | [diff] [blame] | 1872 | #ifdef HAVE_CREATEFILEHANDLER |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1873 | {"createfilehandler", Tkapp_CreateFileHandler, 1}, |
| 1874 | {"deletefilehandler", Tkapp_DeleteFileHandler, 1}, |
Guido van Rossum | 02c0467 | 1997-08-07 00:12:22 +0000 | [diff] [blame] | 1875 | #endif |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1876 | {"createtimerhandler", Tkapp_CreateTimerHandler, 1}, |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1877 | {"mainloop", Tkapp_MainLoop, 1}, |
| 1878 | {"dooneevent", Tkapp_DoOneEvent, 1}, |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1879 | {"quit", Tkapp_Quit, 1}, |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1880 | {NULL, NULL} |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1881 | }; |
| 1882 | |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1883 | #ifdef WAIT_FOR_STDIN |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1884 | |
| 1885 | static int stdin_ready = 0; |
| 1886 | |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 1887 | #ifndef MS_WINDOWS |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1888 | static void |
| 1889 | MyFileProc(clientData, mask) |
| 1890 | void *clientData; |
| 1891 | int mask; |
| 1892 | { |
| 1893 | stdin_ready = 1; |
| 1894 | } |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 1895 | #endif |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1896 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1897 | static PyThreadState *event_tstate = NULL; |
Guido van Rossum | 0e8457c | 1997-10-07 18:51:41 +0000 | [diff] [blame] | 1898 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1899 | static int |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 1900 | EventHook() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1901 | { |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 1902 | #ifndef MS_WINDOWS |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1903 | FHANDLE tfile; |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 1904 | #endif |
Guido van Rossum | e9bc62d | 1998-11-17 03:45:24 +0000 | [diff] [blame] | 1905 | #ifdef WITH_THREAD |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 1906 | PyEval_RestoreThread(event_tstate); |
Guido van Rossum | e9bc62d | 1998-11-17 03:45:24 +0000 | [diff] [blame] | 1907 | #endif |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1908 | stdin_ready = 0; |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 1909 | errorInCmd = 0; |
| 1910 | #ifndef MS_WINDOWS |
| 1911 | tfile = MAKEFHANDLE(fileno(stdin)); |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1912 | Tcl_CreateFileHandler(tfile, TCL_READABLE, MyFileProc, NULL); |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 1913 | #endif |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1914 | while (!errorInCmd && !stdin_ready) { |
| 1915 | int result; |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 1916 | #ifdef MS_WINDOWS |
| 1917 | if (_kbhit()) { |
| 1918 | stdin_ready = 1; |
| 1919 | break; |
| 1920 | } |
| 1921 | #endif |
| 1922 | #if defined(WITH_THREAD) || defined(MS_WINDOWS) |
Guido van Rossum | 62320c9 | 1998-06-15 04:36:09 +0000 | [diff] [blame] | 1923 | Py_BEGIN_ALLOW_THREADS |
| 1924 | acquire_lock(tcl_lock, 1); |
Guido van Rossum | 41f0a98 | 1998-10-12 16:26:22 +0000 | [diff] [blame] | 1925 | tcl_tstate = event_tstate; |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 1926 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1927 | result = Tcl_DoOneEvent(TCL_DONT_WAIT); |
Guido van Rossum | dc1adab | 1998-10-09 20:51:18 +0000 | [diff] [blame] | 1928 | |
| 1929 | tcl_tstate = NULL; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1930 | release_lock(tcl_lock); |
| 1931 | if (result == 0) |
| 1932 | Sleep(20); |
| 1933 | Py_END_ALLOW_THREADS |
| 1934 | #else |
| 1935 | result = Tcl_DoOneEvent(0); |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1936 | #endif |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1937 | |
| 1938 | if (result < 0) |
| 1939 | break; |
| 1940 | } |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 1941 | #ifndef MS_WINDOWS |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1942 | Tcl_DeleteFileHandler(tfile); |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 1943 | #endif |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1944 | if (errorInCmd) { |
| 1945 | errorInCmd = 0; |
| 1946 | PyErr_Restore(excInCmd, valInCmd, trbInCmd); |
| 1947 | excInCmd = valInCmd = trbInCmd = NULL; |
| 1948 | PyErr_Print(); |
| 1949 | } |
Guido van Rossum | e9bc62d | 1998-11-17 03:45:24 +0000 | [diff] [blame] | 1950 | #ifdef WITH_THREAD |
Guido van Rossum | ad4db17 | 1998-06-13 13:56:28 +0000 | [diff] [blame] | 1951 | PyEval_SaveThread(); |
Guido van Rossum | e9bc62d | 1998-11-17 03:45:24 +0000 | [diff] [blame] | 1952 | #endif |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1953 | return 0; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1954 | } |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1955 | |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1956 | #endif |
| 1957 | |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1958 | static void |
| 1959 | EnableEventHook() |
| 1960 | { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1961 | #ifdef WAIT_FOR_STDIN |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1962 | if (PyOS_InputHook == NULL) { |
Guido van Rossum | e9bc62d | 1998-11-17 03:45:24 +0000 | [diff] [blame] | 1963 | #ifdef WITH_THREAD |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1964 | event_tstate = PyThreadState_Get(); |
Guido van Rossum | e9bc62d | 1998-11-17 03:45:24 +0000 | [diff] [blame] | 1965 | #endif |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1966 | PyOS_InputHook = EventHook; |
| 1967 | } |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1968 | #endif |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | static void |
| 1972 | DisableEventHook() |
| 1973 | { |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1974 | #ifdef WAIT_FOR_STDIN |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1975 | if (Tk_GetNumMainWindows() == 0 && PyOS_InputHook == EventHook) { |
| 1976 | PyOS_InputHook = NULL; |
| 1977 | } |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 1978 | #endif |
Guido van Rossum | 7bf1564 | 1998-05-22 18:28:17 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 1981 | |
| 1982 | /* all errors will be checked in one fell swoop in init_tkinter() */ |
| 1983 | static void |
| 1984 | ins_long(d, name, val) |
| 1985 | PyObject *d; |
| 1986 | char *name; |
| 1987 | long val; |
| 1988 | { |
| 1989 | PyObject *v = PyInt_FromLong(val); |
| 1990 | if (v) { |
| 1991 | PyDict_SetItemString(d, name, v); |
| 1992 | Py_DECREF(v); |
| 1993 | } |
| 1994 | } |
| 1995 | static void |
| 1996 | ins_string(d, name, val) |
| 1997 | PyObject *d; |
| 1998 | char *name; |
| 1999 | char *val; |
| 2000 | { |
| 2001 | PyObject *v = PyString_FromString(val); |
| 2002 | if (v) { |
| 2003 | PyDict_SetItemString(d, name, v); |
| 2004 | Py_DECREF(v); |
| 2005 | } |
| 2006 | } |
| 2007 | |
| 2008 | |
Guido van Rossum | 3886bb6 | 1998-12-04 18:50:17 +0000 | [diff] [blame^] | 2009 | DL_EXPORT(void) |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 2010 | init_tkinter() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 2011 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2012 | PyObject *m, *d; |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 2013 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2014 | Tkapp_Type.ob_type = &PyType_Type; |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 2015 | |
| 2016 | #ifdef WITH_THREAD |
| 2017 | tcl_lock = allocate_lock(); |
| 2018 | #endif |
Guido van Rossum | ae92f01 | 1996-08-21 19:03:36 +0000 | [diff] [blame] | 2019 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2020 | m = Py_InitModule("_tkinter", moduleMethods); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 2021 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2022 | d = PyModule_GetDict(m); |
| 2023 | Tkinter_TclError = Py_BuildValue("s", "TclError"); |
| 2024 | PyDict_SetItemString(d, "TclError", Tkinter_TclError); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 2025 | |
Guido van Rossum | 35d4337 | 1997-08-02 00:09:09 +0000 | [diff] [blame] | 2026 | ins_long(d, "READABLE", TCL_READABLE); |
| 2027 | ins_long(d, "WRITABLE", TCL_WRITABLE); |
| 2028 | ins_long(d, "EXCEPTION", TCL_EXCEPTION); |
| 2029 | ins_long(d, "WINDOW_EVENTS", TCL_WINDOW_EVENTS); |
| 2030 | ins_long(d, "FILE_EVENTS", TCL_FILE_EVENTS); |
| 2031 | ins_long(d, "TIMER_EVENTS", TCL_TIMER_EVENTS); |
| 2032 | ins_long(d, "IDLE_EVENTS", TCL_IDLE_EVENTS); |
| 2033 | ins_long(d, "ALL_EVENTS", TCL_ALL_EVENTS); |
| 2034 | ins_long(d, "DONT_WAIT", TCL_DONT_WAIT); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2035 | ins_string(d, "TK_VERSION", TK_VERSION); |
| 2036 | ins_string(d, "TCL_VERSION", TCL_VERSION); |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 2037 | |
Guido van Rossum | 83551bf | 1997-09-13 00:44:23 +0000 | [diff] [blame] | 2038 | PyDict_SetItemString(d, "TkappType", (PyObject *)&Tkapp_Type); |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 2039 | |
| 2040 | Tktt_Type.ob_type = &PyType_Type; |
Guido van Rossum | 83551bf | 1997-09-13 00:44:23 +0000 | [diff] [blame] | 2041 | PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type); |
| 2042 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2043 | if (PyErr_Occurred()) |
Guido van Rossum | 07e9fbf | 1998-02-06 22:35:46 +0000 | [diff] [blame] | 2044 | return; |
| 2045 | |
Guido van Rossum | 43ff868 | 1998-07-14 18:02:13 +0000 | [diff] [blame] | 2046 | #if 0 |
| 2047 | /* This was not a good idea; through <Destroy> bindings, |
| 2048 | Tcl_Finalize() may invoke Python code but at that point the |
| 2049 | interpreter and thread state have already been destroyed! */ |
Guido van Rossum | 2621637 | 1998-04-20 18:47:52 +0000 | [diff] [blame] | 2050 | #if TKMAJORMINOR >= 8000 |
Guido van Rossum | 07e9fbf | 1998-02-06 22:35:46 +0000 | [diff] [blame] | 2051 | Py_AtExit(Tcl_Finalize); |
Guido van Rossum | 2621637 | 1998-04-20 18:47:52 +0000 | [diff] [blame] | 2052 | #endif |
Guido van Rossum | 43ff868 | 1998-07-14 18:02:13 +0000 | [diff] [blame] | 2053 | #endif |
Guido van Rossum | 07e9fbf | 1998-02-06 22:35:46 +0000 | [diff] [blame] | 2054 | |
Jack Jansen | 34cc5c3 | 1995-10-31 16:15:12 +0000 | [diff] [blame] | 2055 | #ifdef macintosh |
Guido van Rossum | 0d2390c | 1997-08-14 19:57:07 +0000 | [diff] [blame] | 2056 | /* |
| 2057 | ** Part of this code is stolen from MacintoshInit in tkMacAppInit. |
| 2058 | ** Most of the initializations in that routine (toolbox init calls and |
| 2059 | ** such) have already been done for us, so we only need these. |
| 2060 | */ |
| 2061 | #if TKMAJORMINOR >= 8000 |
| 2062 | tcl_macQdPtr = &qd; |
| 2063 | #endif |
| 2064 | |
| 2065 | Tcl_MacSetEventProc(PyMacConvertEvent); |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 2066 | #if GENERATINGCFM |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2067 | mac_addlibresources(); |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 2068 | #endif /* GENERATINGCFM */ |
| 2069 | #endif /* macintosh */ |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 2070 | } |
Guido van Rossum | 9722ad8 | 1995-09-22 23:49:28 +0000 | [diff] [blame] | 2071 | |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 2072 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2073 | |
Guido van Rossum | 9722ad8 | 1995-09-22 23:49:28 +0000 | [diff] [blame] | 2074 | #ifdef macintosh |
Guido van Rossum | dfd428d | 1996-02-25 04:46:40 +0000 | [diff] [blame] | 2075 | |
| 2076 | /* |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 2077 | ** Anyone who embeds Tcl/Tk on the Mac must define panic(). |
Guido van Rossum | dfd428d | 1996-02-25 04:46:40 +0000 | [diff] [blame] | 2078 | */ |
| 2079 | |
Guido van Rossum | 9722ad8 | 1995-09-22 23:49:28 +0000 | [diff] [blame] | 2080 | void |
| 2081 | panic(char * format, ...) |
| 2082 | { |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2083 | va_list varg; |
Guido van Rossum | 9722ad8 | 1995-09-22 23:49:28 +0000 | [diff] [blame] | 2084 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2085 | va_start(varg, format); |
Guido van Rossum | 9722ad8 | 1995-09-22 23:49:28 +0000 | [diff] [blame] | 2086 | |
Guido van Rossum | 227cf76 | 1998-08-05 13:53:32 +0000 | [diff] [blame] | 2087 | vfprintf(stderr, format, varg); |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2088 | (void) fflush(stderr); |
Guido van Rossum | 9722ad8 | 1995-09-22 23:49:28 +0000 | [diff] [blame] | 2089 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2090 | va_end(varg); |
Guido van Rossum | 9722ad8 | 1995-09-22 23:49:28 +0000 | [diff] [blame] | 2091 | |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2092 | Py_FatalError("Tcl/Tk panic"); |
Guido van Rossum | 9722ad8 | 1995-09-22 23:49:28 +0000 | [diff] [blame] | 2093 | } |
Jack Jansen | 40b546d | 1995-11-14 10:34:45 +0000 | [diff] [blame] | 2094 | |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 2095 | /* |
| 2096 | ** Pass events to SIOUX before passing them to Tk. |
| 2097 | */ |
Guido van Rossum | dfd428d | 1996-02-25 04:46:40 +0000 | [diff] [blame] | 2098 | |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 2099 | static int |
| 2100 | PyMacConvertEvent(eventPtr) |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2101 | EventRecord *eventPtr; |
Guido van Rossum | dfd428d | 1996-02-25 04:46:40 +0000 | [diff] [blame] | 2102 | { |
Guido van Rossum | 2ea1c94 | 1998-04-28 16:12:43 +0000 | [diff] [blame] | 2103 | WindowPtr frontwin; |
| 2104 | /* |
Guido van Rossum | 00d9306 | 1998-05-28 23:06:38 +0000 | [diff] [blame] | 2105 | ** Sioux eats too many events, so we don't pass it everything. We |
| 2106 | ** always pass update events to Sioux, and we only pass other events if |
Guido van Rossum | 2ea1c94 | 1998-04-28 16:12:43 +0000 | [diff] [blame] | 2107 | ** the Sioux window is frontmost. This means that Tk menus don't work |
| 2108 | ** in that case, but at least we can scroll the sioux window. |
| 2109 | ** Note that the SIOUXIsAppWindow() routine we use here is not really |
| 2110 | ** part of the external interface of Sioux... |
| 2111 | */ |
| 2112 | frontwin = FrontWindow(); |
| 2113 | if ( eventPtr->what == updateEvt || SIOUXIsAppWindow(frontwin) ) { |
| 2114 | if (SIOUXHandleOneEvent(eventPtr)) |
| 2115 | return 0; /* Nothing happened to the Tcl event queue */ |
| 2116 | } |
Barry Warsaw | fa701a8 | 1997-01-16 00:15:11 +0000 | [diff] [blame] | 2117 | return TkMacConvertEvent(eventPtr); |
Guido van Rossum | dfd428d | 1996-02-25 04:46:40 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
Guido van Rossum | 0d2390c | 1997-08-14 19:57:07 +0000 | [diff] [blame] | 2120 | #if defined(USE_GUSI) && TKMAJORMINOR < 8000 |
Guido van Rossum | 290283b | 1997-06-02 22:16:43 +0000 | [diff] [blame] | 2121 | /* |
| 2122 | * For Python we have to override this routine (from TclMacNotify), |
| 2123 | * since we use GUSI for our sockets, not Tcl streams. Hence, we have |
| 2124 | * to use GUSI select to see whether our socket is ready. Note that |
| 2125 | * createfilehandler (above) sets the type to TCL_UNIX_FD for our |
| 2126 | * files and sockets. |
| 2127 | * |
| 2128 | * NOTE: this code was lifted from Tcl 7.6, it may need to be modified |
| 2129 | * for other versions. */ |
| 2130 | |
| 2131 | int |
| 2132 | Tcl_FileReady(file, mask) |
| 2133 | Tcl_File file; /* File handle for a stream. */ |
| 2134 | int mask; /* OR'ed combination of TCL_READABLE, |
| 2135 | * TCL_WRITABLE, and TCL_EXCEPTION: |
| 2136 | * indicates conditions caller cares about. */ |
| 2137 | { |
| 2138 | int type; |
| 2139 | int fd; |
| 2140 | |
| 2141 | fd = (int) Tcl_GetFileInfo(file, &type); |
| 2142 | |
| 2143 | if (type == TCL_MAC_SOCKET) { |
| 2144 | return TclMacSocketReady(file, mask); |
| 2145 | } else if (type == TCL_MAC_FILE) { |
| 2146 | /* |
| 2147 | * Under the Macintosh, files are always ready, so we just |
| 2148 | * return the mask that was passed in. |
| 2149 | */ |
| 2150 | |
| 2151 | return mask; |
| 2152 | } else if (type == TCL_UNIX_FD) { |
| 2153 | fd_set readset, writeset, excset; |
| 2154 | struct timeval tv; |
| 2155 | |
| 2156 | FD_ZERO(&readset); |
| 2157 | FD_ZERO(&writeset); |
| 2158 | FD_ZERO(&excset); |
| 2159 | |
| 2160 | if ( mask & TCL_READABLE ) FD_SET(fd, &readset); |
| 2161 | if ( mask & TCL_WRITABLE ) FD_SET(fd, &writeset); |
| 2162 | if ( mask & TCL_EXCEPTION ) FD_SET(fd, &excset); |
| 2163 | |
| 2164 | tv.tv_sec = tv.tv_usec = 0; |
| 2165 | if ( select(fd+1, &readset, &writeset, &excset, &tv) <= 0 ) |
| 2166 | return 0; |
| 2167 | |
| 2168 | mask = 0; |
| 2169 | if ( FD_ISSET(fd, &readset) ) mask |= TCL_READABLE; |
| 2170 | if ( FD_ISSET(fd, &writeset) ) mask |= TCL_WRITABLE; |
| 2171 | if ( FD_ISSET(fd, &excset) ) mask |= TCL_EXCEPTION; |
| 2172 | |
| 2173 | return mask; |
| 2174 | } |
| 2175 | |
| 2176 | return 0; |
| 2177 | } |
| 2178 | #endif /* USE_GUSI */ |
| 2179 | |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 2180 | #if GENERATINGCFM |
Guido van Rossum | dfd428d | 1996-02-25 04:46:40 +0000 | [diff] [blame] | 2181 | |
| 2182 | /* |
| 2183 | ** Additional Mac specific code for dealing with shared libraries. |
| 2184 | */ |
| 2185 | |
| 2186 | #include <Resources.h> |
| 2187 | #include <CodeFragments.h> |
| 2188 | |
| 2189 | static int loaded_from_shlib = 0; |
| 2190 | static FSSpec library_fss; |
Guido van Rossum | 9722ad8 | 1995-09-22 23:49:28 +0000 | [diff] [blame] | 2191 | |
Jack Jansen | 34cc5c3 | 1995-10-31 16:15:12 +0000 | [diff] [blame] | 2192 | /* |
| 2193 | ** If this module is dynamically loaded the following routine should |
| 2194 | ** be the init routine. It takes care of adding the shared library to |
| 2195 | ** the resource-file chain, so that the tk routines can find their |
| 2196 | ** resources. |
| 2197 | */ |
| 2198 | OSErr pascal |
Guido van Rossum | 8ec9e63 | 1997-04-29 15:49:04 +0000 | [diff] [blame] | 2199 | init_tkinter_shlib(CFragInitBlockPtr data) |
Jack Jansen | 34cc5c3 | 1995-10-31 16:15:12 +0000 | [diff] [blame] | 2200 | { |
Guido van Rossum | c9970ee | 1996-08-26 14:37:15 +0000 | [diff] [blame] | 2201 | __initialize(); |
Jack Jansen | 34cc5c3 | 1995-10-31 16:15:12 +0000 | [diff] [blame] | 2202 | if ( data == nil ) return noErr; |
Guido van Rossum | 8ec9e63 | 1997-04-29 15:49:04 +0000 | [diff] [blame] | 2203 | if ( data->fragLocator.where == kDataForkCFragLocator ) { |
Jack Jansen | 34cc5c3 | 1995-10-31 16:15:12 +0000 | [diff] [blame] | 2204 | library_fss = *data->fragLocator.u.onDisk.fileSpec; |
| 2205 | loaded_from_shlib = 1; |
Guido van Rossum | 8ec9e63 | 1997-04-29 15:49:04 +0000 | [diff] [blame] | 2206 | } else if ( data->fragLocator.where == kResourceCFragLocator ) { |
Jack Jansen | 34cc5c3 | 1995-10-31 16:15:12 +0000 | [diff] [blame] | 2207 | library_fss = *data->fragLocator.u.inSegs.fileSpec; |
| 2208 | loaded_from_shlib = 1; |
| 2209 | } |
| 2210 | return noErr; |
| 2211 | } |
| 2212 | |
| 2213 | /* |
| 2214 | ** Insert the library resources into the search path. Put them after |
| 2215 | ** the resources from the application. Again, we ignore errors. |
| 2216 | */ |
Guido van Rossum | dfd428d | 1996-02-25 04:46:40 +0000 | [diff] [blame] | 2217 | static |
Jack Jansen | 34cc5c3 | 1995-10-31 16:15:12 +0000 | [diff] [blame] | 2218 | mac_addlibresources() |
| 2219 | { |
| 2220 | if ( !loaded_from_shlib ) |
| 2221 | return; |
| 2222 | (void)FSpOpenResFile(&library_fss, fsRdPerm); |
| 2223 | } |
| 2224 | |
Guido van Rossum | ec22c92 | 1996-02-25 04:50:29 +0000 | [diff] [blame] | 2225 | #endif /* GENERATINGCFM */ |
| 2226 | #endif /* macintosh */ |