Skip to content

Commit cb85244

Browse files
committed
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
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.
1 parent edeea04 commit cb85244

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

Modules/_tkinter.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ Copyright (C) 1994 Steen Lumholt.
4141
#define MAC_TCL
4242
#endif
4343

44+
#ifdef TK_FRAMEWORK
45+
#include <Tcl/tcl.h>
46+
#include <Tk/tk.h>
47+
#else
4448
#include <tcl.h>
4549
#include <tk.h>
50+
#endif
4651

4752
#define TKMAJORMINOR (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION)
4853

@@ -454,6 +459,7 @@ Tkapp_New(char *screenName, char *baseName, char *className, int interactive)
454459
ClearMenuBar();
455460
TkMacInitMenus(v->interp);
456461
#endif
462+
457463
/* Delete the 'exit' command, which can screw things up */
458464
Tcl_DeleteCommand(v->interp, "exit");
459465

@@ -1580,7 +1586,7 @@ Tktt_Repr(PyObject *self)
15801586
char buf[100];
15811587

15821588
PyOS_snprintf(buf, sizeof(buf), "<tktimertoken at %p%s>", v,
1583-
v->func == NULL ? ", handler deleted" : "");
1589+
v->func == NULL ? ", handler deleted" : "");
15841590
return PyString_FromString(buf);
15851591
}
15861592

@@ -2137,6 +2143,22 @@ init_tkinter(void)
21372143
Tktt_Type.ob_type = &PyType_Type;
21382144
PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type);
21392145

2146+
2147+
#ifdef TK_AQUA
2148+
/* Tk_MacOSXSetupTkNotifier must be called before Tcl's subsystems
2149+
* start waking up. Note that Tcl_FindExecutable will do this, this
2150+
* code must be above it! The original warning from
2151+
* tkMacOSXAppInit.c is copied below.
2152+
*
2153+
* NB - You have to swap in the Tk Notifier BEFORE you start up the
2154+
* Tcl interpreter for now. It probably should work to do this
2155+
* in the other order, but for now it doesn't seem to.
2156+
*
2157+
*/
2158+
Tk_MacOSXSetupTkNotifier();
2159+
#endif
2160+
2161+
21402162
/* This helps the dynamic loader; in Unicode aware Tcl versions
21412163
it also helps Tcl find its encodings. */
21422164
Tcl_FindExecutable(Py_GetProgramName());

Modules/tkappinit.c

+51
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,64 @@ Tcl_AppInit(Tcl_Interp *interp)
2020
{
2121
Tk_Window main_window;
2222

23+
#ifdef TK_AQUA
24+
#ifndef MAX_PATH_LEN
25+
#define MAX_PATH_LEN 1024
26+
#endif
27+
char tclLibPath[MAX_PATH_LEN], tkLibPath[MAX_PATH_LEN];
28+
Tcl_Obj* pathPtr;
29+
30+
/* pre- Tcl_Init code copied from tkMacOSXAppInit.c */
31+
Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tcllibrary",
32+
tclLibPath, MAX_PATH_LEN, 0);
33+
34+
if (tclLibPath[0] != '\0') {
35+
Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
36+
Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
37+
Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
38+
}
39+
40+
if (tclLibPath[0] != '\0') {
41+
Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
42+
Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
43+
Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
44+
}
45+
#endif
2346
if (Tcl_Init (interp) == TCL_ERROR)
2447
return TCL_ERROR;
48+
49+
#ifdef TK_AQUA
50+
/* pre- Tk_Init code copied from tkMacOSXAppInit.c */
51+
Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tklibrary",
52+
tkLibPath, MAX_PATH_LEN, 1);
53+
54+
if (tclLibPath[0] != '\0') {
55+
pathPtr = Tcl_NewStringObj(tclLibPath, -1);
56+
} else {
57+
Tcl_Obj *pathPtr = TclGetLibraryPath();
58+
}
59+
60+
if (tkLibPath[0] != '\0') {
61+
Tcl_Obj *objPtr;
62+
63+
Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
64+
objPtr = Tcl_NewStringObj(tkLibPath, -1);
65+
Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
66+
}
67+
68+
TclSetLibraryPath(pathPtr);
69+
#endif
70+
2571
if (Tk_Init (interp) == TCL_ERROR)
2672
return TCL_ERROR;
2773

2874
main_window = Tk_MainWindow(interp);
2975

76+
#ifdef TK_AQUA
77+
TkMacOSXInitAppleEvents(interp);
78+
TkMacOSXInitMenus(interp);
79+
#endif
80+
3081
#ifdef WITH_MOREBUTTONS
3182
{
3283
extern Tcl_CmdProc studButtonCmd;

0 commit comments

Comments
 (0)