]> granicus.if.org Git - python/commitdiff
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
authorJack Jansen <jack.jansen@cwi.nl>
Sun, 9 Dec 2001 23:15:56 +0000 (23:15 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Sun, 9 Dec 2001 23:15:56 +0000 (23:15 +0000)
work with Mac OS X Aqua-Tk, all nicely within ifdefs.

The process is not for the faint of heart, though: you need to download
and install the (alfa) Aqua-Tk, obtain a few needed X11 headers from
somewhere else and then everything builds. To run scripts using Tkinter
you must build with --enable-framework, build Python.app in Mac/OSX
and run your Tkinter scripts with that. Then, about half the tests in
Demo/tkinter work (or at least do something).

Checking this in anyway because it shouldn't break anything, and newer
versions of Aqua-Tk will streamline the process.

Modules/_tkinter.c
Modules/tkappinit.c

index 4e701ad3e39daf47706ef8ed3228c10b4e456b5d..44f6420c715bfc3fe1bb72e7382427da2af57c88 100644 (file)
@@ -41,8 +41,13 @@ Copyright (C) 1994 Steen Lumholt.
 #define MAC_TCL
 #endif
 
+#ifdef TK_FRAMEWORK
+#include <Tcl/tcl.h>
+#include <Tk/tk.h>
+#else
 #include <tcl.h>
 #include <tk.h>
+#endif
 
 #define TKMAJORMINOR (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION)
 
@@ -454,6 +459,7 @@ Tkapp_New(char *screenName, char *baseName, char *className, int interactive)
        ClearMenuBar();
        TkMacInitMenus(v->interp);
 #endif
+
        /* Delete the 'exit' command, which can screw things up */
        Tcl_DeleteCommand(v->interp, "exit");
 
@@ -1580,7 +1586,7 @@ Tktt_Repr(PyObject *self)
        char buf[100];
 
        PyOS_snprintf(buf, sizeof(buf), "<tktimertoken at %p%s>", v,
-                     v->func == NULL ? ", handler deleted" : "");
+                       v->func == NULL ? ", handler deleted" : "");
        return PyString_FromString(buf);
 }
 
@@ -2137,6 +2143,22 @@ init_tkinter(void)
        Tktt_Type.ob_type = &PyType_Type;
        PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type);
 
+
+#ifdef TK_AQUA
+       /* Tk_MacOSXSetupTkNotifier must be called before Tcl's subsystems
+        * start waking up.  Note that Tcl_FindExecutable will do this, this
+        * code must be above it! The original warning from
+        * tkMacOSXAppInit.c is copied below.
+        *
+        * NB - You have to swap in the Tk Notifier BEFORE you start up the
+        * Tcl interpreter for now.  It probably should work to do this
+        * in the other order, but for now it doesn't seem to.
+        *
+        */
+       Tk_MacOSXSetupTkNotifier();
+#endif
+
+
        /* This helps the dynamic loader; in Unicode aware Tcl versions
           it also helps Tcl find its encodings. */
        Tcl_FindExecutable(Py_GetProgramName());
index c551fcab44d5c5e2b22149c1a3ceb49ad2eca6a1..96c545d7e9a4873d81e7100c895d4821a3c54696 100644 (file)
@@ -20,13 +20,64 @@ Tcl_AppInit(Tcl_Interp *interp)
 {
        Tk_Window main_window;
 
+#ifdef TK_AQUA
+#ifndef MAX_PATH_LEN
+#define MAX_PATH_LEN 1024
+#endif
+       char tclLibPath[MAX_PATH_LEN], tkLibPath[MAX_PATH_LEN];
+       Tcl_Obj*        pathPtr;
+
+        /* pre- Tcl_Init code copied from tkMacOSXAppInit.c */
+       Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tcllibrary",
+               tclLibPath, MAX_PATH_LEN, 0);
+
+       if (tclLibPath[0] != '\0') {
+               Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
+               Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
+               Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
+       }
+       
+       if (tclLibPath[0] != '\0') {
+               Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
+               Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
+               Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
+       }
+#endif
        if (Tcl_Init (interp) == TCL_ERROR)
                return TCL_ERROR;
+
+#ifdef TK_AQUA
+        /* pre- Tk_Init code copied from tkMacOSXAppInit.c */
+       Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tklibrary",
+            tkLibPath, MAX_PATH_LEN, 1);
+
+       if (tclLibPath[0] != '\0') {
+               pathPtr = Tcl_NewStringObj(tclLibPath, -1);
+       } else {
+               Tcl_Obj *pathPtr = TclGetLibraryPath();
+       }
+
+       if (tkLibPath[0] != '\0') {
+               Tcl_Obj *objPtr;
+
+               Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
+               objPtr = Tcl_NewStringObj(tkLibPath, -1);
+               Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
+       }
+
+       TclSetLibraryPath(pathPtr);
+#endif
+
        if (Tk_Init (interp) == TCL_ERROR)
                return TCL_ERROR;
 
        main_window = Tk_MainWindow(interp);
 
+#ifdef TK_AQUA
+       TkMacOSXInitAppleEvents(interp);
+       TkMacOSXInitMenus(interp);
+#endif
+    
 #ifdef WITH_MOREBUTTONS
        {
                extern Tcl_CmdProc studButtonCmd;