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