annotate Modules/_tkinter.c @ 18830:fdb388f2df4e legacy-trunk

Don't "import *" from stat at all -- just import what's needed, and do it back in copy_file() (not at module level).
author Greg Ward <gward@python.net>
date Wed, 25 Jul 2001 19:48:03 +0000
parents 05cf6b3e63de
children d915a0edb2ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3703
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
1 /***********************************************************
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
2 Copyright (C) 1994 Steen Lumholt.
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
3
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
4 All Rights Reserved
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
5
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
6 ******************************************************************/
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
7
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
8 /* _tkinter.c -- Interface to libtk.a and libtcl.a. */
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
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
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
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
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 #include <tcl.h>
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 #include <tk.h>
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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 #if defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__)
929b7e6e7520 On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents: 8096
diff changeset
187 #pragma import on
929b7e6e7520 On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents: 8096
diff changeset
188 #endif
929b7e6e7520 On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents: 8096
diff changeset
189
929b7e6e7520 On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents: 8096
diff changeset
190 #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
191 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
192
929b7e6e7520 On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents: 8096
diff changeset
193 #if defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__)
929b7e6e7520 On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents: 8096
diff changeset
194 #pragma import reset
929b7e6e7520 On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents: 8096
diff changeset
195 #endif
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
196 #endif /* macintosh */
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
197
3973
3d1e4b76f745 Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents: 3899
diff changeset
198 #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
199 #define FREECAST (char *)
3973
3d1e4b76f745 Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents: 3899
diff changeset
200 #endif
3d1e4b76f745 Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents: 3899
diff changeset
201
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 /**** Tkapp Object Declaration ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
203
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 staticforward PyTypeObject Tkapp_Type;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
205
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
206 typedef struct {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
207 PyObject_HEAD
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
208 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
209 } TkappObject;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
210
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 #define Tkapp_Check(v) ((v)->ob_type == &Tkapp_Type)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 #define Tkapp_Interp(v) (((TkappObject *) (v))->interp)
15177
52d2d36b8bf7 Fix for Bug #116453.
Guido van Rossum <guido@python.org>
parents: 15053
diff changeset
213 #define Tkapp_Result(v) Tcl_GetStringResult(Tkapp_Interp(v))
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
214
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
215 #define DEBUG_REFCNT(v) (printf("DEBUG: id=%p, refcnt=%i\n", \
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
216 (void *) v, ((PyObject *) v)->ob_refcnt))
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
217
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
218
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
219
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 /**** Error Handling ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
221
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 static PyObject *Tkinter_TclError;
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
223 static int quitMainLoop = 0;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 static int errorInCmd = 0;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 static PyObject *excInCmd;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 static PyObject *valInCmd;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 2009
diff changeset
227 static PyObject *trbInCmd;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
228
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
229
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
230
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
232 Tkinter_Error(PyObject *v)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
234 PyErr_SetString(Tkinter_TclError, Tkapp_Result(v));
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
235 return NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
237
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
238
8444
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 /**** Utils ****/
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
241
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
242 #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
243 #ifndef MS_WINDOWS
8987
3e127bca84e7 Need mytime.h for Sleep().
Guido van Rossum <guido@python.org>
parents: 8828
diff changeset
244
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
245 /* 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
246
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
247 static void
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
248 Sleep(int milli)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
250 /* 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
251 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
252 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
253 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
254 select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 }
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
256 #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
257 #endif /* WITH_THREAD */
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
258
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
259
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 static char *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
261 AsString(PyObject *value, PyObject *tmp)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
263 if (PyString_Check(value))
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
264 return PyString_AsString(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
265 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
266 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
267 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
268 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
269 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
270 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
271 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
272 }
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 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
274 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
275 }
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
276 else {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
277 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
278 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
279 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
280 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
281 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
282 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
283 }
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
284 Py_DECREF(v);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
285 return PyString_AsString(v);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
286 }
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
288
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
289
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
290
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 #define ARGSZ 64
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
292
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 static char *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
294 Merge(PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
296 PyObject *tmp = NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
297 char *argvStore[ARGSZ];
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
298 char **argv = NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
299 int fvStore[ARGSZ];
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
300 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
301 int argc = 0, fvc = 0, i;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
302 char *res = NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
303
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
304 if (!(tmp = PyList_New(0)))
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
305 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
306
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
307 argv = argvStore;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
308 fv = fvStore;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
309
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
310 if (args == NULL)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
311 argc = 0;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
312
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
313 else if (!PyTuple_Check(args)) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
314 argc = 1;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
315 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
316 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
317 goto finally;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
318 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
319 else {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
320 argc = PyTuple_Size(args);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
321
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
322 if (argc > ARGSZ) {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
323 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
324 fv = (int *)ckalloc(argc * sizeof(int));
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
325 if (argv == NULL || fv == NULL) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
326 PyErr_NoMemory();
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
327 goto finally;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
328 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
329 }
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
330
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
331 for (i = 0; i < argc; i++) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
332 PyObject *v = PyTuple_GetItem(args, i);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
333 if (PyTuple_Check(v)) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
334 fv[i] = 1;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
335 if (!(argv[i] = Merge(v)))
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
336 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
337 fvc++;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
338 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
339 else if (v == Py_None) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
340 argc = i;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
341 break;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
342 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
343 else {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
344 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
345 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
346 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
347 fvc++;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
348 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
349 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
350 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
351 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
352 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
353 PyErr_SetString(Tkinter_TclError, "merge failed");
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
354
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
355 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
356 for (i = 0; i < fvc; i++)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
357 if (fv[i]) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
358 ckfree(argv[i]);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
359 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
360 if (argv != argvStore)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
361 ckfree(FREECAST argv);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
362 if (fv != fvStore)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
363 ckfree(FREECAST fv);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
364
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
365 Py_DECREF(tmp);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
366 return res;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
367 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
368
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
369
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
370
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
371 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
372 Split(char *list)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
373 {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
374 int argc;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
375 char **argv;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
376 PyObject *v;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
377
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
378 if (list == NULL) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
379 Py_INCREF(Py_None);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
380 return Py_None;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
382
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
383 if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
384 /* Not a list.
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
385 * Could be a quoted string containing funnies, e.g. {"}.
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
386 * Return the string itself.
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
387 */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
388 return PyString_FromString(list);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
390
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
391 if (argc == 0)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
392 v = PyString_FromString("");
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
393 else if (argc == 1)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
394 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
395 else if ((v = PyTuple_New(argc)) != NULL) {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
396 int i;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
397 PyObject *w;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
398
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
399 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
400 if ((w = Split(argv[i])) == NULL) {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
401 Py_DECREF(v);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
402 v = NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
403 break;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
404 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
405 PyTuple_SetItem(v, i, w);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
406 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
407 }
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
408 Tcl_Free(FREECAST argv);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
409 return v;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
410 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
411
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
412
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
413
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
414 /**** Tkapp Object ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
415
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
416 #ifndef WITH_APPINIT
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 int
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
418 Tcl_AppInit(Tcl_Interp *interp)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
419 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
420 Tk_Window main;
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
421
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
422 main = Tk_MainWindow(interp);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
423 if (Tcl_Init(interp) == TCL_ERROR) {
15177
52d2d36b8bf7 Fix for Bug #116453.
Guido van Rossum <guido@python.org>
parents: 15053
diff changeset
424 PySys_WriteStderr("Tcl_Init error: %s\n", Tcl_GetStringResult(interp));
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
425 return TCL_ERROR;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
426 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
427 if (Tk_Init(interp) == TCL_ERROR) {
15177
52d2d36b8bf7 Fix for Bug #116453.
Guido van Rossum <guido@python.org>
parents: 15053
diff changeset
428 PySys_WriteStderr("Tk_Init error: %s\n", Tcl_GetStringResult(interp));
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
429 return TCL_ERROR;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
430 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
431 return TCL_OK;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 }
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
433 #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
434
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
435
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
436
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
437
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 /* Initialize the Tk application; see the `main' function in
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
439 * `tkMain.c'.
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
440 */
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
441
13690
c09c0171474f ANSIfy some more forward declarations.
Thomas Wouters <thomas@python.org>
parents: 13651
diff changeset
442 static void EnableEventHook(void); /* Forward */
c09c0171474f ANSIfy some more forward declarations.
Thomas Wouters <thomas@python.org>
parents: 13651
diff changeset
443 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
444
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
445 static TkappObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
446 Tkapp_New(char *screenName, char *baseName, char *className, int interactive)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
447 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
448 TkappObject *v;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
449 char *argv0;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
450
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12513
diff changeset
451 v = PyObject_New(TkappObject, &Tkapp_Type);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
452 if (v == NULL)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
453 return NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
454
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
455 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
456
12071
9750af5e71b0 Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents: 12063
diff changeset
457 #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
458 /* 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
459 ClearMenuBar();
929b7e6e7520 On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents: 8096
diff changeset
460 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
461 #endif
7416
13f29b62a209 Delete the 'exit' command from the Tcl interpreter -- it would allow
Guido van Rossum <guido@python.org>
parents: 7212
diff changeset
462 /* 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
463 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
464
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
465 if (screenName != NULL)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
466 Tcl_SetVar2(v->interp, "env", "DISPLAY",
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
467 screenName, TCL_GLOBAL_ONLY);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
468
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
469 if (interactive)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
470 Tcl_SetVar(v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
471 else
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
472 Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
473
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
474 /* This is used to get the application class for Tk 4.1 and up */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
475 argv0 = (char*)ckalloc(strlen(className) + 1);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
476 if (!argv0) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
477 PyErr_NoMemory();
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
478 Py_DECREF(v);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
479 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
480 }
3973
3d1e4b76f745 Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents: 3899
diff changeset
481
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
482 strcpy(argv0, className);
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 7416
diff changeset
483 if (isupper((int)(argv0[0])))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
484 argv0[0] = tolower(argv0[0]);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
485 Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
486 ckfree(argv0);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
487
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
488 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
489 return (TkappObject *)Tkinter_Error((PyObject *)v);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
490
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
491 EnableEventHook();
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
492
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
493 return v;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
494 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
495
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
496
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
497
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
498 /** Tcl Eval **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
499
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
500 #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
501 #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
502 #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
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 #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
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 static Tcl_Obj*
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
507 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
508 {
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 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
510
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 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
512 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
513 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
514 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
515 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
516 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
517 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
518 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
519 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
520 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
521 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
522 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
523 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
524 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
525 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
526 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
527 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
528 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
529 }
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 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
531 #if TKMAJORMINOR <= 8001
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
532 /* 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
533 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
534 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
535 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
536 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
537 PyString_GET_SIZE(utf8));
12513
ca0e9d97d554 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 12162
diff changeset
538 Py_DECREF(utf8);
ca0e9d97d554 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 12162
diff changeset
539 return result;
12580
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
540 #else /* TKMAJORMINOR > 8001 */
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
541 /* 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
542 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
543 /* 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
544 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
545 "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
546 return 0;
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
547 }
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
548 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
549 PyUnicode_GET_SIZE(value));
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
550 #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
551 }
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 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
553 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
554 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
555 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
556 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
557 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
558 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
559 }
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
560 }
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
561
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
562 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
563 Tkapp_Call(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
564 {
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
565 Tcl_Obj *objStore[ARGSZ];
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
566 Tcl_Obj **objv = NULL;
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
567 int objc = 0, i;
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
568 PyObject *res = NULL;
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
569 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
570 /* 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
571 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
572
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
573 objv = objStore;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
574
8200
482e4ba33c08 Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents: 8199
diff changeset
575 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
576 /* do nothing */;
8200
482e4ba33c08 Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents: 8199
diff changeset
577
482e4ba33c08 Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents: 8199
diff changeset
578 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
579 objv[0] = AsObj(args);
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
580 if (objv[0] == 0)
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
581 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
582 objc = 1;
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
583 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
584 }
482e4ba33c08 Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents: 8199
diff changeset
585 else {
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
586 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
587
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
588 if (objc > ARGSZ) {
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
589 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
590 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
591 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
592 objc = 0;
8200
482e4ba33c08 Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents: 8199
diff changeset
593 goto finally;
482e4ba33c08 Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents: 8199
diff changeset
594 }
482e4ba33c08 Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents: 8199
diff changeset
595 }
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
596
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
597 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
598 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
599 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
600 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
601 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
602 }
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
603 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
604 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
605 /* 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
606 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
607 objc = i;
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
608 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
609 }
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
610 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
611 }
482e4ba33c08 Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents: 8199
diff changeset
612 }
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
613
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
614 ENTER_TCL
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
615
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
616 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
617
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
618 ENTER_OVERLAP
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
619 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
620 Tkinter_Error(self);
12580
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
621 else {
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
622 /* 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
623 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
624 char *s = Tcl_GetStringResult(interp);
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
625 char *p = s;
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
626 /* 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
627 it's UTF-8 and we should decode it to Unicode */
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
628 while (*p != '\0') {
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
629 if (*p & 0x80)
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
630 break;
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
631 p++;
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
632 }
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 }
e0a12095fac2 Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents: 12576
diff changeset
644 }
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
645
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
646 LEAVE_OVERLAP_TCL
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
647
8200
482e4ba33c08 Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents: 8199
diff changeset
648 finally:
12087
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
649 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
650 Tcl_DecrRefCount(objv[i]);
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
651 if (objv != objStore)
e2db89a98cb2 The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents: 12071
diff changeset
652 ckfree(FREECAST objv);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
653 return res;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
654 }
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
655
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
656 #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
657
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
658 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
659 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
660 {
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 /* 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
662 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
663 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
664 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
665 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
666 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
667 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
668 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
669 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
670 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
671
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 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
673 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
674
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 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
676 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
677
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 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
679 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
680
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 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
682 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
683 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
684 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
685 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
686 }
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 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
688 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
689
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 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
691 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
692 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
693 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
694 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
695 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
696 }
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 }
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
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 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
700 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
701 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
702 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
703 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
704 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
705 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
706 }
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 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
708 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
709 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
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 {
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 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
713 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
714 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
715 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
716 }
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
717 }
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
718 }
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
719 /* 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
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 /* 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
722 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
723 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
724 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
725 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
726 }
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 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
728 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
729 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
730 !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
731 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
732 {
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 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
734 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
735 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
736 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
737 }
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 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
739 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
740 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
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 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
743 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
744 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
745 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
746 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
747 PySys_WriteStderr("... error: '%s'\n",
15177
52d2d36b8bf7 Fix for Bug #116453.
Guido van Rossum <guido@python.org>
parents: 15053
diff changeset
748 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
749 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
750 }
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 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
752 if (Py_VerboseFlag >= 2)
15177
52d2d36b8bf7 Fix for Bug #116453.
Guido van Rossum <guido@python.org>
parents: 15053
diff changeset
753 PySys_WriteStderr("-> '%s'\n", Tcl_GetStringResult(interp));
52d2d36b8bf7 Fix for Bug #116453.
Guido van Rossum <guido@python.org>
parents: 15053
diff changeset
754 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
755 }
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 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
757
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
758 /* 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
759 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
760 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
761 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
762 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
763 }
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
764 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
765 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
766 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
767 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
768
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 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
770 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
771 }
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 #endif /* !USING_OBJECTS */
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
774
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
775 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
776 Tkapp_GlobalCall(PyObject *self, PyObject *args)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
777 {
8200
482e4ba33c08 Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents: 8199
diff changeset
778 /* 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
779 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
780 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
781 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
782 scope pointer). */
482e4ba33c08 Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents: 8199
diff changeset
783
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
784 char *cmd;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
785 PyObject *res = NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
786
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
787 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
788 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
789 int err;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
790 ENTER_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
791 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
792 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
793 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
794 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
795 else
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
796 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
797 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
798 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
799 }
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
800
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
801 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
802 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
803
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
804 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
805 Tkapp_Eval(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
806 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
807 char *script;
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
808 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
809 int err;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
810
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
811 if (!PyArg_ParseTuple(args, "s:eval", &script))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
812 return NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
813
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
814 ENTER_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
815 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
816 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
817 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
818 res = Tkinter_Error(self);
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
819 else
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
820 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
821 LEAVE_OVERLAP_TCL
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
822 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
823 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
824
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
825 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
826 Tkapp_GlobalEval(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
827 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
828 char *script;
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
829 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
830 int err;
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
831
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
832 if (!PyArg_ParseTuple(args, "s:globaleval", &script))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
833 return NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
834
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
835 ENTER_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
836 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
837 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
838 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
839 res = Tkinter_Error(self);
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
840 else
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
841 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
842 LEAVE_OVERLAP_TCL
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
843 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
844 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
845
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
846 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
847 Tkapp_EvalFile(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
848 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
849 char *fileName;
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
850 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
851 int err;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
852
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
853 if (!PyArg_ParseTuple(args, "s:evalfile", &fileName))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
854 return NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
855
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
856 ENTER_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
857 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
858 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
859 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
860 res = Tkinter_Error(self);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
861
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
862 else
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
863 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
864 LEAVE_OVERLAP_TCL
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
865 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
866 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
867
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
868 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
869 Tkapp_Record(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
870 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
871 char *script;
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
872 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
873 int err;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
874
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
875 if (!PyArg_ParseTuple(args, "s", &script))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
876 return NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
877
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
878 ENTER_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
879 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
880 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
881 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
882 res = Tkinter_Error(self);
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
883 else
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
884 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
885 LEAVE_OVERLAP_TCL
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
886 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
887 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
888
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
889 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
890 Tkapp_AddErrorInfo(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
891 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
892 char *msg;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
893
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
894 if (!PyArg_ParseTuple(args, "s:adderrorinfo", &msg))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
895 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
896 ENTER_TCL
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
897 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
898 LEAVE_TCL
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
899
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
900 Py_INCREF(Py_None);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
901 return Py_None;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
902 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
903
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
904
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
905
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
906 /** Tcl Variable **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
907
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
908 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
909 SetVar(PyObject *self, PyObject *args, int flags)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
910 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
911 char *name1, *name2, *ok, *s;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
912 PyObject *newValue;
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
913 PyObject *tmp;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
914
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
915 tmp = PyList_New(0);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
916 if (!tmp)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
917 return NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
918
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
919 if (PyArg_ParseTuple(args, "sO:setvar", &name1, &newValue)) {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
920 /* 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
921 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
922 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
923 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
924 ENTER_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
925 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
926 LEAVE_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
927 }
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
928 else {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
929 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
930 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
931 &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
932 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
933 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
934 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
935 ENTER_TCL
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
936 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
937 s, flags);
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
938 LEAVE_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
939 }
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
940 else {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
941 Py_DECREF(tmp);
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
942 return NULL;
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
943 }
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
944 }
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
945 Py_DECREF(tmp);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
946
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
947 if (!ok)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
948 return Tkinter_Error(self);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
949
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
950 Py_INCREF(Py_None);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
951 return Py_None;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
952 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
953
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
954 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
955 Tkapp_SetVar(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
956 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
957 return SetVar(self, args, TCL_LEAVE_ERR_MSG);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
958 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
959
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
960 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
961 Tkapp_GlobalSetVar(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
962 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
963 return SetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
964 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
965
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
966
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
967
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
968 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
969 GetVar(PyObject *self, PyObject *args, int flags)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
970 {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
971 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
972 PyObject *res = NULL;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
973
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
974 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
975 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
976 ENTER_TCL
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
977 if (name2 == NULL)
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
978 s = Tcl_GetVar(Tkapp_Interp(self), name1, flags);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
979
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
980 else
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
981 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
982 ENTER_OVERLAP
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
983
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
984 if (s == NULL)
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
985 res = Tkinter_Error(self);
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
986 else
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
987 res = PyString_FromString(s);
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
988 LEAVE_OVERLAP_TCL
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
989 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
990 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
991
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
992 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
993 Tkapp_GetVar(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
994 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
995 return GetVar(self, args, TCL_LEAVE_ERR_MSG);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
996 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
997
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
998 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
999 Tkapp_GlobalGetVar(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1000 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1001 return GetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1002 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1003
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1004
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1005
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1006 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1007 UnsetVar(PyObject *self, PyObject *args, int flags)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1008 {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1009 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
1010 PyObject *res = NULL;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1011 int code;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1012
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1013 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
1014 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
1015 ENTER_TCL
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1016 if (name2 == NULL)
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1017 code = Tcl_UnsetVar(Tkapp_Interp(self), name1, flags);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1018
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1019 else
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1020 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
1021 ENTER_OVERLAP
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1022
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1023 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
1024 res = Tkinter_Error(self);
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1025 else {
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1026 Py_INCREF(Py_None);
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1027 res = Py_None;
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1028 }
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1029 LEAVE_OVERLAP_TCL
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1030 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1031 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1032
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1033 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1034 Tkapp_UnsetVar(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1035 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1036 return UnsetVar(self, args, TCL_LEAVE_ERR_MSG);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1037 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1038
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1039 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1040 Tkapp_GlobalUnsetVar(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1041 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1042 return UnsetVar(self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1043 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1044
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1045
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1046
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1047 /** Tcl to Python **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1048
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1049 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1050 Tkapp_GetInt(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1051 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1052 char *s;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1053 int v;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1054
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1055 if (!PyArg_ParseTuple(args, "s:getint", &s))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1056 return NULL;
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1057 if (Tcl_GetInt(Tkapp_Interp(self), s, &v) == TCL_ERROR)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1058 return Tkinter_Error(self);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1059 return Py_BuildValue("i", v);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1060 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1061
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1062 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1063 Tkapp_GetDouble(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1064 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1065 char *s;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1066 double v;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1067
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1068 if (!PyArg_ParseTuple(args, "s:getdouble", &s))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1069 return NULL;
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1070 if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1071 return Tkinter_Error(self);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1072 return Py_BuildValue("d", v);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1073 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1074
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1075 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1076 Tkapp_GetBoolean(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1077 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1078 char *s;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1079 int v;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1080
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1081 if (!PyArg_ParseTuple(args, "s:getboolean", &s))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1082 return NULL;
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1083 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
1084 return Tkinter_Error(self);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1085 return Py_BuildValue("i", v);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1086 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1087
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1088 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1089 Tkapp_ExprString(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1090 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1091 char *s;
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1092 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
1093 int retval;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1094
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1095 if (!PyArg_ParseTuple(args, "s:exprstring", &s))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1096 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
1097 ENTER_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1098 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
1099 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
1100 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
1101 res = Tkinter_Error(self);
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1102 else
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1103 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
1104 LEAVE_OVERLAP_TCL
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1105 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1106 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1107
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1108 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1109 Tkapp_ExprLong(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1110 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1111 char *s;
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1112 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
1113 int retval;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1114 long v;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1115
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1116 if (!PyArg_ParseTuple(args, "s:exprlong", &s))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1117 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
1118 ENTER_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1119 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
1120 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
1121 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
1122 res = Tkinter_Error(self);
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1123 else
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1124 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
1125 LEAVE_OVERLAP_TCL
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1126 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1127 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1128
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1129 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1130 Tkapp_ExprDouble(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1131 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1132 char *s;
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1133 PyObject *res = NULL;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1134 double v;
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4968
diff changeset
1135 int retval;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1136
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1137 if (!PyArg_ParseTuple(args, "s:exprdouble", &s))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1138 return NULL;
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4968
diff changeset
1139 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
1140 ENTER_TCL
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1141 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
1142 ENTER_OVERLAP
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5120
diff changeset
1143 PyFPE_END_PROTECT(retval)
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 4968
diff changeset
1144 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
1145 res = Tkinter_Error(self);
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1146 else
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1147 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
1148 LEAVE_OVERLAP_TCL
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1149 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1150 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1151
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1152 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1153 Tkapp_ExprBoolean(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1154 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1155 char *s;
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1156 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
1157 int retval;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1158 int v;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1159
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1160 if (!PyArg_ParseTuple(args, "s:exprboolean", &s))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1161 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
1162 ENTER_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1163 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
1164 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
1165 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
1166 res = Tkinter_Error(self);
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1167 else
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1168 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
1169 LEAVE_OVERLAP_TCL
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1170 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1171 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1172
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1173
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1174
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1175 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1176 Tkapp_SplitList(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1177 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1178 char *list;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1179 int argc;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1180 char **argv;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1181 PyObject *v;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1182 int i;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1183
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1184 if (!PyArg_ParseTuple(args, "s:splitlist", &list))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1185 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1186
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1187 if (Tcl_SplitList(Tkapp_Interp(self), list, &argc, &argv) == TCL_ERROR)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1188 return Tkinter_Error(self);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1189
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1190 if (!(v = PyTuple_New(argc)))
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1191 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1192
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1193 for (i = 0; i < argc; i++) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1194 PyObject *s = PyString_FromString(argv[i]);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1195 if (!s || PyTuple_SetItem(v, i, s)) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1196 Py_DECREF(v);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1197 v = NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1198 goto finally;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1199 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1200 }
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1201
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1202 finally:
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1203 ckfree(FREECAST argv);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1204 return v;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1205 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1206
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1207 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1208 Tkapp_Split(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1209 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1210 char *list;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1211
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1212 if (!PyArg_ParseTuple(args, "s:split", &list))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1213 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
1214 return Split(list);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1215 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1216
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1217 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1218 Tkapp_Merge(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1219 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1220 char *s = Merge(args);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1221 PyObject *res = NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1222
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1223 if (s) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1224 res = PyString_FromString(s);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1225 ckfree(s);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1226 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1227
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1228 return res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1229 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1230
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1231
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1232
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1233 /** Tcl Command **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1234
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1235 /* 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
1236 typedef struct {
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1237 PyObject *self;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1238 PyObject *func;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1239 } PythonCmd_ClientData;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1240
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1241 static int
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1242 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
1243 {
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1244 errorInCmd = 1;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1245 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
1246 LEAVE_PYTHON
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1247 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
1248 }
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1249
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1250 /* This is the Tcl command that acts as a wrapper for Python
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1251 * function or method.
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1252 */
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1253 static int
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1254 PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1255 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1256 PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1257 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
1258 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
1259 char *s;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1260
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
1261 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
1262
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1263 /* TBD: no error checking here since we know, via the
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1264 * Tkapp_CreateCommand() that the client data is a two-tuple
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1265 */
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1266 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
1267 func = data->func;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1268
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1269 /* Create argument list (argv1, ..., argvN) */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1270 if (!(arg = PyTuple_New(argc - 1)))
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1271 return PythonCmd_Error(interp);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1272
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1273 for (i = 0; i < (argc - 1); i++) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1274 PyObject *s = PyString_FromString(argv[i + 1]);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1275 if (!s || PyTuple_SetItem(arg, i, s)) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1276 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
1277 return PythonCmd_Error(interp);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1278 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1279 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1280 res = PyEval_CallObject(func, arg);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1281 Py_DECREF(arg);
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1282
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1283 if (res == NULL)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1284 return PythonCmd_Error(interp);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1285
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1286 if (!(tmp = PyList_New(0))) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1287 Py_DECREF(res);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1288 return PythonCmd_Error(interp);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1289 }
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1290
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
1291 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
1292 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
1293 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
1294 }
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 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
1296 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
1297 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
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
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1300 Py_DECREF(res);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1301 Py_DECREF(tmp);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1302
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1303 LEAVE_PYTHON
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1304
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
1305 return rv;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1306 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1307
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1308 static void
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1309 PythonCmdDelete(ClientData clientData)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1310 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1311 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
1312
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
1313 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
1314 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
1315 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
1316 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
1317 LEAVE_PYTHON
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1318 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1319
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1320
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1321
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1322 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1323 Tkapp_CreateCommand(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1324 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1325 PythonCmd_ClientData *data;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1326 char *cmdName;
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1327 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
1328 Tcl_Command err;
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1329
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1330 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
1331 return NULL;
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1332 if (!PyCallable_Check(func)) {
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1333 PyErr_SetString(PyExc_TypeError, "command not callable");
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1334 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1335 }
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1336
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1337 data = PyMem_NEW(PythonCmd_ClientData, 1);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1338 if (!data)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1339 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
1340 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
1341 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
1342 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
1343 data->func = func;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1344
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1345 ENTER_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1346 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
1347 (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
1348 LEAVE_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1349 if (err == NULL) {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1350 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
1351 PyMem_DEL(data);
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1352 return NULL;
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1353 }
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1354
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1355 Py_INCREF(Py_None);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1356 return Py_None;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1357 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1358
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1359
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1360
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1361 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1362 Tkapp_DeleteCommand(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1363 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1364 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
1365 int err;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1366
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1367 if (!PyArg_ParseTuple(args, "s:deletecommand", &cmdName))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1368 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
1369 ENTER_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1370 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
1371 LEAVE_TCL
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1372 if (err == -1) {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1373 PyErr_SetString(Tkinter_TclError, "can't delete Tcl command");
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1374 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1375 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1376 Py_INCREF(Py_None);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1377 return Py_None;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1378 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1379
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1380
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1381
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1382 #ifdef HAVE_CREATEFILEHANDLER
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1383 /** File Handler **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1384
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1385 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
1386 PyObject *func;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1387 PyObject *file;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1388 int id;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1389 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
1390 } FileHandler_ClientData;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1391
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1392 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
1393
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1394 static FileHandler_ClientData *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1395 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
1396 {
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1397 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
1398 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
1399 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
1400 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
1401 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
1402 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
1403 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
1404 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
1405 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
1406 HeadFHCD = p;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1407 }
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1408 return p;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1409 }
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1410
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1411 static void
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1412 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
1413 {
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1414 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
1415
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1416 pp = &HeadFHCD;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1417 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
1418 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
1419 *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
1420 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
1421 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
1422 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
1423 }
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1424 else
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1425 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
1426 }
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
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
1429 static void
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1430 FileHandler(ClientData clientData, int mask)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1431 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1432 FileHandler_ClientData *data = (FileHandler_ClientData *)clientData;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1433 PyObject *func, *file, *arg, *res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1434
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
1435 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
1436 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
1437 file = data->file;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1438
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1439 arg = Py_BuildValue("(Oi)", file, (long) mask);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1440 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
1441 Py_DECREF(arg);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1442
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1443 if (res == NULL) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1444 errorInCmd = 1;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1445 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1446 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1447 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
1448 LEAVE_PYTHON
1771
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
1449 }
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
1450
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1451 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1452 Tkapp_CreateFileHandler(PyObject *self, PyObject *args)
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1453 /* args is (file, mask, func) */
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1454 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1455 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
1456 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
1457 int mask, tfile;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1458
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
1459 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
1460 &file, &mask, &func))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1461 return NULL;
13593
df64cc0e84e2 Use PyObject_AsFileDescriptor
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
1462 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
1463 if (tfile < 0)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1464 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1465 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
1466 PyErr_SetString(PyExc_TypeError, "bad argument list");
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1467 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1468 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1469
12071
9750af5e71b0 Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents: 12063
diff changeset
1470 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
1471 if (data == NULL)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1472 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1473
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1474 /* 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
1475 ENTER_TCL
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1476 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
1477 LEAVE_TCL
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1478 Py_INCREF(Py_None);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1479 return Py_None;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1480 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1481
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1482 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1483 Tkapp_DeleteFileHandler(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1484 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1485 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
1486 int tfile;
3554
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
1487
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1488 if (!PyArg_ParseTuple(args, "O:deletefilehandler", &file))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1489 return NULL;
13593
df64cc0e84e2 Use PyObject_AsFileDescriptor
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
1490 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
1491 if (tfile < 0)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1492 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1493
12071
9750af5e71b0 Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents: 12063
diff changeset
1494 DeleteFHCD(tfile);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1495
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1496 /* 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
1497 ENTER_TCL
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1498 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
1499 LEAVE_TCL
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1500 Py_INCREF(Py_None);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1501 return Py_None;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1502 }
6026
b5804154af4d Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents: 5973
diff changeset
1503 #endif /* HAVE_CREATEFILEHANDLER */
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1504
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1505
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1506 /**** 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
1507
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1508 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
1509
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1510 typedef struct {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1511 PyObject_HEAD
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1512 Tcl_TimerToken token;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1513 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
1514 } TkttObject;
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1515
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1516 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1517 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
1518 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1519 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
1520 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
1521
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1522 if (!PyArg_ParseTuple(args, ":deletetimerhandler"))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1523 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
1524 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
1525 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
1526 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
1527 }
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1528 if (func != NULL) {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1529 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
1530 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
1531 Py_DECREF(v); /* See Tktt_New() */
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1532 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1533 Py_INCREF(Py_None);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1534 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
1535 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1536
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1537 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
1538 {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1539 {"deletetimerhandler", Tktt_DeleteTimerHandler, 1},
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1540 {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
1541 };
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1542
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1543 static TkttObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1544 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
1545 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1546 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
1547
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12513
diff changeset
1548 v = PyObject_New(TkttObject, &Tktt_Type);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1549 if (v == NULL)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1550 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
1551
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1552 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
1553 v->token = NULL;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1554 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
1555
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1556 /* 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
1557 Py_INCREF(v);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1558 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
1559 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1560
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1561 static void
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1562 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
1563 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1564 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
1565 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
1566
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1567 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
1568
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12513
diff changeset
1569 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
1570 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1571
8312
d67be13da3cc Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents: 8200
diff changeset
1572 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1573 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
1574 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1575 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
1576 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
1577
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12958
diff changeset
1578 sprintf(buf, "<tktimertoken at %p%s>", v,
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1579 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
1580 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
1581 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1582
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1583 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1584 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
1585 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1586 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
1587 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1588
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1589 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
1590 {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1591 PyObject_HEAD_INIT(NULL)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1592 0, /*ob_size */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1593 "tktimertoken", /*tp_name */
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1594 sizeof(TkttObject), /*tp_basicsize */
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1595 0, /*tp_itemsize */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1596 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
1597 0, /*tp_print */
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1598 Tktt_GetAttr, /*tp_getattr */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1599 0, /*tp_setattr */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1600 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
1601 Tktt_Repr, /*tp_repr */
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1602 0, /*tp_as_number */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1603 0, /*tp_as_sequence */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1604 0, /*tp_as_mapping */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1605 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
1606 };
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1607
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1608
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1609
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1610 /** Timer Handler **/
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1611
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1612 static void
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1613 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
1614 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1615 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
1616 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
1617 PyObject *res;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1618
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1619 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
1620 return;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1621
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1622 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
1623
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
1624 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
1625
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1626 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
1627 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
1628 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
1629
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1630 if (res == NULL) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1631 errorInCmd = 1;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1632 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1633 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1634 else
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1635 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
1636
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1637 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
1638 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1639
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1640 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1641 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
1642 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1643 int milliseconds;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1644 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
1645 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
1646
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
1647 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
1648 &milliseconds, &func))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1649 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1650 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
1651 PyErr_SetString(PyExc_TypeError, "bad argument list");
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1652 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1653 }
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1654 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
1655 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
1656 (ClientData)v);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
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 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
1659 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1660
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1661
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1662 /** Event Loop **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1663
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1664 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1665 Tkapp_MainLoop(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1666 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1667 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
1668 #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
1669 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
1670 #endif
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1671
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1672 if (!PyArg_ParseTuple(args, "|i:mainloop", &threshold))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1673 return NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1674
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1675 quitMainLoop = 0;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1676 while (Tk_GetNumMainWindows() > threshold &&
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1677 !quitMainLoop &&
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1678 !errorInCmd)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1679 {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1680 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
1681
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1682 #ifdef WITH_THREAD
8500
92cf7f427723 # (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents: 8499
diff changeset
1683 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
1684 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
1685 tcl_tstate = tstate;
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1686 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
1687 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
1688 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
1689 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
1690 Sleep(20);
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1691 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
1692 #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
1693 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
1694 #endif
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1695
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1696 if (PyErr_CheckSignals() != 0)
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1697 return NULL;
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1698 if (result < 0)
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1699 break;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1700 }
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1701 quitMainLoop = 0;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1702
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1703 if (errorInCmd) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1704 errorInCmd = 0;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1705 PyErr_Restore(excInCmd, valInCmd, trbInCmd);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1706 excInCmd = valInCmd = trbInCmd = NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1707 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1708 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1709 Py_INCREF(Py_None);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1710 return Py_None;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1711 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1712
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1713 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1714 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
1715 {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1716 int flags = 0;
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1717 int rv;
2121
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1718
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1719 if (!PyArg_ParseTuple(args, "|i:dooneevent", &flags))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1720 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1721
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1722 ENTER_TCL
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1723 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
1724 LEAVE_TCL
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1725 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
1726 }
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1727
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1728 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1729 Tkapp_Quit(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1730 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1731
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1732 if (!PyArg_ParseTuple(args, ":quit"))
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1733 return NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1734
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1735 quitMainLoop = 1;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1736 Py_INCREF(Py_None);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1737 return Py_None;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1738 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1739
8199
c31c59f192af Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents: 8185
diff changeset
1740 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1741 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
1742 {
c31c59f192af Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents: 8185
diff changeset
1743
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1744 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
1745 return NULL;
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 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
1748 }
c31c59f192af Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents: 8185
diff changeset
1749
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1750
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1751
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1752 /**** Tkapp Method List ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1753
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1754 static PyMethodDef Tkapp_methods[] =
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1755 {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1756 {"call", Tkapp_Call, 0},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1757 {"globalcall", Tkapp_GlobalCall, 0},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1758 {"eval", Tkapp_Eval, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1759 {"globaleval", Tkapp_GlobalEval, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1760 {"evalfile", Tkapp_EvalFile, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1761 {"record", Tkapp_Record, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1762 {"adderrorinfo", Tkapp_AddErrorInfo, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1763 {"setvar", Tkapp_SetVar, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1764 {"globalsetvar", Tkapp_GlobalSetVar, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1765 {"getvar", Tkapp_GetVar, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1766 {"globalgetvar", Tkapp_GlobalGetVar, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1767 {"unsetvar", Tkapp_UnsetVar, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1768 {"globalunsetvar", Tkapp_GlobalUnsetVar, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1769 {"getint", Tkapp_GetInt, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1770 {"getdouble", Tkapp_GetDouble, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1771 {"getboolean", Tkapp_GetBoolean, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1772 {"exprstring", Tkapp_ExprString, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1773 {"exprlong", Tkapp_ExprLong, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1774 {"exprdouble", Tkapp_ExprDouble, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1775 {"exprboolean", Tkapp_ExprBoolean, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1776 {"splitlist", Tkapp_SplitList, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1777 {"split", Tkapp_Split, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1778 {"merge", Tkapp_Merge, 0},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1779 {"createcommand", Tkapp_CreateCommand, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1780 {"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
1781 #ifdef HAVE_CREATEFILEHANDLER
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1782 {"createfilehandler", Tkapp_CreateFileHandler, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1783 {"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
1784 #endif
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1785 {"createtimerhandler", Tkapp_CreateTimerHandler, 1},
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1786 {"mainloop", Tkapp_MainLoop, 1},
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1787 {"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
1788 {"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
1789 {"interpaddr", Tkapp_InterpAddr, 1},
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1790 {NULL, NULL}
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1791 };
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1792
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1793
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1794
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1795 /**** Tkapp Type Methods ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1796
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1797 static void
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1798 Tkapp_Dealloc(PyObject *self)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1799 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1800 ENTER_TCL
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1801 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
1802 LEAVE_TCL
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12513
diff changeset
1803 PyObject_Del(self);
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
1804 DisableEventHook();
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1805 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1806
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1807 static PyObject *
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1808 Tkapp_GetAttr(PyObject *self, char *name)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1809 {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1810 return Py_FindMethod(Tkapp_methods, self, name);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1811 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1812
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1813 static PyTypeObject Tkapp_Type =
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1814 {
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1815 PyObject_HEAD_INIT(NULL)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1816 0, /*ob_size */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1817 "tkapp", /*tp_name */
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1818 sizeof(TkappObject), /*tp_basicsize */
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1819 0, /*tp_itemsize */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1820 Tkapp_Dealloc, /*tp_dealloc */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1821 0, /*tp_print */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1822 Tkapp_GetAttr, /*tp_getattr */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1823 0, /*tp_setattr */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1824 0, /*tp_compare */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1825 0, /*tp_repr */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1826 0, /*tp_as_number */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1827 0, /*tp_as_sequence */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1828 0, /*tp_as_mapping */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1829 0, /*tp_hash */
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1830 };
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1831
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1832
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1833
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1834 /**** Tkinter Module ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1835
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1836 typedef struct {
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1837 PyObject* tuple;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1838 int size; /* current size */
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1839 int maxsize; /* allocated size */
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1840 } FlattenContext;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1841
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1842 static int
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1843 _bump(FlattenContext* context, int size)
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1844 {
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
1845 /* 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
1846 return true if successful, false if an exception was raised */
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1847
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1848 int maxsize = context->maxsize * 2;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1849
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1850 if (maxsize < context->size + size)
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1851 maxsize = context->size + size;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1852
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1853 context->maxsize = maxsize;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1854
17976
d579a5d8b3fe Cruft cleanup: Removed the unused last_is_sticky argument from the internal
Tim Peters <tim.peters@gmail.com>
parents: 15356
diff changeset
1855 return _PyTuple_Resize(&context->tuple, maxsize) >= 0;
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1856 }
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1857
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1858 static int
12958
3c6641c810db Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents: 12953
diff changeset
1859 _flatten1(FlattenContext* context, PyObject* item, int depth)
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1860 {
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1861 /* add tuple or list to argument tuple (recursively) */
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1862
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1863 int i, size;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1864
12958
3c6641c810db Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents: 12953
diff changeset
1865 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
1866 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
1867 "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
1868 return 0;
3c6641c810db Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents: 12953
diff changeset
1869 } else if (PyList_Check(item)) {
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1870 size = PyList_GET_SIZE(item);
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1871 /* 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
1872 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
1873 !_bump(context, size))
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1874 return 0;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1875 /* copy items to output tuple */
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1876 for (i = 0; i < size; i++) {
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1877 PyObject *o = PyList_GET_ITEM(item, i);
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1878 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
1879 if (!_flatten1(context, o, depth + 1))
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1880 return 0;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1881 } 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
1882 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
1883 !_bump(context, 1))
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1884 return 0;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1885 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
1886 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
1887 context->size++, o);
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1888 }
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1889 }
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1890 } else if (PyTuple_Check(item)) {
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1891 /* same, for tuples */
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1892 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
1893 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
1894 !_bump(context, size))
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1895 return 0;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1896 for (i = 0; i < size; i++) {
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1897 PyObject *o = PyTuple_GET_ITEM(item, i);
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1898 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
1899 if (!_flatten1(context, o, depth + 1))
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1900 return 0;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1901 } 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
1902 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
1903 !_bump(context, 1))
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1904 return 0;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1905 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
1906 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
1907 context->size++, o);
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1908 }
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1909 }
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1910 } else {
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1911 PyErr_SetString(PyExc_TypeError, "argument must be sequence");
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1912 return 0;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1913 }
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1914 return 1;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1915 }
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1916
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1917 static PyObject *
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1918 Tkinter_Flatten(PyObject* self, PyObject* args)
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1919 {
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1920 FlattenContext context;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1921 PyObject* item;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1922
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1923 if (!PyArg_ParseTuple(args, "O:_flatten", &item))
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1924 return NULL;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1925
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13503
diff changeset
1926 context.maxsize = PySequence_Size(item);
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1927 if (context.maxsize <= 0)
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1928 return PyTuple_New(0);
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1929
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1930 context.tuple = PyTuple_New(context.maxsize);
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1931 if (!context.tuple)
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1932 return NULL;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1933
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1934 context.size = 0;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1935
12958
3c6641c810db Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents: 12953
diff changeset
1936 if (!_flatten1(&context, item,0))
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1937 return NULL;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1938
17976
d579a5d8b3fe Cruft cleanup: Removed the unused last_is_sticky argument from the internal
Tim Peters <tim.peters@gmail.com>
parents: 15356
diff changeset
1939 if (_PyTuple_Resize(&context.tuple, context.size))
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1940 return NULL;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1941
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1942 return context.tuple;
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1943 }
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1944
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1945 static PyObject *
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13593
diff changeset
1946 Tkinter_Create(PyObject *self, PyObject *args)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1947 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1948 char *screenName = NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1949 char *baseName = NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1950 char *className = NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1951 int interactive = 0;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1952
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1953 baseName = strrchr(Py_GetProgramName(), '/');
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1954 if (baseName != NULL)
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1955 baseName++;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1956 else
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1957 baseName = Py_GetProgramName();
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1958 className = "Tk";
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1959
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11443
diff changeset
1960 if (!PyArg_ParseTuple(args, "|zssi:create",
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1961 &screenName, &baseName, &className,
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1962 &interactive))
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1963 return NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1964
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1965 return (PyObject *) Tkapp_New(screenName, baseName, className,
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1966 interactive);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1967 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1968
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1969 static PyMethodDef moduleMethods[] =
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1970 {
12953
a3e12881cc3c Patch from /F:
Andrew M. Kuchling <amk@amk.ca>
parents: 12583
diff changeset
1971 {"_flatten", Tkinter_Flatten, 1},
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1972 {"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
1973 #ifdef HAVE_CREATEFILEHANDLER
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1974 {"createfilehandler", Tkapp_CreateFileHandler, 1},
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1975 {"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
1976 #endif
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
1977 {"createtimerhandler", Tkapp_CreateTimerHandler, 1},
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1978 {"mainloop", Tkapp_MainLoop, 1},
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1979 {"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
1980 {"quit", Tkapp_Quit, 1},
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
1981 {NULL, NULL}
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1982 };
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1983
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
1984 #ifdef WAIT_FOR_STDIN
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
1985
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
1986 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
1987
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
1988 #ifndef MS_WINDOWS
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
1989 static void
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
1990 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
1991 {
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
1992 stdin_ready = 1;
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
1993 }
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
1994 #endif
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
1995
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
1996 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
1997
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1998 static int
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13593
diff changeset
1999 EventHook(void)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2000 {
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
2001 #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
2002 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
2003 #endif
9488
b0ca2ca586b1 RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents: 9327
diff changeset
2004 #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
2005 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
2006 #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
2007 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
2008 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
2009 #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
2010 tfile = fileno(stdin);
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
2011 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
2012 #endif
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2013 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
2014 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
2015 #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
2016 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
2017 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
2018 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
2019 }
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 #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
2021 #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
2022 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
2023 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
2024 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
2025
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2026 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
2027
8918e4f54eca Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents: 9308
diff changeset
2028 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
2029 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
2030 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
2031 Sleep(20);
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2032 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
2033 #else
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2034 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
2035 #endif
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2036
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2037 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
2038 break;
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2039 }
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
2040 #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
2041 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
2042 #endif
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2043 if (errorInCmd) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2044 errorInCmd = 0;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2045 PyErr_Restore(excInCmd, valInCmd, trbInCmd);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2046 excInCmd = valInCmd = trbInCmd = NULL;
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2047 PyErr_Print();
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2048 }
9488
b0ca2ca586b1 RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents: 9327
diff changeset
2049 #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
2050 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
2051 #endif
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2052 return 0;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2053 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2054
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2055 #endif
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2056
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
2057 static void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13593
diff changeset
2058 EnableEventHook(void)
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
2059 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2060 #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
2061 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
2062 #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
2063 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
2064 #endif
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
2065 PyOS_InputHook = EventHook;
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
2066 }
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2067 #endif
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
2068 }
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
2069
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
2070 static void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13593
diff changeset
2071 DisableEventHook(void)
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
2072 {
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2073 #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
2074 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
2075 PyOS_InputHook = NULL;
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 #endif
8417
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
2078 }
f398419d50f9 Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents: 8315
diff changeset
2079
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2080
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2081 /* all errors will be checked in one fell swoop in init_tkinter() */
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2082 static void
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
2083 ins_long(PyObject *d, char *name, long val)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2084 {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2085 PyObject *v = PyInt_FromLong(val);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2086 if (v) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2087 PyDict_SetItemString(d, name, v);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2088 Py_DECREF(v);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2089 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2090 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2091 static void
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
2092 ins_string(PyObject *d, char *name, char *val)
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2093 {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2094 PyObject *v = PyString_FromString(val);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2095 if (v) {
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2096 PyDict_SetItemString(d, name, v);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2097 Py_DECREF(v);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2098 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2099 }
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2100
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2101
9588
38023a425e48 Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents: 9488
diff changeset
2102 DL_EXPORT(void)
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13593
diff changeset
2103 init_tkinter(void)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2104 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2105 PyObject *m, *d;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2106
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2107 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
2108
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2109 #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
2110 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
2111 #endif
4091
dc946cab7b9b Hacks to support being a Windows DLL
Guido van Rossum <guido@python.org>
parents: 4079
diff changeset
2112
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2113 m = Py_InitModule("_tkinter", moduleMethods);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2114
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2115 d = PyModule_GetDict(m);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2116 Tkinter_TclError = Py_BuildValue("s", "TclError");
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2117 PyDict_SetItemString(d, "TclError", Tkinter_TclError);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2118
5914
5155b2c35e15 Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents: 5913
diff changeset
2119 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
2120 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
2121 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
2122 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
2123 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
2124 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
2125 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
2126 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
2127 ins_long(d, "DONT_WAIT", TCL_DONT_WAIT);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2128 ins_string(d, "TK_VERSION", TK_VERSION);
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2129 ins_string(d, "TCL_VERSION", TCL_VERSION);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2130
6311
13fbd98d81cc Export names for the types defined by this module: TkappType and TkttType.
Guido van Rossum <guido@python.org>
parents: 6265
diff changeset
2131 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
2132
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2133 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
2134 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
2135
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
2136 /* 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
2137 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
2138 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
2139
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2140 if (PyErr_Occurred())
7212
b9bbfa169920 Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents: 6478
diff changeset
2141 return;
b9bbfa169920 Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents: 6478
diff changeset
2142
8670
07e47370fcb8 Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents: 8639
diff changeset
2143 #if 0
07e47370fcb8 Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents: 8639
diff changeset
2144 /* 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
2145 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
2146 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
2147 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
2148 #endif
7212
b9bbfa169920 Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents: 6478
diff changeset
2149
3240
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2150 #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
2151 /*
b5804154af4d Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents: 5973
diff changeset
2152 ** 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
2153 ** 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
2154 ** 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
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 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
2157
b5804154af4d Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents: 5973
diff changeset
2158 Tcl_MacSetEventProc(PyMacConvertEvent);
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
2159 #if GENERATINGCFM
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2160 mac_addlibresources();
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
2161 #endif /* GENERATINGCFM */
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
2162 #endif /* macintosh */
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2163 }
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
2164
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
2165
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2166
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
2167 #ifdef macintosh
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
2168
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
2169 /*
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
2170 ** 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
2171 */
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
2172
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
2173 void
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
2174 panic(char * format, ...)
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
2175 {
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2176 va_list varg;
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
2177
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2178 va_start(varg, format);
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
2179
8828
8532141cff4c Undo a silly effect of a global substitution: the macintosh panic()
Guido van Rossum <guido@python.org>
parents: 8670
diff changeset
2180 vfprintf(stderr, format, varg);
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2181 (void) fflush(stderr);
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
2182
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2183 va_end(varg);
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
2184
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2185 Py_FatalError("Tcl/Tk panic");
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
2186 }
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
2187
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
2188 /*
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
2189 ** 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
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 static int
13421
346df1920873 Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents: 13255
diff changeset
2193 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
2194 {
8185
929b7e6e7520 On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents: 8096
diff changeset
2195 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
2196 /*
8444
6f70ca7c84e6 Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents: 8417
diff changeset
2197 ** 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
2198 ** 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
2199 ** 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
2200 ** 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
2201 ** 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
2202 ** 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
2203 */
929b7e6e7520 On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents: 8096
diff changeset
2204 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
2205 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
2206 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
2207 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
2208 }
4968
3d32da37d627 reformatted
Barry Warsaw <barry@python.org>
parents: 4754
diff changeset
2209 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
2210 }
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
2211
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
2212 #if GENERATINGCFM
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
2213
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 ** 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
2216 */
3262
bfb63b45ff0f Initialize GUSI on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3240
diff changeset
2217
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
2218 #include <Resources.h>
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
2219 #include <CodeFragments.h>
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
2220
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
2221 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
2222 static FSSpec library_fss;
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
2223
3240
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2224 /*
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2225 ** 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
2226 ** 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
2227 ** 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
2228 ** resources.
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2229 */
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2230 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
2231 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
2232 {
4139
010344b4a616 Call __initialize(), not __sinit() on Mac dynamic loading entry.
Guido van Rossum <guido@python.org>
parents: 4091
diff changeset
2233 __initialize();
3240
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2234 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
2235 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
2236 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
2237 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
2238 } 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
2239 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
2240 loaded_from_shlib = 1;
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2241 }
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2242 return noErr;
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2243 }
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2244
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 ** 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
2247 ** 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
2248 */
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
2249 static
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13593
diff changeset
2250 mac_addlibresources(void)
3240
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2251 {
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2252 if ( !loaded_from_shlib )
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2253 return;
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
2254 (void)FSpOpenResFile(&library_fss, fsRdPerm);
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
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
2257 #endif /* GENERATINGCFM */
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
2258 #endif /* macintosh */