annotate Modules/_tkinter.c @ 11518:cc412dfd79f7 legacy-trunk

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