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