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