[Python-checkins] python/dist/src/Modules _tkinter.c, 1.163,
1.164 tkappinit.c, 1.10, 1.11
david_ascher at users.sourceforge.net
david_ascher at users.sourceforge.net
Wed Feb 18 00:59:56 EST 2004
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24617/dist/src/Modules
Modified Files:
_tkinter.c tkappinit.c
Log Message:
Implementation of patch 869468
Allow the user to create Tkinter.Tcl objects which are
just like Tkinter.Tk objects except that they do not
initialize Tk. This is useful in circumstances where the
script is being run on machines that do not have an X
server running -- in those cases, Tk initialization fails,
even if no window is ever created.
Includes documentation change and tests.
Tested on Linux, Solaris and Windows.
Reviewed by Martin von Loewis.
Index: _tkinter.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_tkinter.c,v
retrieving revision 1.163
retrieving revision 1.164
diff -C2 -d -r1.163 -r1.164
*** _tkinter.c 20 Nov 2003 01:44:58 -0000 1.163
--- _tkinter.c 18 Feb 2004 05:59:53 -0000 1.164
***************
*** 547,559 ****
{
Tk_Window main;
- main = Tk_MainWindow(interp);
if (Tcl_Init(interp) == TCL_ERROR) {
PySys_WriteStderr("Tcl_Init error: %s\n", Tcl_GetStringResult(interp));
return TCL_ERROR;
}
! if (Tk_Init(interp) == TCL_ERROR) {
! PySys_WriteStderr("Tk_Init error: %s\n", Tcl_GetStringResult(interp));
! return TCL_ERROR;
}
return TCL_OK;
--- 547,563 ----
{
Tk_Window main;
+ const char * _tkinter_skip_tk_init;
if (Tcl_Init(interp) == TCL_ERROR) {
PySys_WriteStderr("Tcl_Init error: %s\n", Tcl_GetStringResult(interp));
return TCL_ERROR;
}
! _tkinter_skip_tk_init = Tcl_GetVar(interp, "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY);
! if (_tkinter_skip_tk_init == NULL || strcmp(_tkinter_skip_tk_init, "1") != 0) {
! main = Tk_MainWindow(interp);
! if (Tk_Init(interp) == TCL_ERROR) {
! PySys_WriteStderr("Tk_Init error: %s\n", Tcl_GetStringResult(interp));
! return TCL_ERROR;
! }
}
return TCL_OK;
***************
*** 573,581 ****
static TkappObject *
Tkapp_New(char *screenName, char *baseName, char *className,
! int interactive, int wantobjects)
{
TkappObject *v;
char *argv0;
-
v = PyObject_New(TkappObject, &Tkapp_Type);
if (v == NULL)
--- 577,584 ----
static TkappObject *
Tkapp_New(char *screenName, char *baseName, char *className,
! int interactive, int wantobjects, int wantTk)
{
TkappObject *v;
char *argv0;
v = PyObject_New(TkappObject, &Tkapp_Type);
if (v == NULL)
***************
*** 638,641 ****
--- 641,648 ----
ckfree(argv0);
+ if (! wantTk) {
+ Tcl_SetVar(v->interp, "_tkinter_skip_tk_init", "1", TCL_GLOBAL_ONLY);
+ }
+
if (Tcl_AppInit(v->interp) != TCL_OK)
return (TkappObject *)Tkinter_Error((PyObject *)v);
***************
*** 2563,2566 ****
--- 2570,2608 ----
}
+ static PyObject *
+ Tkapp_TkInit(PyObject *self, PyObject *args)
+ {
+ Tcl_Interp *interp = Tkapp_Interp(self);
+ Tk_Window main;
+ const char * _tk_exists = NULL;
+ PyObject *res = NULL;
+ int err;
+ main = Tk_MainWindow(interp);
+ if (!PyArg_ParseTuple(args, ":loadtk"))
+ return NULL;
+
+ /* We want to guard against calling Tk_Init() multiple times */
+ CHECK_TCL_APPARTMENT;
+ ENTER_TCL
+ err = Tcl_Eval(Tkapp_Interp(self), "info exists tk_version");
+ ENTER_OVERLAP
+ if (err == TCL_ERROR) {
+ res = Tkinter_Error(self);
+ } else {
+ _tk_exists = Tkapp_Result(self);
+ }
+ LEAVE_OVERLAP_TCL
+ if (err == TCL_ERROR) {
+ return NULL;
+ }
+ if (_tk_exists == NULL || strcmp(_tk_exists, "1") != 0) {
+ if (Tk_Init(interp) == TCL_ERROR) {
+ PyErr_SetString(Tkinter_TclError, Tcl_GetStringResult(Tkapp_Interp(self)));
+ return NULL;
+ }
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
static PyObject *
***************
*** 2630,2633 ****
--- 2672,2676 ----
{"quit", Tkapp_Quit, METH_VARARGS},
{"interpaddr", Tkapp_InterpAddr, METH_VARARGS},
+ {"loadtk", Tkapp_TkInit, METH_VARARGS},
{NULL, NULL}
};
***************
*** 2794,2797 ****
--- 2837,2841 ----
int interactive = 0;
int wantobjects = 0;
+ int wantTk = 1; /* If false, then Tk_Init() doesn't get called */
baseName = strrchr(Py_GetProgramName(), '/');
***************
*** 2802,2812 ****
className = "Tk";
! if (!PyArg_ParseTuple(args, "|zssii:create",
&screenName, &baseName, &className,
! &interactive, &wantobjects))
return NULL;
return (PyObject *) Tkapp_New(screenName, baseName, className,
! interactive, wantobjects);
}
--- 2846,2856 ----
className = "Tk";
! if (!PyArg_ParseTuple(args, "|zssiii:create",
&screenName, &baseName, &className,
! &interactive, &wantobjects, &wantTk))
return NULL;
return (PyObject *) Tkapp_New(screenName, baseName, className,
! interactive, wantobjects, wantTk);
}
Index: tkappinit.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/tkappinit.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** tkappinit.c 9 Dec 2001 23:15:56 -0000 1.10
--- tkappinit.c 18 Feb 2004 05:59:53 -0000 1.11
***************
*** 20,23 ****
--- 20,24 ----
{
Tk_Window main_window;
+ const char * _tkinter_skip_tk_init;
#ifdef TK_AQUA
***************
*** 69,73 ****
#endif
! if (Tk_Init (interp) == TCL_ERROR)
return TCL_ERROR;
--- 70,82 ----
#endif
! #ifdef WITH_XXX
! // Initialize modules that don't require Tk
! #endif
!
! _tkinter_skip_tk_init = Tcl_GetVar(interp, "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY);
! if (_tkinter_skip_tk_init != NULL && strcmp(_tkinter_skip_tk_init, "1") == 0) {
! return TCL_OK;
! }
! if (Tk_Init(interp) == TCL_ERROR)
return TCL_ERROR;
More information about the Python-checkins
mailing list