annotate Modules/_tkinter.c @ 12357:5b59ea41db4e legacy-trunk

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