annotate Modules/_tkinter.c @ 8831:00a6bb65ff29 legacy-trunk

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