Mercurial > cpython-lru_cache-weakref
annotate Modules/_tkinter.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 65d2d8e67da3 |
| children | d36250aefb82 |
| rev | line source |
|---|---|
| 3703 | 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 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
8 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
9 documentation for any purpose and without fee is hereby granted, |
| 3703 | 10 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
11 both that copyright notice and this permission notice appear in |
| 3703 | 12 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
13 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
14 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
15 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
16 permission. |
| 3703 | 17 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
18 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
19 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
20 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
21 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
22 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
23 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
24 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
25 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
26 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
27 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
28 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4299
diff
changeset
|
29 PERFORMANCE OF THIS SOFTWARE. |
| 3703 | 30 |
| 31 ******************************************************************/ | |
| 32 | |
| 33 /* _tkinter.c -- Interface to libtk.a and libtcl.a. */ | |
| 1664 | 34 |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
35 /* TCL/TK VERSION INFO: |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
36 |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
37 Unix: |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
38 This should work with any version from Tcl 4.0 / Tck 7.4. |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
39 Do not use older versions. |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
40 |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
41 Mac and Windows: |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
42 Use Tcl 4.1p1 / Tk 7.5p1 or possibly newer. |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
43 It does not seem to work reliably with the original 4.1/7.5 |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
44 release. (4.0/7.4 were never released for these platforms.) |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
45 */ |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
46 |
| 3120 | 47 #include "Python.h" |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
48 #include <ctype.h> |
| 3120 | 49 |
|
4079
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
50 #ifdef macintosh |
|
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
51 #define MAC_TCL |
|
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
52 #endif |
|
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
53 |
| 1664 | 54 #include <tcl.h> |
| 55 #include <tk.h> | |
| 56 | |
|
3899
584936890f86
getprogramname --> Py_GetProgramName
Guido van Rossum <guido@python.org>
parents:
3703
diff
changeset
|
57 extern char *Py_GetProgramName (); |
| 1713 | 58 |
| 3120 | 59 /* Internal declarations from tkInt.h. */ |
| 60 #if (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) >= 4001 | |
| 61 extern int Tk_GetNumMainWindows(); | |
| 62 #else | |
| 1664 | 63 extern int tk_NumMainWindows; |
| 3120 | 64 #define Tk_GetNumMainWindows() (tk_NumMainWindows) |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
65 #define NEED_TKCREATEMAINWINDOW 1 |
| 3120 | 66 #endif |
| 67 | |
| 68 #if TK_MAJOR_VERSION < 4 | |
| 1713 | 69 extern struct { Tk_Window win; } *tkMainWindowList; |
| 3120 | 70 #endif |
| 1664 | 71 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
72 #ifdef macintosh |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
73 |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
74 /* |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
75 ** Additional cruft needed by Tcl/Tk on the Mac. |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
76 ** This is for Tcl 7.5 and Tk 4.1 (patch release 1). |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
77 */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
78 |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
79 /* ckfree() expects a char* */ |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
80 #define FREECAST (char *) |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
81 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
82 #include <Events.h> /* For EventRecord */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
83 |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
84 typedef int (*TclMacConvertEventPtr) Py_PROTO((EventRecord *eventPtr)); |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
85 void TclMacSetEventProc Py_PROTO((TclMacConvertEventPtr procPtr)); |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
86 int TkMacConvertEvent Py_PROTO((EventRecord *eventPtr)); |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
87 |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
88 staticforward int PyMacConvertEvent Py_PROTO((EventRecord *eventPtr)); |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
89 |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
90 #endif /* macintosh */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
91 |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
92 #ifndef FREECAST |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
93 #define FREECAST (char *) |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
94 #endif |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
95 |
| 1664 | 96 /**** Tkapp Object Declaration ****/ |
| 97 | |
| 98 staticforward PyTypeObject Tkapp_Type; | |
| 99 | |
| 100 typedef struct | |
| 101 { | |
| 102 PyObject_HEAD | |
| 103 Tcl_Interp *interp; | |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
104 #ifdef NEED_TKCREATEMAINWINDOW |
| 1664 | 105 Tk_Window tkwin; |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
106 #endif |
| 1664 | 107 } |
| 108 TkappObject; | |
| 109 | |
| 110 #define Tkapp_Check(v) ((v)->ob_type == &Tkapp_Type) | |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
111 #ifdef NEED_TKCREATEMAINWINDOW |
| 1664 | 112 #define Tkapp_Tkwin(v) (((TkappObject *) (v))->tkwin) |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
113 #endif |
| 1664 | 114 #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) |
| 115 #define Tkapp_Result(v) (((TkappObject *) (v))->interp->result) | |
| 116 | |
| 117 #define DEBUG_REFCNT(v) (printf ("DEBUG: id=%p, refcnt=%i\n", \ | |
| 118 (void *) v, ((PyObject *) v)->ob_refcnt)) | |
| 119 | |
| 120 /**** Error Handling ****/ | |
| 121 | |
| 122 static PyObject *Tkinter_TclError; | |
| 1713 | 123 static int quitMainLoop = 0; |
| 1664 | 124 static int errorInCmd = 0; |
| 125 static PyObject *excInCmd; | |
| 126 static PyObject *valInCmd; | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
127 static PyObject *trbInCmd; |
| 1664 | 128 |
| 129 static PyObject * | |
| 130 Tkinter_Error (v) | |
| 131 PyObject *v; | |
| 132 { | |
| 133 PyErr_SetString (Tkinter_TclError, Tkapp_Result (v)); | |
| 134 return NULL; | |
| 135 } | |
| 136 | |
| 137 int | |
| 138 PythonCmd_Error (interp) | |
| 139 Tcl_Interp *interp; | |
| 140 { | |
| 141 errorInCmd = 1; | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
142 PyErr_Fetch (&excInCmd, &valInCmd, &trbInCmd); |
| 1664 | 143 return TCL_ERROR; |
| 144 } | |
| 145 | |
| 146 /**** Utils ****/ | |
| 147 | |
| 148 static char * | |
| 149 AsString (value, tmp) | |
| 150 PyObject *value; | |
| 151 PyObject *tmp; | |
| 152 { | |
| 153 if (PyString_Check (value)) | |
| 154 return PyString_AsString (value); | |
| 155 else | |
| 156 { | |
| 157 PyObject *v; | |
| 158 | |
|
2150
448435bfeadc
Made some more things static, and other cleanup for new naming scheme
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
159 v = PyObject_Str (value); |
| 1664 | 160 PyList_Append (tmp, v); |
| 161 Py_DECREF (v); | |
| 162 return PyString_AsString (v); | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 #define ARGSZ 64 | |
| 167 | |
| 168 static char * | |
| 169 Merge (args) | |
| 170 PyObject *args; | |
| 171 { | |
| 172 PyObject *tmp; | |
| 173 char *argvStore[ARGSZ]; | |
| 174 char **argv; | |
| 175 int fvStore[ARGSZ]; | |
| 176 int *fv; | |
| 177 int argc; | |
| 178 char *res; | |
| 179 int i; | |
| 180 | |
| 181 tmp = PyList_New (0); | |
| 182 argv = argvStore; | |
| 183 fv = fvStore; | |
| 184 | |
| 3703 | 185 if (args == NULL) |
| 186 { | |
| 187 argc = 0; | |
| 188 } | |
| 189 else if (!PyTuple_Check (args)) | |
| 1664 | 190 { |
| 191 argc = 1; | |
| 192 fv[0] = 0; | |
| 193 argv[0] = AsString (args, tmp); | |
| 194 } | |
| 195 else | |
| 196 { | |
| 197 PyObject *v; | |
| 198 | |
| 199 if (PyTuple_Size (args) > ARGSZ) | |
| 200 { | |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
201 argv = (char **) ckalloc (PyTuple_Size (args) * sizeof (char *)); |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
202 fv = (int *) ckalloc (PyTuple_Size (args) * sizeof (int)); |
| 1664 | 203 if (argv == NULL || fv == NULL) |
| 204 PyErr_NoMemory (); | |
| 205 } | |
| 206 | |
| 207 argc = PyTuple_Size (args); | |
| 208 for (i = 0; i < argc; i++) | |
| 209 { | |
| 210 v = PyTuple_GetItem (args, i); | |
| 211 if (PyTuple_Check (v)) | |
| 212 { | |
| 213 fv[i] = 1; | |
| 214 argv[i] = Merge (v); | |
| 215 } | |
| 216 else if (v == Py_None) | |
| 217 { | |
| 218 argc = i; | |
| 219 break; | |
| 220 } | |
| 221 else | |
| 222 { | |
| 223 fv[i] = 0; | |
| 224 argv[i] = AsString (v, tmp); | |
| 225 } | |
| 226 } | |
| 227 } | |
| 228 | |
| 229 res = Tcl_Merge (argc, argv); | |
| 230 | |
| 231 Py_DECREF (tmp); | |
| 232 for (i = 0; i < argc; i++) | |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
233 if (fv[i]) ckfree (argv[i]); |
| 1664 | 234 if (argv != argvStore) |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
235 ckfree (FREECAST argv); |
| 1664 | 236 if (fv != fvStore) |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
237 ckfree (FREECAST fv); |
| 1664 | 238 |
| 239 return res; | |
| 240 } | |
| 241 | |
| 242 static PyObject * | |
| 243 Split (self, list) | |
| 244 PyObject *self; | |
| 245 char *list; | |
| 246 { | |
| 247 int argc; | |
| 248 char **argv; | |
| 249 PyObject *v; | |
| 250 | |
| 251 if (list == NULL) | |
| 252 { | |
| 253 Py_INCREF (Py_None); | |
| 254 return Py_None; | |
| 255 } | |
| 256 | |
| 257 if (Tcl_SplitList (Tkapp_Interp (self), list, &argc, &argv) == TCL_ERROR) | |
| 258 return Tkinter_Error (self); | |
| 259 | |
| 260 if (argc == 0) | |
| 261 v = PyString_FromString (""); | |
| 262 else if (argc == 1) | |
| 263 v = PyString_FromString (argv[0]); | |
| 264 else | |
| 265 { | |
| 266 int i; | |
| 267 | |
| 268 v = PyTuple_New (argc); | |
| 269 for (i = 0; i < argc; i++) | |
| 270 PyTuple_SetItem (v, i, Split (self, argv[i])); | |
| 271 } | |
| 272 | |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
273 ckfree (FREECAST argv); |
| 1664 | 274 return v; |
| 275 } | |
| 276 | |
| 277 /**** Tkapp Object ****/ | |
| 278 | |
| 279 #ifndef WITH_APPINIT | |
| 280 int | |
| 281 Tcl_AppInit (interp) | |
| 282 Tcl_Interp *interp; | |
| 283 { | |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
284 Tk_Window main; |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
285 |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
286 main = Tk_MainWindow(interp); |
|
2300
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
287 if (Tcl_Init (interp) == TCL_ERROR) { |
|
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
288 fprintf(stderr, "Tcl_Init error: %s\n", interp->result); |
| 1664 | 289 return TCL_ERROR; |
|
2300
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
290 } |
|
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
291 if (Tk_Init (interp) == TCL_ERROR) { |
|
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
292 fprintf(stderr, "Tk_Init error: %s\n", interp->result); |
| 1664 | 293 return TCL_ERROR; |
|
2300
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
294 } |
| 1664 | 295 return TCL_OK; |
| 296 } | |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
297 |
| 1664 | 298 #endif /* !WITH_APPINIT */ |
| 299 | |
| 300 /* Initialize the Tk application; see the `main' function in | |
| 301 `tkMain.c'. */ | |
| 302 static TkappObject * | |
| 303 Tkapp_New (screenName, baseName, className, interactive) | |
| 304 char *screenName; | |
| 305 char *baseName; | |
| 306 char *className; | |
| 307 int interactive; | |
| 308 { | |
| 309 TkappObject *v; | |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
310 char *argv0; |
| 1664 | 311 |
| 312 v = PyObject_NEW (TkappObject, &Tkapp_Type); | |
| 313 if (v == NULL) | |
| 314 return NULL; | |
| 315 | |
| 316 v->interp = Tcl_CreateInterp (); | |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
317 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
318 #ifdef NEED_TKCREATEMAINWINDOW |
| 1664 | 319 v->tkwin = Tk_CreateMainWindow (v->interp, screenName, |
| 320 baseName, className); | |
| 321 if (v->tkwin == NULL) | |
| 322 return (TkappObject *) Tkinter_Error ((PyObject *) v); | |
| 323 | |
| 324 Tk_GeometryRequest (v->tkwin, 200, 200); | |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
325 #endif |
| 1664 | 326 |
| 327 if (screenName != NULL) | |
| 328 Tcl_SetVar2 (v->interp, "env", "DISPLAY", screenName, TCL_GLOBAL_ONLY); | |
| 329 | |
| 330 if (interactive) | |
| 331 Tcl_SetVar (v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); | |
| 332 else | |
| 333 Tcl_SetVar (v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); | |
| 334 | |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
335 /* This is used to get the application class for Tk 4.1 and up */ |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
336 argv0 = (char*) ckalloc (strlen (className) + 1); |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
337 if (argv0 != NULL) { |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
338 strcpy (argv0, className); |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
339 if (isupper (argv0[0])) |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
340 argv0[0] = tolower (argv0[0]); |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
341 Tcl_SetVar (v->interp, "argv0", argv0, TCL_GLOBAL_ONLY); |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
342 ckfree (argv0); |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
343 } |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
344 |
| 1664 | 345 if (Tcl_AppInit (v->interp) != TCL_OK) |
| 3703 | 346 return (TkappObject *) Tkinter_Error (v); |
| 1664 | 347 |
| 348 return v; | |
| 349 } | |
| 350 | |
| 351 /** Tcl Eval **/ | |
| 352 | |
| 353 static PyObject * | |
| 354 Tkapp_Call (self, args) | |
| 355 PyObject *self; | |
| 356 PyObject *args; | |
| 357 { | |
| 358 char *cmd; | |
| 359 | |
| 360 cmd = Merge (args); | |
| 361 if (Tcl_Eval (Tkapp_Interp (self), cmd) == TCL_ERROR) | |
| 362 { | |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
363 ckfree (cmd); |
| 1664 | 364 return Tkinter_Error (self); |
| 365 } | |
| 366 | |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
367 ckfree (cmd); |
| 1664 | 368 return PyString_FromString (Tkapp_Result (self)); |
| 369 } | |
| 370 | |
| 371 static PyObject * | |
| 372 Tkapp_GlobalCall (self, args) | |
| 373 PyObject *self; | |
| 374 PyObject *args; | |
| 375 { | |
| 376 char *cmd; | |
| 377 | |
| 378 cmd = Merge (args); | |
| 379 if (Tcl_GlobalEval (Tkapp_Interp (self), cmd) == TCL_ERROR) | |
| 380 { | |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
381 ckfree (cmd); |
| 1664 | 382 return Tkinter_Error (self); |
| 383 } | |
| 384 | |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
385 ckfree (cmd); |
| 1664 | 386 return PyString_FromString (Tkapp_Result (self)); |
| 387 } | |
| 388 | |
| 389 static PyObject * | |
| 390 Tkapp_Eval (self, args) | |
| 391 PyObject *self; | |
| 392 PyObject *args; | |
| 393 { | |
| 394 char *script; | |
| 395 | |
| 396 if (!PyArg_Parse (args, "s", &script)) | |
| 397 return NULL; | |
| 398 | |
| 399 if (Tcl_Eval (Tkapp_Interp (self), script) == TCL_ERROR) | |
| 400 return Tkinter_Error (self); | |
| 401 | |
| 402 return PyString_FromString (Tkapp_Result (self)); | |
| 403 } | |
| 404 | |
| 405 static PyObject * | |
| 406 Tkapp_GlobalEval (self, args) | |
| 407 PyObject *self; | |
| 408 PyObject *args; | |
| 409 { | |
| 410 char *script; | |
| 411 | |
| 412 if (!PyArg_Parse (args, "s", &script)) | |
| 413 return NULL; | |
| 414 | |
| 415 if (Tcl_GlobalEval (Tkapp_Interp (self), script) == TCL_ERROR) | |
| 416 return Tkinter_Error (self); | |
| 417 | |
| 418 return PyString_FromString (Tkapp_Result (self)); | |
| 419 } | |
| 420 | |
| 421 static PyObject * | |
| 422 Tkapp_EvalFile (self, args) | |
| 423 PyObject *self; | |
| 424 PyObject *args; | |
| 425 { | |
| 426 char *fileName; | |
| 427 | |
| 428 if (!PyArg_Parse (args, "s", &fileName)) | |
| 429 return NULL; | |
| 430 | |
| 431 if (Tcl_EvalFile (Tkapp_Interp (self), fileName) == TCL_ERROR) | |
| 432 return Tkinter_Error (self); | |
| 433 | |
| 434 return PyString_FromString (Tkapp_Result (self)); | |
| 435 } | |
| 436 | |
| 437 static PyObject * | |
| 438 Tkapp_Record (self, args) | |
| 439 PyObject *self; | |
| 440 PyObject *args; | |
| 441 { | |
| 442 char *script; | |
| 443 | |
| 444 if (!PyArg_Parse (args, "s", &script)) | |
| 445 return NULL; | |
| 446 | |
| 447 if (Tcl_RecordAndEval (Tkapp_Interp (self), | |
| 448 script, TCL_NO_EVAL) == TCL_ERROR) | |
| 449 return Tkinter_Error (self); | |
| 450 | |
| 451 return PyString_FromString (Tkapp_Result (self)); | |
| 452 } | |
| 453 | |
| 454 static PyObject * | |
| 455 Tkapp_AddErrorInfo (self, args) | |
| 456 PyObject *self; | |
| 457 PyObject *args; | |
| 458 { | |
| 459 char *msg; | |
| 460 | |
| 461 if (!PyArg_Parse (args, "s", &msg)) | |
| 462 return NULL; | |
| 463 Tcl_AddErrorInfo (Tkapp_Interp (self), msg); | |
| 464 | |
| 465 Py_INCREF(Py_None); | |
| 466 return Py_None; | |
| 467 } | |
| 468 | |
| 469 /** Tcl Variable **/ | |
| 470 | |
| 471 static PyObject * | |
| 472 SetVar (self, args, flags) | |
| 473 PyObject *self; | |
| 474 PyObject *args; | |
| 475 int flags; | |
| 476 { | |
| 477 char *name1, *name2, *ok; | |
| 478 PyObject *newValue; | |
| 479 PyObject *tmp; | |
| 480 | |
| 481 tmp = PyList_New (0); | |
| 482 | |
| 483 if (PyArg_Parse (args, "(sO)", &name1, &newValue)) | |
| 484 ok = Tcl_SetVar (Tkapp_Interp (self), name1, | |
| 485 AsString (newValue, tmp), flags); /* XXX Merge? */ | |
| 486 else if (PyArg_Parse (args, "(ssO)", &name1, &name2, &newValue)) | |
| 487 ok = Tcl_SetVar2 (Tkapp_Interp (self), name1, name2, | |
| 488 AsString (newValue, tmp), flags); | |
| 489 else | |
| 490 { | |
| 491 Py_DECREF (tmp); | |
| 492 return NULL; | |
| 493 } | |
| 494 Py_DECREF (tmp); | |
| 495 | |
| 496 if (!ok) | |
| 497 return Tkinter_Error (self); | |
| 498 | |
| 499 Py_INCREF (Py_None); | |
| 500 return Py_None; | |
| 501 } | |
| 502 | |
| 503 static PyObject * | |
| 504 Tkapp_SetVar (self, args) | |
| 505 PyObject *self; | |
| 506 PyObject *args; | |
| 507 { | |
| 508 return SetVar (self, args, TCL_LEAVE_ERR_MSG); | |
| 509 } | |
| 510 | |
| 511 static PyObject * | |
| 512 Tkapp_GlobalSetVar (self, args) | |
| 513 PyObject *self; | |
| 514 PyObject *args; | |
| 515 { | |
| 516 return SetVar (self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); | |
| 517 } | |
| 518 | |
| 519 static PyObject * | |
| 520 GetVar (self, args, flags) | |
| 521 PyObject *self; | |
| 522 PyObject *args; | |
| 523 int flags; | |
| 524 { | |
| 525 char *name1, *name2, *s; | |
| 526 | |
| 527 if (PyArg_Parse (args, "s", &name1)) | |
| 528 s = Tcl_GetVar (Tkapp_Interp (self), name1, flags); | |
| 529 else if (PyArg_Parse (args, "(ss)", &name1, &name2)) | |
| 530 s = Tcl_GetVar2 (Tkapp_Interp (self), name1, name2, flags); | |
| 531 else | |
| 532 return NULL; | |
| 533 | |
| 534 if (s == NULL) | |
| 535 return Tkinter_Error (self); | |
| 536 | |
| 537 return PyString_FromString (s); | |
| 538 } | |
| 539 | |
| 540 static PyObject * | |
| 541 Tkapp_GetVar (self, args) | |
| 542 PyObject *self; | |
| 543 PyObject *args; | |
| 544 { | |
| 545 return GetVar (self, args, TCL_LEAVE_ERR_MSG); | |
| 546 } | |
| 547 | |
| 548 static PyObject * | |
| 549 Tkapp_GlobalGetVar (self, args) | |
| 550 PyObject *self; | |
| 551 PyObject *args; | |
| 552 { | |
| 553 return GetVar (self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); | |
| 554 } | |
| 555 | |
| 556 static PyObject * | |
| 557 UnsetVar (self, args, flags) | |
| 558 PyObject *self; | |
| 559 PyObject *args; | |
| 560 int flags; | |
| 561 { | |
| 562 char *name1, *name2; | |
| 563 int code; | |
| 564 | |
| 565 if (PyArg_Parse (args, "s", &name1)) | |
| 566 code = Tcl_UnsetVar (Tkapp_Interp (self), name1, flags); | |
| 567 else if (PyArg_Parse (args, "(ss)", &name1, &name2)) | |
| 568 code = Tcl_UnsetVar2 (Tkapp_Interp (self), name1, name2, flags); | |
| 569 else | |
| 570 return NULL; | |
| 571 | |
| 572 if (code == TCL_ERROR) | |
| 573 return Tkinter_Error (self); | |
| 574 | |
| 575 Py_INCREF (Py_None); | |
| 576 return Py_None; | |
| 577 } | |
| 578 | |
| 579 static PyObject * | |
| 580 Tkapp_UnsetVar (self, args) | |
| 581 PyObject *self; | |
| 582 PyObject *args; | |
| 583 { | |
| 584 return UnsetVar (self, args, TCL_LEAVE_ERR_MSG); | |
| 585 } | |
| 586 | |
| 587 static PyObject * | |
| 588 Tkapp_GlobalUnsetVar (self, args) | |
| 589 PyObject *self; | |
| 590 PyObject *args; | |
| 591 { | |
| 592 return UnsetVar (self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); | |
| 593 } | |
| 594 | |
| 595 /** Tcl to Python **/ | |
| 596 | |
| 597 static PyObject * | |
| 598 Tkapp_GetInt (self, args) | |
| 599 PyObject *self; | |
| 600 PyObject *args; | |
| 601 { | |
| 602 char *s; | |
| 603 int v; | |
| 604 | |
| 605 if (!PyArg_Parse (args, "s", &s)) | |
| 606 return NULL; | |
| 607 if (Tcl_GetInt (Tkapp_Interp (self), s, &v) == TCL_ERROR) | |
| 608 return Tkinter_Error (self); | |
| 609 return Py_BuildValue ("i", v); | |
| 610 } | |
| 611 | |
| 612 static PyObject * | |
| 613 Tkapp_GetDouble (self, args) | |
| 614 PyObject *self; | |
| 615 PyObject *args; | |
| 616 { | |
| 617 char *s; | |
| 618 double v; | |
| 619 | |
| 620 if (!PyArg_Parse (args, "s", &s)) | |
| 621 return NULL; | |
| 622 if (Tcl_GetDouble (Tkapp_Interp (self), s, &v) == TCL_ERROR) | |
| 623 return Tkinter_Error (self); | |
| 624 return Py_BuildValue ("d", v); | |
| 625 } | |
| 626 | |
| 627 static PyObject * | |
| 628 Tkapp_GetBoolean (self, args) | |
| 629 PyObject *self; | |
| 630 PyObject *args; | |
| 631 { | |
| 632 char *s; | |
| 633 int v; | |
| 634 | |
| 635 if (!PyArg_Parse (args, "s", &s)) | |
| 636 return NULL; | |
| 637 if (Tcl_GetBoolean (Tkapp_Interp (self), s, &v) == TCL_ERROR) | |
| 638 return Tkinter_Error (self); | |
| 639 return Py_BuildValue ("i", v); | |
| 640 } | |
| 641 | |
| 642 static PyObject * | |
| 643 Tkapp_ExprString (self, args) | |
| 644 PyObject *self; | |
| 645 PyObject *args; | |
| 646 { | |
| 647 char *s; | |
| 648 | |
| 649 if (!PyArg_Parse (args, "s", &s)) | |
| 650 return NULL; | |
| 651 if (Tcl_ExprString (Tkapp_Interp (self), s) == TCL_ERROR) | |
| 652 return Tkinter_Error (self); | |
| 653 return Py_BuildValue ("s", Tkapp_Result (self)); | |
| 654 } | |
| 655 | |
| 656 static PyObject * | |
| 657 Tkapp_ExprLong (self, args) | |
| 658 PyObject *self; | |
| 659 PyObject *args; | |
| 660 { | |
| 661 char *s; | |
| 662 long v; | |
| 663 | |
| 664 if (!PyArg_Parse (args, "s", &s)) | |
| 665 return NULL; | |
| 666 if (Tcl_ExprLong (Tkapp_Interp (self), s, &v) == TCL_ERROR) | |
| 667 return Tkinter_Error (self); | |
| 668 return Py_BuildValue ("l", v); | |
| 669 } | |
| 670 | |
| 671 static PyObject * | |
| 672 Tkapp_ExprDouble (self, args) | |
| 673 PyObject *self; | |
| 674 PyObject *args; | |
| 675 { | |
| 676 char *s; | |
| 677 double v; | |
| 678 | |
| 679 if (!PyArg_Parse (args, "s", &s)) | |
| 680 return NULL; | |
| 681 if (Tcl_ExprDouble (Tkapp_Interp (self), s, &v) == TCL_ERROR) | |
| 682 return Tkinter_Error (self); | |
| 683 return Py_BuildValue ("d", v); | |
| 684 } | |
| 685 | |
| 686 static PyObject * | |
| 687 Tkapp_ExprBoolean (self, args) | |
| 688 PyObject *self; | |
| 689 PyObject *args; | |
| 690 { | |
| 691 char *s; | |
| 692 int v; | |
| 693 | |
| 694 if (!PyArg_Parse (args, "s", &s)) | |
| 695 return NULL; | |
| 696 if (Tcl_ExprBoolean (Tkapp_Interp (self), s, &v) == TCL_ERROR) | |
| 697 return Tkinter_Error (self); | |
| 698 return Py_BuildValue ("i", v); | |
| 699 } | |
| 700 | |
| 701 static PyObject * | |
| 702 Tkapp_SplitList (self, args) | |
| 703 PyObject *self; | |
| 704 PyObject *args; | |
| 705 { | |
| 706 char *list; | |
| 707 int argc; | |
| 708 char **argv; | |
| 709 PyObject *v; | |
| 710 int i; | |
| 711 | |
| 712 if (!PyArg_Parse (args, "s", &list)) | |
| 713 return NULL; | |
| 714 | |
| 715 if (Tcl_SplitList (Tkapp_Interp (self), list, &argc, &argv) == TCL_ERROR) | |
| 716 return Tkinter_Error (self); | |
| 717 | |
| 718 v = PyTuple_New (argc); | |
| 719 for (i = 0; i < argc; i++) | |
| 720 PyTuple_SetItem (v, i, PyString_FromString (argv[i])); | |
| 721 | |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
722 ckfree (FREECAST argv); |
| 1664 | 723 return v; |
| 724 } | |
| 725 | |
| 726 static PyObject * | |
| 727 Tkapp_Split (self, args) | |
| 728 PyObject *self; | |
| 729 PyObject *args; | |
| 730 { | |
| 731 char *list; | |
| 732 | |
| 733 if (!PyArg_Parse (args, "s", &list)) | |
| 734 return NULL; | |
| 735 return Split (self, list); | |
| 736 } | |
| 737 | |
| 738 static PyObject * | |
| 739 Tkapp_Merge (self, args) | |
| 740 PyObject *self; | |
| 741 PyObject *args; | |
| 742 { | |
| 743 char *s; | |
| 744 PyObject *v; | |
| 745 | |
| 746 s = Merge (args); | |
| 747 v = PyString_FromString (s); | |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
748 ckfree (s); |
| 1664 | 749 return v; |
| 750 } | |
| 751 | |
| 752 /** Tcl Command **/ | |
| 753 | |
| 754 /* This is the Tcl command that acts as a wrapper for Python | |
| 755 function or method. */ | |
| 756 static int | |
| 757 PythonCmd (clientData, interp, argc, argv) | |
| 758 ClientData clientData; /* Is (self, func) */ | |
| 759 Tcl_Interp *interp; | |
| 760 int argc; | |
| 761 char *argv[]; | |
| 762 { | |
| 763 PyObject *self, *func, *arg, *res, *tmp; | |
| 764 int i; | |
| 765 | |
| 766 self = PyTuple_GetItem ((PyObject *) clientData, 0); | |
| 767 func = PyTuple_GetItem ((PyObject *) clientData, 1); | |
| 768 | |
| 769 /* Create argument list (argv1, ..., argvN) */ | |
| 770 arg = PyTuple_New (argc - 1); | |
| 771 for (i = 0; i < (argc - 1); i++) | |
| 772 PyTuple_SetItem (arg, i, PyString_FromString (argv[i + 1])); | |
| 773 | |
| 774 res = PyEval_CallObject (func, arg); | |
| 775 Py_DECREF (arg); | |
| 1713 | 776 |
| 1664 | 777 if (res == NULL) |
| 778 return PythonCmd_Error (interp); | |
| 779 | |
| 780 tmp = PyList_New (0); | |
| 781 Tcl_SetResult (Tkapp_Interp (self), AsString (res, tmp), TCL_VOLATILE); | |
| 782 Py_DECREF (res); | |
| 783 Py_DECREF (tmp); | |
| 784 | |
| 785 return TCL_OK; | |
| 786 } | |
| 787 | |
| 788 static void | |
| 789 PythonCmdDelete (clientData) | |
| 790 ClientData clientData; /* Is (self, func) */ | |
| 791 { | |
| 792 Py_DECREF ((PyObject *) clientData); | |
| 793 } | |
| 794 | |
| 795 static PyObject * | |
| 796 Tkapp_CreateCommand (self, args) | |
| 797 PyObject *self; | |
| 798 PyObject *args; | |
| 799 { | |
| 800 char *cmdName; | |
| 801 PyObject *data; | |
| 802 PyObject *func; | |
| 803 | |
| 804 /* Args is: (cmdName, func) */ | |
| 805 if (!PyTuple_Check (args) | |
| 806 || !(PyTuple_Size (args) == 2) | |
| 807 || !PyString_Check (PyTuple_GetItem (args, 0)) | |
|
2300
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
808 || !PyCallable_Check (PyTuple_GetItem (args, 1))) |
| 1664 | 809 { |
| 810 PyErr_SetString (PyExc_TypeError, "bad argument list"); | |
| 811 return NULL; | |
| 812 } | |
| 813 | |
| 814 cmdName = PyString_AsString (PyTuple_GetItem (args, 0)); | |
| 815 func = PyTuple_GetItem (args, 1); | |
| 816 | |
| 817 data = PyTuple_New (2); /* ClientData is: (self, func) */ | |
| 818 | |
| 819 Py_INCREF (self); | |
| 820 PyTuple_SetItem (data, 0, self); | |
| 821 | |
| 822 Py_INCREF (func); | |
| 823 PyTuple_SetItem (data, 1, func); | |
| 824 | |
| 825 Tcl_CreateCommand (Tkapp_Interp (self), cmdName, PythonCmd, | |
| 826 (ClientData) data, PythonCmdDelete); | |
| 827 | |
| 828 Py_INCREF (Py_None); | |
| 829 return Py_None; | |
| 830 } | |
| 831 | |
| 832 static PyObject * | |
| 833 Tkapp_DeleteCommand (self, args) | |
| 834 PyObject *self; | |
| 835 PyObject *args; | |
| 836 { | |
| 837 char *cmdName; | |
| 838 | |
| 839 if (!PyArg_Parse (args, "s", &cmdName)) | |
| 840 return NULL; | |
| 841 if (Tcl_DeleteCommand (Tkapp_Interp (self), cmdName) == -1) | |
| 842 { | |
| 843 PyErr_SetString (Tkinter_TclError, "can't delete Tcl command"); | |
| 844 return NULL; | |
| 845 } | |
| 846 Py_INCREF (Py_None); | |
| 847 return Py_None; | |
| 848 } | |
| 849 | |
| 850 /** File Handler **/ | |
| 851 | |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2121
diff
changeset
|
852 static void |
| 1664 | 853 FileHandler (clientData, mask) |
|
1690
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
854 ClientData clientData; /* Is: (func, file) */ |
| 1664 | 855 int mask; |
| 856 { | |
|
1690
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
857 PyObject *func, *file, *arg, *res; |
| 1664 | 858 |
|
1690
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
859 func = PyTuple_GetItem ((PyObject *) clientData, 0); |
|
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
860 file = PyTuple_GetItem ((PyObject *) clientData, 1); |
| 1664 | 861 |
|
1690
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
862 arg = Py_BuildValue ("(Oi)", file, (long) mask); |
| 1664 | 863 res = PyEval_CallObject (func, arg); |
| 864 Py_DECREF (arg); | |
| 865 if (res == NULL) | |
| 866 { | |
| 867 errorInCmd = 1; | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
868 PyErr_Fetch (&excInCmd, &valInCmd, &trbInCmd); |
| 1664 | 869 } |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
870 Py_XDECREF (res); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
871 } |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
872 |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
873 static int |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
874 GetFileNo (file) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
875 PyObject *file; /* Either an int >= 0 or an object with a |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
876 .fileno() method that returns an int >= 0 */ |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
877 { |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2121
diff
changeset
|
878 PyObject *meth, *args, *res; |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
879 int id; |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
880 if (PyInt_Check(file)) { |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
881 id = PyInt_AsLong(file); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
882 if (id < 0) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
883 PyErr_SetString(PyExc_ValueError, "invalid file id"); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
884 return id; |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
885 } |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
886 meth = PyObject_GetAttrString(file, "fileno"); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
887 if (meth == NULL) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
888 return -1; |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
889 args = PyTuple_New(0); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
890 if (args == NULL) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
891 return -1; |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
892 res = PyEval_CallObject(meth, args); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
893 Py_DECREF(args); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
894 Py_DECREF(meth); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
895 if (res == NULL) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
896 return -1; |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
897 if (PyInt_Check(res)) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
898 id = PyInt_AsLong(res); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
899 else |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
900 id = -1; |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
901 if (id < 0) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
902 PyErr_SetString(PyExc_ValueError, |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
903 "invalid fileno() return value"); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
904 Py_DECREF(res); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
905 return id; |
| 1664 | 906 } |
| 907 | |
| 908 static PyObject * | |
| 909 Tkapp_CreateFileHandler (self, args) | |
| 910 PyObject *self; | |
| 911 PyObject *args; /* Is (file, mask, func) */ | |
| 912 { | |
|
1690
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
913 PyObject *file, *func, *data; |
|
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
914 int mask, id; |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
915 #if (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) >= 4001 |
|
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
916 Tcl_File tfile; |
|
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
917 #endif |
| 1664 | 918 |
| 919 if (!PyArg_Parse (args, "(OiO)", &file, &mask, &func)) | |
| 920 return NULL; | |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
921 id = GetFileNo (file); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
922 if (id < 0) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
923 return NULL; |
|
2300
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
924 if (!PyCallable_Check(func)) |
| 1664 | 925 { |
| 926 PyErr_SetString (PyExc_TypeError, "bad argument list"); | |
| 927 return NULL; | |
| 928 } | |
| 929 | |
|
1690
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
930 /* ClientData is: (func, file) */ |
|
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
931 data = Py_BuildValue ("(OO)", func, file); |
|
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
932 |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
933 #if (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) >= 4001 |
|
4299
eb1ed743972c
Rationalize MS #ifdefs
Guido van Rossum <guido@python.org>
parents:
4139
diff
changeset
|
934 #ifdef MS_WINDOWS |
| 3703 | 935 /* We assume this is a socket... */ |
| 936 tfile = Tcl_GetFile((ClientData)id, TCL_WIN_SOCKET); | |
| 937 #else | |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
938 tfile = Tcl_GetFile((ClientData)id, TCL_UNIX_FD); |
| 3703 | 939 #endif |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
940 /* Oughtta check for null Tcl_File object... */ |
|
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
941 Tcl_CreateFileHandler (tfile, mask, FileHandler, (ClientData) data); |
|
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
942 #else |
| 3703 | 943 Tk_CreateFileHandler (id, mask, FileHandler, (ClientData) data); |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
944 #endif |
| 1664 | 945 /* XXX fileHandlerDict */ |
|
1690
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
946 |
| 1664 | 947 Py_INCREF (Py_None); |
| 948 return Py_None; | |
| 949 } | |
| 950 | |
| 951 static PyObject * | |
| 952 Tkapp_DeleteFileHandler (self, args) | |
| 953 PyObject *self; | |
| 954 PyObject *args; /* Args: file */ | |
| 955 { | |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
956 PyObject *file; |
| 1664 | 957 int id; |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
958 #if (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) >= 4001 |
|
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
959 Tcl_File tfile; |
|
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
960 #endif |
|
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
961 |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
962 if (!PyArg_Parse (args, "O", &file)) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
963 return NULL; |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
964 id = GetFileNo (file); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
965 if (id < 0) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
966 return NULL; |
| 1664 | 967 |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
968 #if (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) >= 4001 |
|
4299
eb1ed743972c
Rationalize MS #ifdefs
Guido van Rossum <guido@python.org>
parents:
4139
diff
changeset
|
969 #ifdef MS_WINDOWS |
| 3703 | 970 /* We assume this is a socket... */ |
| 971 tfile = Tcl_GetFile((ClientData)id, TCL_WIN_SOCKET); | |
| 972 #else | |
| 973 tfile = Tcl_GetFile((ClientData)id, TCL_UNIX_FD); | |
| 974 #endif | |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
975 /* Oughtta check for null Tcl_File object... */ |
|
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
976 Tcl_DeleteFileHandler(tfile); |
|
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
977 #else |
| 3703 | 978 Tk_DeleteFileHandler (id); |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
979 #endif |
| 1664 | 980 /* XXX fileHandlerDict */ |
| 981 Py_INCREF (Py_None); | |
| 982 return Py_None; | |
| 983 } | |
| 984 | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
985 /**** Tktt Object (timer token) ****/ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
986 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
987 staticforward PyTypeObject Tktt_Type; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
988 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
989 typedef struct |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
990 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
991 PyObject_HEAD |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
992 Tk_TimerToken token; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
993 PyObject *func; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
994 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
995 TkttObject; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
996 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
997 static PyObject * |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
998 Tktt_DeleteTimerHandler (self, args) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
999 PyObject *self; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1000 PyObject *args; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1001 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1002 TkttObject *v = (TkttObject *) self; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1003 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1004 if (!PyArg_Parse (args, "")) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1005 return NULL; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1006 if (v->func != NULL) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1007 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1008 Tk_DeleteTimerHandler (v->token); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1009 PyMem_DEL (v->func); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1010 v->func = NULL; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1011 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1012 Py_INCREF (Py_None); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1013 return Py_None; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1014 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1015 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1016 static PyMethodDef Tktt_methods[] = |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1017 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1018 {"deletetimerhandler", Tktt_DeleteTimerHandler}, |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1019 {NULL, NULL} |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1020 }; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1021 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1022 static TkttObject * |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1023 Tktt_New (token, func) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1024 Tk_TimerToken token; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1025 PyObject *func; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1026 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1027 TkttObject *v; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1028 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1029 v = PyObject_NEW (TkttObject, &Tktt_Type); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1030 if (v == NULL) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1031 return NULL; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1032 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1033 v->token = token; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1034 v->func = func; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1035 Py_INCREF (v->func); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1036 return v; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1037 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1038 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1039 static void |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1040 Tktt_Dealloc (self) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1041 PyObject *self; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1042 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1043 PyMem_DEL (self); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1044 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1045 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1046 static int |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1047 Tktt_Print (self, fp, flags) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1048 PyObject *self; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1049 FILE *fp; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1050 int flags; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1051 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1052 TkttObject *v = (TkttObject *) self; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1053 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1054 fprintf(fp, "<tktimertoken at 0x%x%s>", v, |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1055 v->func == NULL ? ", handler deleted" : ""); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1056 return 0; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1057 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1058 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1059 static PyObject * |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1060 Tktt_GetAttr (self, name) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1061 PyObject *self; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1062 char *name; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1063 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1064 return Py_FindMethod (Tktt_methods, self, name); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1065 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1066 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1067 static PyTypeObject Tktt_Type = |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1068 { |
|
4091
dc946cab7b9b
Hacks to support being a Windows DLL
Guido van Rossum <guido@python.org>
parents:
4079
diff
changeset
|
1069 PyObject_HEAD_INIT (NULL) |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1070 0, /*ob_size */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1071 "tktimertoken", /*tp_name */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1072 sizeof (TkttObject), /*tp_basicsize */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1073 0, /*tp_itemsize */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1074 Tktt_Dealloc, /*tp_dealloc */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1075 Tktt_Print, /*tp_print */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1076 Tktt_GetAttr, /*tp_getattr */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1077 0, /*tp_setattr */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1078 0, /*tp_compare */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1079 0, /*tp_repr */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1080 0, /*tp_as_number */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1081 0, /*tp_as_sequence */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1082 0, /*tp_as_mapping */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1083 0, /*tp_hash */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1084 }; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1085 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1086 /** Timer Handler **/ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1087 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1088 static void |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1089 TimerHandler (clientData) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1090 ClientData clientData; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1091 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1092 PyObject *func = (PyObject *) clientData; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1093 PyObject *arg, *res; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1094 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1095 arg = PyTuple_New (0); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1096 res = PyEval_CallObject (func, arg); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1097 Py_DECREF (arg); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1098 if (res == NULL) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1099 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1100 errorInCmd = 1; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
1101 PyErr_Fetch (&excInCmd, &valInCmd, &trbInCmd); |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1102 } |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
1103 else |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
1104 Py_DECREF (res); |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1105 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1106 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1107 static PyObject * |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1108 Tkapp_CreateTimerHandler (self, args) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1109 PyObject *self; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1110 PyObject *args; /* Is (milliseconds, func) */ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1111 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1112 int milliseconds; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1113 PyObject *func; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1114 Tk_TimerToken token; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1115 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1116 if (!PyArg_Parse (args, "(iO)", &milliseconds, &func)) |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1117 return NULL; |
|
2300
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1118 if (!PyCallable_Check(func)) |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1119 { |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1120 PyErr_SetString (PyExc_TypeError, "bad argument list"); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1121 return NULL; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1122 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1123 token = Tk_CreateTimerHandler(milliseconds, TimerHandler, (ClientData) func); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1124 return (PyObject *) Tktt_New (token, func); |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1125 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1126 |
| 1664 | 1127 /** Event Loop **/ |
| 1128 | |
| 1129 static PyObject * | |
| 1130 Tkapp_MainLoop (self, args) | |
| 1131 PyObject *self; | |
| 1132 PyObject *args; | |
| 1133 { | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1134 int threshold = 0; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1135 |
|
2858
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1136 if (!PyArg_ParseTuple (args, "|i", &threshold)) |
|
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1137 return NULL; |
| 1664 | 1138 |
| 1139 quitMainLoop = 0; | |
| 3120 | 1140 while (Tk_GetNumMainWindows() > threshold && !quitMainLoop && !errorInCmd) |
| 1664 | 1141 { |
| 1142 if (PyOS_InterruptOccurred ()) | |
| 1143 { | |
| 1144 PyErr_SetNone (PyExc_KeyboardInterrupt); | |
| 1145 return NULL; | |
| 1146 } | |
| 1147 Tk_DoOneEvent (0); | |
| 1148 } | |
|
3134
2677fbb117d6
clear quitMainLoop when we fall through the main loop
Guido van Rossum <guido@python.org>
parents:
3120
diff
changeset
|
1149 quitMainLoop = 0; |
| 1664 | 1150 |
| 1151 if (errorInCmd) | |
| 1152 { | |
| 1153 errorInCmd = 0; | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
1154 PyErr_Restore (excInCmd, valInCmd, trbInCmd); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
1155 excInCmd = valInCmd = trbInCmd = NULL; |
| 1664 | 1156 return NULL; |
| 1157 } | |
| 1158 Py_INCREF (Py_None); | |
| 1159 return Py_None; | |
| 1160 } | |
| 1161 | |
| 1162 static PyObject * | |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1163 Tkapp_DoOneEvent (self, args) |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1164 PyObject *self; |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1165 PyObject *args; |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1166 { |
|
2858
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1167 int flags = TK_ALL_EVENTS; |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1168 int rv; |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1169 |
|
2858
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1170 if (!PyArg_ParseTuple (args, "|i", &flags)) |
|
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1171 return NULL; |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1172 rv = Tk_DoOneEvent(flags); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1173 return Py_BuildValue ("i", rv); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1174 } |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1175 |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1176 static PyObject * |
| 1664 | 1177 Tkapp_Quit (self, args) |
| 1178 PyObject *self; | |
| 1179 PyObject *args; | |
| 1180 { | |
| 1181 | |
| 1182 if (!PyArg_Parse (args, "")) | |
| 1183 return NULL; | |
| 1184 quitMainLoop = 1; | |
| 1185 Py_INCREF (Py_None); | |
| 1186 return Py_None; | |
| 1187 } | |
| 1188 | |
| 1189 /**** Tkapp Method List ****/ | |
| 1190 | |
| 1191 static PyMethodDef Tkapp_methods[] = | |
| 1192 { | |
| 1193 {"call", Tkapp_Call}, | |
| 1194 {"globalcall", Tkapp_GlobalCall}, | |
| 1195 {"eval", Tkapp_Eval}, | |
| 1196 {"globaleval", Tkapp_GlobalEval}, | |
| 1197 {"evalfile", Tkapp_EvalFile}, | |
| 1198 {"record", Tkapp_Record}, | |
| 1199 {"adderrorinfo", Tkapp_AddErrorInfo}, | |
| 1200 {"setvar", Tkapp_SetVar}, | |
| 1201 {"globalsetvar", Tkapp_GlobalSetVar}, | |
| 1202 {"getvar", Tkapp_GetVar}, | |
| 1203 {"globalgetvar", Tkapp_GlobalGetVar}, | |
| 1204 {"unsetvar", Tkapp_UnsetVar}, | |
| 1205 {"globalunsetvar", Tkapp_GlobalUnsetVar}, | |
| 1206 {"getint", Tkapp_GetInt}, | |
| 1207 {"getdouble", Tkapp_GetDouble}, | |
| 1208 {"getboolean", Tkapp_GetBoolean}, | |
| 1209 {"exprstring", Tkapp_ExprString}, | |
| 1210 {"exprlong", Tkapp_ExprLong}, | |
| 1211 {"exprdouble", Tkapp_ExprDouble}, | |
| 1212 {"exprboolean", Tkapp_ExprBoolean}, | |
| 1213 {"splitlist", Tkapp_SplitList}, | |
| 1214 {"split", Tkapp_Split}, | |
| 1215 {"merge", Tkapp_Merge}, | |
| 1216 {"createcommand", Tkapp_CreateCommand}, | |
| 1217 {"deletecommand", Tkapp_DeleteCommand}, | |
| 1218 {"createfilehandler", Tkapp_CreateFileHandler}, | |
| 1219 {"deletefilehandler", Tkapp_DeleteFileHandler}, | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1220 {"createtimerhandler", Tkapp_CreateTimerHandler}, |
|
2858
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1221 {"mainloop", Tkapp_MainLoop, 1}, |
|
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1222 {"dooneevent", Tkapp_DoOneEvent, 1}, |
| 1664 | 1223 {"quit", Tkapp_Quit}, |
| 1224 {NULL, NULL} | |
| 1225 }; | |
| 1226 | |
| 1227 /**** Tkapp Type Methods ****/ | |
| 1228 | |
| 1229 static void | |
| 1230 Tkapp_Dealloc (self) | |
| 1231 PyObject *self; | |
| 1232 { | |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1233 #ifdef NEED_TKCREATEMAINWINDOW |
| 1664 | 1234 Tk_DestroyWindow (Tkapp_Tkwin (self)); |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1235 #endif |
| 1664 | 1236 Tcl_DeleteInterp (Tkapp_Interp (self)); |
| 1237 PyMem_DEL (self); | |
| 1238 } | |
| 1239 | |
| 1240 static PyObject * | |
| 1241 Tkapp_GetAttr (self, name) | |
| 1242 PyObject *self; | |
| 1243 char *name; | |
| 1244 { | |
| 1245 return Py_FindMethod (Tkapp_methods, self, name); | |
| 1246 } | |
| 1247 | |
| 1248 static PyTypeObject Tkapp_Type = | |
| 1249 { | |
|
4091
dc946cab7b9b
Hacks to support being a Windows DLL
Guido van Rossum <guido@python.org>
parents:
4079
diff
changeset
|
1250 PyObject_HEAD_INIT (NULL) |
| 1664 | 1251 0, /*ob_size */ |
| 1252 "tkapp", /*tp_name */ | |
| 1253 sizeof (TkappObject), /*tp_basicsize */ | |
| 1254 0, /*tp_itemsize */ | |
| 1255 Tkapp_Dealloc, /*tp_dealloc */ | |
| 1256 0, /*tp_print */ | |
| 1257 Tkapp_GetAttr, /*tp_getattr */ | |
| 1258 0, /*tp_setattr */ | |
| 1259 0, /*tp_compare */ | |
| 1260 0, /*tp_repr */ | |
| 1261 0, /*tp_as_number */ | |
| 1262 0, /*tp_as_sequence */ | |
| 1263 0, /*tp_as_mapping */ | |
| 1264 0, /*tp_hash */ | |
| 1265 }; | |
| 1266 | |
| 1267 /**** Tkinter Module ****/ | |
| 1268 | |
| 1269 static PyObject * | |
| 1270 Tkinter_Create (self, args) | |
| 1271 PyObject *self; | |
| 1272 PyObject *args; | |
| 1273 { | |
| 1274 char *screenName = NULL; | |
|
2858
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1275 char *baseName = NULL; |
|
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1276 char *className = NULL; |
| 1664 | 1277 int interactive = 0; |
| 1278 | |
|
3899
584936890f86
getprogramname --> Py_GetProgramName
Guido van Rossum <guido@python.org>
parents:
3703
diff
changeset
|
1279 baseName = strrchr (Py_GetProgramName (), '/'); |
| 1664 | 1280 if (baseName != NULL) |
| 1281 baseName++; | |
| 1282 else | |
|
3899
584936890f86
getprogramname --> Py_GetProgramName
Guido van Rossum <guido@python.org>
parents:
3703
diff
changeset
|
1283 baseName = Py_GetProgramName (); |
| 1664 | 1284 className = "Tk"; |
| 1285 | |
|
2858
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1286 if (!PyArg_ParseTuple (args, "|zssi", |
|
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1287 &screenName, &baseName, &className, &interactive)) |
| 1664 | 1288 return NULL; |
| 1289 | |
| 1290 return (PyObject *) Tkapp_New (screenName, baseName, className, | |
| 1291 interactive); | |
| 1292 } | |
| 1293 | |
| 1294 static PyMethodDef moduleMethods[] = | |
| 1295 { | |
|
2858
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1296 {"create", Tkinter_Create, 1}, |
|
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1297 {"createfilehandler", Tkapp_CreateFileHandler, 0}, |
|
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1298 {"deletefilehandler", Tkapp_DeleteFileHandler, 0}, |
|
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1299 {"createtimerhandler", Tkapp_CreateTimerHandler, 0}, |
|
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1300 {"mainloop", Tkapp_MainLoop, 1}, |
|
eb1ed4d84629
use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents:
2505
diff
changeset
|
1301 {"dooneevent", Tkapp_DoOneEvent, 1}, |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1302 {"quit", Tkapp_Quit}, |
| 1664 | 1303 {NULL, NULL} |
| 1304 }; | |
| 1305 | |
|
2300
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1306 #undef WITH_READLINE /* XXX */ |
| 1664 | 1307 #ifdef WITH_READLINE |
| 1308 static int | |
| 1309 EventHook () | |
| 1310 { | |
| 1311 if (errorInCmd) /* XXX Reset tty */ | |
| 1312 { | |
| 1313 errorInCmd = 0; | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
1314 PyErr_Restore (excInCmd, valInCmd, trbInCmd); |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
1315 excInCmd = valInCmd = trbInCmd = NULL; |
| 1664 | 1316 PyErr_Print (); |
| 1317 } | |
| 3120 | 1318 if (Tk_GetNumMainWindows() > 0) |
|
1756
f533791acc77
* tkintermodule.c: OK, I've fixed the "tty" problem. You're right
Guido van Rossum <guido@python.org>
parents:
1713
diff
changeset
|
1319 Tk_DoOneEvent (TK_DONT_WAIT); |
| 1664 | 1320 return 0; |
| 1321 } | |
| 1322 #endif /* WITH_READLINE */ | |
| 1323 | |
| 1324 static void | |
| 1713 | 1325 Tkinter_Cleanup () |
| 1326 { | |
|
2300
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1327 /* This segfault with Tk 4.0 beta and seems unnecessary there as well */ |
|
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1328 #if TK_MAJOR_VERSION < 4 |
| 1713 | 1329 /* XXX rl_deprep_terminal is static, damned! */ |
| 1330 while (tkMainWindowList != 0) | |
| 1331 Tk_DestroyWindow (tkMainWindowList->win); | |
|
2300
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1332 #endif |
| 1713 | 1333 } |
| 1334 | |
| 1664 | 1335 void |
|
3386
6f5feb3b4829
get rid of bogus name for init_tkinter()
Guido van Rossum <guido@python.org>
parents:
3262
diff
changeset
|
1336 init_tkinter () |
| 1664 | 1337 { |
| 1713 | 1338 static inited = 0; |
| 1339 | |
| 1664 | 1340 #ifdef WITH_READLINE |
| 1341 extern int (*rl_event_hook) (); | |
| 1342 #endif /* WITH_READLINE */ | |
| 1343 PyObject *m, *d, *v; | |
| 1344 | |
|
4091
dc946cab7b9b
Hacks to support being a Windows DLL
Guido van Rossum <guido@python.org>
parents:
4079
diff
changeset
|
1345 Tkapp_Type.ob_type = &PyType_Type; |
|
dc946cab7b9b
Hacks to support being a Windows DLL
Guido van Rossum <guido@python.org>
parents:
4079
diff
changeset
|
1346 Tktt_Type.ob_type = &PyType_Type; |
|
dc946cab7b9b
Hacks to support being a Windows DLL
Guido van Rossum <guido@python.org>
parents:
4079
diff
changeset
|
1347 |
|
3231
1acc04478dc3
Renamed module tkinter to _tkinter, moved source to _tkinter.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
3134
diff
changeset
|
1348 m = Py_InitModule ("_tkinter", moduleMethods); |
| 1664 | 1349 |
| 1350 d = PyModule_GetDict (m); | |
| 1351 Tkinter_TclError = Py_BuildValue ("s", "TclError"); | |
| 1352 PyDict_SetItemString (d, "TclError", Tkinter_TclError); | |
| 1353 | |
| 1354 v = Py_BuildValue ("i", TK_READABLE); | |
| 1355 PyDict_SetItemString (d, "READABLE", v); | |
| 1356 v = Py_BuildValue ("i", TK_WRITABLE); | |
| 1357 PyDict_SetItemString (d, "WRITABLE", v); | |
| 1358 v = Py_BuildValue ("i", TK_EXCEPTION); | |
| 1359 PyDict_SetItemString (d, "EXCEPTION", v); | |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1360 v = Py_BuildValue ("i", TK_X_EVENTS); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1361 PyDict_SetItemString (d, "X_EVENTS", v); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1362 v = Py_BuildValue ("i", TK_FILE_EVENTS); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1363 PyDict_SetItemString (d, "FILE_EVENTS", v); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1364 v = Py_BuildValue ("i", TK_TIMER_EVENTS); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1365 PyDict_SetItemString (d, "TIMER_EVENTS", v); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1366 v = Py_BuildValue ("i", TK_IDLE_EVENTS); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1367 PyDict_SetItemString (d, "IDLE_EVENTS", v); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1368 v = Py_BuildValue ("i", TK_ALL_EVENTS); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1369 PyDict_SetItemString (d, "ALL_EVENTS", v); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1370 v = Py_BuildValue ("i", TK_DONT_WAIT); |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1371 PyDict_SetItemString (d, "DONT_WAIT", v); |
|
2300
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1372 v = Py_BuildValue ("s", TK_VERSION); |
|
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1373 PyDict_SetItemString (d, "TK_VERSION", v); |
|
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1374 v = Py_BuildValue ("s", TCL_VERSION); |
|
d2049a1d3cc5
use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1375 PyDict_SetItemString (d, "TCL_VERSION", v); |
| 1664 | 1376 |
| 1377 #ifdef WITH_READLINE | |
| 1378 rl_event_hook = EventHook; | |
| 1379 #endif /* WITH_READLINE */ | |
| 1380 | |
| 1713 | 1381 if (!inited) |
| 1382 { | |
| 1383 inited = 1; | |
|
1867
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1771
diff
changeset
|
1384 if (Py_AtExit (Tkinter_Cleanup) != 0) |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1771
diff
changeset
|
1385 fprintf(stderr, |
|
758c1374f303
Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents:
1771
diff
changeset
|
1386 "Tkinter: warning: cleanup procedure not registered\n"); |
| 1713 | 1387 } |
| 1388 | |
| 1664 | 1389 if (PyErr_Occurred ()) |
|
3231
1acc04478dc3
Renamed module tkinter to _tkinter, moved source to _tkinter.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
3134
diff
changeset
|
1390 Py_FatalError ("can't initialize module _tkinter"); |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1391 #ifdef macintosh |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1392 TclMacSetEventProc(PyMacConvertEvent); |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1393 #if GENERATINGCFM |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1394 mac_addlibresources(); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1395 #endif /* GENERATINGCFM */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1396 #endif /* macintosh */ |
| 1664 | 1397 } |
| 3120 | 1398 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1399 |
| 3120 | 1400 #ifdef macintosh |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1401 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1402 /* |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1403 ** Anyone who embeds Tcl/Tk on the Mac must define panic(). |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1404 */ |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1405 |
| 3120 | 1406 void |
| 1407 panic(char * format, ...) | |
| 1408 { | |
| 1409 va_list varg; | |
| 1410 | |
| 1411 va_start(varg, format); | |
| 1412 | |
| 1413 vfprintf(stderr, format, varg); | |
| 1414 (void) fflush(stderr); | |
| 1415 | |
| 1416 va_end(varg); | |
| 1417 | |
| 1418 Py_FatalError("Tcl/Tk panic"); | |
| 1419 } | |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1420 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1421 /* |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1422 ** Pass events to SIOUX before passing them to Tk. |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1423 */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1424 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1425 static int |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1426 PyMacConvertEvent(eventPtr) |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1427 EventRecord *eventPtr; |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1428 { |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1429 if (SIOUXHandleOneEvent(eventPtr)) |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1430 return 0; /* Nothing happened to the Tcl event queue */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1431 return TkMacConvertEvent(eventPtr); |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1432 } |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1433 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1434 #if GENERATINGCFM |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1435 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1436 /* |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1437 ** Additional Mac specific code for dealing with shared libraries. |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1438 */ |
|
3262
bfb63b45ff0f
Initialize GUSI on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3240
diff
changeset
|
1439 |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1440 #include <Resources.h> |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1441 #include <CodeFragments.h> |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1442 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1443 static int loaded_from_shlib = 0; |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1444 static FSSpec library_fss; |
| 3120 | 1445 |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1446 /* |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1447 ** If this module is dynamically loaded the following routine should |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1448 ** be the init routine. It takes care of adding the shared library to |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1449 ** the resource-file chain, so that the tk routines can find their |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1450 ** resources. |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1451 */ |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1452 OSErr pascal |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1453 init_tkinter_shlib(InitBlockPtr data) |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1454 { |
|
4139
010344b4a616
Call __initialize(), not __sinit() on Mac dynamic loading entry.
Guido van Rossum <guido@python.org>
parents:
4091
diff
changeset
|
1455 __initialize(); |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1456 if ( data == nil ) return noErr; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1457 if ( data->fragLocator.where == kOnDiskFlat ) { |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1458 library_fss = *data->fragLocator.u.onDisk.fileSpec; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1459 loaded_from_shlib = 1; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1460 } else if ( data->fragLocator.where == kOnDiskSegmented ) { |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1461 library_fss = *data->fragLocator.u.inSegs.fileSpec; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1462 loaded_from_shlib = 1; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1463 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1464 return noErr; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1465 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1466 |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1467 /* |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1468 ** Insert the library resources into the search path. Put them after |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1469 ** the resources from the application. Again, we ignore errors. |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1470 */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1471 static |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1472 mac_addlibresources() |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1473 { |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1474 if ( !loaded_from_shlib ) |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1475 return; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1476 (void)FSpOpenResFile(&library_fss, fsRdPerm); |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1477 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1478 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1479 #endif /* GENERATINGCFM */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1480 #endif /* macintosh */ |
