Mercurial > cpython-lru_cache-weakref
annotate Modules/_tkinter.c @ 7278:59d2761ba1cf legacy-trunk
Remove obsolete pagenumbering / pagestyle cruft.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Fri, 13 Feb 1998 07:08:56 +0000 |
| parents | b9bbfa169920 |
| children | 13f29b62a209 |
| 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 |
| 4968 | 340 if (screenName != NULL) |
| 341 Tcl_SetVar2(v->interp, "env", "DISPLAY", | |
| 342 screenName, TCL_GLOBAL_ONLY); | |
| 1664 | 343 |
| 4968 | 344 if (interactive) |
| 345 Tcl_SetVar(v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); | |
| 346 else | |
| 347 Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); | |
| 1664 | 348 |
| 4968 | 349 /* This is used to get the application class for Tk 4.1 and up */ |
| 350 argv0 = (char*)ckalloc(strlen(className) + 1); | |
| 351 if (!argv0) { | |
| 352 PyErr_NoMemory(); | |
| 353 Py_DECREF(v); | |
| 354 return NULL; | |
| 355 } | |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
356 |
| 4968 | 357 strcpy(argv0, className); |
| 358 if (isupper(argv0[0])) | |
| 359 argv0[0] = tolower(argv0[0]); | |
| 360 Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY); | |
| 361 ckfree(argv0); | |
| 1664 | 362 |
| 4968 | 363 if (Tcl_AppInit(v->interp) != TCL_OK) |
| 364 return (TkappObject *)Tkinter_Error(v); | |
| 365 | |
| 366 return v; | |
| 1664 | 367 } |
| 368 | |
| 4968 | 369 |
| 370 | |
| 1664 | 371 /** Tcl Eval **/ |
| 372 | |
| 373 static PyObject * | |
| 4968 | 374 Tkapp_Call(self, args) |
| 375 PyObject *self; | |
| 376 PyObject *args; | |
| 1664 | 377 { |
| 4968 | 378 char *cmd = Merge(args); |
| 379 PyObject *res = NULL; | |
| 380 | |
| 381 if (!cmd) | |
| 382 PyErr_SetString(Tkinter_TclError, "merge failed"); | |
| 383 | |
| 384 else if (Tcl_Eval(Tkapp_Interp(self), cmd) == TCL_ERROR) | |
| 385 res = Tkinter_Error(self); | |
| 386 | |
| 387 else | |
| 388 res = PyString_FromString(Tkapp_Result(self)); | |
| 389 | |
| 390 if (cmd) | |
| 391 ckfree(cmd); | |
| 392 | |
| 393 return res; | |
| 394 } | |
| 1664 | 395 |
| 4968 | 396 |
| 397 static PyObject * | |
| 398 Tkapp_GlobalCall(self, args) | |
| 399 PyObject *self; | |
| 400 PyObject *args; | |
| 401 { | |
| 402 char *cmd = Merge(args); | |
| 403 PyObject *res = NULL; | |
| 404 | |
| 1664 | 405 |
| 4968 | 406 if (!cmd) |
| 407 PyErr_SetString(Tkinter_TclError, "merge failed"); | |
| 408 | |
| 409 else if (Tcl_GlobalEval(Tkapp_Interp(self), cmd) == TCL_ERROR) | |
| 410 res = Tkinter_Error(self); | |
| 411 else | |
| 412 res = PyString_FromString(Tkapp_Result(self)); | |
| 413 | |
| 414 if (cmd) | |
| 415 ckfree(cmd); | |
| 416 | |
| 417 return res; | |
| 1664 | 418 } |
| 419 | |
| 420 static PyObject * | |
| 4968 | 421 Tkapp_Eval(self, args) |
| 422 PyObject *self; | |
| 423 PyObject *args; | |
| 1664 | 424 { |
| 4968 | 425 char *script; |
| 426 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
427 if (!PyArg_ParseTuple(args, "s", &script)) |
| 4968 | 428 return NULL; |
| 1664 | 429 |
| 4968 | 430 if (Tcl_Eval(Tkapp_Interp(self), script) == TCL_ERROR) |
| 431 return Tkinter_Error(self); | |
| 1664 | 432 |
| 4968 | 433 return PyString_FromString(Tkapp_Result(self)); |
| 1664 | 434 } |
| 435 | |
| 436 static PyObject * | |
| 4968 | 437 Tkapp_GlobalEval(self, args) |
| 438 PyObject *self; | |
| 439 PyObject *args; | |
| 1664 | 440 { |
| 4968 | 441 char *script; |
| 1664 | 442 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
443 if (!PyArg_ParseTuple(args, "s", &script)) |
| 4968 | 444 return NULL; |
| 1664 | 445 |
| 4968 | 446 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
|
447 return Tkinter_Error(self); |
| 1664 | 448 |
| 4968 | 449 return PyString_FromString(Tkapp_Result(self)); |
| 1664 | 450 } |
| 451 | |
| 452 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
453 Tkapp_EvalFile(self, args) |
| 4968 | 454 PyObject *self; |
| 455 PyObject *args; | |
| 1664 | 456 { |
| 4968 | 457 char *fileName; |
| 1664 | 458 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
459 if (!PyArg_ParseTuple(args, "s", &fileName)) |
| 4968 | 460 return NULL; |
| 1664 | 461 |
| 4968 | 462 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
|
463 return Tkinter_Error(self); |
| 1664 | 464 |
| 4968 | 465 return PyString_FromString(Tkapp_Result(self)); |
| 1664 | 466 } |
| 467 | |
| 468 static PyObject * | |
| 4968 | 469 Tkapp_Record(self, args) |
| 470 PyObject *self; | |
| 471 PyObject *args; | |
| 1664 | 472 { |
| 4968 | 473 char *script; |
| 1664 | 474 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
475 if (!PyArg_ParseTuple(args, "s", &script)) |
| 4968 | 476 return NULL; |
| 1664 | 477 |
| 4968 | 478 if (TCL_ERROR == Tcl_RecordAndEval(Tkapp_Interp(self), |
| 479 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
|
480 return Tkinter_Error(self); |
| 1664 | 481 |
| 4968 | 482 return PyString_FromString(Tkapp_Result(self)); |
| 1664 | 483 } |
| 484 | |
| 485 static PyObject * | |
| 4968 | 486 Tkapp_AddErrorInfo(self, args) |
| 487 PyObject *self; | |
| 488 PyObject *args; | |
| 1664 | 489 { |
| 4968 | 490 char *msg; |
| 1664 | 491 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
492 if (!PyArg_ParseTuple(args, "s", &msg)) |
| 4968 | 493 return NULL; |
| 494 Tcl_AddErrorInfo(Tkapp_Interp(self), msg); | |
| 1664 | 495 |
| 4968 | 496 Py_INCREF(Py_None); |
| 497 return Py_None; | |
| 1664 | 498 } |
| 499 | |
| 4968 | 500 |
| 501 | |
| 1664 | 502 /** Tcl Variable **/ |
| 503 | |
| 504 static PyObject * | |
| 4968 | 505 SetVar(self, args, flags) |
| 506 PyObject *self; | |
| 507 PyObject *args; | |
| 508 int flags; | |
| 1664 | 509 { |
| 4968 | 510 char *name1, *name2, *ok; |
| 511 PyObject *newValue; | |
| 512 PyObject *tmp = PyList_New(0); | |
| 1664 | 513 |
| 4968 | 514 if (!tmp) |
| 515 return NULL; | |
| 1664 | 516 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
517 if (PyArg_ParseTuple(args, "sO", &name1, &newValue)) |
| 4968 | 518 /* XXX Merge? */ |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
519 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
|
520 AsString(newValue, tmp), flags); |
| 1664 | 521 |
| 4968 | 522 else { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
523 PyErr_Clear(); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
524 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
|
525 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
|
526 AsString (newValue, tmp), flags); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
527 else { |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
528 Py_DECREF (tmp); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
529 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
530 } |
| 4968 | 531 } |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
532 Py_DECREF(tmp); |
| 1664 | 533 |
| 4968 | 534 if (!ok) |
| 535 return Tkinter_Error(self); | |
| 536 | |
| 537 Py_INCREF(Py_None); | |
| 538 return Py_None; | |
| 1664 | 539 } |
| 540 | |
| 541 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
542 Tkapp_SetVar(self, args) |
| 4968 | 543 PyObject *self; |
| 544 PyObject *args; | |
| 1664 | 545 { |
| 4968 | 546 return SetVar(self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 547 } |
| 548 | |
| 549 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
550 Tkapp_GlobalSetVar(self, args) |
| 4968 | 551 PyObject *self; |
| 552 PyObject *args; | |
| 1664 | 553 { |
| 4968 | 554 return SetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 555 } |
| 556 | |
| 4968 | 557 |
| 558 | |
| 1664 | 559 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
560 GetVar(self, args, flags) |
| 4968 | 561 PyObject *self; |
| 562 PyObject *args; | |
| 563 int flags; | |
| 1664 | 564 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
565 char *name1, *name2=NULL, *s; |
| 4968 | 566 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
567 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
|
568 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
569 if (name2 == NULL) |
| 4968 | 570 s = Tcl_GetVar(Tkapp_Interp (self), name1, flags); |
| 1664 | 571 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
572 else |
| 4968 | 573 s = Tcl_GetVar2(Tkapp_Interp(self), name1, name2, flags); |
| 1664 | 574 |
| 4968 | 575 if (s == NULL) |
| 576 return Tkinter_Error(self); | |
| 1664 | 577 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
578 return PyString_FromString(s); |
| 1664 | 579 } |
| 580 | |
| 581 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
582 Tkapp_GetVar(self, args) |
| 4968 | 583 PyObject *self; |
| 584 PyObject *args; | |
| 1664 | 585 { |
| 4968 | 586 return GetVar(self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 587 } |
| 588 | |
| 589 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
590 Tkapp_GlobalGetVar(self, args) |
| 4968 | 591 PyObject *self; |
| 592 PyObject *args; | |
| 1664 | 593 { |
| 4968 | 594 return GetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 595 } |
| 596 | |
| 4968 | 597 |
| 598 | |
| 1664 | 599 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
600 UnsetVar(self, args, flags) |
| 4968 | 601 PyObject *self; |
| 602 PyObject *args; | |
| 603 int flags; | |
| 1664 | 604 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
605 char *name1, *name2=NULL; |
| 4968 | 606 int code; |
| 607 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
608 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
|
609 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
610 if (name2 == NULL) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
611 code = Tcl_UnsetVar(Tkapp_Interp(self), name1, flags); |
| 1664 | 612 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
613 else |
| 4968 | 614 code = Tcl_UnsetVar2(Tkapp_Interp(self), name1, name2, flags); |
| 1664 | 615 |
| 4968 | 616 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
|
617 return Tkinter_Error(self); |
| 1664 | 618 |
| 4968 | 619 Py_INCREF(Py_None); |
| 620 return Py_None; | |
| 1664 | 621 } |
| 622 | |
| 623 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
624 Tkapp_UnsetVar(self, args) |
| 4968 | 625 PyObject *self; |
| 626 PyObject *args; | |
| 1664 | 627 { |
| 4968 | 628 return UnsetVar(self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 629 } |
| 630 | |
| 631 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
632 Tkapp_GlobalUnsetVar(self, args) |
| 4968 | 633 PyObject *self; |
| 634 PyObject *args; | |
| 1664 | 635 { |
| 4968 | 636 return UnsetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 637 } |
| 638 | |
| 4968 | 639 |
| 640 | |
| 1664 | 641 /** Tcl to Python **/ |
| 642 | |
| 643 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
644 Tkapp_GetInt(self, args) |
| 4968 | 645 PyObject *self; |
| 646 PyObject *args; | |
| 1664 | 647 { |
| 4968 | 648 char *s; |
| 649 int v; | |
| 1664 | 650 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
651 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 652 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
653 if (Tcl_GetInt(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
| 4968 | 654 return Tkinter_Error(self); |
| 655 return Py_BuildValue("i", v); | |
| 1664 | 656 } |
| 657 | |
| 658 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
659 Tkapp_GetDouble(self, args) |
| 4968 | 660 PyObject *self; |
| 661 PyObject *args; | |
| 1664 | 662 { |
| 4968 | 663 char *s; |
| 664 double v; | |
| 1664 | 665 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
666 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 667 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
668 if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
| 4968 | 669 return Tkinter_Error(self); |
| 670 return Py_BuildValue("d", v); | |
| 1664 | 671 } |
| 672 | |
| 673 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
674 Tkapp_GetBoolean(self, args) |
| 4968 | 675 PyObject *self; |
| 676 PyObject *args; | |
| 1664 | 677 { |
| 4968 | 678 char *s; |
| 679 int v; | |
| 1664 | 680 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
681 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 682 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
683 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
|
684 return Tkinter_Error(self); |
| 4968 | 685 return Py_BuildValue("i", v); |
| 1664 | 686 } |
| 687 | |
| 688 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
689 Tkapp_ExprString(self, args) |
| 4968 | 690 PyObject *self; |
| 691 PyObject *args; | |
| 1664 | 692 { |
| 4968 | 693 char *s; |
| 1664 | 694 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
695 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 696 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
697 if (Tcl_ExprString(Tkapp_Interp(self), s) == TCL_ERROR) |
| 4968 | 698 return Tkinter_Error(self); |
| 699 return Py_BuildValue("s", Tkapp_Result(self)); | |
| 1664 | 700 } |
| 701 | |
| 702 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
703 Tkapp_ExprLong(self, args) |
| 4968 | 704 PyObject *self; |
| 705 PyObject *args; | |
| 1664 | 706 { |
| 4968 | 707 char *s; |
| 708 long v; | |
| 1664 | 709 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
710 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 711 return NULL; |
| 712 if (Tcl_ExprLong(Tkapp_Interp(self), s, &v) == TCL_ERROR) | |
| 713 return Tkinter_Error(self); | |
| 714 return Py_BuildValue("l", v); | |
| 1664 | 715 } |
| 716 | |
| 717 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
718 Tkapp_ExprDouble(self, args) |
| 4968 | 719 PyObject *self; |
| 720 PyObject *args; | |
| 1664 | 721 { |
| 4968 | 722 char *s; |
| 723 double v; | |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
724 int retval; |
| 1664 | 725 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
726 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 727 return NULL; |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
728 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
|
729 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
|
730 PyFPE_END_PROTECT(retval) |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
731 if (retval == TCL_ERROR) |
| 4968 | 732 return Tkinter_Error(self); |
| 733 return Py_BuildValue("d", v); | |
| 1664 | 734 } |
| 735 | |
| 736 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
737 Tkapp_ExprBoolean(self, args) |
| 4968 | 738 PyObject *self; |
| 739 PyObject *args; | |
| 1664 | 740 { |
| 4968 | 741 char *s; |
| 742 int v; | |
| 1664 | 743 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
744 if (!PyArg_ParseTuple(args, "s", &s)) |
| 4968 | 745 return NULL; |
| 746 if (Tcl_ExprBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR) | |
| 747 return Tkinter_Error(self); | |
| 748 return Py_BuildValue("i", v); | |
| 1664 | 749 } |
| 750 | |
| 4968 | 751 |
| 752 | |
| 1664 | 753 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
754 Tkapp_SplitList(self, args) |
| 4968 | 755 PyObject *self; |
| 756 PyObject *args; | |
| 1664 | 757 { |
| 4968 | 758 char *list; |
| 759 int argc; | |
| 760 char **argv; | |
| 761 PyObject *v; | |
| 762 int i; | |
| 763 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
764 if (!PyArg_ParseTuple(args, "s", &list)) |
| 4968 | 765 return NULL; |
| 766 | |
| 767 if (Tcl_SplitList(Tkapp_Interp(self), list, &argc, &argv) == TCL_ERROR) | |
| 768 return Tkinter_Error(self); | |
| 1664 | 769 |
| 4968 | 770 if (!(v = PyTuple_New(argc))) |
| 771 return NULL; | |
| 772 | |
| 773 for (i = 0; i < argc; i++) { | |
| 774 PyObject *s = PyString_FromString(argv[i]); | |
| 775 if (!s || PyTuple_SetItem(v, i, s)) { | |
| 776 Py_DECREF(v); | |
| 777 v = NULL; | |
| 778 goto finally; | |
| 779 } | |
| 780 } | |
| 1664 | 781 |
| 4968 | 782 finally: |
| 783 ckfree(FREECAST argv); | |
| 784 return v; | |
| 1664 | 785 } |
| 786 | |
| 787 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
788 Tkapp_Split(self, args) |
| 4968 | 789 PyObject *self; |
| 790 PyObject *args; | |
| 1664 | 791 { |
| 4968 | 792 char *list; |
| 1664 | 793 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
794 if (!PyArg_ParseTuple(args, "s", &list)) |
| 4968 | 795 return NULL; |
| 796 return Split(self, list); | |
| 1664 | 797 } |
| 798 | |
| 799 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
800 Tkapp_Merge(self, args) |
| 4968 | 801 PyObject *self; |
| 802 PyObject *args; | |
| 1664 | 803 { |
| 4968 | 804 char *s = Merge(args); |
| 805 PyObject *res = NULL; | |
| 1664 | 806 |
| 4968 | 807 if (s) { |
| 808 res = PyString_FromString(s); | |
| 809 ckfree(s); | |
| 810 } | |
| 811 else | |
| 812 PyErr_SetString(Tkinter_TclError, "merge failed"); | |
| 813 | |
| 814 return res; | |
| 1664 | 815 } |
| 816 | |
| 4968 | 817 |
| 818 | |
| 1664 | 819 /** Tcl Command **/ |
| 820 | |
| 821 /* This is the Tcl command that acts as a wrapper for Python | |
| 4968 | 822 * function or method. |
| 823 */ | |
| 1664 | 824 static int |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
825 PythonCmd(clientData, interp, argc, argv) |
| 4968 | 826 ClientData clientData; /* Is (self, func) */ |
| 827 Tcl_Interp *interp; | |
| 828 int argc; | |
| 829 char *argv[]; | |
| 1664 | 830 { |
| 4968 | 831 PyObject *self, *func, *arg, *res, *tmp; |
| 832 int i; | |
| 1664 | 833 |
| 4968 | 834 /* TBD: no error checking here since we know, via the |
| 835 * Tkapp_CreateCommand() that the client data is a two-tuple | |
| 836 */ | |
| 837 self = PyTuple_GetItem((PyObject *) clientData, 0); | |
| 838 func = PyTuple_GetItem((PyObject *) clientData, 1); | |
| 839 | |
| 840 /* Create argument list (argv1, ..., argvN) */ | |
| 841 if (!(arg = PyTuple_New(argc - 1))) | |
| 842 return PythonCmd_Error(interp); | |
| 1664 | 843 |
| 4968 | 844 for (i = 0; i < (argc - 1); i++) { |
| 845 PyObject *s = PyString_FromString(argv[i + 1]); | |
| 846 if (!s || PyTuple_SetItem(arg, i, s)) { | |
| 847 Py_DECREF(arg); | |
| 848 PythonCmd_Error(interp); | |
| 849 } | |
| 850 } | |
| 851 res = PyEval_CallObject(func, arg); | |
| 852 Py_DECREF(arg); | |
| 1713 | 853 |
| 4968 | 854 if (res == NULL) |
| 855 return PythonCmd_Error(interp); | |
| 1664 | 856 |
| 4968 | 857 if (!(tmp = PyList_New(0))) { |
| 858 Py_DECREF(res); | |
| 859 return PythonCmd_Error(interp); | |
| 860 } | |
| 1664 | 861 |
| 4968 | 862 Tcl_SetResult(Tkapp_Interp(self), AsString(res, tmp), TCL_VOLATILE); |
| 863 Py_DECREF(res); | |
| 864 Py_DECREF(tmp); | |
| 865 | |
| 866 return TCL_OK; | |
| 1664 | 867 } |
| 868 | |
| 869 static void | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
870 PythonCmdDelete(clientData) |
| 4968 | 871 ClientData clientData; /* Is (self, func) */ |
| 1664 | 872 { |
| 4968 | 873 Py_DECREF((PyObject *) clientData); |
| 1664 | 874 } |
| 875 | |
| 4968 | 876 |
| 877 | |
| 1664 | 878 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
879 Tkapp_CreateCommand(self, args) |
| 4968 | 880 PyObject *self; |
| 881 PyObject *args; | |
| 1664 | 882 { |
| 4968 | 883 char *cmdName; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
884 PyObject *func; |
| 4968 | 885 PyObject *data; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
886 |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
887 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
|
888 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
889 if (!PyCallable_Check(func)) { |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
890 PyErr_SetString(PyExc_TypeError, "command not callable"); |
| 4968 | 891 return NULL; |
| 892 } | |
| 1664 | 893 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
894 data = Py_BuildValue("OO", self, func); |
| 4968 | 895 if (!data) |
| 896 return NULL; | |
| 1664 | 897 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
898 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
|
899 (ClientData) data, PythonCmdDelete) == NULL) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
900 { |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
901 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
|
902 Py_DECREF(data); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
903 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
904 } |
| 1664 | 905 |
| 4968 | 906 Py_INCREF(Py_None); |
| 907 return Py_None; | |
| 1664 | 908 } |
| 909 | |
| 4968 | 910 |
| 911 | |
| 1664 | 912 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
913 Tkapp_DeleteCommand(self, args) |
| 4968 | 914 PyObject *self; |
| 915 PyObject *args; | |
| 1664 | 916 { |
| 4968 | 917 char *cmdName; |
| 1664 | 918 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
919 if (!PyArg_ParseTuple(args, "s", &cmdName)) |
| 4968 | 920 return NULL; |
| 921 if (Tcl_DeleteCommand(Tkapp_Interp(self), cmdName) == -1) | |
| 922 { | |
| 923 PyErr_SetString(Tkinter_TclError, "can't delete Tcl command"); | |
| 924 return NULL; | |
| 925 } | |
| 926 Py_INCREF(Py_None); | |
| 927 return Py_None; | |
| 1664 | 928 } |
| 929 | |
| 4968 | 930 |
| 931 | |
| 1664 | 932 /** File Handler **/ |
| 933 | |
|
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
|
934 static void |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
935 FileHandler(clientData, mask) |
| 4968 | 936 ClientData clientData; /* Is: (func, file) */ |
| 937 int mask; | |
| 1664 | 938 { |
| 4968 | 939 PyObject *func, *file, *arg, *res; |
| 1664 | 940 |
| 4968 | 941 func = PyTuple_GetItem((PyObject *) clientData, 0); |
| 942 file = PyTuple_GetItem((PyObject *) clientData, 1); | |
| 1664 | 943 |
| 4968 | 944 arg = Py_BuildValue("(Oi)", file, (long) mask); |
| 945 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
|
946 Py_DECREF(arg); |
| 4968 | 947 |
| 948 if (res == NULL) { | |
| 949 errorInCmd = 1; | |
| 950 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); | |
| 951 } | |
| 952 Py_XDECREF(res); | |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
953 } |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
954 |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
955 static int |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
956 GetFileNo(file) |
| 4968 | 957 /* Either an int >= 0 or an object with a |
| 958 *.fileno() method that returns an int >= 0 | |
| 959 */ | |
| 960 PyObject *file; | |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
961 { |
|
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
|
962 PyObject *meth, *args, *res; |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
963 int id; |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
964 if (PyInt_Check(file)) { |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
965 id = PyInt_AsLong(file); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
966 if (id < 0) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
967 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
|
968 return id; |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
969 } |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
970 args = PyTuple_New(0); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
971 if (args == NULL) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
972 return -1; |
| 4968 | 973 |
| 974 meth = PyObject_GetAttrString(file, "fileno"); | |
| 975 if (meth == NULL) { | |
| 976 Py_DECREF(args); | |
| 977 return -1; | |
| 978 } | |
| 979 | |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
980 res = PyEval_CallObject(meth, args); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
981 Py_DECREF(args); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
982 Py_DECREF(meth); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
983 if (res == NULL) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
984 return -1; |
| 4968 | 985 |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
986 if (PyInt_Check(res)) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
987 id = PyInt_AsLong(res); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
988 else |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
989 id = -1; |
| 4968 | 990 |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
991 if (id < 0) |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
992 PyErr_SetString(PyExc_ValueError, |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
993 "invalid fileno() return value"); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
994 Py_DECREF(res); |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
995 return id; |
| 1664 | 996 } |
| 997 | |
| 4968 | 998 |
| 999 static PyObject* Tkapp_ClientDataDict = NULL; | |
| 1000 | |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1001 #ifdef HAVE_CREATEFILEHANDLER |
| 1664 | 1002 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1003 Tkapp_CreateFileHandler(self, args) |
| 4968 | 1004 PyObject *self; |
| 1005 PyObject *args; /* Is (file, mask, func) */ | |
| 1664 | 1006 { |
| 4968 | 1007 PyObject *file, *func, *data; |
| 1008 PyObject *idkey; | |
| 1009 int mask, id; | |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1010 #if TKMAJORMINOR < 8000 |
| 4968 | 1011 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
|
1012 #endif |
| 1664 | 1013 |
| 4968 | 1014 if (!Tkapp_ClientDataDict) { |
| 1015 if (!(Tkapp_ClientDataDict = PyDict_New())) | |
| 1016 return NULL; | |
| 1017 } | |
| 1664 | 1018 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1019 if (!PyArg_ParseTuple(args, "OiO", &file, &mask, &func)) |
| 4968 | 1020 return NULL; |
| 1021 id = GetFileNo(file); | |
| 1022 if (id < 0) | |
| 1023 return NULL; | |
| 1024 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
|
1025 PyErr_SetString(PyExc_TypeError, "bad argument list"); |
| 4968 | 1026 return NULL; |
| 1027 } | |
| 1028 | |
| 1029 if (!(idkey = PyInt_FromLong(id))) | |
| 1030 return NULL; | |
| 1031 | |
| 1032 /* 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
|
1033 data = Py_BuildValue("(OO)", func, file); |
| 4968 | 1034 if (!data || PyDict_SetItem(Tkapp_ClientDataDict, idkey, data)) { |
| 1035 Py_DECREF(idkey); | |
| 1036 Py_XDECREF(data); | |
| 1037 return NULL; | |
| 1038 } | |
| 1039 Py_DECREF(idkey); | |
|
1690
93e036786b17
* tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents:
1664
diff
changeset
|
1040 |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1041 #if TKMAJORMINOR < 8000 |
|
4299
eb1ed743972c
Rationalize MS #ifdefs
Guido van Rossum <guido@python.org>
parents:
4139
diff
changeset
|
1042 #ifdef MS_WINDOWS |
| 4968 | 1043 /* We assume this is a socket... */ |
| 1044 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
|
1045 #else /* !MS_WINDOWS */ |
| 4968 | 1046 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
|
1047 #endif /* !MS_WINDOWS */ |
| 4968 | 1048 /* Ought to check for null Tcl_File object... */ |
| 1049 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
|
1050 #else /* >= 8000 */ |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1051 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
|
1052 #endif /* >= 8000 */ |
| 4968 | 1053 /* XXX fileHandlerDict */ |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1054 Py_INCREF(Py_None); |
| 4968 | 1055 return Py_None; |
| 1664 | 1056 } |
| 1057 | |
| 4968 | 1058 |
| 1664 | 1059 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1060 Tkapp_DeleteFileHandler(self, args) |
| 4968 | 1061 PyObject *self; |
| 1062 PyObject *args; /* Args: file */ | |
| 1664 | 1063 { |
| 4968 | 1064 PyObject *file; |
| 1065 PyObject *idkey; | |
| 1066 PyObject *data; | |
| 1067 int id; | |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1068 #if TKMAJORMINOR < 8000 |
| 4968 | 1069 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
|
1070 #endif |
|
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
1071 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1072 if (!PyArg_ParseTuple(args, "O", &file)) |
| 4968 | 1073 return NULL; |
| 1074 id = GetFileNo(file); | |
| 1075 if (id < 0) | |
| 1076 return NULL; | |
| 1077 | |
| 1078 if (!(idkey = PyInt_FromLong(id))) | |
| 1079 return NULL; | |
| 1080 | |
| 1081 /* find and free the object created in the | |
| 1082 * Tkapp_CreateFileHandler() call | |
| 1083 */ | |
| 1084 data = PyDict_GetItem(Tkapp_ClientDataDict, idkey); | |
| 1085 Py_XDECREF(data); | |
| 1086 PyDict_DelItem(Tkapp_ClientDataDict, idkey); | |
| 1087 Py_DECREF(idkey); | |
| 1664 | 1088 |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1089 #if TKMAJORMINOR < 8000 |
|
4299
eb1ed743972c
Rationalize MS #ifdefs
Guido van Rossum <guido@python.org>
parents:
4139
diff
changeset
|
1090 #ifdef MS_WINDOWS |
| 4968 | 1091 /* We assume this is a socket... */ |
| 1092 tfile = Tcl_GetFile((ClientData)id, TCL_WIN_SOCKET); | |
| 3703 | 1093 #else |
| 4968 | 1094 tfile = Tcl_GetFile((ClientData)id, TCL_UNIX_FD); |
| 3703 | 1095 #endif |
| 4968 | 1096 /* Ought to check for null Tcl_File object... */ |
| 1097 Tcl_DeleteFileHandler(tfile); | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1098 #else /* >= 8000 */ |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
1099 Tcl_DeleteFileHandler(id); |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1100 #endif /* >= 8000 */ |
| 4968 | 1101 /* XXX fileHandlerDict */ |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1102 Py_INCREF(Py_None); |
| 4968 | 1103 return Py_None; |
| 1664 | 1104 } |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1105 #endif /* HAVE_CREATEFILEHANDLER */ |
| 1664 | 1106 |
| 4968 | 1107 |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1108 /**** 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
|
1109 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1110 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
|
1111 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1112 typedef struct |
| 4968 | 1113 { |
| 1114 PyObject_HEAD | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1115 Tcl_TimerToken token; |
| 4968 | 1116 PyObject *func; |
| 1117 } | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1118 TkttObject; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1119 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1120 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1121 Tktt_DeleteTimerHandler(self, args) |
| 4968 | 1122 PyObject *self; |
| 1123 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
|
1124 { |
| 4968 | 1125 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
|
1126 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1127 if (!PyArg_ParseTuple(args, "")) |
| 4968 | 1128 return NULL; |
| 1129 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
|
1130 Tcl_DeleteTimerHandler(v->token); |
| 4968 | 1131 PyMem_DEL(v->func); |
| 1132 v->func = NULL; | |
| 1133 } | |
| 1134 Py_INCREF(Py_None); | |
| 1135 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
|
1136 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1137 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1138 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
|
1139 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1140 {"deletetimerhandler", Tktt_DeleteTimerHandler, 1}, |
| 4968 | 1141 {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
|
1142 }; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1143 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1144 static TkttObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1145 Tktt_New(token, func) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1146 Tcl_TimerToken token; |
| 4968 | 1147 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
|
1148 { |
| 4968 | 1149 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
|
1150 |
| 4968 | 1151 v = PyObject_NEW(TkttObject, &Tktt_Type); |
| 1152 if (v == NULL) | |
| 1153 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
|
1154 |
| 4968 | 1155 v->token = token; |
| 1156 v->func = func; | |
| 1157 Py_INCREF(v->func); | |
| 1158 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
|
1159 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1160 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1161 static void |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1162 Tktt_Dealloc(self) |
| 4968 | 1163 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
|
1164 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1165 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
|
1166 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1167 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1168 static int |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1169 Tktt_Print(self, fp, flags) |
| 4968 | 1170 PyObject *self; |
| 1171 FILE *fp; | |
| 1172 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
|
1173 { |
| 4968 | 1174 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
|
1175 |
| 4968 | 1176 fprintf(fp, "<tktimertoken at 0x%lx%s>", (long)v, |
| 1177 v->func == NULL ? ", handler deleted" : ""); | |
| 1178 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
|
1179 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1180 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1181 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1182 Tktt_GetAttr(self, name) |
| 4968 | 1183 PyObject *self; |
| 1184 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
|
1185 { |
| 4968 | 1186 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
|
1187 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1188 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1189 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
|
1190 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1191 PyObject_HEAD_INIT(NULL) |
| 4968 | 1192 0, /*ob_size */ |
| 1193 "tktimertoken", /*tp_name */ | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1194 sizeof(TkttObject), /*tp_basicsize */ |
| 4968 | 1195 0, /*tp_itemsize */ |
| 1196 Tktt_Dealloc, /*tp_dealloc */ | |
| 1197 Tktt_Print, /*tp_print */ | |
| 1198 Tktt_GetAttr, /*tp_getattr */ | |
| 1199 0, /*tp_setattr */ | |
| 1200 0, /*tp_compare */ | |
| 1201 0, /*tp_repr */ | |
| 1202 0, /*tp_as_number */ | |
| 1203 0, /*tp_as_sequence */ | |
| 1204 0, /*tp_as_mapping */ | |
| 1205 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
|
1206 }; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1207 |
| 4968 | 1208 |
| 1209 | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1210 /** Timer Handler **/ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1211 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1212 static void |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1213 TimerHandler(clientData) |
| 4968 | 1214 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
|
1215 { |
| 4968 | 1216 PyObject *func = (PyObject *)clientData; |
| 1217 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
|
1218 |
| 4968 | 1219 if (res == NULL) { |
| 1220 errorInCmd = 1; | |
| 1221 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); | |
| 1222 } | |
| 1223 else | |
| 1224 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
|
1225 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1226 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1227 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1228 Tkapp_CreateTimerHandler(self, args) |
| 4968 | 1229 PyObject *self; |
| 1230 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
|
1231 { |
| 4968 | 1232 int milliseconds; |
| 1233 PyObject *func; | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1234 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
|
1235 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1236 if (!PyArg_ParseTuple(args, "iO", &milliseconds, &func)) |
| 4968 | 1237 return NULL; |
| 1238 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
|
1239 PyErr_SetString(PyExc_TypeError, "bad argument list"); |
| 4968 | 1240 return NULL; |
| 1241 } | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1242 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
|
1243 (ClientData)func); |
| 4968 | 1244 |
| 1245 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
|
1246 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1247 |
| 4968 | 1248 |
| 1249 | |
| 1664 | 1250 /** Event Loop **/ |
| 1251 | |
| 1252 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1253 Tkapp_MainLoop(self, args) |
| 4968 | 1254 PyObject *self; |
| 1255 PyObject *args; | |
| 1664 | 1256 { |
| 4968 | 1257 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
|
1258 |
| 4968 | 1259 if (!PyArg_ParseTuple(args, "|i", &threshold)) |
| 1260 return NULL; | |
| 1664 | 1261 |
| 4968 | 1262 quitMainLoop = 0; |
| 1263 while (Tk_GetNumMainWindows() > threshold && | |
| 1264 !quitMainLoop && | |
| 1265 !errorInCmd) | |
| 1664 | 1266 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1267 int result; |
|
6343
689de613ea1c
Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
6311
diff
changeset
|
1268 #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
|
1269 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
|
1270 if (PyErr_CheckSignals() != 0) |
| 4968 | 1271 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1272 if (result) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1273 continue; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1274 /* 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
|
1275 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
|
1276 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
|
1277 Py_BEGIN_ALLOW_THREADS |
|
6343
689de613ea1c
Add an optional hack for threads in Tkinter.
Guido van Rossum <guido@python.org>
parents:
6311
diff
changeset
|
1278 result = PyTcl_WaitUntilEvent(); |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1279 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
|
1280 #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
|
1281 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
|
1282 #endif |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1283 if (PyErr_CheckSignals() != 0) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1284 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1285 if (result < 0) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1286 break; |
| 1664 | 1287 } |
| 4968 | 1288 quitMainLoop = 0; |
| 1664 | 1289 |
| 4968 | 1290 if (errorInCmd) { |
| 1291 errorInCmd = 0; | |
| 1292 PyErr_Restore(excInCmd, valInCmd, trbInCmd); | |
| 1293 excInCmd = valInCmd = trbInCmd = NULL; | |
| 1294 return NULL; | |
| 1295 } | |
| 1296 Py_INCREF(Py_None); | |
| 1297 return Py_None; | |
| 1664 | 1298 } |
| 1299 | |
| 1300 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1301 Tkapp_DoOneEvent(self, args) |
| 4968 | 1302 PyObject *self; |
| 1303 PyObject *args; | |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1304 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1305 int flags = 0; |
| 4968 | 1306 int rv; |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1307 |
| 4968 | 1308 if (!PyArg_ParseTuple(args, "|i", &flags)) |
| 1309 return NULL; | |
| 1310 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1311 rv = Tcl_DoOneEvent(flags); |
| 4968 | 1312 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
|
1313 } |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1314 |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1315 static PyObject * |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1316 Tkapp_Quit(self, args) |
| 4968 | 1317 PyObject *self; |
| 1318 PyObject *args; | |
| 1664 | 1319 { |
| 1320 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1321 if (!PyArg_ParseTuple(args, "")) |
| 4968 | 1322 return NULL; |
| 1323 | |
| 1324 quitMainLoop = 1; | |
| 1325 Py_INCREF(Py_None); | |
| 1326 return Py_None; | |
| 1664 | 1327 } |
| 1328 | |
| 4968 | 1329 |
| 1330 | |
| 1664 | 1331 /**** Tkapp Method List ****/ |
| 1332 | |
| 1333 static PyMethodDef Tkapp_methods[] = | |
| 1334 { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1335 {"call", Tkapp_Call, 0}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1336 {"globalcall", Tkapp_GlobalCall, 0}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1337 {"eval", Tkapp_Eval, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1338 {"globaleval", Tkapp_GlobalEval, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1339 {"evalfile", Tkapp_EvalFile, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1340 {"record", Tkapp_Record, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1341 {"adderrorinfo", Tkapp_AddErrorInfo, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1342 {"setvar", Tkapp_SetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1343 {"globalsetvar", Tkapp_GlobalSetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1344 {"getvar", Tkapp_GetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1345 {"globalgetvar", Tkapp_GlobalGetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1346 {"unsetvar", Tkapp_UnsetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1347 {"globalunsetvar", Tkapp_GlobalUnsetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1348 {"getint", Tkapp_GetInt, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1349 {"getdouble", Tkapp_GetDouble, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1350 {"getboolean", Tkapp_GetBoolean, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1351 {"exprstring", Tkapp_ExprString, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1352 {"exprlong", Tkapp_ExprLong, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1353 {"exprdouble", Tkapp_ExprDouble, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1354 {"exprboolean", Tkapp_ExprBoolean, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1355 {"splitlist", Tkapp_SplitList, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1356 {"split", Tkapp_Split, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1357 {"merge", Tkapp_Merge, 0}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1358 {"createcommand", Tkapp_CreateCommand, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1359 {"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
|
1360 #ifdef HAVE_CREATEFILEHANDLER |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1361 {"createfilehandler", Tkapp_CreateFileHandler, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1362 {"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
|
1363 #endif |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1364 {"createtimerhandler", Tkapp_CreateTimerHandler, 1}, |
| 4968 | 1365 {"mainloop", Tkapp_MainLoop, 1}, |
| 1366 {"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
|
1367 {"quit", Tkapp_Quit, 1}, |
| 4968 | 1368 {NULL, NULL} |
| 1664 | 1369 }; |
| 1370 | |
| 4968 | 1371 |
| 1372 | |
| 1664 | 1373 /**** Tkapp Type Methods ****/ |
| 1374 | |
| 1375 static void | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1376 Tkapp_Dealloc(self) |
| 4968 | 1377 PyObject *self; |
| 1664 | 1378 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1379 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
|
1380 PyMem_DEL(self); |
| 1664 | 1381 } |
| 1382 | |
| 1383 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1384 Tkapp_GetAttr(self, name) |
| 4968 | 1385 PyObject *self; |
| 1386 char *name; | |
| 1664 | 1387 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1388 return Py_FindMethod(Tkapp_methods, self, name); |
| 1664 | 1389 } |
| 1390 | |
| 1391 static PyTypeObject Tkapp_Type = | |
| 1392 { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1393 PyObject_HEAD_INIT(NULL) |
| 4968 | 1394 0, /*ob_size */ |
| 1395 "tkapp", /*tp_name */ | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1396 sizeof(TkappObject), /*tp_basicsize */ |
| 4968 | 1397 0, /*tp_itemsize */ |
| 1398 Tkapp_Dealloc, /*tp_dealloc */ | |
| 1399 0, /*tp_print */ | |
| 1400 Tkapp_GetAttr, /*tp_getattr */ | |
| 1401 0, /*tp_setattr */ | |
| 1402 0, /*tp_compare */ | |
| 1403 0, /*tp_repr */ | |
| 1404 0, /*tp_as_number */ | |
| 1405 0, /*tp_as_sequence */ | |
| 1406 0, /*tp_as_mapping */ | |
| 1407 0, /*tp_hash */ | |
| 1664 | 1408 }; |
| 1409 | |
| 4968 | 1410 |
| 1411 | |
| 1664 | 1412 /**** Tkinter Module ****/ |
| 1413 | |
| 1414 static PyObject * | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1415 Tkinter_Create(self, args) |
| 4968 | 1416 PyObject *self; |
| 1417 PyObject *args; | |
| 1664 | 1418 { |
| 4968 | 1419 char *screenName = NULL; |
| 1420 char *baseName = NULL; | |
| 1421 char *className = NULL; | |
| 1422 int interactive = 0; | |
| 1664 | 1423 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1424 baseName = strrchr(Py_GetProgramName(), '/'); |
| 4968 | 1425 if (baseName != NULL) |
| 1426 baseName++; | |
| 1427 else | |
| 1428 baseName = Py_GetProgramName(); | |
| 1429 className = "Tk"; | |
| 1664 | 1430 |
| 4968 | 1431 if (!PyArg_ParseTuple(args, "|zssi", |
| 1432 &screenName, &baseName, &className, | |
| 1433 &interactive)) | |
| 1434 return NULL; | |
| 1664 | 1435 |
| 4968 | 1436 return (PyObject *) Tkapp_New(screenName, baseName, className, |
| 1437 interactive); | |
| 1664 | 1438 } |
| 1439 | |
| 1440 static PyMethodDef moduleMethods[] = | |
| 1441 { | |
| 4968 | 1442 {"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
|
1443 #ifdef HAVE_CREATEFILEHANDLER |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1444 {"createfilehandler", Tkapp_CreateFileHandler, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1445 {"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
|
1446 #endif |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1447 {"createtimerhandler", Tkapp_CreateTimerHandler, 1}, |
| 4968 | 1448 {"mainloop", Tkapp_MainLoop, 1}, |
| 1449 {"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
|
1450 {"quit", Tkapp_Quit, 1}, |
| 4968 | 1451 {NULL, NULL} |
| 1664 | 1452 }; |
| 1453 | |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1454 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
|
1455 |
| 1664 | 1456 static int |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1457 EventHook() |
| 1664 | 1458 { |
|
6478
297a541eb865
Darn. When thread support is disabled, the BEGIN/END macros don't
Guido van Rossum <guido@python.org>
parents:
6455
diff
changeset
|
1459 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
|
1460 |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1461 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
|
1462 return 0; |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1463 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
|
1464 return 0; |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1465 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
|
1466 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
|
1467 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
|
1468 if (!errorInCmd) |
|
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1469 Tcl_DoOneEvent(TCL_DONT_WAIT); |
| 4968 | 1470 if (errorInCmd) { |
| 1471 errorInCmd = 0; | |
| 1472 PyErr_Restore(excInCmd, valInCmd, trbInCmd); | |
| 1473 excInCmd = valInCmd = trbInCmd = NULL; | |
| 1474 PyErr_Print(); | |
| 1475 } | |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1476 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
|
1477 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
|
1478 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
|
1479 PyThreadState_Delete(tstate); |
| 4968 | 1480 return 0; |
| 1664 | 1481 } |
| 1482 | |
| 4968 | 1483 |
| 1484 /* all errors will be checked in one fell swoop in init_tkinter() */ | |
| 1485 static void | |
| 1486 ins_long(d, name, val) | |
| 1487 PyObject *d; | |
| 1488 char *name; | |
| 1489 long val; | |
| 1490 { | |
| 1491 PyObject *v = PyInt_FromLong(val); | |
| 1492 if (v) { | |
| 1493 PyDict_SetItemString(d, name, v); | |
| 1494 Py_DECREF(v); | |
| 1495 } | |
| 1496 } | |
| 1497 static void | |
| 1498 ins_string(d, name, val) | |
| 1499 PyObject *d; | |
| 1500 char *name; | |
| 1501 char *val; | |
| 1502 { | |
| 1503 PyObject *v = PyString_FromString(val); | |
| 1504 if (v) { | |
| 1505 PyDict_SetItemString(d, name, v); | |
| 1506 Py_DECREF(v); | |
| 1507 } | |
| 1508 } | |
| 1509 | |
| 1510 | |
| 1664 | 1511 void |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1512 init_tkinter() |
| 1664 | 1513 { |
| 4968 | 1514 PyObject *m, *d; |
| 1664 | 1515 |
| 4968 | 1516 Tkapp_Type.ob_type = &PyType_Type; |
| 1517 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
|
1518 |
| 4968 | 1519 m = Py_InitModule("_tkinter", moduleMethods); |
| 1664 | 1520 |
| 4968 | 1521 d = PyModule_GetDict(m); |
| 1522 Tkinter_TclError = Py_BuildValue("s", "TclError"); | |
| 1523 PyDict_SetItemString(d, "TclError", Tkinter_TclError); | |
| 1524 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1525 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
|
1526 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
|
1527 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
|
1528 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
|
1529 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
|
1530 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
|
1531 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
|
1532 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
|
1533 ins_long(d, "DONT_WAIT", TCL_DONT_WAIT); |
| 4968 | 1534 ins_string(d, "TK_VERSION", TK_VERSION); |
| 1535 ins_string(d, "TCL_VERSION", TCL_VERSION); | |
| 1664 | 1536 |
|
6311
13fbd98d81cc
Export names for the types defined by this module: TkappType and TkttType.
Guido van Rossum <guido@python.org>
parents:
6265
diff
changeset
|
1537 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
|
1538 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
|
1539 |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
1540 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
|
1541 event_interp = PyThreadState_Get()->interp; |
|
5973
e77847e1158e
Renamed Py_input_hook to PyOS_InputHook.
Guido van Rossum <guido@python.org>
parents:
5954
diff
changeset
|
1542 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
|
1543 } |
| 1664 | 1544 |
| 4968 | 1545 if (PyErr_Occurred()) |
|
7212
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
1546 return; |
|
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
1547 |
|
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
1548 Py_AtExit(Tcl_Finalize); |
|
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
1549 |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1550 #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
|
1551 /* |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1552 ** 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
|
1553 ** 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
|
1554 ** 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
|
1555 */ |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1556 #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
|
1557 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
|
1558 #endif |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1559 |
|
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_MacSetEventProc(PyMacConvertEvent); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1561 #if GENERATINGCFM |
| 4968 | 1562 mac_addlibresources(); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1563 #endif /* GENERATINGCFM */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1564 #endif /* macintosh */ |
| 1664 | 1565 } |
| 3120 | 1566 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1567 |
| 4968 | 1568 |
| 3120 | 1569 #ifdef macintosh |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1570 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1571 /* |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1572 ** 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
|
1573 */ |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1574 |
| 3120 | 1575 void |
| 1576 panic(char * format, ...) | |
| 1577 { | |
| 4968 | 1578 va_list varg; |
| 3120 | 1579 |
| 4968 | 1580 va_start(varg, format); |
| 3120 | 1581 |
| 4968 | 1582 vfprintf(stderr, format, varg); |
| 1583 (void) fflush(stderr); | |
| 3120 | 1584 |
| 4968 | 1585 va_end(varg); |
| 3120 | 1586 |
| 4968 | 1587 Py_FatalError("Tcl/Tk panic"); |
| 3120 | 1588 } |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1589 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1590 /* |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1591 ** 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
|
1592 */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1593 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1594 static int |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1595 PyMacConvertEvent(eventPtr) |
| 4968 | 1596 EventRecord *eventPtr; |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1597 { |
| 4968 | 1598 if (SIOUXHandleOneEvent(eventPtr)) |
| 1599 return 0; /* Nothing happened to the Tcl event queue */ | |
| 1600 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
|
1601 } |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1602 |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1603 #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
|
1604 /* |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1605 * 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
|
1606 * 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
|
1607 * 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
|
1608 * 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
|
1609 * files and sockets. |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1610 * |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1611 * 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
|
1612 * for other versions. */ |
|
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 int |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1615 Tcl_FileReady(file, mask) |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1616 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
|
1617 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
|
1618 * TCL_WRITABLE, and TCL_EXCEPTION: |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1619 * indicates conditions caller cares about. */ |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1620 { |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1621 int type; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1622 int fd; |
|
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 fd = (int) Tcl_GetFileInfo(file, &type); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1625 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1626 if (type == TCL_MAC_SOCKET) { |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1627 return TclMacSocketReady(file, mask); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1628 } else if (type == TCL_MAC_FILE) { |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1629 /* |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1630 * 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
|
1631 * 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
|
1632 */ |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1633 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1634 return mask; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1635 } else if (type == TCL_UNIX_FD) { |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1636 fd_set readset, writeset, excset; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1637 struct timeval tv; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1638 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1639 FD_ZERO(&readset); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1640 FD_ZERO(&writeset); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1641 FD_ZERO(&excset); |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1642 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1643 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
|
1644 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
|
1645 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
|
1646 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1647 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
|
1648 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
|
1649 return 0; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1650 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1651 mask = 0; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1652 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
|
1653 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
|
1654 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
|
1655 |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1656 return mask; |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1657 } |
|
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 0; |
|
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 #endif /* USE_GUSI */ |
|
02ea9d021427
Mac hack to make select() work again...
Guido van Rossum <guido@python.org>
parents:
5437
diff
changeset
|
1662 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1663 #if GENERATINGCFM |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1664 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1665 /* |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1666 ** 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
|
1667 */ |
|
3262
bfb63b45ff0f
Initialize GUSI on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3240
diff
changeset
|
1668 |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1669 #include <Resources.h> |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1670 #include <CodeFragments.h> |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1671 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1672 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
|
1673 static FSSpec library_fss; |
| 3120 | 1674 |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1675 /* |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1676 ** 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
|
1677 ** 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
|
1678 ** 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
|
1679 ** resources. |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1680 */ |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1681 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
|
1682 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
|
1683 { |
|
4139
010344b4a616
Call __initialize(), not __sinit() on Mac dynamic loading entry.
Guido van Rossum <guido@python.org>
parents:
4091
diff
changeset
|
1684 __initialize(); |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1685 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
|
1686 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
|
1687 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
|
1688 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
|
1689 } 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
|
1690 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
|
1691 loaded_from_shlib = 1; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1692 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1693 return noErr; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1694 } |
|
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 /* |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1697 ** 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
|
1698 ** 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
|
1699 */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
1700 static |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1701 mac_addlibresources() |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1702 { |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1703 if ( !loaded_from_shlib ) |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1704 return; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1705 (void)FSpOpenResFile(&library_fss, fsRdPerm); |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1706 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
1707 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1708 #endif /* GENERATINGCFM */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
1709 #endif /* macintosh */ |
