annotate Modules/_tkinter.c @ 9383:2b34461ba4a3 legacy-trunk

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