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