Mercurial > cpython-lru_cache-weakref
annotate Modules/_tkinter.c @ 20737:00a581bdedeb legacy-trunk
When overriding __str__ or __repr__, set the tp_print slot to NULL.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 29 Oct 2001 14:33:44 +0000 |
| parents | 7257e87e0720 |
| children | 304b34023876 |
| rev | line source |
|---|---|
| 3703 | 1 /*********************************************************** |
| 2 Copyright (C) 1994 Steen Lumholt. | |
| 3 | |
| 4 All Rights Reserved | |
| 5 | |
| 6 ******************************************************************/ | |
| 7 | |
| 8 /* _tkinter.c -- Interface to libtk.a and libtcl.a. */ | |
| 1664 | 9 |
|
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
|
10 /* 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
|
11 |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
12 Only Tcl/Tk 8.0 and later are supported. Older versions are not |
|
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
13 supported. (Use Python 1.5.2 if you cannot upgrade your Tcl/Tk |
|
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
14 libraries.) |
|
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
15 */ |
|
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
|
16 |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
17 /* XXX Further speed-up ideas, involving Tcl 8.0 features: |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
18 |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
19 - 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
|
20 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
|
21 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
|
22 |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
23 - 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
|
24 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
|
25 |
|
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
|
26 */ |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
27 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
28 |
| 3120 | 29 #include "Python.h" |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
30 #include <ctype.h> |
| 3120 | 31 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
32 #ifdef WITH_THREAD |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9128
diff
changeset
|
33 #include "pythread.h" |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
34 #endif |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
35 |
|
8446
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
36 #ifdef MS_WINDOWS |
|
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
37 #include <windows.h> |
|
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
38 #endif |
|
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
39 |
|
4079
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
40 #ifdef macintosh |
|
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
41 #define MAC_TCL |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9128
diff
changeset
|
42 #endif |
|
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9128
diff
changeset
|
43 |
| 1664 | 44 #include <tcl.h> |
| 45 #include <tk.h> | |
| 46 | |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
47 #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
|
48 |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
49 #if TKMAJORMINOR < 8000 |
|
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
50 #error "Tk older than 8.0 not supported" |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
51 #endif |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
52 |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
53 #if defined(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
|
54 /* 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
|
55 #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
|
56 /* 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
|
57 #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
|
58 #endif |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
59 |
|
18637
05cf6b3e63de
File handlers don't work on the mac, so don't pretend they do. I guess this is a 2.1.1 candidate, if it isn't too late for that.
Jack Jansen <jack.jansen@cwi.nl>
parents:
17976
diff
changeset
|
60 #if !(defined(MS_WINDOWS) || defined(__CYGWIN__) || defined(macintosh)) |
|
05cf6b3e63de
File handlers don't work on the mac, so don't pretend they do. I guess this is a 2.1.1 candidate, if it isn't too late for that.
Jack Jansen <jack.jansen@cwi.nl>
parents:
17976
diff
changeset
|
61 /* Mac has it, but it doesn't really work:-( */ |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
62 #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
|
63 #endif |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
64 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
65 #ifdef HAVE_CREATEFILEHANDLER |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
66 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
67 /* Tcl_CreateFileHandler() changed several times; these macros deal with the |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
68 messiness. In Tcl 8.0 and later, it is not available on Windows (and on |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
69 Unix, only because Jack added it back); when available on Windows, it only |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
70 applies to sockets. */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
71 |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
72 #ifdef MS_WINDOWS |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
73 #define FHANDLETYPE TCL_WIN_SOCKET |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
74 #else |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
75 #define FHANDLETYPE TCL_UNIX_FD |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
76 #endif |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
77 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
78 /* If Tcl can wait for a Unix file descriptor, define the EventHook() routine |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
79 which uses this to handle Tcl events while the user is typing commands. */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
80 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
81 #if FHANDLETYPE == TCL_UNIX_FD |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
82 #define WAIT_FOR_STDIN |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
83 #endif |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
84 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
85 #endif /* HAVE_CREATEFILEHANDLER */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
86 |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
87 #ifdef MS_WINDOWS |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
88 #include <conio.h> |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
89 #define WAIT_FOR_STDIN |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
90 #endif |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
91 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
92 #ifdef WITH_THREAD |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
93 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
94 /* The threading situation is complicated. Tcl is not thread-safe, except for |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
95 Tcl 8.1, which will probably remain in alpha status for another 6 months |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
96 (and the README says that Tk will probably remain thread-unsafe forever). |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
97 So we need to use a lock around all uses of Tcl. Previously, the Python |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
98 interpreter lock was used for this. However, this causes problems when |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
99 other Python threads need to run while Tcl is blocked waiting for events. |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
100 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
101 To solve this problem, a separate lock for Tcl is introduced. Holding it |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
102 is incompatible with holding Python's interpreter lock. The following four |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
103 macros manipulate both locks together. |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
104 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
105 ENTER_TCL and LEAVE_TCL are brackets, just like Py_BEGIN_ALLOW_THREADS and |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
106 Py_END_ALLOW_THREADS. They should be used whenever a call into Tcl is made |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
107 that could call an event handler, or otherwise affect the state of a Tcl |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
108 interpreter. These assume that the surrounding code has the Python |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
109 interpreter lock; inside the brackets, the Python interpreter lock has been |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
110 released and the lock for Tcl has been acquired. |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
111 |
|
8504
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
112 Sometimes, it is necessary to have both the Python lock and the Tcl lock. |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
113 (For example, when transferring data from the Tcl interpreter result to a |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
114 Python string object.) This can be done by using different macros to close |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
115 the ENTER_TCL block: ENTER_OVERLAP reacquires the Python lock (and restores |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
116 the thread state) but doesn't release the Tcl lock; LEAVE_OVERLAP_TCL |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
117 releases the Tcl lock. |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
118 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
119 By contrast, ENTER_PYTHON and LEAVE_PYTHON are used in Tcl event |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
120 handlers when the handler needs to use Python. Such event handlers are |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
121 entered while the lock for Tcl is held; the event handler presumably needs |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
122 to use Python. ENTER_PYTHON releases the lock for Tcl and acquires |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
123 the Python interpreter lock, restoring the appropriate thread state, and |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
124 LEAVE_PYTHON releases the Python interpreter lock and re-acquires the lock |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
125 for Tcl. It is okay for ENTER_TCL/LEAVE_TCL pairs to be contained inside |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
126 the code between ENTER_PYTHON and LEAVE_PYTHON. |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
127 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
128 These locks expand to several statements and brackets; they should not be |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
129 used in branches of if statements and the like. |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
130 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
131 */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
132 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
133 static PyThread_type_lock tcl_lock = 0; |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
134 static PyThreadState *tcl_tstate = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
135 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
136 #define ENTER_TCL \ |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
137 { PyThreadState *tstate = PyThreadState_Get(); Py_BEGIN_ALLOW_THREADS \ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
138 PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
139 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
140 #define LEAVE_TCL \ |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
141 tcl_tstate = NULL; PyThread_release_lock(tcl_lock); Py_END_ALLOW_THREADS} |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
142 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
143 #define ENTER_OVERLAP \ |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
144 Py_END_ALLOW_THREADS |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
145 |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
146 #define LEAVE_OVERLAP_TCL \ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
147 tcl_tstate = NULL; PyThread_release_lock(tcl_lock); } |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
148 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
149 #define ENTER_PYTHON \ |
|
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
150 { PyThreadState *tstate = tcl_tstate; tcl_tstate = NULL; \ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
151 PyThread_release_lock(tcl_lock); PyEval_RestoreThread((tstate)); } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
152 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
153 #define LEAVE_PYTHON \ |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
154 { PyThreadState *tstate = PyEval_SaveThread(); \ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
155 PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
156 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
157 #else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
158 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
159 #define ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
160 #define LEAVE_TCL |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
161 #define ENTER_OVERLAP |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
162 #define LEAVE_OVERLAP_TCL |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
163 #define ENTER_PYTHON |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
164 #define LEAVE_PYTHON |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
165 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
166 #endif |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
167 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
168 #ifdef macintosh |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
169 |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
170 /* |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
171 ** 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
|
172 ** 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
|
173 */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
174 |
|
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
|
175 /* ckfree() expects a char* */ |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
176 #define FREECAST (char *) |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
177 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
178 #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
|
179 |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
180 typedef int (*TclMacConvertEventPtr) (EventRecord *eventPtr); |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
181 void Tcl_MacSetEventProc(TclMacConvertEventPtr procPtr); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
182 int TkMacConvertEvent(EventRecord *eventPtr); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
183 |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
184 staticforward int PyMacConvertEvent(EventRecord *eventPtr); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
185 |
|
8185
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
186 #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
|
187 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
|
188 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
189 #endif /* macintosh */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
190 |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
191 #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
|
192 #define FREECAST (char *) |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
193 #endif |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
194 |
| 1664 | 195 /**** Tkapp Object Declaration ****/ |
| 196 | |
| 197 staticforward PyTypeObject Tkapp_Type; | |
| 198 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
199 typedef struct { |
| 4968 | 200 PyObject_HEAD |
| 201 Tcl_Interp *interp; | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
202 } TkappObject; |
| 1664 | 203 |
| 204 #define Tkapp_Check(v) ((v)->ob_type == &Tkapp_Type) | |
| 205 #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) | |
| 15177 | 206 #define Tkapp_Result(v) Tcl_GetStringResult(Tkapp_Interp(v)) |
| 1664 | 207 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
208 #define DEBUG_REFCNT(v) (printf("DEBUG: id=%p, refcnt=%i\n", \ |
| 4968 | 209 (void *) v, ((PyObject *) v)->ob_refcnt)) |
| 1664 | 210 |
| 4968 | 211 |
| 212 | |
| 1664 | 213 /**** Error Handling ****/ |
| 214 | |
| 215 static PyObject *Tkinter_TclError; | |
| 1713 | 216 static int quitMainLoop = 0; |
| 1664 | 217 static int errorInCmd = 0; |
| 218 static PyObject *excInCmd; | |
| 219 static PyObject *valInCmd; | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
220 static PyObject *trbInCmd; |
| 1664 | 221 |
| 4968 | 222 |
| 223 | |
| 1664 | 224 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
225 Tkinter_Error(PyObject *v) |
| 1664 | 226 { |
| 4968 | 227 PyErr_SetString(Tkinter_TclError, Tkapp_Result(v)); |
| 228 return NULL; | |
| 1664 | 229 } |
| 230 | |
| 4968 | 231 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
232 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
233 /**** Utils ****/ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
234 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
235 #ifdef WITH_THREAD |
|
8446
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
236 #ifndef MS_WINDOWS |
|
8987
3e127bca84e7
Need mytime.h for Sleep().
Guido van Rossum <guido@python.org>
parents:
8828
diff
changeset
|
237 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
238 /* Millisecond sleep() for Unix platforms. */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
239 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
240 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
241 Sleep(int milli) |
| 1664 | 242 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
243 /* XXX Too bad if you don't have select(). */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
244 struct timeval t; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
245 t.tv_sec = milli/1000; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
246 t.tv_usec = (milli%1000) * 1000; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
247 select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t); |
| 1664 | 248 } |
|
8446
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
249 #endif /* MS_WINDOWS */ |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
250 #endif /* WITH_THREAD */ |
| 4968 | 251 |
| 252 | |
| 1664 | 253 static char * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
254 AsString(PyObject *value, PyObject *tmp) |
| 1664 | 255 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
256 if (PyString_Check(value)) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
257 return PyString_AsString(value); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
258 #ifdef Py_USING_UNICODE |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
259 else if (PyUnicode_Check(value)) { |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
260 PyObject *v = PyUnicode_AsUTF8String(value); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
261 if (v == NULL) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
262 return NULL; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
263 if (PyList_Append(tmp, v) != 0) { |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
264 Py_DECREF(v); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
265 return NULL; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
266 } |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
267 Py_DECREF(v); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
268 return PyString_AsString(v); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
269 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
270 #endif |
| 4968 | 271 else { |
| 272 PyObject *v = PyObject_Str(value); | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
273 if (v == NULL) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
274 return NULL; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
275 if (PyList_Append(tmp, v) != 0) { |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
276 Py_DECREF(v); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
277 return NULL; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
278 } |
| 4968 | 279 Py_DECREF(v); |
| 280 return PyString_AsString(v); | |
| 281 } | |
| 1664 | 282 } |
| 283 | |
| 4968 | 284 |
| 285 | |
| 1664 | 286 #define ARGSZ 64 |
| 287 | |
| 288 static char * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
289 Merge(PyObject *args) |
| 1664 | 290 { |
| 4968 | 291 PyObject *tmp = NULL; |
| 292 char *argvStore[ARGSZ]; | |
| 293 char **argv = NULL; | |
| 294 int fvStore[ARGSZ]; | |
| 295 int *fv = NULL; | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
296 int argc = 0, fvc = 0, i; |
| 4968 | 297 char *res = NULL; |
| 298 | |
| 299 if (!(tmp = PyList_New(0))) | |
| 300 return NULL; | |
| 301 | |
| 302 argv = argvStore; | |
| 303 fv = fvStore; | |
| 304 | |
| 305 if (args == NULL) | |
| 306 argc = 0; | |
| 1664 | 307 |
| 4968 | 308 else if (!PyTuple_Check(args)) { |
| 309 argc = 1; | |
| 310 fv[0] = 0; | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
311 if (!(argv[0] = AsString(args, tmp))) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
312 goto finally; |
| 4968 | 313 } |
| 314 else { | |
| 315 argc = PyTuple_Size(args); | |
| 316 | |
| 317 if (argc > ARGSZ) { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
318 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
|
319 fv = (int *)ckalloc(argc * sizeof(int)); |
| 4968 | 320 if (argv == NULL || fv == NULL) { |
| 321 PyErr_NoMemory(); | |
| 322 goto finally; | |
| 323 } | |
| 324 } | |
| 1664 | 325 |
| 4968 | 326 for (i = 0; i < argc; i++) { |
| 327 PyObject *v = PyTuple_GetItem(args, i); | |
| 328 if (PyTuple_Check(v)) { | |
| 329 fv[i] = 1; | |
| 330 if (!(argv[i] = Merge(v))) | |
| 331 goto finally; | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
332 fvc++; |
| 4968 | 333 } |
| 334 else if (v == Py_None) { | |
| 335 argc = i; | |
| 336 break; | |
| 337 } | |
| 338 else { | |
| 339 fv[i] = 0; | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
340 if (!(argv[i] = AsString(v, tmp))) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
341 goto finally; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
342 fvc++; |
| 4968 | 343 } |
| 344 } | |
| 345 } | |
| 346 res = Tcl_Merge(argc, argv); | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
347 if (res == NULL) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
348 PyErr_SetString(Tkinter_TclError, "merge failed"); |
| 1664 | 349 |
| 4968 | 350 finally: |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
351 for (i = 0; i < fvc; i++) |
| 4968 | 352 if (fv[i]) { |
| 353 ckfree(argv[i]); | |
| 354 } | |
| 355 if (argv != argvStore) | |
| 356 ckfree(FREECAST argv); | |
| 357 if (fv != fvStore) | |
| 358 ckfree(FREECAST fv); | |
| 359 | |
| 360 Py_DECREF(tmp); | |
| 361 return res; | |
| 362 } | |
| 363 | |
| 364 | |
| 365 | |
| 366 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
367 Split(char *list) |
| 4968 | 368 { |
| 369 int argc; | |
| 370 char **argv; | |
| 371 PyObject *v; | |
| 372 | |
| 373 if (list == NULL) { | |
| 374 Py_INCREF(Py_None); | |
| 375 return Py_None; | |
| 1664 | 376 } |
| 377 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
378 if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { |
| 4968 | 379 /* Not a list. |
| 380 * Could be a quoted string containing funnies, e.g. {"}. | |
| 381 * Return the string itself. | |
| 382 */ | |
| 383 return PyString_FromString(list); | |
| 1664 | 384 } |
| 385 | |
| 4968 | 386 if (argc == 0) |
| 387 v = PyString_FromString(""); | |
| 388 else if (argc == 1) | |
| 389 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
|
390 else if ((v = PyTuple_New(argc)) != NULL) { |
| 4968 | 391 int i; |
| 392 PyObject *w; | |
| 1664 | 393 |
| 4968 | 394 for (i = 0; i < argc; i++) { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
395 if ((w = Split(argv[i])) == NULL) { |
| 4968 | 396 Py_DECREF(v); |
| 397 v = NULL; | |
| 398 break; | |
| 399 } | |
| 400 PyTuple_SetItem(v, i, w); | |
| 401 } | |
| 402 } | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
403 Tcl_Free(FREECAST argv); |
| 4968 | 404 return v; |
| 1664 | 405 } |
| 406 | |
| 407 | |
| 4968 | 408 |
| 1664 | 409 /**** Tkapp Object ****/ |
| 410 | |
| 411 #ifndef WITH_APPINIT | |
| 412 int | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
413 Tcl_AppInit(Tcl_Interp *interp) |
| 1664 | 414 { |
| 4968 | 415 Tk_Window main; |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
416 |
| 4968 | 417 main = Tk_MainWindow(interp); |
| 418 if (Tcl_Init(interp) == TCL_ERROR) { | |
| 15177 | 419 PySys_WriteStderr("Tcl_Init error: %s\n", Tcl_GetStringResult(interp)); |
| 4968 | 420 return TCL_ERROR; |
| 421 } | |
| 422 if (Tk_Init(interp) == TCL_ERROR) { | |
| 15177 | 423 PySys_WriteStderr("Tk_Init error: %s\n", Tcl_GetStringResult(interp)); |
| 4968 | 424 return TCL_ERROR; |
| 425 } | |
| 426 return TCL_OK; | |
| 1664 | 427 } |
| 4968 | 428 #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
|
429 |
| 4968 | 430 |
| 431 | |
| 1664 | 432 |
| 433 /* Initialize the Tk application; see the `main' function in | |
| 4968 | 434 * `tkMain.c'. |
| 435 */ | |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
436 |
|
13690
c09c0171474f
ANSIfy some more forward declarations.
Thomas Wouters <thomas@python.org>
parents:
13651
diff
changeset
|
437 static void EnableEventHook(void); /* Forward */ |
|
c09c0171474f
ANSIfy some more forward declarations.
Thomas Wouters <thomas@python.org>
parents:
13651
diff
changeset
|
438 static void DisableEventHook(void); /* Forward */ |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
439 |
| 1664 | 440 static TkappObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
441 Tkapp_New(char *screenName, char *baseName, char *className, int interactive) |
| 1664 | 442 { |
| 4968 | 443 TkappObject *v; |
| 444 char *argv0; | |
| 1664 | 445 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
446 v = PyObject_New(TkappObject, &Tkapp_Type); |
| 4968 | 447 if (v == NULL) |
| 448 return NULL; | |
| 1664 | 449 |
| 4968 | 450 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
|
451 |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
452 #if defined(macintosh) |
|
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
453 /* This seems to be needed */ |
|
8185
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
454 ClearMenuBar(); |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
455 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
|
456 #endif |
|
7416
13f29b62a209
Delete the 'exit' command from the Tcl interpreter -- it would allow
Guido van Rossum <guido@python.org>
parents:
7212
diff
changeset
|
457 /* 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
|
458 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
|
459 |
| 4968 | 460 if (screenName != NULL) |
| 461 Tcl_SetVar2(v->interp, "env", "DISPLAY", | |
| 462 screenName, TCL_GLOBAL_ONLY); | |
| 1664 | 463 |
| 4968 | 464 if (interactive) |
| 465 Tcl_SetVar(v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); | |
| 466 else | |
| 467 Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); | |
| 1664 | 468 |
| 4968 | 469 /* This is used to get the application class for Tk 4.1 and up */ |
| 470 argv0 = (char*)ckalloc(strlen(className) + 1); | |
| 471 if (!argv0) { | |
| 472 PyErr_NoMemory(); | |
| 473 Py_DECREF(v); | |
| 474 return NULL; | |
| 475 } | |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
476 |
| 4968 | 477 strcpy(argv0, className); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7416
diff
changeset
|
478 if (isupper((int)(argv0[0]))) |
| 4968 | 479 argv0[0] = tolower(argv0[0]); |
| 480 Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY); | |
| 481 ckfree(argv0); | |
| 1664 | 482 |
| 4968 | 483 if (Tcl_AppInit(v->interp) != TCL_OK) |
|
8639
027a1dad1353
Add a cast that a picky SGI compiler found was necessary.
Guido van Rossum <guido@python.org>
parents:
8522
diff
changeset
|
484 return (TkappObject *)Tkinter_Error((PyObject *)v); |
| 4968 | 485 |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
486 EnableEventHook(); |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
487 |
| 4968 | 488 return v; |
| 1664 | 489 } |
| 490 | |
| 4968 | 491 |
| 492 | |
| 1664 | 493 /** Tcl Eval **/ |
| 494 | |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
495 #if TKMAJORMINOR >= 8001 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
496 #define USING_OBJECTS |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
497 #endif |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
498 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
499 #ifdef USING_OBJECTS |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
500 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
501 static Tcl_Obj* |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
502 AsObj(PyObject *value) |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
503 { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
504 Tcl_Obj *result; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
505 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
506 if (PyString_Check(value)) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
507 return Tcl_NewStringObj(PyString_AS_STRING(value), |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
508 PyString_GET_SIZE(value)); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
509 else if (PyInt_Check(value)) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
510 return Tcl_NewLongObj(PyInt_AS_LONG(value)); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
511 else if (PyFloat_Check(value)) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
512 return Tcl_NewDoubleObj(PyFloat_AS_DOUBLE(value)); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
513 else if (PyTuple_Check(value)) { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
514 Tcl_Obj **argv = (Tcl_Obj**) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
515 ckalloc(PyTuple_Size(value)*sizeof(Tcl_Obj*)); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
516 int i; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
517 if(!argv) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
518 return 0; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
519 for(i=0;i<PyTuple_Size(value);i++) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
520 argv[i] = AsObj(PyTuple_GetItem(value,i)); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
521 result = Tcl_NewListObj(PyTuple_Size(value), argv); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
522 ckfree(FREECAST argv); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
523 return result; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
524 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
525 #ifdef Py_USING_UNICODE |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
526 else if (PyUnicode_Check(value)) { |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
527 #if TKMAJORMINOR <= 8001 |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
528 /* In Tcl 8.1 we must use UTF-8 */ |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
529 PyObject* utf8 = PyUnicode_AsUTF8String(value); |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
530 if (!utf8) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
531 return 0; |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
532 result = Tcl_NewStringObj(PyString_AS_STRING(utf8), |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
533 PyString_GET_SIZE(utf8)); |
| 12513 | 534 Py_DECREF(utf8); |
| 535 return result; | |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
536 #else /* TKMAJORMINOR > 8001 */ |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
537 /* In Tcl 8.2 and later, use Tcl_NewUnicodeObj() */ |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
538 if (sizeof(Py_UNICODE) != sizeof(Tcl_UniChar)) { |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
539 /* XXX Should really test this at compile time */ |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
540 PyErr_SetString(PyExc_SystemError, |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
541 "Py_UNICODE and Tcl_UniChar differ in size"); |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
542 return 0; |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
543 } |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
544 return Tcl_NewUnicodeObj(PyUnicode_AS_UNICODE(value), |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
545 PyUnicode_GET_SIZE(value)); |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
546 #endif /* TKMAJORMINOR > 8001 */ |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
547 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
548 #endif |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
549 else { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
550 PyObject *v = PyObject_Str(value); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
551 if (!v) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
552 return 0; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
553 result = AsObj(v); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
554 Py_DECREF(v); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
555 return result; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
556 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
557 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
558 |
| 1664 | 559 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
560 Tkapp_Call(PyObject *self, PyObject *args) |
| 1664 | 561 { |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
562 Tcl_Obj *objStore[ARGSZ]; |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
563 Tcl_Obj **objv = NULL; |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
564 int objc = 0, i; |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
565 PyObject *res = NULL; |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
566 Tcl_Interp *interp = Tkapp_Interp(self); |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
567 /* Could add TCL_EVAL_GLOBAL if wrapped by GlobalCall... */ |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
568 int flags = TCL_EVAL_DIRECT; |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
569 |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
570 objv = objStore; |
| 4968 | 571 |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
572 if (args == NULL) |
|
15356
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
573 /* do nothing */; |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
574 |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
575 else if (!PyTuple_Check(args)) { |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
576 objv[0] = AsObj(args); |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
577 if (objv[0] == 0) |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
578 goto finally; |
|
15356
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
579 objc = 1; |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
580 Tcl_IncrRefCount(objv[0]); |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
581 } |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
582 else { |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
583 objc = PyTuple_Size(args); |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
584 |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
585 if (objc > ARGSZ) { |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
586 objv = (Tcl_Obj **)ckalloc(objc * sizeof(char *)); |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
587 if (objv == NULL) { |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
588 PyErr_NoMemory(); |
|
15356
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
589 objc = 0; |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
590 goto finally; |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
591 } |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
592 } |
| 4968 | 593 |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
594 for (i = 0; i < objc; i++) { |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
595 PyObject *v = PyTuple_GetItem(args, i); |
|
12162
98b09c40d97c
Add back an obscure "feature" to the Obj version of Tkapp_Call(): a
Guido van Rossum <guido@python.org>
parents:
12141
diff
changeset
|
596 if (v == Py_None) { |
|
98b09c40d97c
Add back an obscure "feature" to the Obj version of Tkapp_Call(): a
Guido van Rossum <guido@python.org>
parents:
12141
diff
changeset
|
597 objc = i; |
|
98b09c40d97c
Add back an obscure "feature" to the Obj version of Tkapp_Call(): a
Guido van Rossum <guido@python.org>
parents:
12141
diff
changeset
|
598 break; |
|
98b09c40d97c
Add back an obscure "feature" to the Obj version of Tkapp_Call(): a
Guido van Rossum <guido@python.org>
parents:
12141
diff
changeset
|
599 } |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
600 objv[i] = AsObj(v); |
|
15356
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
601 if (!objv[i]) { |
|
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
602 /* Reset objc, so it attempts to clear |
|
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
603 objects only up to i. */ |
|
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
604 objc = i; |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
605 goto finally; |
|
15356
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
606 } |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
607 Tcl_IncrRefCount(objv[i]); |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
608 } |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
609 } |
| 4968 | 610 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
611 ENTER_TCL |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
612 |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
613 i = Tcl_EvalObjv(interp, objc, objv, flags); |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
614 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
615 ENTER_OVERLAP |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
616 if (i == TCL_ERROR) |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
617 Tkinter_Error(self); |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
618 else { |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
619 /* We could request the object result here, but doing |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
620 so would confuse applications that expect a string. */ |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
621 char *s = Tcl_GetStringResult(interp); |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
622 char *p = s; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
623 |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
624 /* If the result contains any bytes with the top bit set, |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
625 it's UTF-8 and we should decode it to Unicode */ |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
626 #ifdef Py_USING_UNICODE |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
627 while (*p != '\0') { |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
628 if (*p & 0x80) |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
629 break; |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
630 p++; |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
631 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
632 |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
633 if (*p == '\0') |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
634 res = PyString_FromStringAndSize(s, (int)(p-s)); |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
635 else { |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
636 /* Convert UTF-8 to Unicode string */ |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
637 p = strchr(p, '\0'); |
|
12583
db9458c2b631
When the UTF-8 conversion to Unicode fails, return an 8-bit string
Guido van Rossum <guido@python.org>
parents:
12580
diff
changeset
|
638 res = PyUnicode_DecodeUTF8(s, (int)(p-s), "strict"); |
|
db9458c2b631
When the UTF-8 conversion to Unicode fails, return an 8-bit string
Guido van Rossum <guido@python.org>
parents:
12580
diff
changeset
|
639 if (res == NULL) { |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
640 PyErr_Clear(); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
641 res = PyString_FromStringAndSize(s, (int)(p-s)); |
|
12583
db9458c2b631
When the UTF-8 conversion to Unicode fails, return an 8-bit string
Guido van Rossum <guido@python.org>
parents:
12580
diff
changeset
|
642 } |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
643 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
644 #else |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
645 p = strchr(p, '\0'); |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
646 res = PyString_FromStringAndSize(s, (int)(p-s)); |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
647 #endif |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
648 } |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
649 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
650 LEAVE_OVERLAP_TCL |
| 4968 | 651 |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
652 finally: |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
653 for (i = 0; i < objc; i++) |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
654 Tcl_DecrRefCount(objv[i]); |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
655 if (objv != objStore) |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
656 ckfree(FREECAST objv); |
| 4968 | 657 return res; |
| 658 } | |
| 1664 | 659 |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
660 #else /* !USING_OBJECTS */ |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
661 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
662 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
663 Tkapp_Call(PyObject *self, PyObject *args) |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
664 { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
665 /* This is copied from Merge() */ |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
666 PyObject *tmp = NULL; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
667 char *argvStore[ARGSZ]; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
668 char **argv = NULL; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
669 int fvStore[ARGSZ]; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
670 int *fv = NULL; |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
671 int argc = 0, fvc = 0, i; |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
672 PyObject *res = NULL; /* except this has a different type */ |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
673 Tcl_CmdInfo info; /* and this is added */ |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
674 Tcl_Interp *interp = Tkapp_Interp(self); /* and this too */ |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
675 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
676 if (!(tmp = PyList_New(0))) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
677 return NULL; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
678 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
679 argv = argvStore; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
680 fv = fvStore; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
681 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
682 if (args == NULL) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
683 argc = 0; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
684 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
685 else if (!PyTuple_Check(args)) { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
686 argc = 1; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
687 fv[0] = 0; |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
688 if (!(argv[0] = AsString(args, tmp))) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
689 goto finally; |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
690 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
691 else { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
692 argc = PyTuple_Size(args); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
693 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
694 if (argc > ARGSZ) { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
695 argv = (char **)ckalloc(argc * sizeof(char *)); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
696 fv = (int *)ckalloc(argc * sizeof(int)); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
697 if (argv == NULL || fv == NULL) { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
698 PyErr_NoMemory(); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
699 goto finally; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
700 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
701 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
702 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
703 for (i = 0; i < argc; i++) { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
704 PyObject *v = PyTuple_GetItem(args, i); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
705 if (PyTuple_Check(v)) { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
706 fv[i] = 1; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
707 if (!(argv[i] = Merge(v))) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
708 goto finally; |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
709 fvc++; |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
710 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
711 else if (v == Py_None) { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
712 argc = i; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
713 break; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
714 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
715 else { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
716 fv[i] = 0; |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
717 if (!(argv[i] = AsString(v, tmp))) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
718 goto finally; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
719 fvc++; |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
720 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
721 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
722 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
723 /* End code copied from Merge() */ |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
724 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
725 /* All this to avoid a call to Tcl_Merge() and the corresponding call |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
726 to Tcl_SplitList() inside Tcl_Eval()... It can save a bundle! */ |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
727 if (Py_VerboseFlag >= 2) { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
728 for (i = 0; i < argc; i++) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
729 PySys_WriteStderr("%s ", argv[i]); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
730 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
731 ENTER_TCL |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
732 info.proc = NULL; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
733 if (argc < 1 || |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
734 !Tcl_GetCommandInfo(interp, argv[0], &info) || |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
735 info.proc == NULL) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
736 { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
737 char *cmd; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
738 cmd = Tcl_Merge(argc, argv); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
739 i = Tcl_Eval(interp, cmd); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
740 ckfree(cmd); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
741 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
742 else { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
743 Tcl_ResetResult(interp); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
744 i = (*info.proc)(info.clientData, interp, argc, argv); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
745 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
746 ENTER_OVERLAP |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
747 if (info.proc == NULL && Py_VerboseFlag >= 2) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
748 PySys_WriteStderr("... use TclEval "); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
749 if (i == TCL_ERROR) { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
750 if (Py_VerboseFlag >= 2) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
751 PySys_WriteStderr("... error: '%s'\n", |
| 15177 | 752 Tcl_GetStringResult(interp)); |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
753 Tkinter_Error(self); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
754 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
755 else { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
756 if (Py_VerboseFlag >= 2) |
| 15177 | 757 PySys_WriteStderr("-> '%s'\n", Tcl_GetStringResult(interp)); |
| 758 res = PyString_FromString(Tcl_GetStringResult(interp)); | |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
759 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
760 LEAVE_OVERLAP_TCL |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
761 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
762 /* Copied from Merge() again */ |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
763 finally: |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
764 for (i = 0; i < fvc; i++) |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
765 if (fv[i]) { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
766 ckfree(argv[i]); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
767 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
768 if (argv != argvStore) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
769 ckfree(FREECAST argv); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
770 if (fv != fvStore) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
771 ckfree(FREECAST fv); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
772 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
773 Py_DECREF(tmp); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
774 return res; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
775 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
776 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
777 #endif /* !USING_OBJECTS */ |
| 4968 | 778 |
| 779 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
780 Tkapp_GlobalCall(PyObject *self, PyObject *args) |
| 4968 | 781 { |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
782 /* 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
|
783 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
|
784 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
|
785 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
|
786 scope pointer). */ |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
787 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
788 char *cmd; |
| 4968 | 789 PyObject *res = NULL; |
| 1664 | 790 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
791 cmd = Merge(args); |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
792 if (cmd) { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
793 int err; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
794 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
795 err = Tcl_GlobalEval(Tkapp_Interp(self), cmd); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
796 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
797 if (err == TCL_ERROR) |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
798 res = Tkinter_Error(self); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
799 else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
800 res = PyString_FromString(Tkapp_Result(self)); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
801 LEAVE_OVERLAP_TCL |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
802 ckfree(cmd); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
803 } |
| 4968 | 804 |
| 805 return res; | |
| 1664 | 806 } |
| 807 | |
| 808 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
809 Tkapp_Eval(PyObject *self, PyObject *args) |
| 1664 | 810 { |
| 4968 | 811 char *script; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
812 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
813 int err; |
| 4968 | 814 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
815 if (!PyArg_ParseTuple(args, "s:eval", &script)) |
| 4968 | 816 return NULL; |
| 1664 | 817 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
818 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
819 err = Tcl_Eval(Tkapp_Interp(self), script); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
820 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
821 if (err == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
822 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
823 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
824 res = PyString_FromString(Tkapp_Result(self)); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
825 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
826 return res; |
| 1664 | 827 } |
| 828 | |
| 829 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
830 Tkapp_GlobalEval(PyObject *self, PyObject *args) |
| 1664 | 831 { |
| 4968 | 832 char *script; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
833 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
834 int err; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
835 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
836 if (!PyArg_ParseTuple(args, "s:globaleval", &script)) |
| 4968 | 837 return NULL; |
| 1664 | 838 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
839 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
840 err = Tcl_GlobalEval(Tkapp_Interp(self), script); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
841 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
842 if (err == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
843 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
844 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
845 res = PyString_FromString(Tkapp_Result(self)); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
846 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
847 return res; |
| 1664 | 848 } |
| 849 | |
| 850 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
851 Tkapp_EvalFile(PyObject *self, PyObject *args) |
| 1664 | 852 { |
| 4968 | 853 char *fileName; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
854 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
855 int err; |
| 1664 | 856 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
857 if (!PyArg_ParseTuple(args, "s:evalfile", &fileName)) |
| 4968 | 858 return NULL; |
| 1664 | 859 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
860 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
861 err = Tcl_EvalFile(Tkapp_Interp(self), fileName); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
862 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
863 if (err == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
864 res = Tkinter_Error(self); |
| 1664 | 865 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
866 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
867 res = PyString_FromString(Tkapp_Result(self)); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
868 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
869 return res; |
| 1664 | 870 } |
| 871 | |
| 872 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
873 Tkapp_Record(PyObject *self, PyObject *args) |
| 1664 | 874 { |
| 4968 | 875 char *script; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
876 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
877 int err; |
| 1664 | 878 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
879 if (!PyArg_ParseTuple(args, "s", &script)) |
| 4968 | 880 return NULL; |
| 1664 | 881 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
882 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
883 err = Tcl_RecordAndEval(Tkapp_Interp(self), script, TCL_NO_EVAL); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
884 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
885 if (err == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
886 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
887 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
888 res = PyString_FromString(Tkapp_Result(self)); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
889 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
890 return res; |
| 1664 | 891 } |
| 892 | |
| 893 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
894 Tkapp_AddErrorInfo(PyObject *self, PyObject *args) |
| 1664 | 895 { |
| 4968 | 896 char *msg; |
| 1664 | 897 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
898 if (!PyArg_ParseTuple(args, "s:adderrorinfo", &msg)) |
| 4968 | 899 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
900 ENTER_TCL |
| 4968 | 901 Tcl_AddErrorInfo(Tkapp_Interp(self), msg); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
902 LEAVE_TCL |
| 1664 | 903 |
| 4968 | 904 Py_INCREF(Py_None); |
| 905 return Py_None; | |
| 1664 | 906 } |
| 907 | |
| 4968 | 908 |
| 909 | |
| 1664 | 910 /** Tcl Variable **/ |
| 911 | |
| 912 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
913 SetVar(PyObject *self, PyObject *args, int flags) |
| 1664 | 914 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
915 char *name1, *name2, *ok, *s; |
| 4968 | 916 PyObject *newValue; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
917 PyObject *tmp; |
| 1664 | 918 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
919 tmp = PyList_New(0); |
| 4968 | 920 if (!tmp) |
| 921 return NULL; | |
| 1664 | 922 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
923 if (PyArg_ParseTuple(args, "sO:setvar", &name1, &newValue)) { |
| 4968 | 924 /* XXX Merge? */ |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
925 s = AsString(newValue, tmp); |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
926 if (s == NULL) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
927 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
928 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
929 ok = Tcl_SetVar(Tkapp_Interp(self), name1, s, flags); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
930 LEAVE_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
931 } |
| 4968 | 932 else { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
933 PyErr_Clear(); |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
934 if (PyArg_ParseTuple(args, "ssO:setvar", |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
935 &name1, &name2, &newValue)) { |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
936 s = AsString(newValue, tmp); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
937 if (s == NULL) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
938 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
939 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
940 ok = Tcl_SetVar2(Tkapp_Interp(self), name1, name2, |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
941 s, flags); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
942 LEAVE_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
943 } |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
944 else { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
945 Py_DECREF(tmp); |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
946 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
947 } |
| 4968 | 948 } |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
949 Py_DECREF(tmp); |
| 1664 | 950 |
| 4968 | 951 if (!ok) |
| 952 return Tkinter_Error(self); | |
| 953 | |
| 954 Py_INCREF(Py_None); | |
| 955 return Py_None; | |
| 1664 | 956 } |
| 957 | |
| 958 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
959 Tkapp_SetVar(PyObject *self, PyObject *args) |
| 1664 | 960 { |
| 4968 | 961 return SetVar(self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 962 } |
| 963 | |
| 964 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
965 Tkapp_GlobalSetVar(PyObject *self, PyObject *args) |
| 1664 | 966 { |
| 4968 | 967 return SetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 968 } |
| 969 | |
| 4968 | 970 |
| 971 | |
| 1664 | 972 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
973 GetVar(PyObject *self, PyObject *args, int flags) |
| 1664 | 974 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
975 char *name1, *name2=NULL, *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
976 PyObject *res = NULL; |
| 4968 | 977 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
978 if (!PyArg_ParseTuple(args, "s|s:getvar", &name1, &name2)) |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
979 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
980 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
981 if (name2 == NULL) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
982 s = Tcl_GetVar(Tkapp_Interp(self), name1, flags); |
| 1664 | 983 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
984 else |
| 4968 | 985 s = Tcl_GetVar2(Tkapp_Interp(self), name1, name2, flags); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
986 ENTER_OVERLAP |
| 1664 | 987 |
| 4968 | 988 if (s == NULL) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
989 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
990 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
991 res = PyString_FromString(s); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
992 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
993 return res; |
| 1664 | 994 } |
| 995 | |
| 996 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
997 Tkapp_GetVar(PyObject *self, PyObject *args) |
| 1664 | 998 { |
| 4968 | 999 return GetVar(self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 1000 } |
| 1001 | |
| 1002 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1003 Tkapp_GlobalGetVar(PyObject *self, PyObject *args) |
| 1664 | 1004 { |
| 4968 | 1005 return GetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 1006 } |
| 1007 | |
| 4968 | 1008 |
| 1009 | |
| 1664 | 1010 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1011 UnsetVar(PyObject *self, PyObject *args, int flags) |
| 1664 | 1012 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1013 char *name1, *name2=NULL; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1014 PyObject *res = NULL; |
| 4968 | 1015 int code; |
| 1016 | |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1017 if (!PyArg_ParseTuple(args, "s|s:unsetvar", &name1, &name2)) |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1018 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1019 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1020 if (name2 == NULL) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1021 code = Tcl_UnsetVar(Tkapp_Interp(self), name1, flags); |
| 1664 | 1022 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1023 else |
| 4968 | 1024 code = Tcl_UnsetVar2(Tkapp_Interp(self), name1, name2, flags); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1025 ENTER_OVERLAP |
| 1664 | 1026 |
| 4968 | 1027 if (code == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1028 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1029 else { |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1030 Py_INCREF(Py_None); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1031 res = Py_None; |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1032 } |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1033 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1034 return res; |
| 1664 | 1035 } |
| 1036 | |
| 1037 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1038 Tkapp_UnsetVar(PyObject *self, PyObject *args) |
| 1664 | 1039 { |
| 4968 | 1040 return UnsetVar(self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 1041 } |
| 1042 | |
| 1043 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1044 Tkapp_GlobalUnsetVar(PyObject *self, PyObject *args) |
| 1664 | 1045 { |
| 4968 | 1046 return UnsetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 1047 } |
| 1048 | |
| 4968 | 1049 |
| 1050 | |
| 1664 | 1051 /** Tcl to Python **/ |
| 1052 | |
| 1053 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1054 Tkapp_GetInt(PyObject *self, PyObject *args) |
| 1664 | 1055 { |
| 4968 | 1056 char *s; |
| 1057 int v; | |
| 1664 | 1058 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1059 if (!PyArg_ParseTuple(args, "s:getint", &s)) |
| 4968 | 1060 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1061 if (Tcl_GetInt(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
| 4968 | 1062 return Tkinter_Error(self); |
| 1063 return Py_BuildValue("i", v); | |
| 1664 | 1064 } |
| 1065 | |
| 1066 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1067 Tkapp_GetDouble(PyObject *self, PyObject *args) |
| 1664 | 1068 { |
| 4968 | 1069 char *s; |
| 1070 double v; | |
| 1664 | 1071 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1072 if (!PyArg_ParseTuple(args, "s:getdouble", &s)) |
| 4968 | 1073 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1074 if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
| 4968 | 1075 return Tkinter_Error(self); |
| 1076 return Py_BuildValue("d", v); | |
| 1664 | 1077 } |
| 1078 | |
| 1079 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1080 Tkapp_GetBoolean(PyObject *self, PyObject *args) |
| 1664 | 1081 { |
| 4968 | 1082 char *s; |
| 1083 int v; | |
| 1664 | 1084 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1085 if (!PyArg_ParseTuple(args, "s:getboolean", &s)) |
| 4968 | 1086 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1087 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
|
1088 return Tkinter_Error(self); |
| 4968 | 1089 return Py_BuildValue("i", v); |
| 1664 | 1090 } |
| 1091 | |
| 1092 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1093 Tkapp_ExprString(PyObject *self, PyObject *args) |
| 1664 | 1094 { |
| 4968 | 1095 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1096 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1097 int retval; |
| 1664 | 1098 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1099 if (!PyArg_ParseTuple(args, "s:exprstring", &s)) |
| 4968 | 1100 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1101 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1102 retval = Tcl_ExprString(Tkapp_Interp(self), s); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1103 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1104 if (retval == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1105 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1106 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1107 res = Py_BuildValue("s", Tkapp_Result(self)); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1108 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1109 return res; |
| 1664 | 1110 } |
| 1111 | |
| 1112 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1113 Tkapp_ExprLong(PyObject *self, PyObject *args) |
| 1664 | 1114 { |
| 4968 | 1115 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1116 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1117 int retval; |
| 4968 | 1118 long v; |
| 1664 | 1119 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1120 if (!PyArg_ParseTuple(args, "s:exprlong", &s)) |
| 4968 | 1121 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1122 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1123 retval = Tcl_ExprLong(Tkapp_Interp(self), s, &v); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1124 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1125 if (retval == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1126 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1127 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1128 res = Py_BuildValue("l", v); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1129 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1130 return res; |
| 1664 | 1131 } |
| 1132 | |
| 1133 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1134 Tkapp_ExprDouble(PyObject *self, PyObject *args) |
| 1664 | 1135 { |
| 4968 | 1136 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1137 PyObject *res = NULL; |
| 4968 | 1138 double v; |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
1139 int retval; |
| 1664 | 1140 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1141 if (!PyArg_ParseTuple(args, "s:exprdouble", &s)) |
| 4968 | 1142 return NULL; |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
1143 PyFPE_START_PROTECT("Tkapp_ExprDouble", return 0) |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1144 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1145 retval = Tcl_ExprDouble(Tkapp_Interp(self), s, &v); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1146 ENTER_OVERLAP |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5120
diff
changeset
|
1147 PyFPE_END_PROTECT(retval) |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
1148 if (retval == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1149 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1150 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1151 res = Py_BuildValue("d", v); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1152 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1153 return res; |
| 1664 | 1154 } |
| 1155 | |
| 1156 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1157 Tkapp_ExprBoolean(PyObject *self, PyObject *args) |
| 1664 | 1158 { |
| 4968 | 1159 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1160 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1161 int retval; |
| 4968 | 1162 int v; |
| 1664 | 1163 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1164 if (!PyArg_ParseTuple(args, "s:exprboolean", &s)) |
| 4968 | 1165 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1166 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1167 retval = Tcl_ExprBoolean(Tkapp_Interp(self), s, &v); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1168 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1169 if (retval == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1170 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1171 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1172 res = Py_BuildValue("i", v); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1173 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1174 return res; |
| 1664 | 1175 } |
| 1176 | |
| 4968 | 1177 |
| 1178 | |
| 1664 | 1179 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1180 Tkapp_SplitList(PyObject *self, PyObject *args) |
| 1664 | 1181 { |
| 4968 | 1182 char *list; |
| 1183 int argc; | |
| 1184 char **argv; | |
| 1185 PyObject *v; | |
| 1186 int i; | |
| 1187 | |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1188 if (!PyArg_ParseTuple(args, "s:splitlist", &list)) |
| 4968 | 1189 return NULL; |
| 1190 | |
| 1191 if (Tcl_SplitList(Tkapp_Interp(self), list, &argc, &argv) == TCL_ERROR) | |
| 1192 return Tkinter_Error(self); | |
| 1664 | 1193 |
| 4968 | 1194 if (!(v = PyTuple_New(argc))) |
| 1195 return NULL; | |
| 1196 | |
| 1197 for (i = 0; i < argc; i++) { | |
| 1198 PyObject *s = PyString_FromString(argv[i]); | |
| 1199 if (!s || PyTuple_SetItem(v, i, s)) { | |
| 1200 Py_DECREF(v); | |
| 1201 v = NULL; | |
| 1202 goto finally; | |
| 1203 } | |
| 1204 } | |
| 1664 | 1205 |
| 4968 | 1206 finally: |
| 1207 ckfree(FREECAST argv); | |
| 1208 return v; | |
| 1664 | 1209 } |
| 1210 | |
| 1211 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1212 Tkapp_Split(PyObject *self, PyObject *args) |
| 1664 | 1213 { |
| 4968 | 1214 char *list; |
| 1664 | 1215 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1216 if (!PyArg_ParseTuple(args, "s:split", &list)) |
| 4968 | 1217 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1218 return Split(list); |
| 1664 | 1219 } |
| 1220 | |
| 1221 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1222 Tkapp_Merge(PyObject *self, PyObject *args) |
| 1664 | 1223 { |
| 4968 | 1224 char *s = Merge(args); |
| 1225 PyObject *res = NULL; | |
| 1664 | 1226 |
| 4968 | 1227 if (s) { |
| 1228 res = PyString_FromString(s); | |
| 1229 ckfree(s); | |
| 1230 } | |
| 1231 | |
| 1232 return res; | |
| 1664 | 1233 } |
| 1234 | |
| 4968 | 1235 |
| 1236 | |
| 1664 | 1237 /** Tcl Command **/ |
| 1238 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1239 /* Client data struct */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1240 typedef struct { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1241 PyObject *self; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1242 PyObject *func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1243 } PythonCmd_ClientData; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1244 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1245 static int |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1246 PythonCmd_Error(Tcl_Interp *interp) |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1247 { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1248 errorInCmd = 1; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1249 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1250 LEAVE_PYTHON |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1251 return TCL_ERROR; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1252 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1253 |
| 1664 | 1254 /* This is the Tcl command that acts as a wrapper for Python |
| 4968 | 1255 * function or method. |
| 1256 */ | |
| 1664 | 1257 static int |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1258 PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) |
| 1664 | 1259 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1260 PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData; |
| 4968 | 1261 PyObject *self, *func, *arg, *res, *tmp; |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1262 int i, rv; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1263 char *s; |
| 1664 | 1264 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
1265 ENTER_PYTHON |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1266 |
| 4968 | 1267 /* TBD: no error checking here since we know, via the |
| 1268 * Tkapp_CreateCommand() that the client data is a two-tuple | |
| 1269 */ | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1270 self = data->self; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1271 func = data->func; |
| 4968 | 1272 |
| 1273 /* Create argument list (argv1, ..., argvN) */ | |
| 1274 if (!(arg = PyTuple_New(argc - 1))) | |
| 1275 return PythonCmd_Error(interp); | |
| 1664 | 1276 |
| 4968 | 1277 for (i = 0; i < (argc - 1); i++) { |
| 1278 PyObject *s = PyString_FromString(argv[i + 1]); | |
| 1279 if (!s || PyTuple_SetItem(arg, i, s)) { | |
| 1280 Py_DECREF(arg); | |
|
8522
4e4fd954dda0
There was an error check in a loop in PythonCmd which called
Guido van Rossum <guido@python.org>
parents:
8504
diff
changeset
|
1281 return PythonCmd_Error(interp); |
| 4968 | 1282 } |
| 1283 } | |
| 1284 res = PyEval_CallObject(func, arg); | |
| 1285 Py_DECREF(arg); | |
| 1713 | 1286 |
| 4968 | 1287 if (res == NULL) |
| 1288 return PythonCmd_Error(interp); | |
| 1664 | 1289 |
| 4968 | 1290 if (!(tmp = PyList_New(0))) { |
| 1291 Py_DECREF(res); | |
| 1292 return PythonCmd_Error(interp); | |
| 1293 } | |
| 1664 | 1294 |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1295 s = AsString(res, tmp); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1296 if (s == NULL) { |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1297 rv = PythonCmd_Error(interp); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1298 } |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1299 else { |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1300 Tcl_SetResult(Tkapp_Interp(self), s, TCL_VOLATILE); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1301 rv = TCL_OK; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1302 } |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1303 |
| 4968 | 1304 Py_DECREF(res); |
| 1305 Py_DECREF(tmp); | |
| 1306 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1307 LEAVE_PYTHON |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1308 |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1309 return rv; |
| 1664 | 1310 } |
| 1311 | |
| 1312 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1313 PythonCmdDelete(ClientData clientData) |
| 1664 | 1314 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1315 PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1316 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
1317 ENTER_PYTHON |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1318 Py_XDECREF(data->self); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1319 Py_XDECREF(data->func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1320 PyMem_DEL(data); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1321 LEAVE_PYTHON |
| 1664 | 1322 } |
| 1323 | |
| 4968 | 1324 |
| 1325 | |
| 1664 | 1326 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1327 Tkapp_CreateCommand(PyObject *self, PyObject *args) |
| 1664 | 1328 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1329 PythonCmd_ClientData *data; |
| 4968 | 1330 char *cmdName; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1331 PyObject *func; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1332 Tcl_Command err; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1333 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1334 if (!PyArg_ParseTuple(args, "sO:createcommand", &cmdName, &func)) |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1335 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1336 if (!PyCallable_Check(func)) { |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1337 PyErr_SetString(PyExc_TypeError, "command not callable"); |
| 4968 | 1338 return NULL; |
| 1339 } | |
| 1664 | 1340 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1341 data = PyMem_NEW(PythonCmd_ClientData, 1); |
| 4968 | 1342 if (!data) |
| 1343 return NULL; | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1344 Py_XINCREF(self); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1345 Py_XINCREF(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1346 data->self = self; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1347 data->func = func; |
| 1664 | 1348 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1349 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1350 err = Tcl_CreateCommand(Tkapp_Interp(self), cmdName, PythonCmd, |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1351 (ClientData)data, PythonCmdDelete); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1352 LEAVE_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1353 if (err == NULL) { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1354 PyErr_SetString(Tkinter_TclError, "can't create Tcl command"); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1355 PyMem_DEL(data); |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1356 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1357 } |
| 1664 | 1358 |
| 4968 | 1359 Py_INCREF(Py_None); |
| 1360 return Py_None; | |
| 1664 | 1361 } |
| 1362 | |
| 4968 | 1363 |
| 1364 | |
| 1664 | 1365 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1366 Tkapp_DeleteCommand(PyObject *self, PyObject *args) |
| 1664 | 1367 { |
| 4968 | 1368 char *cmdName; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1369 int err; |
| 1664 | 1370 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1371 if (!PyArg_ParseTuple(args, "s:deletecommand", &cmdName)) |
| 4968 | 1372 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1373 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1374 err = Tcl_DeleteCommand(Tkapp_Interp(self), cmdName); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1375 LEAVE_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1376 if (err == -1) { |
| 4968 | 1377 PyErr_SetString(Tkinter_TclError, "can't delete Tcl command"); |
| 1378 return NULL; | |
| 1379 } | |
| 1380 Py_INCREF(Py_None); | |
| 1381 return Py_None; | |
| 1664 | 1382 } |
| 1383 | |
| 4968 | 1384 |
| 1385 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1386 #ifdef HAVE_CREATEFILEHANDLER |
| 1664 | 1387 /** File Handler **/ |
| 1388 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1389 typedef struct _fhcdata { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1390 PyObject *func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1391 PyObject *file; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1392 int id; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1393 struct _fhcdata *next; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1394 } FileHandler_ClientData; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1395 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1396 static FileHandler_ClientData *HeadFHCD; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1397 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1398 static FileHandler_ClientData * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1399 NewFHCD(PyObject *func, PyObject *file, int id) |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1400 { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1401 FileHandler_ClientData *p; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1402 p = PyMem_NEW(FileHandler_ClientData, 1); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1403 if (p != NULL) { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1404 Py_XINCREF(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1405 Py_XINCREF(file); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1406 p->func = func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1407 p->file = file; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1408 p->id = id; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1409 p->next = HeadFHCD; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1410 HeadFHCD = p; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1411 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1412 return p; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1413 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1414 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1415 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1416 DeleteFHCD(int id) |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1417 { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1418 FileHandler_ClientData *p, **pp; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1419 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1420 pp = &HeadFHCD; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1421 while ((p = *pp) != NULL) { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1422 if (p->id == id) { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1423 *pp = p->next; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1424 Py_XDECREF(p->func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1425 Py_XDECREF(p->file); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1426 PyMem_DEL(p); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1427 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1428 else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1429 pp = &p->next; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1430 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1431 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1432 |
|
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
|
1433 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1434 FileHandler(ClientData clientData, int mask) |
| 1664 | 1435 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1436 FileHandler_ClientData *data = (FileHandler_ClientData *)clientData; |
| 4968 | 1437 PyObject *func, *file, *arg, *res; |
| 1664 | 1438 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
1439 ENTER_PYTHON |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1440 func = data->func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1441 file = data->file; |
| 1664 | 1442 |
| 4968 | 1443 arg = Py_BuildValue("(Oi)", file, (long) mask); |
| 1444 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
|
1445 Py_DECREF(arg); |
| 4968 | 1446 |
| 1447 if (res == NULL) { | |
| 1448 errorInCmd = 1; | |
| 1449 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); | |
| 1450 } | |
| 1451 Py_XDECREF(res); | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1452 LEAVE_PYTHON |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
1453 } |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
1454 |
| 1664 | 1455 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1456 Tkapp_CreateFileHandler(PyObject *self, PyObject *args) |
|
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1457 /* args is (file, mask, func) */ |
| 1664 | 1458 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1459 FileHandler_ClientData *data; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1460 PyObject *file, *func; |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
1461 int mask, tfile; |
| 1664 | 1462 |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1463 if (!PyArg_ParseTuple(args, "OiO:createfilehandler", |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1464 &file, &mask, &func)) |
| 4968 | 1465 return NULL; |
|
13593
df64cc0e84e2
Use PyObject_AsFileDescriptor
Andrew M. Kuchling <amk@amk.ca>
parents:
13576
diff
changeset
|
1466 tfile = PyObject_AsFileDescriptor(file); |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
1467 if (tfile < 0) |
| 4968 | 1468 return NULL; |
| 1469 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
|
1470 PyErr_SetString(PyExc_TypeError, "bad argument list"); |
| 4968 | 1471 return NULL; |
| 1472 } | |
| 1473 | |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
1474 data = NewFHCD(func, file, tfile); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1475 if (data == NULL) |
| 4968 | 1476 return NULL; |
| 1477 | |
| 1478 /* Ought to check for null Tcl_File object... */ | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1479 ENTER_TCL |
| 4968 | 1480 Tcl_CreateFileHandler(tfile, mask, FileHandler, (ClientData) data); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1481 LEAVE_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1482 Py_INCREF(Py_None); |
| 4968 | 1483 return Py_None; |
| 1664 | 1484 } |
| 1485 | |
| 1486 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1487 Tkapp_DeleteFileHandler(PyObject *self, PyObject *args) |
| 1664 | 1488 { |
| 4968 | 1489 PyObject *file; |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
1490 int tfile; |
|
3554
24279bafa828
Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents:
3553
diff
changeset
|
1491 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1492 if (!PyArg_ParseTuple(args, "O:deletefilehandler", &file)) |
| 4968 | 1493 return NULL; |
|
13593
df64cc0e84e2
Use PyObject_AsFileDescriptor
Andrew M. Kuchling <amk@amk.ca>
parents:
13576
diff
changeset
|
1494 tfile = PyObject_AsFileDescriptor(file); |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
1495 if (tfile < 0) |
| 4968 | 1496 return NULL; |
| 1497 | |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
1498 DeleteFHCD(tfile); |
| 1664 | 1499 |
| 4968 | 1500 /* Ought to check for null Tcl_File object... */ |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1501 ENTER_TCL |
| 4968 | 1502 Tcl_DeleteFileHandler(tfile); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1503 LEAVE_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1504 Py_INCREF(Py_None); |
| 4968 | 1505 return Py_None; |
| 1664 | 1506 } |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1507 #endif /* HAVE_CREATEFILEHANDLER */ |
| 1664 | 1508 |
| 4968 | 1509 |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1510 /**** 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
|
1511 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1512 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
|
1513 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1514 typedef struct { |
| 4968 | 1515 PyObject_HEAD |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1516 Tcl_TimerToken token; |
| 4968 | 1517 PyObject *func; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1518 } TkttObject; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1519 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1520 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1521 Tktt_DeleteTimerHandler(PyObject *self, 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
|
1522 { |
| 4968 | 1523 TkttObject *v = (TkttObject *)self; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1524 PyObject *func = v->func; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1525 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1526 if (!PyArg_ParseTuple(args, ":deletetimerhandler")) |
| 4968 | 1527 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1528 if (v->token != NULL) { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1529 Tcl_DeleteTimerHandler(v->token); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1530 v->token = NULL; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1531 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1532 if (func != NULL) { |
| 4968 | 1533 v->func = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1534 Py_DECREF(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1535 Py_DECREF(v); /* See Tktt_New() */ |
| 4968 | 1536 } |
| 1537 Py_INCREF(Py_None); | |
| 1538 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
|
1539 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1540 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1541 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
|
1542 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1543 {"deletetimerhandler", Tktt_DeleteTimerHandler, 1}, |
| 4968 | 1544 {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
|
1545 }; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1546 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1547 static TkttObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1548 Tktt_New(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
|
1549 { |
| 4968 | 1550 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
|
1551 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
1552 v = PyObject_New(TkttObject, &Tktt_Type); |
| 4968 | 1553 if (v == NULL) |
| 1554 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
|
1555 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1556 Py_INCREF(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1557 v->token = NULL; |
| 4968 | 1558 v->func = func; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1559 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1560 /* Extra reference, deleted when called or when handler is deleted */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1561 Py_INCREF(v); |
| 4968 | 1562 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
|
1563 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1564 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1565 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1566 Tktt_Dealloc(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
|
1567 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1568 TkttObject *v = (TkttObject *)self; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1569 PyObject *func = v->func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1570 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1571 Py_XDECREF(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1572 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
1573 PyObject_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
|
1574 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1575 |
|
8312
d67be13da3cc
Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents:
8200
diff
changeset
|
1576 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1577 Tktt_Repr(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
|
1578 { |
| 4968 | 1579 TkttObject *v = (TkttObject *)self; |
|
8312
d67be13da3cc
Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents:
8200
diff
changeset
|
1580 char buf[100]; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1581 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12958
diff
changeset
|
1582 sprintf(buf, "<tktimertoken at %p%s>", v, |
| 4968 | 1583 v->func == NULL ? ", handler deleted" : ""); |
|
8312
d67be13da3cc
Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents:
8200
diff
changeset
|
1584 return PyString_FromString(buf); |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1585 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1586 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1587 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1588 Tktt_GetAttr(PyObject *self, 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
|
1589 { |
| 4968 | 1590 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
|
1591 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1592 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1593 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
|
1594 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1595 PyObject_HEAD_INIT(NULL) |
| 4968 | 1596 0, /*ob_size */ |
| 1597 "tktimertoken", /*tp_name */ | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1598 sizeof(TkttObject), /*tp_basicsize */ |
| 4968 | 1599 0, /*tp_itemsize */ |
| 1600 Tktt_Dealloc, /*tp_dealloc */ | |
|
8312
d67be13da3cc
Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents:
8200
diff
changeset
|
1601 0, /*tp_print */ |
| 4968 | 1602 Tktt_GetAttr, /*tp_getattr */ |
| 1603 0, /*tp_setattr */ | |
| 1604 0, /*tp_compare */ | |
|
8312
d67be13da3cc
Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents:
8200
diff
changeset
|
1605 Tktt_Repr, /*tp_repr */ |
| 4968 | 1606 0, /*tp_as_number */ |
| 1607 0, /*tp_as_sequence */ | |
| 1608 0, /*tp_as_mapping */ | |
| 1609 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
|
1610 }; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1611 |
| 4968 | 1612 |
| 1613 | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1614 /** Timer Handler **/ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1615 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1616 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1617 TimerHandler(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
|
1618 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1619 TkttObject *v = (TkttObject *)clientData; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1620 PyObject *func = v->func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1621 PyObject *res; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1622 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1623 if (func == NULL) |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1624 return; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1625 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1626 v->func = NULL; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1627 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
1628 ENTER_PYTHON |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1629 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1630 res = PyEval_CallObject(func, NULL); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1631 Py_DECREF(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1632 Py_DECREF(v); /* See Tktt_New() */ |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1633 |
| 4968 | 1634 if (res == NULL) { |
| 1635 errorInCmd = 1; | |
| 1636 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); | |
| 1637 } | |
| 1638 else | |
| 1639 Py_DECREF(res); | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1640 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1641 LEAVE_PYTHON |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1642 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1643 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1644 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1645 Tkapp_CreateTimerHandler(PyObject *self, 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
|
1646 { |
| 4968 | 1647 int milliseconds; |
| 1648 PyObject *func; | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1649 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
|
1650 |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1651 if (!PyArg_ParseTuple(args, "iO:createtimerhandler", |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1652 &milliseconds, &func)) |
| 4968 | 1653 return NULL; |
| 1654 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
|
1655 PyErr_SetString(PyExc_TypeError, "bad argument list"); |
| 4968 | 1656 return NULL; |
| 1657 } | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1658 v = Tktt_New(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1659 v->token = Tcl_CreateTimerHandler(milliseconds, TimerHandler, |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1660 (ClientData)v); |
| 4968 | 1661 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1662 return (PyObject *) v; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1663 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1664 |
| 4968 | 1665 |
| 1664 | 1666 /** Event Loop **/ |
| 1667 | |
| 1668 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1669 Tkapp_MainLoop(PyObject *self, PyObject *args) |
| 1664 | 1670 { |
| 4968 | 1671 int threshold = 0; |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
1672 #ifdef WITH_THREAD |
|
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
1673 PyThreadState *tstate = PyThreadState_Get(); |
|
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
1674 #endif |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
1675 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1676 if (!PyArg_ParseTuple(args, "|i:mainloop", &threshold)) |
| 4968 | 1677 return NULL; |
| 1664 | 1678 |
| 4968 | 1679 quitMainLoop = 0; |
| 1680 while (Tk_GetNumMainWindows() > threshold && | |
| 1681 !quitMainLoop && | |
| 1682 !errorInCmd) | |
| 1664 | 1683 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1684 int result; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1685 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1686 #ifdef WITH_THREAD |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1687 Py_BEGIN_ALLOW_THREADS |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1688 PyThread_acquire_lock(tcl_lock, 1); |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
1689 tcl_tstate = tstate; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1690 result = Tcl_DoOneEvent(TCL_DONT_WAIT); |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
1691 tcl_tstate = NULL; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1692 PyThread_release_lock(tcl_lock); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1693 if (result == 0) |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1694 Sleep(20); |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1695 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
|
1696 #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
|
1697 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
|
1698 #endif |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1699 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1700 if (PyErr_CheckSignals() != 0) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1701 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1702 if (result < 0) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1703 break; |
| 1664 | 1704 } |
| 4968 | 1705 quitMainLoop = 0; |
| 1664 | 1706 |
| 4968 | 1707 if (errorInCmd) { |
| 1708 errorInCmd = 0; | |
| 1709 PyErr_Restore(excInCmd, valInCmd, trbInCmd); | |
| 1710 excInCmd = valInCmd = trbInCmd = NULL; | |
| 1711 return NULL; | |
| 1712 } | |
| 1713 Py_INCREF(Py_None); | |
| 1714 return Py_None; | |
| 1664 | 1715 } |
| 1716 | |
| 1717 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1718 Tkapp_DoOneEvent(PyObject *self, PyObject *args) |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1719 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1720 int flags = 0; |
| 4968 | 1721 int rv; |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1722 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1723 if (!PyArg_ParseTuple(args, "|i:dooneevent", &flags)) |
| 4968 | 1724 return NULL; |
| 1725 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1726 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1727 rv = Tcl_DoOneEvent(flags); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1728 LEAVE_TCL |
| 4968 | 1729 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
|
1730 } |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1731 |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
1732 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1733 Tkapp_Quit(PyObject *self, PyObject *args) |
| 1664 | 1734 { |
| 1735 | |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1736 if (!PyArg_ParseTuple(args, ":quit")) |
| 4968 | 1737 return NULL; |
| 1738 | |
| 1739 quitMainLoop = 1; | |
| 1740 Py_INCREF(Py_None); | |
| 1741 return Py_None; | |
| 1664 | 1742 } |
| 1743 | |
|
8199
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
1744 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1745 Tkapp_InterpAddr(PyObject *self, PyObject *args) |
|
8199
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
1746 { |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
1747 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1748 if (!PyArg_ParseTuple(args, ":interpaddr")) |
|
8199
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
1749 return NULL; |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
1750 |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
1751 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
|
1752 } |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
1753 |
| 4968 | 1754 |
| 1755 | |
| 1664 | 1756 /**** Tkapp Method List ****/ |
| 1757 | |
| 1758 static PyMethodDef Tkapp_methods[] = | |
| 1759 { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1760 {"call", Tkapp_Call, 0}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1761 {"globalcall", Tkapp_GlobalCall, 0}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1762 {"eval", Tkapp_Eval, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1763 {"globaleval", Tkapp_GlobalEval, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1764 {"evalfile", Tkapp_EvalFile, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1765 {"record", Tkapp_Record, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1766 {"adderrorinfo", Tkapp_AddErrorInfo, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1767 {"setvar", Tkapp_SetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1768 {"globalsetvar", Tkapp_GlobalSetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1769 {"getvar", Tkapp_GetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1770 {"globalgetvar", Tkapp_GlobalGetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1771 {"unsetvar", Tkapp_UnsetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1772 {"globalunsetvar", Tkapp_GlobalUnsetVar, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1773 {"getint", Tkapp_GetInt, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1774 {"getdouble", Tkapp_GetDouble, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1775 {"getboolean", Tkapp_GetBoolean, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1776 {"exprstring", Tkapp_ExprString, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1777 {"exprlong", Tkapp_ExprLong, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1778 {"exprdouble", Tkapp_ExprDouble, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1779 {"exprboolean", Tkapp_ExprBoolean, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1780 {"splitlist", Tkapp_SplitList, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1781 {"split", Tkapp_Split, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1782 {"merge", Tkapp_Merge, 0}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1783 {"createcommand", Tkapp_CreateCommand, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1784 {"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
|
1785 #ifdef HAVE_CREATEFILEHANDLER |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1786 {"createfilehandler", Tkapp_CreateFileHandler, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1787 {"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
|
1788 #endif |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1789 {"createtimerhandler", Tkapp_CreateTimerHandler, 1}, |
| 4968 | 1790 {"mainloop", Tkapp_MainLoop, 1}, |
| 1791 {"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
|
1792 {"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
|
1793 {"interpaddr", Tkapp_InterpAddr, 1}, |
| 4968 | 1794 {NULL, NULL} |
| 1664 | 1795 }; |
| 1796 | |
| 4968 | 1797 |
| 1798 | |
| 1664 | 1799 /**** Tkapp Type Methods ****/ |
| 1800 | |
| 1801 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1802 Tkapp_Dealloc(PyObject *self) |
| 1664 | 1803 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1804 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1805 Tcl_DeleteInterp(Tkapp_Interp(self)); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1806 LEAVE_TCL |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
1807 PyObject_Del(self); |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
1808 DisableEventHook(); |
| 1664 | 1809 } |
| 1810 | |
| 1811 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1812 Tkapp_GetAttr(PyObject *self, char *name) |
| 1664 | 1813 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1814 return Py_FindMethod(Tkapp_methods, self, name); |
| 1664 | 1815 } |
| 1816 | |
| 1817 static PyTypeObject Tkapp_Type = | |
| 1818 { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1819 PyObject_HEAD_INIT(NULL) |
| 4968 | 1820 0, /*ob_size */ |
| 1821 "tkapp", /*tp_name */ | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1822 sizeof(TkappObject), /*tp_basicsize */ |
| 4968 | 1823 0, /*tp_itemsize */ |
| 1824 Tkapp_Dealloc, /*tp_dealloc */ | |
| 1825 0, /*tp_print */ | |
| 1826 Tkapp_GetAttr, /*tp_getattr */ | |
| 1827 0, /*tp_setattr */ | |
| 1828 0, /*tp_compare */ | |
| 1829 0, /*tp_repr */ | |
| 1830 0, /*tp_as_number */ | |
| 1831 0, /*tp_as_sequence */ | |
| 1832 0, /*tp_as_mapping */ | |
| 1833 0, /*tp_hash */ | |
| 1664 | 1834 }; |
| 1835 | |
| 4968 | 1836 |
| 1837 | |
| 1664 | 1838 /**** Tkinter Module ****/ |
| 1839 | |
| 12953 | 1840 typedef struct { |
| 1841 PyObject* tuple; | |
| 1842 int size; /* current size */ | |
| 1843 int maxsize; /* allocated size */ | |
| 1844 } FlattenContext; | |
| 1845 | |
| 1846 static int | |
| 1847 _bump(FlattenContext* context, int size) | |
| 1848 { | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1849 /* expand tuple to hold (at least) size new items. |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1850 return true if successful, false if an exception was raised */ |
| 12953 | 1851 |
| 1852 int maxsize = context->maxsize * 2; | |
| 1853 | |
| 1854 if (maxsize < context->size + size) | |
| 1855 maxsize = context->size + size; | |
| 1856 | |
| 1857 context->maxsize = maxsize; | |
| 1858 | |
|
17976
d579a5d8b3fe
Cruft cleanup: Removed the unused last_is_sticky argument from the internal
Tim Peters <tim.peters@gmail.com>
parents:
15356
diff
changeset
|
1859 return _PyTuple_Resize(&context->tuple, maxsize) >= 0; |
| 12953 | 1860 } |
| 1861 | |
| 1862 static int | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
1863 _flatten1(FlattenContext* context, PyObject* item, int depth) |
| 12953 | 1864 { |
| 1865 /* add tuple or list to argument tuple (recursively) */ | |
| 1866 | |
| 1867 int i, size; | |
| 1868 | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
1869 if (depth > 1000) { |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1870 PyErr_SetString(PyExc_ValueError, |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1871 "nesting too deep in _flatten"); |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
1872 return 0; |
|
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
1873 } else if (PyList_Check(item)) { |
| 12953 | 1874 size = PyList_GET_SIZE(item); |
| 1875 /* preallocate (assume no nesting) */ | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1876 if (context->size + size > context->maxsize && |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1877 !_bump(context, size)) |
| 12953 | 1878 return 0; |
| 1879 /* copy items to output tuple */ | |
| 1880 for (i = 0; i < size; i++) { | |
| 1881 PyObject *o = PyList_GET_ITEM(item, i); | |
| 1882 if (PyList_Check(o) || PyTuple_Check(o)) { | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
1883 if (!_flatten1(context, o, depth + 1)) |
| 12953 | 1884 return 0; |
| 1885 } else if (o != Py_None) { | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1886 if (context->size + 1 > context->maxsize && |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1887 !_bump(context, 1)) |
| 12953 | 1888 return 0; |
| 1889 Py_INCREF(o); | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1890 PyTuple_SET_ITEM(context->tuple, |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1891 context->size++, o); |
| 12953 | 1892 } |
| 1893 } | |
| 1894 } else if (PyTuple_Check(item)) { | |
| 1895 /* same, for tuples */ | |
| 1896 size = PyTuple_GET_SIZE(item); | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1897 if (context->size + size > context->maxsize && |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1898 !_bump(context, size)) |
| 12953 | 1899 return 0; |
| 1900 for (i = 0; i < size; i++) { | |
| 1901 PyObject *o = PyTuple_GET_ITEM(item, i); | |
| 1902 if (PyList_Check(o) || PyTuple_Check(o)) { | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
1903 if (!_flatten1(context, o, depth + 1)) |
| 12953 | 1904 return 0; |
| 1905 } else if (o != Py_None) { | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1906 if (context->size + 1 > context->maxsize && |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1907 !_bump(context, 1)) |
| 12953 | 1908 return 0; |
| 1909 Py_INCREF(o); | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1910 PyTuple_SET_ITEM(context->tuple, |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1911 context->size++, o); |
| 12953 | 1912 } |
| 1913 } | |
| 1914 } else { | |
| 1915 PyErr_SetString(PyExc_TypeError, "argument must be sequence"); | |
| 1916 return 0; | |
| 1917 } | |
| 1918 return 1; | |
| 1919 } | |
| 1920 | |
| 1921 static PyObject * | |
| 1922 Tkinter_Flatten(PyObject* self, PyObject* args) | |
| 1923 { | |
| 1924 FlattenContext context; | |
| 1925 PyObject* item; | |
| 1926 | |
| 1927 if (!PyArg_ParseTuple(args, "O:_flatten", &item)) | |
| 1928 return NULL; | |
| 1929 | |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13503
diff
changeset
|
1930 context.maxsize = PySequence_Size(item); |
| 12953 | 1931 if (context.maxsize <= 0) |
| 1932 return PyTuple_New(0); | |
| 1933 | |
| 1934 context.tuple = PyTuple_New(context.maxsize); | |
| 1935 if (!context.tuple) | |
| 1936 return NULL; | |
| 1937 | |
| 1938 context.size = 0; | |
| 1939 | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
1940 if (!_flatten1(&context, item,0)) |
| 12953 | 1941 return NULL; |
| 1942 | |
|
17976
d579a5d8b3fe
Cruft cleanup: Removed the unused last_is_sticky argument from the internal
Tim Peters <tim.peters@gmail.com>
parents:
15356
diff
changeset
|
1943 if (_PyTuple_Resize(&context.tuple, context.size)) |
| 12953 | 1944 return NULL; |
| 1945 | |
| 1946 return context.tuple; | |
| 1947 } | |
| 1948 | |
| 1664 | 1949 static PyObject * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
1950 Tkinter_Create(PyObject *self, PyObject *args) |
| 1664 | 1951 { |
| 4968 | 1952 char *screenName = NULL; |
| 1953 char *baseName = NULL; | |
| 1954 char *className = NULL; | |
| 1955 int interactive = 0; | |
| 1664 | 1956 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1957 baseName = strrchr(Py_GetProgramName(), '/'); |
| 4968 | 1958 if (baseName != NULL) |
| 1959 baseName++; | |
| 1960 else | |
| 1961 baseName = Py_GetProgramName(); | |
| 1962 className = "Tk"; | |
| 1664 | 1963 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1964 if (!PyArg_ParseTuple(args, "|zssi:create", |
| 4968 | 1965 &screenName, &baseName, &className, |
| 1966 &interactive)) | |
| 1967 return NULL; | |
| 1664 | 1968 |
| 4968 | 1969 return (PyObject *) Tkapp_New(screenName, baseName, className, |
| 1970 interactive); | |
| 1664 | 1971 } |
| 1972 | |
| 1973 static PyMethodDef moduleMethods[] = | |
| 1974 { | |
| 12953 | 1975 {"_flatten", Tkinter_Flatten, 1}, |
| 4968 | 1976 {"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
|
1977 #ifdef HAVE_CREATEFILEHANDLER |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1978 {"createfilehandler", Tkapp_CreateFileHandler, 1}, |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1979 {"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
|
1980 #endif |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1981 {"createtimerhandler", Tkapp_CreateTimerHandler, 1}, |
| 4968 | 1982 {"mainloop", Tkapp_MainLoop, 1}, |
| 1983 {"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
|
1984 {"quit", Tkapp_Quit, 1}, |
| 4968 | 1985 {NULL, NULL} |
| 1664 | 1986 }; |
| 1987 | |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
1988 #ifdef WAIT_FOR_STDIN |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
1989 |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
1990 static int stdin_ready = 0; |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
1991 |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
1992 #ifndef MS_WINDOWS |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
1993 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1994 MyFileProc(void *clientData, int mask) |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
1995 { |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
1996 stdin_ready = 1; |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
1997 } |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
1998 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
1999 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2000 static PyThreadState *event_tstate = NULL; |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
2001 |
| 1664 | 2002 static int |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
2003 EventHook(void) |
| 1664 | 2004 { |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2005 #ifndef MS_WINDOWS |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
2006 int tfile; |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2007 #endif |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
2008 #ifdef WITH_THREAD |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2009 PyEval_RestoreThread(event_tstate); |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
2010 #endif |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2011 stdin_ready = 0; |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2012 errorInCmd = 0; |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2013 #ifndef MS_WINDOWS |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
2014 tfile = fileno(stdin); |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2015 Tcl_CreateFileHandler(tfile, TCL_READABLE, MyFileProc, NULL); |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2016 #endif |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2017 while (!errorInCmd && !stdin_ready) { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2018 int result; |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2019 #ifdef MS_WINDOWS |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2020 if (_kbhit()) { |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2021 stdin_ready = 1; |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2022 break; |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2023 } |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2024 #endif |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2025 #if defined(WITH_THREAD) || defined(MS_WINDOWS) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
2026 Py_BEGIN_ALLOW_THREADS |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
2027 PyThread_acquire_lock(tcl_lock, 1); |
|
9327
c91e4d87f694
Looks like I didn't test this interactively. The EventHook() code was
Guido van Rossum <guido@python.org>
parents:
9319
diff
changeset
|
2028 tcl_tstate = event_tstate; |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
2029 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2030 result = Tcl_DoOneEvent(TCL_DONT_WAIT); |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
2031 |
|
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
2032 tcl_tstate = NULL; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
2033 PyThread_release_lock(tcl_lock); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2034 if (result == 0) |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2035 Sleep(20); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2036 Py_END_ALLOW_THREADS |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2037 #else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2038 result = Tcl_DoOneEvent(0); |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2039 #endif |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2040 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2041 if (result < 0) |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2042 break; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2043 } |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2044 #ifndef MS_WINDOWS |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2045 Tcl_DeleteFileHandler(tfile); |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2046 #endif |
| 4968 | 2047 if (errorInCmd) { |
| 2048 errorInCmd = 0; | |
| 2049 PyErr_Restore(excInCmd, valInCmd, trbInCmd); | |
| 2050 excInCmd = valInCmd = trbInCmd = NULL; | |
| 2051 PyErr_Print(); | |
| 2052 } | |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
2053 #ifdef WITH_THREAD |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2054 PyEval_SaveThread(); |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
2055 #endif |
| 4968 | 2056 return 0; |
| 1664 | 2057 } |
| 2058 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2059 #endif |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2060 |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2061 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
2062 EnableEventHook(void) |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2063 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2064 #ifdef WAIT_FOR_STDIN |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2065 if (PyOS_InputHook == NULL) { |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
2066 #ifdef WITH_THREAD |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2067 event_tstate = PyThreadState_Get(); |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
2068 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2069 PyOS_InputHook = EventHook; |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2070 } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2071 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2072 } |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2073 |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2074 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
2075 DisableEventHook(void) |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2076 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2077 #ifdef WAIT_FOR_STDIN |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2078 if (Tk_GetNumMainWindows() == 0 && PyOS_InputHook == EventHook) { |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2079 PyOS_InputHook = NULL; |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2080 } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2081 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2082 } |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2083 |
| 4968 | 2084 |
| 2085 /* all errors will be checked in one fell swoop in init_tkinter() */ | |
| 2086 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2087 ins_long(PyObject *d, char *name, long val) |
| 4968 | 2088 { |
| 2089 PyObject *v = PyInt_FromLong(val); | |
| 2090 if (v) { | |
| 2091 PyDict_SetItemString(d, name, v); | |
| 2092 Py_DECREF(v); | |
| 2093 } | |
| 2094 } | |
| 2095 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2096 ins_string(PyObject *d, char *name, char *val) |
| 4968 | 2097 { |
| 2098 PyObject *v = PyString_FromString(val); | |
| 2099 if (v) { | |
| 2100 PyDict_SetItemString(d, name, v); | |
| 2101 Py_DECREF(v); | |
| 2102 } | |
| 2103 } | |
| 2104 | |
| 2105 | |
|
9588
38023a425e48
Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents:
9488
diff
changeset
|
2106 DL_EXPORT(void) |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
2107 init_tkinter(void) |
| 1664 | 2108 { |
| 4968 | 2109 PyObject *m, *d; |
| 1664 | 2110 |
| 4968 | 2111 Tkapp_Type.ob_type = &PyType_Type; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2112 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2113 #ifdef WITH_THREAD |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
2114 tcl_lock = PyThread_allocate_lock(); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2115 #endif |
|
4091
dc946cab7b9b
Hacks to support being a Windows DLL
Guido van Rossum <guido@python.org>
parents:
4079
diff
changeset
|
2116 |
| 4968 | 2117 m = Py_InitModule("_tkinter", moduleMethods); |
| 1664 | 2118 |
| 4968 | 2119 d = PyModule_GetDict(m); |
| 2120 Tkinter_TclError = Py_BuildValue("s", "TclError"); | |
| 2121 PyDict_SetItemString(d, "TclError", Tkinter_TclError); | |
| 2122 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2123 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
|
2124 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
|
2125 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
|
2126 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
|
2127 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
|
2128 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
|
2129 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
|
2130 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
|
2131 ins_long(d, "DONT_WAIT", TCL_DONT_WAIT); |
| 4968 | 2132 ins_string(d, "TK_VERSION", TK_VERSION); |
| 2133 ins_string(d, "TCL_VERSION", TCL_VERSION); | |
| 1664 | 2134 |
|
6311
13fbd98d81cc
Export names for the types defined by this module: TkappType and TkttType.
Guido van Rossum <guido@python.org>
parents:
6265
diff
changeset
|
2135 PyDict_SetItemString(d, "TkappType", (PyObject *)&Tkapp_Type); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2136 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2137 Tktt_Type.ob_type = &PyType_Type; |
|
6311
13fbd98d81cc
Export names for the types defined by this module: TkappType and TkttType.
Guido van Rossum <guido@python.org>
parents:
6265
diff
changeset
|
2138 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
|
2139 |
|
12063
ca8880cf3674
Add a call to Tcl_FindExecutable(). This was inspired by a patch by
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
2140 /* This helps the dynamic loader; in Unicode aware Tcl versions |
|
ca8880cf3674
Add a call to Tcl_FindExecutable(). This was inspired by a patch by
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
2141 it also helps Tcl find its encodings. */ |
|
ca8880cf3674
Add a call to Tcl_FindExecutable(). This was inspired by a patch by
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
2142 Tcl_FindExecutable(Py_GetProgramName()); |
|
ca8880cf3674
Add a call to Tcl_FindExecutable(). This was inspired by a patch by
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
2143 |
| 4968 | 2144 if (PyErr_Occurred()) |
|
7212
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
2145 return; |
|
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
2146 |
|
8670
07e47370fcb8
Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents:
8639
diff
changeset
|
2147 #if 0 |
|
07e47370fcb8
Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents:
8639
diff
changeset
|
2148 /* This was not a good idea; through <Destroy> bindings, |
|
07e47370fcb8
Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents:
8639
diff
changeset
|
2149 Tcl_Finalize() may invoke Python code but at that point the |
|
07e47370fcb8
Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents:
8639
diff
changeset
|
2150 interpreter and thread state have already been destroyed! */ |
|
7212
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
2151 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
|
2152 #endif |
|
7212
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
2153 |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2154 #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
|
2155 /* |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
2156 ** 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
|
2157 ** 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
|
2158 ** 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
|
2159 */ |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
2160 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
|
2161 |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
2162 Tcl_MacSetEventProc(PyMacConvertEvent); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
2163 #if GENERATINGCFM |
| 4968 | 2164 mac_addlibresources(); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
2165 #endif /* GENERATINGCFM */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
2166 #endif /* macintosh */ |
| 1664 | 2167 } |
| 3120 | 2168 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
2169 |
| 4968 | 2170 |
| 3120 | 2171 #ifdef macintosh |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2172 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2173 /* |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
2174 ** 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
|
2175 */ |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2176 |
| 3120 | 2177 void |
| 2178 panic(char * format, ...) | |
| 2179 { | |
| 4968 | 2180 va_list varg; |
| 3120 | 2181 |
| 4968 | 2182 va_start(varg, format); |
| 3120 | 2183 |
|
8828
8532141cff4c
Undo a silly effect of a global substitution: the macintosh panic()
Guido van Rossum <guido@python.org>
parents:
8670
diff
changeset
|
2184 vfprintf(stderr, format, varg); |
| 4968 | 2185 (void) fflush(stderr); |
| 3120 | 2186 |
| 4968 | 2187 va_end(varg); |
| 3120 | 2188 |
| 4968 | 2189 Py_FatalError("Tcl/Tk panic"); |
| 3120 | 2190 } |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2191 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
2192 /* |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
2193 ** 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
|
2194 */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2195 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
2196 static int |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2197 PyMacConvertEvent(EventRecord *eventPtr) |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2198 { |
|
8185
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
2199 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
|
2200 /* |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2201 ** Sioux eats too many events, so we don't pass it everything. We |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2202 ** always pass update events to Sioux, and we only pass other events if |
|
8185
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
2203 ** 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
|
2204 ** 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
|
2205 ** 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
|
2206 ** 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
|
2207 */ |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
2208 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
|
2209 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
|
2210 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
|
2211 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
|
2212 } |
| 4968 | 2213 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
|
2214 } |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2215 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
2216 #if GENERATINGCFM |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2217 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2218 /* |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2219 ** 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
|
2220 */ |
|
3262
bfb63b45ff0f
Initialize GUSI on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3240
diff
changeset
|
2221 |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2222 #include <Resources.h> |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2223 #include <CodeFragments.h> |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2224 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2225 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
|
2226 static FSSpec library_fss; |
| 3120 | 2227 |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2228 /* |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2229 ** 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
|
2230 ** 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
|
2231 ** 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
|
2232 ** resources. |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2233 */ |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2234 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
|
2235 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
|
2236 { |
|
4139
010344b4a616
Call __initialize(), not __sinit() on Mac dynamic loading entry.
Guido van Rossum <guido@python.org>
parents:
4091
diff
changeset
|
2237 __initialize(); |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2238 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
|
2239 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
|
2240 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
|
2241 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
|
2242 } 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
|
2243 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
|
2244 loaded_from_shlib = 1; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2245 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2246 return noErr; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2247 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2248 |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2249 /* |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2250 ** 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
|
2251 ** 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
|
2252 */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
2253 static |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
2254 mac_addlibresources(void) |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2255 { |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2256 if ( !loaded_from_shlib ) |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2257 return; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2258 (void)FSpOpenResFile(&library_fss, fsRdPerm); |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2259 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
2260 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
2261 #endif /* GENERATINGCFM */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
2262 #endif /* macintosh */ |
