annotate Modules/_tkinter.c @ 3930:52c19ee83a6b legacy-trunk

Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
author Jack Jansen <jack.jansen@cwi.nl>
date Fri, 02 Aug 1996 15:16:16 +0000
parents 584936890f86
children 3d1e4b76f745
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
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
8 Permission to use, copy, modify, and distribute this software and its
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
9 documentation for any purpose and without fee is hereby granted,
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
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
11 both that copyright notice and this permission notice appear in
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
12 supporting documentation, and that the names of Stichting Mathematisch
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
13 Centrum or CWI not be used in advertising or publicity pertaining to
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
14 distribution of the software without specific, written prior permission.
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
15
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
16 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
17 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
18 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
19 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
22 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
23
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
24 ******************************************************************/
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
25
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
26 /* _tkinter.c -- Interface to libtk.a and libtcl.a. */
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
28 #include "Python.h"
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
29
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 #include <tcl.h>
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 #include <tk.h>
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
3899
584936890f86 getprogramname --> Py_GetProgramName
Guido van Rossum <guido@python.org>
parents: 3703
diff changeset
33 extern char *Py_GetProgramName ();
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
34
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
35 /* Internal declarations from tkInt.h. */
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
36 #if (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) >= 4001
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
37 extern int Tk_GetNumMainWindows();
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
38 #else
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 extern int tk_NumMainWindows;
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
40 #define Tk_GetNumMainWindows() (tk_NumMainWindows)
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
41 #define NEED_TKCREATEMAINWINDOW 1
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
42 #endif
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
43
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
44 #if TK_MAJOR_VERSION < 4
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
45 extern struct { Tk_Window win; } *tkMainWindowList;
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
46 #endif
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
48 #ifdef macintosh
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
49
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
50 /*
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
51 ** Additional cruft needed by Tcl/Tk on the Mac.
3703
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
52 ** This is for Tcl 7.5 and Tk 4.1 (final releases).
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
53 */
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
54
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
55 #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
56
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
57 typedef int (*TclMacConvertEventPtr) Py_PROTO((EventRecord *eventPtr));
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
58 void TclMacSetEventProc Py_PROTO((TclMacConvertEventPtr procPtr));
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
59 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
60
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
61 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
62
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
63 #endif /* macintosh */
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
64
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 /**** Tkapp Object Declaration ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 staticforward PyTypeObject Tkapp_Type;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
68
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 typedef struct
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 PyObject_HEAD
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 Tcl_Interp *interp;
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
73 #ifdef NEED_TKCREATEMAINWINDOW
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 Tk_Window tkwin;
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
75 #endif
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 TkappObject;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
78
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 #define Tkapp_Check(v) ((v)->ob_type == &Tkapp_Type)
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
80 #ifdef NEED_TKCREATEMAINWINDOW
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 #define Tkapp_Tkwin(v) (((TkappObject *) (v))->tkwin)
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
82 #endif
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 #define Tkapp_Interp(v) (((TkappObject *) (v))->interp)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 #define Tkapp_Result(v) (((TkappObject *) (v))->interp->result)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
85
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 #define DEBUG_REFCNT(v) (printf ("DEBUG: id=%p, refcnt=%i\n", \
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 (void *) v, ((PyObject *) v)->ob_refcnt))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
88
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 /**** Error Handling ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 static PyObject *Tkinter_TclError;
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
92 static int quitMainLoop = 0;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 static int errorInCmd = 0;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 static PyObject *excInCmd;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 static PyObject *valInCmd;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 2009
diff changeset
96 static PyObject *trbInCmd;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
97
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 Tkinter_Error (v)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 PyObject *v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 PyErr_SetString (Tkinter_TclError, Tkapp_Result (v));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
105
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 int
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 PythonCmd_Error (interp)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 Tcl_Interp *interp;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 errorInCmd = 1;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 2009
diff changeset
111 PyErr_Fetch (&excInCmd, &valInCmd, &trbInCmd);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 return TCL_ERROR;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 /**** Utils ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
116
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 static char *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 AsString (value, tmp)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 PyObject *value;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 PyObject *tmp;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 if (PyString_Check (value))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 return PyString_AsString (value);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 else
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 PyObject *v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127
2150
448435bfeadc Made some more things static, and other cleanup for new naming scheme
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
128 v = PyObject_Str (value);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 PyList_Append (tmp, v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 Py_DECREF (v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 return PyString_AsString (v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
134
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 #define ARGSZ 64
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
136
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 static char *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 Merge (args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 PyObject *tmp;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 char *argvStore[ARGSZ];
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 char **argv;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 int fvStore[ARGSZ];
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 int *fv;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 int argc;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 char *res;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 int i;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
149
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 tmp = PyList_New (0);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 argv = argvStore;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 fv = fvStore;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
153
3703
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
154 if (args == NULL)
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
155 {
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
156 argc = 0;
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
157 }
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
158 else if (!PyTuple_Check (args))
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 argc = 1;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 fv[0] = 0;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 argv[0] = AsString (args, tmp);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 else
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 PyObject *v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 if (PyTuple_Size (args) > ARGSZ)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 {
2505
e920e6c27208 add casts to malloc() calls
Guido van Rossum <guido@python.org>
parents: 2300
diff changeset
170 argv = (char **) malloc (PyTuple_Size (args) * sizeof (char *));
e920e6c27208 add casts to malloc() calls
Guido van Rossum <guido@python.org>
parents: 2300
diff changeset
171 fv = (int *) malloc (PyTuple_Size (args) * sizeof (int));
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 if (argv == NULL || fv == NULL)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 PyErr_NoMemory ();
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 argc = PyTuple_Size (args);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 for (i = 0; i < argc; i++)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 v = PyTuple_GetItem (args, i);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 if (PyTuple_Check (v))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 fv[i] = 1;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 argv[i] = Merge (v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 else if (v == Py_None)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 argc = i;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 break;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 else
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 fv[i] = 0;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 argv[i] = AsString (v, tmp);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
197
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 res = Tcl_Merge (argc, argv);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
199
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 Py_DECREF (tmp);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 for (i = 0; i < argc; i++)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 if (fv[i]) free (argv[i]);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 if (argv != argvStore)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 free (argv);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 if (fv != fvStore)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 free (fv);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
207
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 return res;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
210
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 Split (self, list)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 char *list;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 int argc;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 char **argv;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 PyObject *v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
219
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 if (list == NULL)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 Py_INCREF (Py_None);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 return Py_None;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
225
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 if (Tcl_SplitList (Tkapp_Interp (self), list, &argc, &argv) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
228
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 if (argc == 0)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 v = PyString_FromString ("");
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 else if (argc == 1)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 v = PyString_FromString (argv[0]);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 else
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 int i;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
236
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 v = PyTuple_New (argc);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 for (i = 0; i < argc; i++)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 PyTuple_SetItem (v, i, Split (self, argv[i]));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
241
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 free (argv);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 return v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
245
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 /**** Tkapp Object ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
247
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 #ifndef WITH_APPINIT
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 int
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 Tcl_AppInit (interp)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 Tcl_Interp *interp;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 {
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
253 Tk_Window main;
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
254
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
255 main = Tk_MainWindow(interp);
2300
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
256 if (Tcl_Init (interp) == TCL_ERROR) {
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
257 fprintf(stderr, "Tcl_Init error: %s\n", interp->result);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 return TCL_ERROR;
2300
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
259 }
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
260 if (Tk_Init (interp) == TCL_ERROR) {
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
261 fprintf(stderr, "Tk_Init error: %s\n", interp->result);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 return TCL_ERROR;
2300
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
263 }
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 return TCL_OK;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 }
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
266
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 #endif /* !WITH_APPINIT */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
268
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 /* Initialize the Tk application; see the `main' function in
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 `tkMain.c'. */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 static TkappObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 Tkapp_New (screenName, baseName, className, interactive)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 char *screenName;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 char *baseName;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 char *className;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 int interactive;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 TkappObject *v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
279
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 v = PyObject_NEW (TkappObject, &Tkapp_Type);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 if (v == NULL)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
283
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 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
285
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
286 #ifdef NEED_TKCREATEMAINWINDOW
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 v->tkwin = Tk_CreateMainWindow (v->interp, screenName,
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 baseName, className);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 if (v->tkwin == NULL)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 return (TkappObject *) Tkinter_Error ((PyObject *) v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
291
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 Tk_GeometryRequest (v->tkwin, 200, 200);
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
293 #endif
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
294
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 if (screenName != NULL)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 Tcl_SetVar2 (v->interp, "env", "DISPLAY", screenName, TCL_GLOBAL_ONLY);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
297
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 if (interactive)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 Tcl_SetVar (v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 else
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 Tcl_SetVar (v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
302
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 if (Tcl_AppInit (v->interp) != TCL_OK)
3703
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
304 return (TkappObject *) Tkinter_Error (v);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
305
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 return v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
308
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 /** Tcl Eval **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
310
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 Tkapp_Call (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 char *cmd;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
317
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
318 cmd = Merge (args);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 if (Tcl_Eval (Tkapp_Interp (self), cmd) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 free (cmd);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 return Tkinter_Error (self);
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
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 free (cmd);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 return PyString_FromString (Tkapp_Result (self));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
328
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 Tkapp_GlobalCall (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 char *cmd;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
335
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 cmd = Merge (args);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 if (Tcl_GlobalEval (Tkapp_Interp (self), cmd) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 free (cmd);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
342
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 free (cmd);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 return PyString_FromString (Tkapp_Result (self));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
346
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 Tkapp_Eval (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 char *script;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
353
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 if (!PyArg_Parse (args, "s", &script))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
356
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 if (Tcl_Eval (Tkapp_Interp (self), script) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
359
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 return PyString_FromString (Tkapp_Result (self));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
362
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 Tkapp_GlobalEval (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 char *script;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
369
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 if (!PyArg_Parse (args, "s", &script))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
372
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 if (Tcl_GlobalEval (Tkapp_Interp (self), script) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
375
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 return PyString_FromString (Tkapp_Result (self));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
378
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 Tkapp_EvalFile (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 char *fileName;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
385
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 if (!PyArg_Parse (args, "s", &fileName))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
388
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 if (Tcl_EvalFile (Tkapp_Interp (self), fileName) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
391
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 return PyString_FromString (Tkapp_Result (self));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
394
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 Tkapp_Record (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 char *script;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
401
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 if (!PyArg_Parse (args, "s", &script))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
403 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
404
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 if (Tcl_RecordAndEval (Tkapp_Interp (self),
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 script, TCL_NO_EVAL) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
407 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
408
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 return PyString_FromString (Tkapp_Result (self));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
410 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
411
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
412 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 Tkapp_AddErrorInfo (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
414 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
415 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
416 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 char *msg;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
418
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
419 if (!PyArg_Parse (args, "s", &msg))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
420 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
421 Tcl_AddErrorInfo (Tkapp_Interp (self), msg);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
422
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 Py_INCREF(Py_None);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 return Py_None;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
426
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 /** Tcl Variable **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
428
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
430 SetVar (self, args, flags)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
433 int flags;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 char *name1, *name2, *ok;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
436 PyObject *newValue;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 PyObject *tmp;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
438
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
439 tmp = PyList_New (0);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
440
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 if (PyArg_Parse (args, "(sO)", &name1, &newValue))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
442 ok = Tcl_SetVar (Tkapp_Interp (self), name1,
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 AsString (newValue, tmp), flags); /* XXX Merge? */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 else if (PyArg_Parse (args, "(ssO)", &name1, &name2, &newValue))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
445 ok = Tcl_SetVar2 (Tkapp_Interp (self), name1, name2,
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
446 AsString (newValue, tmp), flags);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
447 else
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 Py_DECREF (tmp);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
450 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
451 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
452 Py_DECREF (tmp);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
453
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
454 if (!ok)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
455 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
456
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
457 Py_INCREF (Py_None);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
458 return Py_None;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
460
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
461 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
462 Tkapp_SetVar (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
463 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
464 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
465 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
466 return SetVar (self, args, TCL_LEAVE_ERR_MSG);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
467 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
468
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
469 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
470 Tkapp_GlobalSetVar (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
471 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
472 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
473 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
474 return SetVar (self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
475 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
476
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
477 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
478 GetVar (self, args, flags)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
479 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
480 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
481 int flags;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
482 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
483 char *name1, *name2, *s;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
484
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
485 if (PyArg_Parse (args, "s", &name1))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
486 s = Tcl_GetVar (Tkapp_Interp (self), name1, flags);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
487 else if (PyArg_Parse (args, "(ss)", &name1, &name2))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
488 s = Tcl_GetVar2 (Tkapp_Interp (self), name1, name2, flags);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
489 else
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
490 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
491
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
492 if (s == NULL)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
493 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
494
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
495 return PyString_FromString (s);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
496 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
497
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
498 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
499 Tkapp_GetVar (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
500 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
501 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
502 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
503 return GetVar (self, args, TCL_LEAVE_ERR_MSG);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
504 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
505
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
506 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
507 Tkapp_GlobalGetVar (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
508 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
509 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
510 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
511 return GetVar (self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
512 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
513
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
514 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
515 UnsetVar (self, args, flags)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
516 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
517 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
518 int flags;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
519 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
520 char *name1, *name2;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
521 int code;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
522
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
523 if (PyArg_Parse (args, "s", &name1))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
524 code = Tcl_UnsetVar (Tkapp_Interp (self), name1, flags);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
525 else if (PyArg_Parse (args, "(ss)", &name1, &name2))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
526 code = Tcl_UnsetVar2 (Tkapp_Interp (self), name1, name2, flags);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
527 else
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
528 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
529
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
530 if (code == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
531 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
532
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
533 Py_INCREF (Py_None);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
534 return Py_None;
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
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
537 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
538 Tkapp_UnsetVar (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
539 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
540 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
541 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
542 return UnsetVar (self, args, TCL_LEAVE_ERR_MSG);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
543 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
544
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
545 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
546 Tkapp_GlobalUnsetVar (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
547 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
548 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
549 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
550 return UnsetVar (self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
551 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
552
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
553 /** Tcl to Python **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
554
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
555 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
556 Tkapp_GetInt (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
557 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
558 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
559 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
560 char *s;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
561 int v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
562
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
563 if (!PyArg_Parse (args, "s", &s))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
564 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
565 if (Tcl_GetInt (Tkapp_Interp (self), s, &v) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
566 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
567 return Py_BuildValue ("i", v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
568 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
569
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
570 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
571 Tkapp_GetDouble (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
572 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
573 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
574 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
575 char *s;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
576 double v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
577
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
578 if (!PyArg_Parse (args, "s", &s))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
579 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
580 if (Tcl_GetDouble (Tkapp_Interp (self), s, &v) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
581 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
582 return Py_BuildValue ("d", v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
583 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
584
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
585 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
586 Tkapp_GetBoolean (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
587 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
588 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
589 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
590 char *s;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
591 int v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
592
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
593 if (!PyArg_Parse (args, "s", &s))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
594 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
595 if (Tcl_GetBoolean (Tkapp_Interp (self), s, &v) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
596 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
597 return Py_BuildValue ("i", v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
598 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
599
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
600 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
601 Tkapp_ExprString (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
602 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
603 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
604 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
605 char *s;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
606
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
607 if (!PyArg_Parse (args, "s", &s))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
608 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
609 if (Tcl_ExprString (Tkapp_Interp (self), s) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
610 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
611 return Py_BuildValue ("s", Tkapp_Result (self));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
612 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
613
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
614 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
615 Tkapp_ExprLong (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
616 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
617 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
618 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
619 char *s;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
620 long v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
621
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
622 if (!PyArg_Parse (args, "s", &s))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
623 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
624 if (Tcl_ExprLong (Tkapp_Interp (self), s, &v) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
625 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
626 return Py_BuildValue ("l", v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
627 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
628
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
629 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
630 Tkapp_ExprDouble (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
631 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
632 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
633 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
634 char *s;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
635 double v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
636
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
637 if (!PyArg_Parse (args, "s", &s))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
638 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
639 if (Tcl_ExprDouble (Tkapp_Interp (self), s, &v) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
640 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
641 return Py_BuildValue ("d", v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
642 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
643
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
644 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
645 Tkapp_ExprBoolean (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
646 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
647 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
648 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
649 char *s;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
650 int v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
651
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
652 if (!PyArg_Parse (args, "s", &s))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
653 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
654 if (Tcl_ExprBoolean (Tkapp_Interp (self), s, &v) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
655 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
656 return Py_BuildValue ("i", v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
657 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
658
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
659 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
660 Tkapp_SplitList (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
661 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
662 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
663 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
664 char *list;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
665 int argc;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
666 char **argv;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
667 PyObject *v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
668 int i;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
669
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
670 if (!PyArg_Parse (args, "s", &list))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
671 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
672
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
673 if (Tcl_SplitList (Tkapp_Interp (self), list, &argc, &argv) == TCL_ERROR)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
674 return Tkinter_Error (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
675
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
676 v = PyTuple_New (argc);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
677 for (i = 0; i < argc; i++)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
678 PyTuple_SetItem (v, i, PyString_FromString (argv[i]));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
679
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
680 free (argv);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
681 return v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
682 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
683
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
684 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
685 Tkapp_Split (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
686 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
687 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
688 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
689 char *list;
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 if (!PyArg_Parse (args, "s", &list))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
692 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
693 return Split (self, list);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
694 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
695
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
696 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
697 Tkapp_Merge (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
698 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
699 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
700 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
701 char *s;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
702 PyObject *v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
703
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
704 s = Merge (args);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
705 v = PyString_FromString (s);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
706 free (s);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
707 return v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
708 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
709
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
710 /** Tcl Command **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
711
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
712 /* This is the Tcl command that acts as a wrapper for Python
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
713 function or method. */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
714 static int
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
715 PythonCmd (clientData, interp, argc, argv)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
716 ClientData clientData; /* Is (self, func) */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
717 Tcl_Interp *interp;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
718 int argc;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
719 char *argv[];
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
720 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
721 PyObject *self, *func, *arg, *res, *tmp;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
722 int i;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
723
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
724 self = PyTuple_GetItem ((PyObject *) clientData, 0);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
725 func = PyTuple_GetItem ((PyObject *) clientData, 1);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
726
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
727 /* Create argument list (argv1, ..., argvN) */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
728 arg = PyTuple_New (argc - 1);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
729 for (i = 0; i < (argc - 1); i++)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
730 PyTuple_SetItem (arg, i, PyString_FromString (argv[i + 1]));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
731
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
732 res = PyEval_CallObject (func, arg);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
733 Py_DECREF (arg);
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
734
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
735 if (res == NULL)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
736 return PythonCmd_Error (interp);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
737
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
738 tmp = PyList_New (0);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
739 Tcl_SetResult (Tkapp_Interp (self), AsString (res, tmp), TCL_VOLATILE);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
740 Py_DECREF (res);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
741 Py_DECREF (tmp);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
742
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
743 return TCL_OK;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
744 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
745
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
746 static void
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
747 PythonCmdDelete (clientData)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
748 ClientData clientData; /* Is (self, func) */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
749 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
750 Py_DECREF ((PyObject *) clientData);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
751 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
752
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
753 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
754 Tkapp_CreateCommand (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
755 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
756 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
757 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
758 char *cmdName;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
759 PyObject *data;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
760 PyObject *func;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
761
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
762 /* Args is: (cmdName, func) */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
763 if (!PyTuple_Check (args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
764 || !(PyTuple_Size (args) == 2)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
765 || !PyString_Check (PyTuple_GetItem (args, 0))
2300
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
766 || !PyCallable_Check (PyTuple_GetItem (args, 1)))
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
767 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
768 PyErr_SetString (PyExc_TypeError, "bad argument list");
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
769 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
770 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
771
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
772 cmdName = PyString_AsString (PyTuple_GetItem (args, 0));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
773 func = PyTuple_GetItem (args, 1);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
774
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
775 data = PyTuple_New (2); /* ClientData is: (self, func) */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
776
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
777 Py_INCREF (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
778 PyTuple_SetItem (data, 0, self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
779
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
780 Py_INCREF (func);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
781 PyTuple_SetItem (data, 1, func);
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 Tcl_CreateCommand (Tkapp_Interp (self), cmdName, PythonCmd,
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
784 (ClientData) data, PythonCmdDelete);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
785
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
786 Py_INCREF (Py_None);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
787 return Py_None;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
788 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
789
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
790 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
791 Tkapp_DeleteCommand (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
792 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
793 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
794 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
795 char *cmdName;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
796
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
797 if (!PyArg_Parse (args, "s", &cmdName))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
798 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
799 if (Tcl_DeleteCommand (Tkapp_Interp (self), cmdName) == -1)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
800 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
801 PyErr_SetString (Tkinter_TclError, "can't delete Tcl command");
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
802 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
803 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
804 Py_INCREF (Py_None);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
805 return Py_None;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
806 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
807
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
808 /** File Handler **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
809
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
810 static void
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
811 FileHandler (clientData, mask)
1690
93e036786b17 * tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents: 1664
diff changeset
812 ClientData clientData; /* Is: (func, file) */
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
813 int mask;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
814 {
1690
93e036786b17 * tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents: 1664
diff changeset
815 PyObject *func, *file, *arg, *res;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
816
1690
93e036786b17 * tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents: 1664
diff changeset
817 func = PyTuple_GetItem ((PyObject *) clientData, 0);
93e036786b17 * tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents: 1664
diff changeset
818 file = PyTuple_GetItem ((PyObject *) clientData, 1);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
819
1690
93e036786b17 * tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents: 1664
diff changeset
820 arg = Py_BuildValue ("(Oi)", file, (long) mask);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
821 res = PyEval_CallObject (func, arg);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
822 Py_DECREF (arg);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
823 if (res == NULL)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
824 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
825 errorInCmd = 1;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 2009
diff changeset
826 PyErr_Fetch (&excInCmd, &valInCmd, &trbInCmd);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
827 }
1771
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
828 Py_XDECREF (res);
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
829 }
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
830
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
831 static int
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
832 GetFileNo (file)
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
833 PyObject *file; /* Either an int >= 0 or an object with a
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
834 .fileno() method that returns an int >= 0 */
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
835 {
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
836 PyObject *meth, *args, *res;
1771
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
837 int id;
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
838 if (PyInt_Check(file)) {
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
839 id = PyInt_AsLong(file);
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
840 if (id < 0)
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
841 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
842 return id;
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
843 }
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
844 meth = PyObject_GetAttrString(file, "fileno");
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
845 if (meth == NULL)
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
846 return -1;
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
847 args = PyTuple_New(0);
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
848 if (args == NULL)
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
849 return -1;
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
850 res = PyEval_CallObject(meth, args);
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
851 Py_DECREF(args);
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
852 Py_DECREF(meth);
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
853 if (res == NULL)
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
854 return -1;
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
855 if (PyInt_Check(res))
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
856 id = PyInt_AsLong(res);
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
857 else
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
858 id = -1;
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
859 if (id < 0)
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
860 PyErr_SetString(PyExc_ValueError,
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
861 "invalid fileno() return value");
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
862 Py_DECREF(res);
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
863 return id;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
864 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
865
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
866 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
867 Tkapp_CreateFileHandler (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
868 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
869 PyObject *args; /* Is (file, mask, func) */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
870 {
1690
93e036786b17 * tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents: 1664
diff changeset
871 PyObject *file, *func, *data;
93e036786b17 * tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents: 1664
diff changeset
872 int mask, id;
3554
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
873 #if (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) >= 4001
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
874 Tcl_File tfile;
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
875 #endif
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
876
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
877 if (!PyArg_Parse (args, "(OiO)", &file, &mask, &func))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
878 return NULL;
1771
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
879 id = GetFileNo (file);
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
880 if (id < 0)
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
881 return NULL;
2300
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
882 if (!PyCallable_Check(func))
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
883 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
884 PyErr_SetString (PyExc_TypeError, "bad argument list");
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
885 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
886 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
887
1690
93e036786b17 * tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents: 1664
diff changeset
888 /* ClientData is: (func, file) */
93e036786b17 * tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents: 1664
diff changeset
889 data = Py_BuildValue ("(OO)", func, file);
93e036786b17 * tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents: 1664
diff changeset
890
3554
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
891 #if (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) >= 4001
3703
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
892 #ifdef NT
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
893 /* We assume this is a socket... */
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
894 tfile = Tcl_GetFile((ClientData)id, TCL_WIN_SOCKET);
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
895 #else
3554
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
896 tfile = Tcl_GetFile((ClientData)id, TCL_UNIX_FD);
3703
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
897 #endif
3554
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
898 /* Oughtta check for null Tcl_File object... */
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
899 Tcl_CreateFileHandler (tfile, mask, FileHandler, (ClientData) data);
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
900 #else
3703
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
901 Tk_CreateFileHandler (id, mask, FileHandler, (ClientData) data);
3554
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
902 #endif
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
903 /* XXX fileHandlerDict */
1690
93e036786b17 * tkintermodule.c (Tkapp_New): Remove #ifdef WITH_APPINIT.
Guido van Rossum <guido@python.org>
parents: 1664
diff changeset
904
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
905 Py_INCREF (Py_None);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
906 return Py_None;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
907 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
908
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
909 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
910 Tkapp_DeleteFileHandler (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
911 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
912 PyObject *args; /* Args: file */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
913 {
1771
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
914 PyObject *file;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
915 int id;
3554
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
916 #if (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) >= 4001
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
917 Tcl_File tfile;
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
918 #endif
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
919
1771
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
920 if (!PyArg_Parse (args, "O", &file))
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
921 return NULL;
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
922 id = GetFileNo (file);
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
923 if (id < 0)
51c2e5a9f39c * tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents: 1756
diff changeset
924 return NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
925
3554
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
926 #if (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) >= 4001
3703
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
927 #ifdef NT
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
928 /* We assume this is a socket... */
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
929 tfile = Tcl_GetFile((ClientData)id, TCL_WIN_SOCKET);
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
930 #else
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
931 tfile = Tcl_GetFile((ClientData)id, TCL_UNIX_FD);
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
932 #endif
3554
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
933 /* Oughtta check for null Tcl_File object... */
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
934 Tcl_DeleteFileHandler(tfile);
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
935 #else
3703
ff7fa59f62e8 Added CWI copyright.
Guido van Rossum <guido@python.org>
parents: 3554
diff changeset
936 Tk_DeleteFileHandler (id);
3554
24279bafa828 Patch from the net for 4.1 file handler changes.
Guido van Rossum <guido@python.org>
parents: 3553
diff changeset
937 #endif
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
938 /* XXX fileHandlerDict */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
939 Py_INCREF (Py_None);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
940 return Py_None;
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
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
943 /**** 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
944
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
945 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
946
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
947 typedef struct
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
948 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
949 PyObject_HEAD
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
950 Tk_TimerToken token;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
951 PyObject *func;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
952 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
953 TkttObject;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
954
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
955 static PyObject *
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
956 Tktt_DeleteTimerHandler (self, args)
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
957 PyObject *self;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
958 PyObject *args;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
959 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
960 TkttObject *v = (TkttObject *) self;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
961
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
962 if (!PyArg_Parse (args, ""))
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
963 return NULL;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
964 if (v->func != NULL)
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
965 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
966 Tk_DeleteTimerHandler (v->token);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
967 PyMem_DEL (v->func);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
968 v->func = NULL;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
969 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
970 Py_INCREF (Py_None);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
971 return Py_None;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
972 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
973
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
974 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
975 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
976 {"deletetimerhandler", Tktt_DeleteTimerHandler},
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
977 {NULL, NULL}
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
978 };
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
979
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
980 static TkttObject *
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
981 Tktt_New (token, func)
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
982 Tk_TimerToken token;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
983 PyObject *func;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
984 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
985 TkttObject *v;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
986
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
987 v = PyObject_NEW (TkttObject, &Tktt_Type);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
988 if (v == NULL)
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
989 return NULL;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
990
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
991 v->token = token;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
992 v->func = func;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
993 Py_INCREF (v->func);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
994 return v;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
995 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
996
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
997 static void
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
998 Tktt_Dealloc (self)
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
999 PyObject *self;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1000 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1001 PyMem_DEL (self);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1002 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1003
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1004 static int
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1005 Tktt_Print (self, fp, flags)
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1006 PyObject *self;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1007 FILE *fp;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1008 int flags;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1009 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1010 TkttObject *v = (TkttObject *) self;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1011
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1012 fprintf(fp, "<tktimertoken at 0x%x%s>", v,
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1013 v->func == NULL ? ", handler deleted" : "");
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1014 return 0;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1015 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1016
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1017 static PyObject *
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1018 Tktt_GetAttr (self, name)
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1019 PyObject *self;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1020 char *name;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1021 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1022 return Py_FindMethod (Tktt_methods, self, name);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1023 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1024
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1025 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
1026 {
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
1027 PyObject_HEAD_INIT (&PyType_Type)
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1028 0, /*ob_size */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1029 "tktimertoken", /*tp_name */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1030 sizeof (TkttObject), /*tp_basicsize */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1031 0, /*tp_itemsize */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1032 Tktt_Dealloc, /*tp_dealloc */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1033 Tktt_Print, /*tp_print */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1034 Tktt_GetAttr, /*tp_getattr */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1035 0, /*tp_setattr */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1036 0, /*tp_compare */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1037 0, /*tp_repr */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1038 0, /*tp_as_number */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1039 0, /*tp_as_sequence */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1040 0, /*tp_as_mapping */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1041 0, /*tp_hash */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1042 };
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1043
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1044 /** Timer Handler **/
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1045
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1046 static void
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1047 TimerHandler (clientData)
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1048 ClientData clientData;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1049 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1050 PyObject *func = (PyObject *) clientData;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1051 PyObject *arg, *res;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1052
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1053 arg = PyTuple_New (0);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1054 res = PyEval_CallObject (func, arg);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1055 Py_DECREF (arg);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1056 if (res == NULL)
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1057 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1058 errorInCmd = 1;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 2009
diff changeset
1059 PyErr_Fetch (&excInCmd, &valInCmd, &trbInCmd);
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1060 }
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 2009
diff changeset
1061 else
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 2009
diff changeset
1062 Py_DECREF (res);
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1063 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1064
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1065 static PyObject *
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1066 Tkapp_CreateTimerHandler (self, args)
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1067 PyObject *self;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1068 PyObject *args; /* Is (milliseconds, func) */
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1069 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1070 int milliseconds;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1071 PyObject *func;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1072 Tk_TimerToken token;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1073
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1074 if (!PyArg_Parse (args, "(iO)", &milliseconds, &func))
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1075 return NULL;
2300
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
1076 if (!PyCallable_Check(func))
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1077 {
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1078 PyErr_SetString (PyExc_TypeError, "bad argument list");
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1079 return NULL;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1080 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1081 token = Tk_CreateTimerHandler(milliseconds, TimerHandler, (ClientData) func);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1082 return (PyObject *) Tktt_New (token, func);
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1083 }
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1084
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1085 /** Event Loop **/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1086
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1087 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1088 Tkapp_MainLoop (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1089 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1090 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1091 {
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1092 int threshold = 0;
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1093
2858
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1094 if (!PyArg_ParseTuple (args, "|i", &threshold))
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1095 return NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1096
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1097 quitMainLoop = 0;
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1098 while (Tk_GetNumMainWindows() > threshold && !quitMainLoop && !errorInCmd)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1099 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1100 if (PyOS_InterruptOccurred ())
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1101 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1102 PyErr_SetNone (PyExc_KeyboardInterrupt);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1103 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1104 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1105 Tk_DoOneEvent (0);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1106 }
3134
2677fbb117d6 clear quitMainLoop when we fall through the main loop
Guido van Rossum <guido@python.org>
parents: 3120
diff changeset
1107 quitMainLoop = 0;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1108
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1109 if (errorInCmd)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1110 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1111 errorInCmd = 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 2009
diff changeset
1112 PyErr_Restore (excInCmd, valInCmd, trbInCmd);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 2009
diff changeset
1113 excInCmd = valInCmd = trbInCmd = NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1114 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1115 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1116 Py_INCREF (Py_None);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1117 return Py_None;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1118 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1119
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1120 static PyObject *
2121
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1121 Tkapp_DoOneEvent (self, args)
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1122 PyObject *self;
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1123 PyObject *args;
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1124 {
2858
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1125 int flags = TK_ALL_EVENTS;
2121
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1126 int rv;
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1127
2858
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1128 if (!PyArg_ParseTuple (args, "|i", &flags))
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1129 return NULL;
2121
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1130 rv = Tk_DoOneEvent(flags);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1131 return Py_BuildValue ("i", rv);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1132 }
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1133
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1134 static PyObject *
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1135 Tkapp_Quit (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1136 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1137 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1138 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1139
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1140 if (!PyArg_Parse (args, ""))
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1141 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1142 quitMainLoop = 1;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1143 Py_INCREF (Py_None);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1144 return Py_None;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1145 }
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 /**** Tkapp Method List ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1148
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1149 static PyMethodDef Tkapp_methods[] =
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1150 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1151 {"call", Tkapp_Call},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1152 {"globalcall", Tkapp_GlobalCall},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1153 {"eval", Tkapp_Eval},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1154 {"globaleval", Tkapp_GlobalEval},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1155 {"evalfile", Tkapp_EvalFile},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1156 {"record", Tkapp_Record},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1157 {"adderrorinfo", Tkapp_AddErrorInfo},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1158 {"setvar", Tkapp_SetVar},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1159 {"globalsetvar", Tkapp_GlobalSetVar},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1160 {"getvar", Tkapp_GetVar},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1161 {"globalgetvar", Tkapp_GlobalGetVar},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1162 {"unsetvar", Tkapp_UnsetVar},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1163 {"globalunsetvar", Tkapp_GlobalUnsetVar},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1164 {"getint", Tkapp_GetInt},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1165 {"getdouble", Tkapp_GetDouble},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1166 {"getboolean", Tkapp_GetBoolean},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1167 {"exprstring", Tkapp_ExprString},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1168 {"exprlong", Tkapp_ExprLong},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1169 {"exprdouble", Tkapp_ExprDouble},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1170 {"exprboolean", Tkapp_ExprBoolean},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1171 {"splitlist", Tkapp_SplitList},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1172 {"split", Tkapp_Split},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1173 {"merge", Tkapp_Merge},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1174 {"createcommand", Tkapp_CreateCommand},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1175 {"deletecommand", Tkapp_DeleteCommand},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1176 {"createfilehandler", Tkapp_CreateFileHandler},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1177 {"deletefilehandler", Tkapp_DeleteFileHandler},
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1178 {"createtimerhandler", Tkapp_CreateTimerHandler},
2858
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1179 {"mainloop", Tkapp_MainLoop, 1},
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1180 {"dooneevent", Tkapp_DoOneEvent, 1},
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1181 {"quit", Tkapp_Quit},
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1182 {NULL, NULL}
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1183 };
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1184
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1185 /**** Tkapp Type Methods ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1186
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1187 static void
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1188 Tkapp_Dealloc (self)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1189 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1190 {
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1191 #ifdef NEED_TKCREATEMAINWINDOW
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1192 Tk_DestroyWindow (Tkapp_Tkwin (self));
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1193 #endif
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1194 Tcl_DeleteInterp (Tkapp_Interp (self));
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1195 PyMem_DEL (self);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1196 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1197
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1198 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1199 Tkapp_GetAttr (self, name)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1200 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1201 char *name;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1202 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1203 return Py_FindMethod (Tkapp_methods, self, name);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1204 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1205
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1206 static PyTypeObject Tkapp_Type =
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1207 {
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
1208 PyObject_HEAD_INIT (&PyType_Type)
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1209 0, /*ob_size */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1210 "tkapp", /*tp_name */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1211 sizeof (TkappObject), /*tp_basicsize */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1212 0, /*tp_itemsize */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1213 Tkapp_Dealloc, /*tp_dealloc */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1214 0, /*tp_print */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1215 Tkapp_GetAttr, /*tp_getattr */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1216 0, /*tp_setattr */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1217 0, /*tp_compare */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1218 0, /*tp_repr */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1219 0, /*tp_as_number */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1220 0, /*tp_as_sequence */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1221 0, /*tp_as_mapping */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1222 0, /*tp_hash */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1223 };
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1224
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1225 /**** Tkinter Module ****/
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1226
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1227 static PyObject *
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1228 Tkinter_Create (self, args)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1229 PyObject *self;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1230 PyObject *args;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1231 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1232 char *screenName = NULL;
2858
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1233 char *baseName = NULL;
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1234 char *className = NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1235 int interactive = 0;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1236
3899
584936890f86 getprogramname --> Py_GetProgramName
Guido van Rossum <guido@python.org>
parents: 3703
diff changeset
1237 baseName = strrchr (Py_GetProgramName (), '/');
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1238 if (baseName != NULL)
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1239 baseName++;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1240 else
3899
584936890f86 getprogramname --> Py_GetProgramName
Guido van Rossum <guido@python.org>
parents: 3703
diff changeset
1241 baseName = Py_GetProgramName ();
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1242 className = "Tk";
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1243
2858
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1244 if (!PyArg_ParseTuple (args, "|zssi",
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1245 &screenName, &baseName, &className, &interactive))
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1246 return NULL;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1247
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1248 return (PyObject *) Tkapp_New (screenName, baseName, className,
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1249 interactive);
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
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1252 static PyMethodDef moduleMethods[] =
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1253 {
2858
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1254 {"create", Tkinter_Create, 1},
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1255 {"createfilehandler", Tkapp_CreateFileHandler, 0},
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1256 {"deletefilehandler", Tkapp_DeleteFileHandler, 0},
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1257 {"createtimerhandler", Tkapp_CreateTimerHandler, 0},
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1258 {"mainloop", Tkapp_MainLoop, 1},
eb1ed4d84629 use getnewargs where it makes sense
Guido van Rossum <guido@python.org>
parents: 2505
diff changeset
1259 {"dooneevent", Tkapp_DoOneEvent, 1},
2009
392db1881190 added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
1260 {"quit", Tkapp_Quit},
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1261 {NULL, NULL}
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1262 };
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1263
2300
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
1264 #undef WITH_READLINE /* XXX */
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1265 #ifdef WITH_READLINE
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1266 static int
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1267 EventHook ()
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1268 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1269 if (errorInCmd) /* XXX Reset tty */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1270 {
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1271 errorInCmd = 0;
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 2009
diff changeset
1272 PyErr_Restore (excInCmd, valInCmd, trbInCmd);
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 2009
diff changeset
1273 excInCmd = valInCmd = trbInCmd = NULL;
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1274 PyErr_Print ();
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1275 }
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1276 if (Tk_GetNumMainWindows() > 0)
1756
f533791acc77 * tkintermodule.c: OK, I've fixed the "tty" problem. You're right
Guido van Rossum <guido@python.org>
parents: 1713
diff changeset
1277 Tk_DoOneEvent (TK_DONT_WAIT);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1278 return 0;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1279 }
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1280 #endif /* WITH_READLINE */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1281
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1282 static void
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1283 Tkinter_Cleanup ()
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1284 {
2300
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
1285 /* This segfault with Tk 4.0 beta and seems unnecessary there as well */
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
1286 #if TK_MAJOR_VERSION < 4
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1287 /* XXX rl_deprep_terminal is static, damned! */
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1288 while (tkMainWindowList != 0)
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1289 Tk_DestroyWindow (tkMainWindowList->win);
2300
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
1290 #endif
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1291 }
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1292
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1293 void
3386
6f5feb3b4829 get rid of bogus name for init_tkinter()
Guido van Rossum <guido@python.org>
parents: 3262
diff changeset
1294 init_tkinter ()
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1295 {
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1296 static inited = 0;
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1297
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1298 #ifdef WITH_READLINE
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1299 extern int (*rl_event_hook) ();
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1300 #endif /* WITH_READLINE */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1301 PyObject *m, *d, *v;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1302
3231
1acc04478dc3 Renamed module tkinter to _tkinter, moved source to _tkinter.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 3134
diff changeset
1303 m = Py_InitModule ("_tkinter", moduleMethods);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1304
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1305 d = PyModule_GetDict (m);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1306 Tkinter_TclError = Py_BuildValue ("s", "TclError");
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1307 PyDict_SetItemString (d, "TclError", Tkinter_TclError);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1308
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1309 v = Py_BuildValue ("i", TK_READABLE);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1310 PyDict_SetItemString (d, "READABLE", v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1311 v = Py_BuildValue ("i", TK_WRITABLE);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1312 PyDict_SetItemString (d, "WRITABLE", v);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1313 v = Py_BuildValue ("i", TK_EXCEPTION);
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1314 PyDict_SetItemString (d, "EXCEPTION", v);
2121
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1315 v = Py_BuildValue ("i", TK_X_EVENTS);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1316 PyDict_SetItemString (d, "X_EVENTS", v);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1317 v = Py_BuildValue ("i", TK_FILE_EVENTS);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1318 PyDict_SetItemString (d, "FILE_EVENTS", v);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1319 v = Py_BuildValue ("i", TK_TIMER_EVENTS);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1320 PyDict_SetItemString (d, "TIMER_EVENTS", v);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1321 v = Py_BuildValue ("i", TK_IDLE_EVENTS);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1322 PyDict_SetItemString (d, "IDLE_EVENTS", v);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1323 v = Py_BuildValue ("i", TK_ALL_EVENTS);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1324 PyDict_SetItemString (d, "ALL_EVENTS", v);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1325 v = Py_BuildValue ("i", TK_DONT_WAIT);
86d9e91405c8 added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
1326 PyDict_SetItemString (d, "DONT_WAIT", v);
2300
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
1327 v = Py_BuildValue ("s", TK_VERSION);
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
1328 PyDict_SetItemString (d, "TK_VERSION", v);
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
1329 v = Py_BuildValue ("s", TCL_VERSION);
d2049a1d3cc5 use PyCallable_Check; export TK_VERSION and TCL_VERSION strings;
Guido van Rossum <guido@python.org>
parents: 2150
diff changeset
1330 PyDict_SetItemString (d, "TCL_VERSION", v);
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1331
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1332 #ifdef WITH_READLINE
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1333 rl_event_hook = EventHook;
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1334 #endif /* WITH_READLINE */
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1335
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1336 if (!inited)
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1337 {
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1338 inited = 1;
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1771
diff changeset
1339 if (Py_AtExit (Tkinter_Cleanup) != 0)
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1771
diff changeset
1340 fprintf(stderr,
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1771
diff changeset
1341 "Tkinter: warning: cleanup procedure not registered\n");
1713
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1342 }
bb566d28caa0 * tkintermodule.c
Guido van Rossum <guido@python.org>
parents: 1690
diff changeset
1343
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1344 if (PyErr_Occurred ())
3231
1acc04478dc3 Renamed module tkinter to _tkinter, moved source to _tkinter.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 3134
diff changeset
1345 Py_FatalError ("can't initialize module _tkinter");
3240
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1346 #ifdef macintosh
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1347 TclMacSetEventProc(PyMacConvertEvent);
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1348 #if GENERATINGCFM
3240
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1349 mac_addlibresources();
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1350 #endif /* GENERATINGCFM */
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1351 #endif /* macintosh */
1664
a09efb135de5 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1352 }
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1353
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1354
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1355 #ifdef macintosh
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1356
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1357 /*
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1358 ** 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
1359 */
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1360
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1361 void
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1362 panic(char * format, ...)
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1363 {
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1364 va_list varg;
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1365
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1366 va_start(varg, format);
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1367
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1368 vfprintf(stderr, format, varg);
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1369 (void) fflush(stderr);
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1370
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1371 va_end(varg);
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1372
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1373 Py_FatalError("Tcl/Tk panic");
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1374 }
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1375
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1376 /*
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1377 ** 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
1378 */
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1379
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1380 static int
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1381 PyMacConvertEvent(eventPtr)
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1382 EventRecord *eventPtr;
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1383 {
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1384 if (SIOUXHandleOneEvent(eventPtr))
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1385 return 0; /* Nothing happened to the Tcl event queue */
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1386 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
1387 }
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1388
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1389 #if GENERATINGCFM
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1390
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1391 /*
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1392 ** 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
1393 */
3262
bfb63b45ff0f Initialize GUSI on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3240
diff changeset
1394
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1395 #include <Resources.h>
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1396 #include <CodeFragments.h>
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1397
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1398 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
1399 static FSSpec library_fss;
3120
4a12a543175d Mac changes
Guido van Rossum <guido@python.org>
parents: 2858
diff changeset
1400
3240
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1401 /*
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1402 ** 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
1403 ** 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
1404 ** 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
1405 ** resources.
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1406 */
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1407 OSErr pascal
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1408 init_tkinter_shlib(InitBlockPtr data)
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1409 {
3553
1d035e211209 Add __sinit() call according to Jack.
Guido van Rossum <guido@python.org>
parents: 3414
diff changeset
1410 __sinit(); /* Sez Jack */
3240
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1411 if ( data == nil ) return noErr;
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1412 if ( data->fragLocator.where == kOnDiskFlat ) {
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1413 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
1414 loaded_from_shlib = 1;
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1415 } else if ( data->fragLocator.where == kOnDiskSegmented ) {
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1416 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
1417 loaded_from_shlib = 1;
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1418 }
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1419 return noErr;
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1420 }
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1421
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1422 /*
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1423 ** 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
1424 ** 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
1425 */
3413
2fe7d489654e Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents: 3386
diff changeset
1426 static
3240
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1427 mac_addlibresources()
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1428 {
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1429 if ( !loaded_from_shlib )
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1430 return;
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1431 (void)FSpOpenResFile(&library_fss, fsRdPerm);
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1432 }
f7fd85b32a7d Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents: 3231
diff changeset
1433
3414
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1434 #endif /* GENERATINGCFM */
098cbd6d196e Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents: 3413
diff changeset
1435 #endif /* macintosh */