Mercurial > cpython-lru_cache-weakref
annotate Modules/_tkinter.c @ 7464:021237ba5007 legacy-trunk
Make this work better with a4 paper.
Make the table of contents "hot" for PDF output. No additional packages are
needed.
Move code for \b@code, \e@code into the macros for the verbatim environment
directly since they're not used elsewhere.
Derive the name of the modules .idx from the jobname.
Some clean ups.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Wed, 25 Feb 1998 15:29:43 +0000 |
| parents | 13f29b62a209 |
| children | a909a2869ac5 |
| 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: |
|
5866
f1c03276873a
Removed remaining support for Tk versions below 4.0.
Guido van Rossum <guido@python.org>
parents:
5695
diff
changeset
|
38 Tcl/Tk 8.0 (even alpha or beta) or 7.6/4.2 are recommended. |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
39 Versions 7.5/4.1 are the earliest versions still supported. |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
40 Versions 7.4/4.0 or Tk 3.x are no longer supported. |
|
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
|
41 |
|
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 Mac and Windows: |
|
5866
f1c03276873a
Removed remaining support for Tk versions below 4.0.
Guido van Rossum <guido@python.org>
parents:
5695
diff
changeset
|
43 Use Tcl 8.0 if available (even alpha or beta). |
|
f1c03276873a
Removed remaining support for Tk versions below 4.0.
Guido van Rossum <guido@python.org>
parents:
5695
diff
changeset
|
44 The oldest usable version is 4.1p1/7.5p1. |
|
f1c03276873a
Removed remaining support for Tk versions below 4.0.
Guido van Rossum <guido@python.org>
parents:
5695
diff
changeset
|
45 |
|
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
|
46 */ |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
47 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
48 |
| 3120 | 49 #include "Python.h" |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
50 #include <ctype.h> |
| 3120 | 51 |
|
4079
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
52 #ifdef macintosh |
|
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
53 #define MAC_TCL |
|
5695
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
54 #include "myselect.h" |
|
4079
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
55 #endif |
|
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
56 |
| 1664 | 57 #include <tcl.h> |
| 58 #include <tk.h> | |
| 59 | |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
60 #define TKMAJORMINOR (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) |
|
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
61 |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
62 #if TKMAJORMINOR >= 8000 && defined(macintosh) |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
63 /* Sigh, we have to include this to get at the tcl qd pointer */ |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
64 #include <tkMac.h> |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
65 #endif |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
66 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
67 #if TKMAJORMINOR < 4001 |
|
6265
8a50249aa72f
Indent the #error so that a strict K&R cpp doesn't complain.
Guido van Rossum <guido@python.org>
parents:
6134
diff
changeset
|
68 #error "Tk 4.0 or 3.x are not supported -- use 4.1 or higher" |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
69 #endif |
| 1713 | 70 |
|
6455
2138cf3bdc5a
Mac does support createfilehandler now (Jack)
Guido van Rossum <guido@python.org>
parents:
6438
diff
changeset
|
71 #if TKMAJORMINOR < 8000 || !defined(MS_WINDOWS) |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
72 #define HAVE_CREATEFILEHANDLER |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
73 #endif |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
74 |
| 3120 | 75 extern int Tk_GetNumMainWindows(); |
| 76 | |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
77 #ifdef macintosh |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
78 |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
79 /* |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
80 ** 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
|
81 ** 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
|
82 */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
83 |
|
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
|
84 /* ckfree() expects a char* */ |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
85 #define FREECAST (char *) |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
86 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
87 #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
|
88 |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
89 typedef int (*TclMacConvertEventPtr) Py_PROTO((EventRecord *eventPtr)); |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
90 /* They changed the name... */ |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
91 #if TKMAJORMINOR < 8000 |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
92 #define Tcl_MacSetEventProc TclMacSetEventProc |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
93 #endif |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
94 void Tcl_MacSetEventProc Py_PROTO((TclMacConvertEventPtr procPtr)); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
95 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
|
96 |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
97 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
|
98 |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
99 #endif /* macintosh */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
100 |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
101 #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
|
102 #define FREECAST (char *) |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
103 #endif |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
104 |
| 1664 | 105 /**** Tkapp Object Declaration ****/ |
| 106 | |
| 107 staticforward PyTypeObject Tkapp_Type; | |
| 108 | |
| 109 typedef struct | |
| 4968 | 110 { |
| 111 PyObject_HEAD | |
| 112 Tcl_Interp *interp; | |
| 113 } | |
| 1664 | 114 TkappObject; |
| 115 | |
| 116 #define Tkapp_Check(v) ((v)->ob_type == &Tkapp_Type) | |
| 117 #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) | |
| 118 #define Tkapp_Result(v) (((TkappObject *) (v))->interp->result) | |
| 119 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
120 #define DEBUG_REFCNT(v) (printf("DEBUG: id=%p, refcnt=%i\n", \ |
| 4968 | 121 (void *) v, ((PyObject *) v)->ob_refcnt)) |
| 1664 | 122 |
| 4968 | 123 |
| 124 | |
| 1664 | 125 /**** Error Handling ****/ |
| 126 | |
| 127 static PyObject *Tkinter_TclError; | |
| 1713 | 128 static int quitMainLoop = 0; |
| 1664 | 129 static int errorInCmd = 0; |
| 130 static PyObject *excInCmd; | |
| 131 static PyObject *valInCmd; | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
132 static PyObject *trbInCmd; |
| 1664 | 133 |
| 4968 | 134 |
| 135 | |
| 1664 | 136 static PyObject * |
| 4968 | 137 Tkinter_Error(v) |
| 138 PyObject *v; | |
| 1664 | 139 { |
| 4968 | 140 PyErr_SetString(Tkinter_TclError, Tkapp_Result(v)); |
| 141 return NULL; | |
| 1664 | 142 } |
| 143 | |
| 4968 | 144 |
| 1664 | 145 int |
| 4968 | 146 PythonCmd_Error(interp) |
| 147 Tcl_Interp *interp; | |
| 1664 | 148 { |
| 4968 | 149 errorInCmd = 1; |
| 150 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); | |
| 151 return TCL_ERROR; | |
| 1664 | 152 } |
| 153 | |
| 4968 | 154 |
| 155 | |
| 1664 | 156 /**** Utils ****/ |
| 157 static char * | |
| 4968 | 158 AsString(value, tmp) |
| 159 PyObject *value; | |
| 160 PyObject *tmp; | |
| 1664 | 161 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
162 if (PyString_Check(value)) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
163 return PyString_AsString(value); |
| 4968 | 164 else { |
| 165 PyObject *v = PyObject_Str(value); | |
| 166 PyList_Append(tmp, v); | |
| 167 Py_DECREF(v); | |
| 168 return PyString_AsString(v); | |
| 169 } | |
| 1664 | 170 } |
| 171 | |
| 4968 | 172 |
| 173 | |
| 1664 | 174 #define ARGSZ 64 |
| 175 | |
| 176 static char * | |
| 4968 | 177 Merge(args) |
| 178 PyObject *args; | |
| 1664 | 179 { |
| 4968 | 180 PyObject *tmp = NULL; |
| 181 char *argvStore[ARGSZ]; | |
| 182 char **argv = NULL; | |
| 183 int fvStore[ARGSZ]; | |
| 184 int *fv = NULL; | |
| 185 int argc = 0, i; | |
| 186 char *res = NULL; | |
| 187 | |
| 188 if (!(tmp = PyList_New(0))) | |
| 189 return NULL; | |
| 190 | |
| 191 argv = argvStore; | |
| 192 fv = fvStore; | |
| 193 | |
| 194 if (args == NULL) | |
| 195 argc = 0; | |
| 1664 | 196 |
| 4968 | 197 else if (!PyTuple_Check(args)) { |
| 198 argc = 1; | |
| 199 fv[0] = 0; | |
| 200 argv[0] = AsString(args, tmp); | |
| 201 } | |
| 202 else { | |
| 203 argc = PyTuple_Size(args); | |
| 204 | |
| 205 if (argc > ARGSZ) { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
206 argv = (char **)ckalloc(argc * sizeof(char *)); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
207 fv = (int *)ckalloc(argc * sizeof(int)); |
| 4968 | 208 if (argv == NULL || fv == NULL) { |
| 209 PyErr_NoMemory(); | |
| 210 goto finally; | |
| 211 } | |
| 212 } | |
| 1664 | 213 |
| 4968 | 214 for (i = 0; i < argc; i++) { |
| 215 PyObject *v = PyTuple_GetItem(args, i); | |
| 216 if (PyTuple_Check(v)) { | |
| 217 fv[i] = 1; | |
| 218 if (!(argv[i] = Merge(v))) | |
| 219 goto finally; | |
| 220 } | |
| 221 else if (v == Py_None) { | |
| 222 argc = i; | |
| 223 break; | |
| 224 } | |
| 225 else { | |
| 226 fv[i] = 0; | |
| 227 argv[i] = AsString(v, tmp); | |
| 228 } | |
| 229 } | |
| 230 } | |
| 231 res = Tcl_Merge(argc, argv); | |
| 1664 | 232 |
| 4968 | 233 finally: |
| 234 for (i = 0; i < argc; i++) | |
| 235 if (fv[i]) { | |
| 236 ckfree(argv[i]); | |
| 237 } | |
| 238 if (argv != argvStore) | |
| 239 ckfree(FREECAST argv); | |
| 240 if (fv != fvStore) | |
| 241 ckfree(FREECAST fv); | |
| 242 | |
| 243 Py_DECREF(tmp); | |
| 244 return res; | |
| 245 } | |
| 246 | |
| 247 | |
| 248 | |
| 249 static PyObject * | |
| 250 Split(self, list) | |
| 251 PyObject *self; | |
| 252 char *list; | |
| 253 { | |
| 254 int argc; | |
| 255 char **argv; | |
| 256 PyObject *v; | |
| 257 | |
| 258 if (list == NULL) { | |
| 259 Py_INCREF(Py_None); | |
| 260 return Py_None; | |
| 1664 | 261 } |
| 262 | |
| 4968 | 263 if (Tcl_SplitList(Tkapp_Interp(self), list, &argc, &argv) == TCL_ERROR) |
| 1664 | 264 { |
| 4968 | 265 /* Not a list. |
| 266 * Could be a quoted string containing funnies, e.g. {"}. | |
| 267 * Return the string itself. | |
| 268 */ | |
| 269 PyErr_Clear(); | |
| 270 return PyString_FromString(list); | |
| 1664 | 271 } |
| 272 | |
| 4968 | 273 if (argc == 0) |
| 274 v = PyString_FromString(""); | |
| 275 else if (argc == 1) | |
| 276 v = PyString_FromString(argv[0]); | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
277 else if ((v = PyTuple_New(argc)) != NULL) { |
| 4968 | 278 int i; |
| 279 PyObject *w; | |
| 1664 | 280 |
| 4968 | 281 for (i = 0; i < argc; i++) { |
| 282 if ((w = Split(self, argv[i])) == NULL) { | |
| 283 Py_DECREF(v); | |
| 284 v = NULL; | |
| 285 break; | |
| 286 } | |
| 287 PyTuple_SetItem(v, i, w); | |
| 288 } | |
| 289 } | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
290 ckfree(FREECAST argv); |
| 4968 | 291 return v; |
| 1664 | 292 } |
| 293 | |
| 294 | |
| 4968 | 295 |
| 1664 | 296 /**** Tkapp Object ****/ |
| 297 | |
| 298 #ifndef WITH_APPINIT | |
| 299 int | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
300 Tcl_AppInit(interp) |
| 4968 | 301 Tcl_Interp *interp; |
| 1664 | 302 { |
| 4968 | 303 Tk_Window main; |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
304 |
| 4968 | 305 main = Tk_MainWindow(interp); |
| 306 if (Tcl_Init(interp) == TCL_ERROR) { | |
| 307 fprintf(stderr, "Tcl_Init error: %s\n", interp->result); | |
| 308 return TCL_ERROR; | |
| 309 } | |
| 310 if (Tk_Init(interp) == TCL_ERROR) { | |
| 311 fprintf(stderr, "Tk_Init error: %s\n", interp->result); | |
| 312 return TCL_ERROR; | |
| 313 } | |
| 314 return TCL_OK; | |
| 1664 | 315 } |
| 4968 | 316 #endif /* !WITH_APPINIT */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
317 |
| 4968 | 318 |
| 319 | |
| 1664 | 320 |
| 321 /* Initialize the Tk application; see the `main' function in | |
| 4968 | 322 * `tkMain.c'. |
| 323 */ | |
| 1664 | 324 static TkappObject * |
| 4968 | 325 Tkapp_New(screenName, baseName, className, interactive) |
| 326 char *screenName; | |
| 327 char *baseName; | |
| 328 char *className; | |
| 329 int interactive; | |
| 1664 | 330 { |
| 4968 | 331 TkappObject *v; |
| 332 char *argv0; | |
| 1664 | 333 |
| 4968 | 334 v = PyObject_NEW(TkappObject, &Tkapp_Type); |
| 335 if (v == NULL) | |
| 336 return NULL; | |
| 1664 | 337 |
| 4968 | 338 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
|
339 |
|
7416
13f29b62a209
Delete the 'exit' command from the Tcl interpreter -- it would allow
Guido van Rossum <guido@python.org>
parents:
7212
diff
changeset
|
340 /* Delete the 'exit' command, which can screw things up */ |
|
13f29b62a209
Delete the 'exit' command from the Tcl interpreter -- it would allow
Guido van Rossum <guido@python.org>
parents:
7212
diff
changeset
|
341 Tcl_DeleteCommand(v->interp, "exit"); |
|
13f29b62a209
Delete the 'exit' command from the Tcl interpreter -- it would allow
Guido van Rossum <guido@python.org>
parents:
7212
diff
changeset
|
342 |
| 4968 | 343 if (screenName != NULL) |
| 344 Tcl_SetVar2(v->interp, "env", "DISPLAY", | |
| 345 screenName, TCL_GLOBAL_ONLY); | |
| 1664 | 346 |
| 4968 | 347 if (interactive) |
| 348 Tcl_SetVar(v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); | |
| 349 else | |
| 350 Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); | |
| 1664 | 351 |
| 4968 | 352 /* This is used to get the application class for Tk 4.1 and up */ |
| 353 argv0 = (char*)ckalloc(strlen(className) + 1); | |
| 354 if (!argv0) { | |
| 355 PyErr_NoMemory(); | |
| 356 Py_DECREF(v); | |
| 357 return NULL; | |
| 358 } | |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
359 |
| 4968 | 360 strcpy(argv0, className); |
| 361 if (isupper(argv0[0])) | |
| 362 argv0[0] = tolower(argv0[0]); | |
| 363 Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY); | |
| 364 ckfree(argv0); | |
| 1664 | 365 |
| 4968 | 366 if (Tcl_AppInit(v->interp) != TCL_OK) |
| 367 return (TkappObject *)Tkinter_Error(v); | |
| 368 | |
| 369 return v; | |
| 1664 | 370 } |
| 371 | |
| 4968 | 372 |
| 373 | |
| 1664 | 374 /** Tcl Eval **/ |
| 375 | |
| 376 static PyObject * | |
| 4968 | 377 Tkapp_Call(self, args) |
| 378 PyObject *self; | |
| 379 PyObject *args; | |
| 1664 | 380 { |
| 4968 | 381 char *cmd = Merge(args); |
| 382 PyObject *res = NULL; | |
| 383 | |
| 384 if (!cmd) | |
| 385 PyErr_SetString(Tkinter_TclError, "merge failed"); | |
| 386 | |
| 387 else if (Tcl_Eval(Tkapp_Interp(self), cmd) == TCL_ERROR) | |
| 388 res = Tkinter_Error(self); | |
| 389 | |
| 390 else | |
| 391 res = PyString_FromString(Tkapp_Result(self)); | |
| 392 | |
| 393 if (cmd) | |
| 394 ckfree(cmd); | |
| 395 | |
| 396 return res; | |
| 397 } | |
| 1664 | 398 |
| 4968 | 399 |
| 400 static PyObject * | |
| 401 Tkapp_GlobalCall(self, args) | |
| 402 PyObject *self; | |
| 403 PyObject *args; | |
| 404 { | |
| 405 char *cmd = Merge(args); | |
| 406 PyObject *res = NULL; | |
| 407 | |
| 1664 | 408 |
| 4968 | 409 if (!cmd) |
| 410 PyErr_SetString(Tkinter_TclError, "merge failed"); | |
| 411 | |
| 412 else if (Tcl_GlobalEval(Tkapp_Interp(self), cmd) == TCL_ERROR) | |
| 413 res = Tkinter_Error(self); | |
| 414 else | |
| 415 res = PyString_FromString(Tkapp_Result(self)); | |
| 416 | |
| 417 if (cmd) | |
| 418 ckfree(cmd); | |
| 419 | |
| 420 return res; | |
| 1664 | 421 } |
| 422 | |
| 423 static PyObject * | |
| 4968 | 424 Tkapp_Eval(self, args) |
| 425 PyObject *self; | |
| 426 PyObject *args; | |
| 1664 | 427 { |
| 4968 | 428 char *script; |
| 429 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
430 if (!PyArg_ParseTuple(args, "s", &script)) |
| 4968 | 431 return NULL; |
| 1664 | 432 |
| 4968 | 433 if (Tcl_Eval(Tkapp_Interp(self), script) == TCL_ERROR) |
| 434 return Tkinter_Error(self); | |
| 1664 | 435 |
| 4968 | 436 return PyString_FromString(Tkapp_Result(self)); |
| 1664 | 437 } |
| 438 | |
| 439 static PyObject * | |
| 4968 | 440 Tkapp_GlobalEval(self, args) |
| 441 PyObject *self; | |
| 442 PyObject *args; | |
| 1664 | 443 { |
| 4968 | 444 char *script; |
| 1664 | 445 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
446 if (!PyArg_ParseTuple(args, "s", &script)) |
| 4968 | 447 return NULL; |
| 1664 | 448 |
| 4968 | 449 if (Tcl_GlobalEval(Tkapp_Interp(self), script) == TCL_ERROR) |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
450 return Tkinter_Error(self); |
| 1664 | 451 |
| 4968 | 452 return PyString_FromString(Tkapp_Result(self)); |
| 1664 | 453 } |
| 454 | |
| 455 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
456 Tkapp_EvalFile(self, args) |
| 4968 | 457 PyObject *self; |
| 458 PyObject *args; | |
| 1664 | 459 { |
| 4968 | 460 char *fileName; |
| 1664 | 461 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
462 if (!PyArg_ParseTuple(args, "s", &fileName)) |
| 4968 | 463 return NULL; |
| 1664 | 464 |
| 4968 | 465 if (Tcl_EvalFile(Tkapp_Interp(self), fileName) == TCL_ERROR) |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
466 return Tkinter_Error(self); |
| 1664 | 467 |
| 4968 | 468 return PyString_FromString(Tkapp_Result(self)); |
| 1664 | 469 } |
| 470 | |
| 471 static PyObject * | |
| 4968 | 472 Tkapp_Record(self, args) |
| 473 PyObject *self; | |
| 474 PyObject *args; | |
| 1664 | 475 { |
| 4968 | 476 char *script; |
| 1664 | 477 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
478 if (!PyArg_ParseTuple(args, "s", &script)) |
| 4968 | 479 return NULL; |
| 1664 | 480 |
| 4968 | 481 if (TCL_ERROR == Tcl_RecordAndEval(Tkapp_Interp(self), |
| 482 script, TCL_NO_EVAL)) | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
483 return Tkinter_Error(self); |
| 1664 | 484 |
| 4968 | 485 return PyString_FromString(Tkapp_Result(self)); |
| 1664 | 486 } |
| 487 | |
| 488 static PyObject * | |
| 4968 | 489 Tkapp_AddErrorInfo(self, args) |
| 490 PyObject *self; | |
| 491 PyObject *args; | |
| 1664 | 492 { |
| 4968 | 493 char *msg; |
| 1664 | 494 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
495 if (!PyArg_ParseTuple(args, "s", &msg)) |
| 4968 | 496 return NULL; |
| 497 Tcl_AddErrorInfo(Tkapp_Interp(self), msg); | |
| 1664 | 498 |
| 4968 | 499 Py_INCREF(Py_None); |
| 500 return Py_None; | |
| 1664 | 501 } |
| 502 | |
| 4968 | 503 |
| 504 | |
| 1664 | 505 /** Tcl Variable **/ |
| 506 | |
| 507 static PyObject * | |
| 4968 | 508 SetVar(self, args, flags) |
| 509 PyObject *self; | |
| 510 PyObject *args; | |
| 511 int flags; | |
| 1664 | 512 { |
| 4968 | 513 char *name1, *name2, *ok; |
| 514 PyObject *newValue; | |
| 515 PyObject *tmp = PyList_New(0); | |
| 1664 | 516 |
| 4968 | 517 if (!tmp) |
| 518 return NULL; | |
| 1664 | 519 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
520 if (PyArg_ParseTuple(args, "sO", &name1, &newValue)) |
| 4968 | 521 /* XXX Merge? */ |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
522 ok = Tcl_SetVar(Tkapp_Interp(self), name1, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
523 AsString(newValue, tmp), flags); |
| 1664 | 524 |
| 4968 | 525 else { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
526 PyErr_Clear(); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
527 if (PyArg_ParseTuple(args, "ssO", &name1, &name2, &newValue)) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
528 ok = Tcl_SetVar2(Tkapp_Interp(self), name1, name2, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
529 AsString (newValue, tmp), flags); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
530 else { |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
531 Py_DECREF (tmp); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
532 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
533 } |
| 4968 | 534 } |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
535 Py_DECREF(tmp); |
| 1664 | 536 |
| 4968 | 537 if (!ok) |
| 538 return Tkinter_Error(self); | |
| 539 | |
| 540 Py_INCREF(Py_None); | |
| 541 return Py_None; | |
| 1664 | 542 } |
| 543 | |
| 544 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
545 Tkapp_SetVar(self, args) |
| 4968 | 546 PyObject *self; |
| 547 PyObject *args; | |
| 1664 | 548 { |
| 4968 | 549 return SetVar(self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 550 } |
| 551 | |
| 552 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
553 Tkapp_GlobalSetVar(self, args) |
| 4968 | 554 PyObject *self; |
| 555 PyObject *args; | |
| 1664 | 556 { |
| 4968 | 557 return SetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 558 } |
| 559 | |
| 4968 | 560 |
| 561 | |
| 1664 | 562 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
563 GetVar(self, args, flags) |
| 4968 | 564 PyObject *self; |
| 565 PyObject *args; | |
| 566 int flags; | |
| 1664 | 567 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
568 char *name1, *name2=NULL, *s; |
| 4968 | 569 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
570 if (!PyArg_ParseTuple(args, "s|s", &name1, &name2)) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
571 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
572 if (name2 == NULL) |
| 4968 | 573 s = Tcl_GetVar(Tkapp_Interp (self), name1, flags); |
| 1664 | 574 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
575 else |
| 4968 | 576 s = Tcl_GetVar2(Tkapp_Interp(self), name1, name2, flags); |
| 1664 | 577 |
| 4968 | 578 if (s == NULL) |
| 579 return Tkinter_Error(self); | |
| 1664 | 580 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
581 return PyString_FromString(s); |
| 1664 | 582 } |
| 583 | |
| 584 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
585 Tkapp_GetVar(self, args) |
| 4968 | 586 PyObject *self; |
| 587 PyObject *args; | |
| 1664 | 588 { |
| 4968 | 589 return GetVar(self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 590 } |
| 591 | |
| 592 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
593 Tkapp_GlobalGetVar(self, args) |
| 4968 | 594 PyObject *self; |
| 595 PyObject *args; | |
| 1664 | 596 { |
| 4968 | 597 return GetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 598 } |
| 599 | |
| 4968 | 600 |
| 601 | |
| 1664 | 602 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
603 UnsetVar(self, args, flags) |
| 4968 | 604 PyObject *self; |
| 605 PyObject *args; | |
| 606 int flags; | |
| 1664 | 607 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
608 char *name1, *name2=NULL; |
| 4968 | 609 int code; |
| 610 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
611 if (!PyArg_ParseTuple(args, "s|s", &name1, &name2)) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
612 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
613 if (name2 == NULL) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
614 code = Tcl_UnsetVar(Tkapp_Interp(self), name1, flags); |
| 1664 | 615 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
616 else |
| 4968 | 617 code = Tcl_UnsetVar2(Tkapp_Interp(self), name1, name2, flags); |
| 1664 | 618 |
| 4968 | 619 if (code == TCL_ERROR) |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
620 return Tkinter_Error(self); |
| 1664 | 621 |
| 4968 | 622 Py_INCREF(Py_None); |
| 623 return Py_None; | |
| 1664 | 624 } |
| 625 | |
| 626 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
627 Tkapp_UnsetVar(self, args) |
| 4968 | 628 PyObject *self; |
| 629 PyObject *args; | |
| 1664 | 630 { |
| 4968 | 631 return UnsetVar(self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 632 } |
| 633 | |
| 634 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
635 Tkapp_GlobalUnsetVar(self, args) |
| 4968 | 636 PyObject *self; |
| 637 PyObject *args; | |
| 1664 | 638 { |
| 4968 | 639 return UnsetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 640 } |
| 641 | |
| 4968 | 642 |
| 643 | |
| 1664 | 644 /** Tcl to Python **/ |
| 645 | |
| 646 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
647 Tkapp_GetInt(self, args) |
| 4968 | 648 PyObject *self; |
| 649 PyObject *args; | |
| 1664 | 650 { |
| 4968 | 651 char *s; |
| 652 int v; | |
| 1664 | 653 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
654 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 655 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
656 if (Tcl_GetInt(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
| 4968 | 657 return Tkinter_Error(self); |
| 658 return Py_BuildValue("i", v); | |
| 1664 | 659 } |
| 660 | |
| 661 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
662 Tkapp_GetDouble(self, args) |
| 4968 | 663 PyObject *self; |
| 664 PyObject *args; | |
| 1664 | 665 { |
| 4968 | 666 char *s; |
| 667 double v; | |
| 1664 | 668 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
669 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 670 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
671 if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
| 4968 | 672 return Tkinter_Error(self); |
| 673 return Py_BuildValue("d", v); | |
| 1664 | 674 } |
| 675 | |
| 676 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
677 Tkapp_GetBoolean(self, args) |
| 4968 | 678 PyObject *self; |
| 679 PyObject *args; | |
| 1664 | 680 { |
| 4968 | 681 char *s; |
| 682 int v; | |
| 1664 | 683 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
684 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 685 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
686 if (Tcl_GetBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
687 return Tkinter_Error(self); |
| 4968 | 688 return Py_BuildValue("i", v); |
| 1664 | 689 } |
| 690 | |
| 691 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
692 Tkapp_ExprString(self, args) |
| 4968 | 693 PyObject *self; |
| 694 PyObject *args; | |
| 1664 | 695 { |
| 4968 | 696 char *s; |
| 1664 | 697 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
698 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 699 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
700 if (Tcl_ExprString(Tkapp_Interp(self), s) == TCL_ERROR) |
| 4968 | 701 return Tkinter_Error(self); |
| 702 return Py_BuildValue("s", Tkapp_Result(self)); | |
| 1664 | 703 } |
| 704 | |
| 705 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
706 Tkapp_ExprLong(self, args) |
| 4968 | 707 PyObject *self; |
| 708 PyObject *args; | |
| 1664 | 709 { |
| 4968 | 710 char *s; |
| 711 long v; | |
| 1664 | 712 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
713 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 714 return NULL; |
| 715 if (Tcl_ExprLong(Tkapp_Interp(self), s, &v) == TCL_ERROR) | |
| 716 return Tkinter_Error(self); | |
| 717 return Py_BuildValue("l", v); | |
| 1664 | 718 } |
| 719 | |
| 720 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
721 Tkapp_ExprDouble(self, args) |
| 4968 | 722 PyObject *self; |
| 723 PyObject *args; | |
| 1664 | 724 { |
| 4968 | 725 char *s; |
| 726 double v; | |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
727 int retval; |
| 1664 | 728 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
729 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 730 return NULL; |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
731 PyFPE_START_PROTECT("Tkapp_ExprDouble", return 0) |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
732 retval = Tcl_ExprDouble(Tkapp_Interp(self), s, &v); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5120
diff
changeset
|
733 PyFPE_END_PROTECT(retval) |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
734 if (retval == TCL_ERROR) |
| 4968 | 735 return Tkinter_Error(self); |
| 736 return Py_BuildValue("d", v); | |
| 1664 | 737 } |
| 738 | |
| 739 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
740 Tkapp_ExprBoolean(self, args) |
| 4968 | 741 PyObject *self; |
| 742 PyObject *args; | |
| 1664 | 743 { |
| 4968 | 744 char *s; |
| 745 int v; | |
| 1664 | 746 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
747 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 748 return NULL; |
| 749 if (Tcl_ExprBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR) | |
| 750 return Tkinter_Error(self); | |
| 751 return Py_BuildValue("i", v); | |
| 1664 | 752 } |
| 753 | |
| 4968 | 754 |
| 755 | |
| 1664 | 756 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
757 Tkapp_SplitList(self, args) |
| 4968 | 758 PyObject *self; |
| 759 PyObject *args; | |
| 1664 | 760 { |
| 4968 | 761 char *list; |
| 762 int argc; | |
| 763 char **argv; | |
| 764 PyObject *v; | |
| 765 int i; | |
| 766 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
767 if (!PyArg_ParseTuple(args, "s", &list)) |
| 4968 | 768 return NULL; |
| 769 | |
| 770 if (Tcl_SplitList(Tkapp_Interp(self), list, &argc, &argv) == TCL_ERROR) | |
| 771 return Tkinter_Error(self); | |
| 1664 | 772 |
| 4968 | 773 if (!(v = PyTuple_New(argc))) |
| 774 return NULL; | |
| 775 | |
| 776 for (i = 0; i < argc; i++) { | |
| 777 PyObject *s = PyString_FromString(argv[i]); | |
| 778 if (!s || PyTuple_SetItem(v, i, s)) { | |
| 779 Py_DECREF(v); | |
| 780 v = NULL; | |
| 781 goto finally; | |
| 782 } | |
| 783 } | |
| 1664 | 784 |
| 4968 | 785 finally: |
| 786 ckfree(FREECAST argv); | |
| 787 return v; | |
| 1664 | 788 } |
| 789 | |
| 790 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
791 Tkapp_Split(self, args) |
| 4968 | 792 PyObject *self; |
| 793 PyObject *args; | |
| 1664 | 794 { |
| 4968 | 795 char *list; |
| 1664 | 796 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
797 if (!PyArg_ParseTuple(args, "s", &list)) |
| 4968 | 798 return NULL; |
| 799 return Split(self, list); | |
| 1664 | 800 } |
| 801 | |
| 802 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
803 Tkapp_Merge(self, args) |
| 4968 | 804 PyObject *self; |
| 805 PyObject *args; | |
| 1664 | 806 { |
| 4968 | 807 char *s = Merge(args); |
| 808 PyObject *res = NULL; | |
| 1664 | 809 |
| 4968 | 810 if (s) { |
| 811 res = PyString_FromString(s); | |
| 812 ckfree(s); | |
| 813 } | |
| 814 else | |
| 815 PyErr_SetString(Tkinter_TclError, "merge failed"); | |
| 816 | |
| 817 return res; | |
| 1664 | 818 } |
| 819 | |
| 4968 | 820 |
| 821 | |
| 1664 | 822 /** Tcl Command **/ |
| 823 | |
| 824 /* This is the Tcl command that acts as a wrapper for Python | |
| 4968 | 825 * function or method. |
| 826 */ | |
| 1664 | 827 static int |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
828 PythonCmd(clientData, interp, argc, argv) |
| 4968 | 829 ClientData clientData; /* Is (self, func) */ |
| 830 Tcl_Interp *interp; | |
| 831 int argc; | |
| 832 char *argv[]; | |
| 1664 | 833 { |
| 4968 | 834 PyObject *self, *func, *arg, *res, *tmp; |
| 835 int i; | |
| 1664 | 836 |
| 4968 | 837 /* TBD: no error checking here since we know, via the |
| 838 * Tkapp_CreateCommand() that the client data is a two-tuple | |
| 839 */ | |
| 840 self = PyTuple_GetItem((PyObject *) clientData, 0); | |
| 841 func = PyTuple_GetItem((PyObject *) clientData, 1); | |
| 842 | |
| 843 /* Create argument list (argv1, ..., argvN) */ | |
| 844 if (!(arg = PyTuple_New(argc - 1))) | |
| 845 return PythonCmd_Error(interp); | |
| 1664 | 846 |
| 4968 | 847 for (i = 0; i < (argc - 1); i++) { |
| 848 PyObject *s = PyString_FromString(argv[i + 1]); | |
| 849 if (!s || PyTuple_SetItem(arg, i, s)) { | |
| 850 Py_DECREF(arg); | |
| 851 PythonCmd_Error(interp); | |
| 852 } | |
| 853 } | |
| 854 res = PyEval_CallObject(func, arg); | |
| 855 Py_DECREF(arg); | |
| 1713 | 856 |
| 4968 | 857 if (res == NULL) |
| 858 return PythonCmd_Error(interp); | |
| 1664 | 859 |
| 4968 | 860 if (!(tmp = PyList_New(0))) { |
| 861 Py_DECREF(res); | |
| 862 return PythonCmd_Error(interp); | |
| 863 } | |
| 1664 | 864 |
| 4968 | 865 Tcl_SetResult(Tkapp_Interp(self), AsString(res, tmp), TCL_VOLATILE); |
| 866 Py_DECREF(res); | |
| 867 Py_DECREF(tmp); | |
| 868 | |
| 869 return TCL_OK; | |
| 1664 | 870 } |
| 871 | |
| 872 static void | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
873 PythonCmdDelete(clientData) |
| 4968 | 874 ClientData clientData; /* Is (self, func) */ |
| 1664 | 875 { |
| 4968 | 876 Py_DECREF((PyObject *) clientData); |
| 1664 | 877 } |
| 878 | |
| 4968 | 879 |
| 880 | |
| 1664 | 881 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
882 Tkapp_CreateCommand(self, args) |
| 4968 | 883 PyObject *self; |
| 884 PyObject *args; | |
| 1664 | 885 { |
| 4968 | 886 char *cmdName; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
887 PyObject *func; |
| 4968 | 888 PyObject *data; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
889 |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
890 if (!PyArg_ParseTuple(args, "sO", &cmdName, &func)) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
891 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
892 if (!PyCallable_Check(func)) { |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
893 PyErr_SetString(PyExc_TypeError, "command not callable"); |
| 4968 | 894 return NULL; |
| 895 } | |
| 1664 | 896 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
897 data = Py_BuildValue("OO", self, func); |
| 4968 | 898 if (!data) |
| 899 return NULL; | |
| 1664 | 900 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
901 if (Tcl_CreateCommand(Tkapp_Interp(self), cmdName, PythonCmd, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
902 (ClientData) data, PythonCmdDelete) == NULL) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
903 { |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
904 PyErr_SetString(Tkinter_TclError, "can't create Tcl command"); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
905 Py_DECREF(data); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
906 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
907 } |
| 1664 | 908 |
| 4968 | 909 Py_INCREF(Py_None); |
| 910 return Py_None; | |
| 1664 | 911 } |
| 912 | |
| 4968 | 913 |
| 914 | |
| 1664 | 915 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
916 Tkapp_DeleteCommand(self, args) |
| 4968 | 917 PyObject *self; |
| 918 PyObject *args; | |
| 1664 | 919 { |
| 4968 | 920 char *cmdName; |
| 1664 | 921 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
922 if (!PyArg_ParseTuple(args, "s", &cmdName)) |
| 4968 | 923 return NULL; |
| 924 if (Tcl_DeleteCommand(Tkapp_Interp(self), cmdName) == -1) | |
| 925 { | |
| 926 PyErr_SetString(Tkinter_TclError, "can't delete Tcl command"); | |
| 927 return NULL; | |
| 928 } | |
| 929 Py_INCREF(Py_None); | |
| 930 return Py_None; | |
| 1664 | 931 } |
| 932 | |
| 4968 | 933 |
| 934 | |
| 1664 | 935 /** File Handler **/ |
| 936 | |
|
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
|
937 static void |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
938 FileHandler(clientData, mask) |
| 4968 | 939 ClientData clientData; /* Is: (func, file) */ |
| 940 int mask; | |
| 1664 | 941 { |
| 4968 | 942 PyObject *func, *file, *arg, *res; |
| 1664 | 943 |
| 4968 | 944 func = PyTuple_GetItem((PyObject *) clientData, 0); |
| 945 file = PyTuple_GetItem((PyObject *) clientData, 1); | |
| 1664 | 946 |
| 4968 | 947 arg = Py_BuildValue("(Oi)", file, (long) mask); |
| 948 res = PyEval_CallObject(func, arg); | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
949 Py_DECREF(arg); |
| 4968 | 950 |
| 951 if (res == NULL) { | |
| 952 errorInCmd = 1; | |
| 953 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); | |
| 954 } | |
| 955 Py_XDECREF(res); | |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
956 } |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
957 |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
958 static int |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
959 GetFileNo(file) |
| 4968 | 960 /* Either an int >= 0 or an object with a |
| 961 *.fileno() method that returns an int >= 0 | |
| 962 */ | |
| 963 PyObject *file; | |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
964 { |
|
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
|
965 PyObject *meth, *args, *res; |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
966 int id; |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
967 if (PyInt_Check(file)) { |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
968 id = PyInt_AsLong(file); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
969 if (id < 0) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
970 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
|
971 return id; |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
972 } |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
973 args = PyTuple_New(0); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
974 if (args == NULL) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
975 return -1; |
| 4968 | 976 |
| 977 meth = PyObject_GetAttrString(file, "fileno"); | |
| 978 if (meth == NULL) { | |
| 979 Py_DECREF(args); | |
| 980 return -1; | |
| 981 } | |
| 982 | |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
983 res = PyEval_CallObject(meth, args); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
984 Py_DECREF(args); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
985 Py_DECREF(meth); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
986 if (res == NULL) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
987 return -1; |
| 4968 | 988 |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
989 if (PyInt_Check(res)) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
990 id = PyInt_AsLong(res); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
991 else |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
992 id = -1; |
| 4968 | 993 |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
994 if (id < 0) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
995 PyErr_SetString(PyExc_ValueError, |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
996 "invalid fileno() return value"); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
997 Py_DECREF(res); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
998 return id; |
| 1664 | 999 } |
| 1000 | |
| 4968 | 1001 |
| 1002 static PyObject* Tkapp_ClientDataDict = NULL; | |
| 1003 | |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1004 #ifdef HAVE_CREATEFILEHANDLER |
| 1664 | 1005 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1006 Tkapp_CreateFileHandler(self, args) |
| 4968 | 1007 PyObject *self; |
| 1008 PyObject *args; /* Is (file, mask, func) */ | |
| 1664 | 1009 { |
| 4968 | 1010 PyObject *file, *func, *data; |
| 1011 PyObject *idkey; | |
| 1012 int mask, id; | |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1013 #if TKMAJORMINOR < 8000 |
| 4968 | 1014 Tcl_File tfile; |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
1015 #endif |
| 1664 | 1016 |
| 4968 | 1017 if (!Tkapp_ClientDataDict) { |
| 1018 if (!(Tkapp_ClientDataDict = PyDict_New())) | |
| 1019 return NULL; | |
| 1020 } | |
| 1664 | 1021 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1022 if (!PyArg_ParseTuple(args, "OiO", &file, &mask, &func)) |
| 4968 | 1023 return NULL; |
| 1024 id = GetFileNo(file); | |
| 1025 if (id < 0) | |
| 1026 return NULL; | |
| 1027 if (!PyCallable_Check(func)) { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1028 PyErr_SetString(PyExc_TypeError, "bad argument list"); |
| 4968 | 1029 return NULL; |
| 1030 } | |
| 1031 | |
| 1032 if (!(idkey = PyInt_FromLong(id))) | |
| 1033 return NULL; | |
| 1034 | |
| 1035 /* ClientData is: (func, file) */ | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1036 data = Py_BuildValue("(OO)", func, file); |
| 4968 | 1037 if (!data || PyDict_SetItem(Tkapp_ClientDataDict, idkey, data)) { |
| 1038 Py_DECREF(idkey); | |
| 1039 Py_XDECREF(data); | |
| 1040 return NULL; | |
| 1041 } | |
| 1042 Py_DECREF(idkey); | |
|
1690
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
1043 |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1044 #if TKMAJORMINOR < 8000 |
|
4299
eb1ed743972c
Rationalize MS #ifdefs
Guido van Rossum <guido@python.org>
parents:
4139
diff
changeset
|
1045 #ifdef MS_WINDOWS |
| 4968 | 1046 /* We assume this is a socket... */ |
| 1047 tfile = Tcl_GetFile((ClientData)id, TCL_WIN_SOCKET); | |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1048 #else /* !MS_WINDOWS */ |
| 4968 | 1049 tfile = Tcl_GetFile((ClientData)id, TCL_UNIX_FD); |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1050 #endif /* !MS_WINDOWS */ |
| 4968 | 1051 /* Ought to check for null Tcl_File object... */ |
| 1052 Tcl_CreateFileHandler(tfile, mask, FileHandler, (ClientData) data); | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1053 #else /* >= 8000 */ |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1054 Tcl_CreateFileHandler(id, mask, FileHandler, (ClientData) data); |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1055 #endif /* >= 8000 */ |
| 4968 | 1056 /* XXX fileHandlerDict */ |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1057 Py_INCREF(Py_None); |
| 4968 | 1058 return Py_None; |
| 1664 | 1059 } |
| 1060 | |
| 4968 | 1061 |
| 1664 | 1062 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1063 Tkapp_DeleteFileHandler(self, args) |
| 4968 | 1064 PyObject *self; |
| 1065 PyObject *args; /* Args: file */ | |
| 1664 | 1066 { |
| 4968 | 1067 PyObject *file; |
| 1068 PyObject *idkey; | |
| 1069 PyObject *data; | |
| 1070 int id; | |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1071 #if TKMAJORMINOR < 8000 |
| 4968 | 1072 Tcl_File tfile; |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
1073 #endif |
|
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
1074 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1075 if (!PyArg_ParseTuple(args, "O", &file)) |
| 4968 | 1076 return NULL; |
| 1077 id = GetFileNo(file); | |
| 1078 if (id < 0) | |
| 1079 return NULL; | |
| 1080 | |
| 1081 if (!(idkey = PyInt_FromLong(id))) | |
| 1082 return NULL; | |
| 1083 | |
| 1084 /* find and free the object created in the | |
| 1085 * Tkapp_CreateFileHandler() call | |
| 1086 */ | |
| 1087 data = PyDict_GetItem(Tkapp_ClientDataDict, idkey); | |
| 1088 Py_XDECREF(data); | |
| 1089 PyDict_DelItem(Tkapp_ClientDataDict, idkey); | |
| 1090 Py_DECREF(idkey); | |
| 1664 | 1091 |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1092 #if TKMAJORMINOR < 8000 |
|
4299
eb1ed743972c
Rationalize MS #ifdefs
Guido van Rossum <guido@python.org>
parents:
4139
diff
changeset
|
1093 #ifdef MS_WINDOWS |
| 4968 | 1094 /* We assume this is a socket... */ |
| 1095 tfile = Tcl_GetFile((ClientData)id, TCL_WIN_SOCKET); | |
| 3703 | 1096 #else |
| 4968 | 1097 tfile = Tcl_GetFile((ClientData)id, TCL_UNIX_FD); |
| 3703 | 1098 #endif |
| 4968 | 1099 /* Ought to check for null Tcl_File object... */ |
| 1100 Tcl_DeleteFileHandler(tfile); | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1101 #else /* >= 8000 */ |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1102 Tcl_DeleteFileHandler(id); |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1103 #endif /* >= 8000 */ |
| 4968 | 1104 /* XXX fileHandlerDict */ |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1105 Py_INCREF(Py_None); |
| 4968 | 1106 return Py_None; |
| 1664 | 1107 } |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1108 #endif /* HAVE_CREATEFILEHANDLER */ |
| 1664 | 1109 |
| 4968 | 1110 |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1111 /**** 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
|
1112 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1113 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
|
1114 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1115 typedef struct |
| 4968 | 1116 { |
| 1117 PyObject_HEAD | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1118 Tcl_TimerToken token; |
| 4968 | 1119 PyObject *func; |
| 1120 } | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1121 TkttObject; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1122 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1123 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1124 Tktt_DeleteTimerHandler(self, args) |
| 4968 | 1125 PyObject *self; |
| 1126 PyObject *args; | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1127 { |
| 4968 | 1128 TkttObject *v = (TkttObject *)self; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1129 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1130 if (!PyArg_ParseTuple(args, "")) |
| 4968 | 1131 return NULL; |
| 1132 if (v->func != NULL) { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1133 Tcl_DeleteTimerHandler(v->token); |
| 4968 | 1134 PyMem_DEL(v->func); |
| 1135 v->func = NULL; | |
| 1136 } | |
| 1137 Py_INCREF(Py_None); | |
| 1138 return Py_None; | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1139 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1140 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1141 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
|
1142 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1143 {"deletetimerhandler", Tktt_DeleteTimerHandler, 1}, |
| 4968 | 1144 {NULL, NULL} |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1145 }; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1146 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1147 static TkttObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1148 Tktt_New(token, func) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1149 Tcl_TimerToken token; |
| 4968 | 1150 PyObject *func; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1151 { |
| 4968 | 1152 TkttObject *v; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1153 |
| 4968 | 1154 v = PyObject_NEW(TkttObject, &Tktt_Type); |
| 1155 if (v == NULL) | |
| 1156 return NULL; | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1157 |
| 4968 | 1158 v->token = token; |
| 1159 v->func = func; | |
| 1160 Py_INCREF(v->func); | |
| 1161 return v; | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1162 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1163 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1164 static void |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1165 Tktt_Dealloc(self) |
| 4968 | 1166 PyObject *self; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1167 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1168 PyMem_DEL(self); |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1169 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1170 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1171 static int |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1172 Tktt_Print(self, fp, flags) |
| 4968 | 1173 PyObject *self; |
| 1174 FILE *fp; | |
| 1175 int flags; | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1176 { |
| 4968 | 1177 TkttObject *v = (TkttObject *)self; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1178 |
| 4968 | 1179 fprintf(fp, "<tktimertoken at 0x%lx%s>", (long)v, |
| 1180 v->func == NULL ? ", handler deleted" : ""); | |
| 1181 return 0; | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1182 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1183 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1184 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1185 Tktt_GetAttr(self, name) |
| 4968 | 1186 PyObject *self; |
| 1187 char *name; | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1188 { |
| 4968 | 1189 return Py_FindMethod(Tktt_methods, self, name); |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1190 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1191 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1192 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
|
1193 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1194 PyObject_HEAD_INIT(NULL) |
| 4968 | 1195 0, /*ob_size */ |
| 1196 "tktimertoken", /*tp_name */ | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1197 sizeof(TkttObject), /*tp_basicsize */ |
| 4968 | 1198 0, /*tp_itemsize */ |
| 1199 Tktt_Dealloc, /*tp_dealloc */ | |
| 1200 Tktt_Print, /*tp_print */ | |
| 1201 Tktt_GetAttr, /*tp_getattr */ | |
| 1202 0, /*tp_setattr */ | |
| 1203 0, /*tp_compare */ | |
| 1204 0, /*tp_repr */ | |
| 1205 0, /*tp_as_number */ | |
| 1206 0, /*tp_as_sequence */ | |
| 1207 0, /*tp_as_mapping */ | |
| 1208 0, /*tp_hash */ | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1209 }; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1210 |
| 4968 | 1211 |
| 1212 | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1213 /** Timer Handler **/ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1214 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1215 static void |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1216 TimerHandler(clientData) |
| 4968 | 1217 ClientData clientData; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1218 { |
| 4968 | 1219 PyObject *func = (PyObject *)clientData; |
| 1220 PyObject *res = PyEval_CallObject(func, NULL); | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1221 |
| 4968 | 1222 if (res == NULL) { |
| 1223 errorInCmd = 1; | |
| 1224 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); | |
| 1225 } | |
| 1226 else | |
| 1227 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
|
1228 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1229 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1230 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1231 Tkapp_CreateTimerHandler(self, args) |
| 4968 | 1232 PyObject *self; |
| 1233 PyObject *args; /* Is (milliseconds, func) */ | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1234 { |
| 4968 | 1235 int milliseconds; |
| 1236 PyObject *func; | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1237 Tcl_TimerToken token; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1238 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1239 if (!PyArg_ParseTuple(args, "iO", &milliseconds, &func)) |
| 4968 | 1240 return NULL; |
| 1241 if (!PyCallable_Check(func)) { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1242 PyErr_SetString(PyExc_TypeError, "bad argument list"); |
| 4968 | 1243 return NULL; |
| 1244 } | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1245 token = Tcl_CreateTimerHandler(milliseconds, TimerHandler, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1246 (ClientData)func); |
| 4968 | 1247 |
| 1248 return (PyObject *) Tktt_New(token, func); | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1249 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1250 |
| 4968 | 1251 |
| 1252 | |
| 1664 | 1253 /** Event Loop **/ |
| 1254 | |
| 1255 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1256 Tkapp_MainLoop(self, args) |
| 4968 | 1257 PyObject *self; |
| 1258 PyObject *args; | |
| 1664 | 1259 { |
| 4968 | 1260 int threshold = 0; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1261 |
| 4968 | 1262 if (!PyArg_ParseTuple(args, "|i", &threshold)) |
| 1263 return NULL; | |
| 1664 | 1264 |
| 4968 | 1265 quitMainLoop = 0; |
| 1266 while (Tk_GetNumMainWindows() > threshold && | |
| 1267 !quitMainLoop && | |
| 1268 !errorInCmd) | |
| 1664 | 1269 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1270 int result; |
|
6343
689de613ea1c
Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
6311
diff
changeset
|
1271 #ifdef HAVE_PYTCL_WAITUNTILEVENT |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1272 result = Tcl_DoOneEvent(TCL_DONT_WAIT); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1273 if (PyErr_CheckSignals() != 0) |
| 4968 | 1274 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1275 if (result) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1276 continue; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1277 /* XXX It's not *quite* certain that this is |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1278 thread-safe, but it seems *rather* safe as long as |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1279 no two threads call mainloop() simultaneously. */ |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1280 Py_BEGIN_ALLOW_THREADS |
|
6343
689de613ea1c
Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
6311
diff
changeset
|
1281 result = PyTcl_WaitUntilEvent(); |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1282 Py_END_ALLOW_THREADS |
|
6106
36b3b337c566
Alas, the thread support for Tk didn't work. Withdraw it, until I
Guido van Rossum <guido@python.org>
parents:
6093
diff
changeset
|
1283 #else |
|
36b3b337c566
Alas, the thread support for Tk didn't work. Withdraw it, until I
Guido van Rossum <guido@python.org>
parents:
6093
diff
changeset
|
1284 result = Tcl_DoOneEvent(0); |
|
36b3b337c566
Alas, the thread support for Tk didn't work. Withdraw it, until I
Guido van Rossum <guido@python.org>
parents:
6093
diff
changeset
|
1285 #endif |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1286 if (PyErr_CheckSignals() != 0) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1287 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1288 if (result < 0) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1289 break; |
| 1664 | 1290 } |
| 4968 | 1291 quitMainLoop = 0; |
| 1664 | 1292 |
| 4968 | 1293 if (errorInCmd) { |
| 1294 errorInCmd = 0; | |
| 1295 PyErr_Restore(excInCmd, valInCmd, trbInCmd); | |
| 1296 excInCmd = valInCmd = trbInCmd = NULL; | |
| 1297 return NULL; | |
| 1298 } | |
| 1299 Py_INCREF(Py_None); | |
| 1300 return Py_None; | |
| 1664 | 1301 } |
| 1302 | |
| 1303 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1304 Tkapp_DoOneEvent(self, args) |
| 4968 | 1305 PyObject *self; |
| 1306 PyObject *args; | |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1307 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1308 int flags = 0; |
| 4968 | 1309 int rv; |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1310 |
| 4968 | 1311 if (!PyArg_ParseTuple(args, "|i", &flags)) |
| 1312 return NULL; | |
| 1313 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1314 rv = Tcl_DoOneEvent(flags); |
| 4968 | 1315 return Py_BuildValue("i", rv); |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1316 } |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1317 |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1318 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1319 Tkapp_Quit(self, args) |
| 4968 | 1320 PyObject *self; |
| 1321 PyObject *args; | |
| 1664 | 1322 { |
| 1323 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1324 if (!PyArg_ParseTuple(args, "")) |
| 4968 | 1325 return NULL; |
| 1326 | |
| 1327 quitMainLoop = 1; | |
| 1328 Py_INCREF(Py_None); | |
| 1329 return Py_None; | |
| 1664 | 1330 } |
| 1331 | |
| 4968 | 1332 |
| 1333 | |
| 1664 | 1334 /**** Tkapp Method List ****/ |
| 1335 | |
| 1336 static PyMethodDef Tkapp_methods[] = | |
| 1337 { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1338 {"call", Tkapp_Call, 0}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1339 {"globalcall", Tkapp_GlobalCall, 0}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1340 {"eval", Tkapp_Eval, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1341 {"globaleval", Tkapp_GlobalEval, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1342 {"evalfile", Tkapp_EvalFile, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1343 {"record", Tkapp_Record, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1344 {"adderrorinfo", Tkapp_AddErrorInfo, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1345 {"setvar", Tkapp_SetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1346 {"globalsetvar", Tkapp_GlobalSetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1347 {"getvar", Tkapp_GetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1348 {"globalgetvar", Tkapp_GlobalGetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1349 {"unsetvar", Tkapp_UnsetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1350 {"globalunsetvar", Tkapp_GlobalUnsetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1351 {"getint", Tkapp_GetInt, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1352 {"getdouble", Tkapp_GetDouble, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1353 {"getboolean", Tkapp_GetBoolean, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1354 {"exprstring", Tkapp_ExprString, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1355 {"exprlong", Tkapp_ExprLong, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1356 {"exprdouble", Tkapp_ExprDouble, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1357 {"exprboolean", Tkapp_ExprBoolean, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1358 {"splitlist", Tkapp_SplitList, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1359 {"split", Tkapp_Split, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1360 {"merge", Tkapp_Merge, 0}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1361 {"createcommand", Tkapp_CreateCommand, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1362 {"deletecommand", Tkapp_DeleteCommand, 1}, |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1363 #ifdef HAVE_CREATEFILEHANDLER |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1364 {"createfilehandler", Tkapp_CreateFileHandler, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1365 {"deletefilehandler", Tkapp_DeleteFileHandler, 1}, |
|
5954
d3835a6a18c9
Rather unsatisfactory temporary hack to get it to run
Guido van Rossum <guido@python.org>
parents:
5947
diff
changeset
|
1366 #endif |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1367 {"createtimerhandler", Tkapp_CreateTimerHandler, 1}, |
| 4968 | 1368 {"mainloop", Tkapp_MainLoop, 1}, |
| 1369 {"dooneevent", Tkapp_DoOneEvent, 1}, | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1370 {"quit", Tkapp_Quit, 1}, |
| 4968 | 1371 {NULL, NULL} |
| 1664 | 1372 }; |
| 1373 | |
| 4968 | 1374 |
| 1375 | |
| 1664 | 1376 /**** Tkapp Type Methods ****/ |
| 1377 | |
| 1378 static void | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1379 Tkapp_Dealloc(self) |
| 4968 | 1380 PyObject *self; |
| 1664 | 1381 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1382 Tcl_DeleteInterp(Tkapp_Interp(self)); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1383 PyMem_DEL(self); |
| 1664 | 1384 } |
| 1385 | |
| 1386 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1387 Tkapp_GetAttr(self, name) |
| 4968 | 1388 PyObject *self; |
| 1389 char *name; | |
| 1664 | 1390 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1391 return Py_FindMethod(Tkapp_methods, self, name); |
| 1664 | 1392 } |
| 1393 | |
| 1394 static PyTypeObject Tkapp_Type = | |
| 1395 { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1396 PyObject_HEAD_INIT(NULL) |
| 4968 | 1397 0, /*ob_size */ |
| 1398 "tkapp", /*tp_name */ | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1399 sizeof(TkappObject), /*tp_basicsize */ |
| 4968 | 1400 0, /*tp_itemsize */ |
| 1401 Tkapp_Dealloc, /*tp_dealloc */ | |
| 1402 0, /*tp_print */ | |
| 1403 Tkapp_GetAttr, /*tp_getattr */ | |
| 1404 0, /*tp_setattr */ | |
| 1405 0, /*tp_compare */ | |
| 1406 0, /*tp_repr */ | |
| 1407 0, /*tp_as_number */ | |
| 1408 0, /*tp_as_sequence */ | |
| 1409 0, /*tp_as_mapping */ | |
| 1410 0, /*tp_hash */ | |
| 1664 | 1411 }; |
| 1412 | |
| 4968 | 1413 |
| 1414 | |
| 1664 | 1415 /**** Tkinter Module ****/ |
| 1416 | |
| 1417 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1418 Tkinter_Create(self, args) |
| 4968 | 1419 PyObject *self; |
| 1420 PyObject *args; | |
| 1664 | 1421 { |
| 4968 | 1422 char *screenName = NULL; |
| 1423 char *baseName = NULL; | |
| 1424 char *className = NULL; | |
| 1425 int interactive = 0; | |
| 1664 | 1426 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1427 baseName = strrchr(Py_GetProgramName(), '/'); |
| 4968 | 1428 if (baseName != NULL) |
| 1429 baseName++; | |
| 1430 else | |
| 1431 baseName = Py_GetProgramName(); | |
| 1432 className = "Tk"; | |
| 1664 | 1433 |
| 4968 | 1434 if (!PyArg_ParseTuple(args, "|zssi", |
| 1435 &screenName, &baseName, &className, | |
| 1436 &interactive)) | |
| 1437 return NULL; | |
| 1664 | 1438 |
| 4968 | 1439 return (PyObject *) Tkapp_New(screenName, baseName, className, |
| 1440 interactive); | |
| 1664 | 1441 } |
| 1442 | |
| 1443 static PyMethodDef moduleMethods[] = | |
| 1444 { | |
| 4968 | 1445 {"create", Tkinter_Create, 1}, |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1446 #ifdef HAVE_CREATEFILEHANDLER |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1447 {"createfilehandler", Tkapp_CreateFileHandler, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1448 {"deletefilehandler", Tkapp_DeleteFileHandler, 1}, |
|
5954
d3835a6a18c9
Rather unsatisfactory temporary hack to get it to run
Guido van Rossum <guido@python.org>
parents:
5947
diff
changeset
|
1449 #endif |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1450 {"createtimerhandler", Tkapp_CreateTimerHandler, 1}, |
| 4968 | 1451 {"mainloop", Tkapp_MainLoop, 1}, |
| 1452 {"dooneevent", Tkapp_DoOneEvent, 1}, | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1453 {"quit", Tkapp_Quit, 1}, |
| 4968 | 1454 {NULL, NULL} |
| 1664 | 1455 }; |
| 1456 | |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1457 static PyInterpreterState *event_interp = NULL; |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1458 |
| 1664 | 1459 static int |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1460 EventHook() |
| 1664 | 1461 { |
|
6478
297a541eb865
Darn. When thread support is disabled, the BEGIN/END macros don't
Guido van Rossum <guido@python.org>
parents:
6455
diff
changeset
|
1462 PyThreadState *tstate, *save_tstate; |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1463 |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1464 if (Tk_GetNumMainWindows() == 0) |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1465 return 0; |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1466 if (event_interp == NULL) |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1467 return 0; |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1468 tstate = PyThreadState_New(event_interp); |
|
6478
297a541eb865
Darn. When thread support is disabled, the BEGIN/END macros don't
Guido van Rossum <guido@python.org>
parents:
6455
diff
changeset
|
1469 save_tstate = PyThreadState_Swap(NULL); |
|
297a541eb865
Darn. When thread support is disabled, the BEGIN/END macros don't
Guido van Rossum <guido@python.org>
parents:
6455
diff
changeset
|
1470 PyEval_RestoreThread(tstate); |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1471 if (!errorInCmd) |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1472 Tcl_DoOneEvent(TCL_DONT_WAIT); |
| 4968 | 1473 if (errorInCmd) { |
| 1474 errorInCmd = 0; | |
| 1475 PyErr_Restore(excInCmd, valInCmd, trbInCmd); | |
| 1476 excInCmd = valInCmd = trbInCmd = NULL; | |
| 1477 PyErr_Print(); | |
| 1478 } | |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1479 PyThreadState_Clear(tstate); |
|
6478
297a541eb865
Darn. When thread support is disabled, the BEGIN/END macros don't
Guido van Rossum <guido@python.org>
parents:
6455
diff
changeset
|
1480 PyEval_SaveThread(); |
|
297a541eb865
Darn. When thread support is disabled, the BEGIN/END macros don't
Guido van Rossum <guido@python.org>
parents:
6455
diff
changeset
|
1481 PyThreadState_Swap(save_tstate); |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1482 PyThreadState_Delete(tstate); |
| 4968 | 1483 return 0; |
| 1664 | 1484 } |
| 1485 | |
| 4968 | 1486 |
| 1487 /* all errors will be checked in one fell swoop in init_tkinter() */ | |
| 1488 static void | |
| 1489 ins_long(d, name, val) | |
| 1490 PyObject *d; | |
| 1491 char *name; | |
| 1492 long val; | |
| 1493 { | |
| 1494 PyObject *v = PyInt_FromLong(val); | |
| 1495 if (v) { | |
| 1496 PyDict_SetItemString(d, name, v); | |
| 1497 Py_DECREF(v); | |
| 1498 } | |
| 1499 } | |
| 1500 static void | |
| 1501 ins_string(d, name, val) | |
| 1502 PyObject *d; | |
| 1503 char *name; | |
| 1504 char *val; | |
| 1505 { | |
| 1506 PyObject *v = PyString_FromString(val); | |
| 1507 if (v) { | |
| 1508 PyDict_SetItemString(d, name, v); | |
| 1509 Py_DECREF(v); | |
| 1510 } | |
| 1511 } | |
| 1512 | |
| 1513 | |
| 1664 | 1514 void |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1515 init_tkinter() |
| 1664 | 1516 { |
| 4968 | 1517 PyObject *m, *d; |
| 1664 | 1518 |
| 4968 | 1519 Tkapp_Type.ob_type = &PyType_Type; |
| 1520 Tktt_Type.ob_type = &PyType_Type; | |
|
4091
dc946cab7b9b
Hacks to support being a Windows DLL
Guido van Rossum <guido@python.org>
parents:
4079
diff
changeset
|
1521 |
| 4968 | 1522 m = Py_InitModule("_tkinter", moduleMethods); |
| 1664 | 1523 |
| 4968 | 1524 d = PyModule_GetDict(m); |
| 1525 Tkinter_TclError = Py_BuildValue("s", "TclError"); | |
| 1526 PyDict_SetItemString(d, "TclError", Tkinter_TclError); | |
| 1527 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1528 ins_long(d, "READABLE", TCL_READABLE); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1529 ins_long(d, "WRITABLE", TCL_WRITABLE); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1530 ins_long(d, "EXCEPTION", TCL_EXCEPTION); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1531 ins_long(d, "WINDOW_EVENTS", TCL_WINDOW_EVENTS); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1532 ins_long(d, "FILE_EVENTS", TCL_FILE_EVENTS); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1533 ins_long(d, "TIMER_EVENTS", TCL_TIMER_EVENTS); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1534 ins_long(d, "IDLE_EVENTS", TCL_IDLE_EVENTS); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1535 ins_long(d, "ALL_EVENTS", TCL_ALL_EVENTS); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1536 ins_long(d, "DONT_WAIT", TCL_DONT_WAIT); |
| 4968 | 1537 ins_string(d, "TK_VERSION", TK_VERSION); |
| 1538 ins_string(d, "TCL_VERSION", TCL_VERSION); | |
| 1664 | 1539 |
|
6311
13fbd98d81cc
Export names for the types defined by this module: TkappType and TkttType.
Guido van Rossum <guido@python.org>
parents:
6265
diff
changeset
|
1540 PyDict_SetItemString(d, "TkappType", (PyObject *)&Tkapp_Type); |
|
13fbd98d81cc
Export names for the types defined by this module: TkappType and TkttType.
Guido van Rossum <guido@python.org>
parents:
6265
diff
changeset
|
1541 PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type); |
|
13fbd98d81cc
Export names for the types defined by this module: TkappType and TkttType.
Guido van Rossum <guido@python.org>
parents:
6265
diff
changeset
|
1542 |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1543 if (PyOS_InputHook == NULL) { |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1544 event_interp = PyThreadState_Get()->interp; |
|
5973
e77847e1158e
Renamed Py_input_hook to PyOS_InputHook.
Guido van Rossum <guido@python.org>
parents:
5954
diff
changeset
|
1545 PyOS_InputHook = EventHook; |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1546 } |
| 1664 | 1547 |
| 4968 | 1548 if (PyErr_Occurred()) |
|
7212
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
1549 return; |
|
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
1550 |
|
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
1551 Py_AtExit(Tcl_Finalize); |
|
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
1552 |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1553 #ifdef macintosh |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1554 /* |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1555 ** Part of this code is stolen from MacintoshInit in tkMacAppInit. |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1556 ** Most of the initializations in that routine (toolbox init calls and |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1557 ** such) have already been done for us, so we only need these. |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1558 */ |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1559 #if TKMAJORMINOR >= 8000 |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1560 tcl_macQdPtr = &qd; |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1561 #endif |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1562 |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1563 Tcl_MacSetEventProc(PyMacConvertEvent); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1564 #if GENERATINGCFM |
| 4968 | 1565 mac_addlibresources(); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1566 #endif /* GENERATINGCFM */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1567 #endif /* macintosh */ |
| 1664 | 1568 } |
| 3120 | 1569 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1570 |
| 4968 | 1571 |
| 3120 | 1572 #ifdef macintosh |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1573 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1574 /* |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1575 ** 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
|
1576 */ |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1577 |
| 3120 | 1578 void |
| 1579 panic(char * format, ...) | |
| 1580 { | |
| 4968 | 1581 va_list varg; |
| 3120 | 1582 |
| 4968 | 1583 va_start(varg, format); |
| 3120 | 1584 |
| 4968 | 1585 vfprintf(stderr, format, varg); |
| 1586 (void) fflush(stderr); | |
| 3120 | 1587 |
| 4968 | 1588 va_end(varg); |
| 3120 | 1589 |
| 4968 | 1590 Py_FatalError("Tcl/Tk panic"); |
| 3120 | 1591 } |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1592 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1593 /* |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1594 ** 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
|
1595 */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1596 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1597 static int |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1598 PyMacConvertEvent(eventPtr) |
| 4968 | 1599 EventRecord *eventPtr; |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1600 { |
| 4968 | 1601 if (SIOUXHandleOneEvent(eventPtr)) |
| 1602 return 0; /* Nothing happened to the Tcl event queue */ | |
| 1603 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
|
1604 } |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1605 |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1606 #if defined(USE_GUSI) && TKMAJORMINOR < 8000 |
|
5695
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1607 /* |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1608 * For Python we have to override this routine (from TclMacNotify), |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1609 * since we use GUSI for our sockets, not Tcl streams. Hence, we have |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1610 * to use GUSI select to see whether our socket is ready. Note that |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1611 * createfilehandler (above) sets the type to TCL_UNIX_FD for our |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1612 * files and sockets. |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1613 * |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1614 * NOTE: this code was lifted from Tcl 7.6, it may need to be modified |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1615 * for other versions. */ |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1616 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1617 int |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1618 Tcl_FileReady(file, mask) |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1619 Tcl_File file; /* File handle for a stream. */ |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1620 int mask; /* OR'ed combination of TCL_READABLE, |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1621 * TCL_WRITABLE, and TCL_EXCEPTION: |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1622 * indicates conditions caller cares about. */ |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1623 { |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1624 int type; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1625 int fd; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1626 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1627 fd = (int) Tcl_GetFileInfo(file, &type); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1628 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1629 if (type == TCL_MAC_SOCKET) { |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1630 return TclMacSocketReady(file, mask); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1631 } else if (type == TCL_MAC_FILE) { |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1632 /* |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1633 * Under the Macintosh, files are always ready, so we just |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1634 * return the mask that was passed in. |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1635 */ |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1636 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1637 return mask; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1638 } else if (type == TCL_UNIX_FD) { |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1639 fd_set readset, writeset, excset; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1640 struct timeval tv; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1641 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1642 FD_ZERO(&readset); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1643 FD_ZERO(&writeset); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1644 FD_ZERO(&excset); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1645 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1646 if ( mask & TCL_READABLE ) FD_SET(fd, &readset); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1647 if ( mask & TCL_WRITABLE ) FD_SET(fd, &writeset); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1648 if ( mask & TCL_EXCEPTION ) FD_SET(fd, &excset); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1649 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1650 tv.tv_sec = tv.tv_usec = 0; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1651 if ( select(fd+1, &readset, &writeset, &excset, &tv) <= 0 ) |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1652 return 0; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1653 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1654 mask = 0; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1655 if ( FD_ISSET(fd, &readset) ) mask |= TCL_READABLE; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1656 if ( FD_ISSET(fd, &writeset) ) mask |= TCL_WRITABLE; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1657 if ( FD_ISSET(fd, &excset) ) mask |= TCL_EXCEPTION; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1658 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1659 return mask; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1660 } |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1661 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1662 return 0; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1663 } |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1664 #endif /* USE_GUSI */ |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1665 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1666 #if GENERATINGCFM |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1667 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1668 /* |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1669 ** 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
|
1670 */ |
|
3262
bfb63b45ff0f
Initialize GUSI on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3240
diff
changeset
|
1671 |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1672 #include <Resources.h> |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1673 #include <CodeFragments.h> |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1674 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1675 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
|
1676 static FSSpec library_fss; |
| 3120 | 1677 |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1678 /* |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1679 ** 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
|
1680 ** 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
|
1681 ** 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
|
1682 ** resources. |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1683 */ |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1684 OSErr pascal |
|
5360
f858038b64c2
Adapt Mac specific code to new universal headers (I think -- this is
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1685 init_tkinter_shlib(CFragInitBlockPtr data) |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1686 { |
|
4139
010344b4a616
Call __initialize(), not __sinit() on Mac dynamic loading entry.
Guido van Rossum <guido@python.org>
parents:
4091
diff
changeset
|
1687 __initialize(); |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1688 if ( data == nil ) return noErr; |
|
5360
f858038b64c2
Adapt Mac specific code to new universal headers (I think -- this is
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1689 if ( data->fragLocator.where == kDataForkCFragLocator ) { |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1690 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
|
1691 loaded_from_shlib = 1; |
|
5360
f858038b64c2
Adapt Mac specific code to new universal headers (I think -- this is
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1692 } else if ( data->fragLocator.where == kResourceCFragLocator ) { |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1693 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
|
1694 loaded_from_shlib = 1; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1695 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1696 return noErr; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1697 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1698 |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1699 /* |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1700 ** 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
|
1701 ** 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
|
1702 */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1703 static |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1704 mac_addlibresources() |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1705 { |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1706 if ( !loaded_from_shlib ) |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1707 return; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1708 (void)FSpOpenResFile(&library_fss, fsRdPerm); |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1709 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1710 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1711 #endif /* GENERATINGCFM */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1712 #endif /* macintosh */ |
