blob: 05c48a4a6a8e4349508d733fd72ee53de1ee412c [file] [log] [blame]
Guido van Rossum7a206c81997-11-22 17:34:41 +00001/* appinit.c -- Tcl and Tk application initialization.
2
3 The function Tcl_AppInit() below initializes various Tcl packages.
4 It is called for each Tcl interpreter created by _tkinter.create().
5 It needs to be compiled with -DWITH_<package> flags for each package
6 that you are statically linking with. You may have to add sections
7 for packages not yet listed below.
8
9 Note that those packages for which Tcl_StaticPackage() is called with
10 a NULL first argument are known as "static loadable" packages to
11 Tcl but not actually initialized. To use these, you have to load
12 it explicitly, e.g. tkapp.eval("load {} Blt").
13 */
Guido van Rossumf7132471994-06-27 08:00:16 +000014
Neal Norwitz0a8266a2004-06-13 20:29:55 +000015#include <string.h>
Guido van Rossumf7132471994-06-27 08:00:16 +000016#include <tcl.h>
17#include <tk.h>
18
19int
Peter Schneider-Kampfaaad372000-07-10 09:26:41 +000020Tcl_AppInit(Tcl_Interp *interp)
Guido van Rossumf7132471994-06-27 08:00:16 +000021{
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000022 Tk_Window main_window;
23 const char * _tkinter_skip_tk_init;
Guido van Rossumf7132471994-06-27 08:00:16 +000024
Jack Jansencb852442001-12-09 23:15:56 +000025#ifdef TK_AQUA
26#ifndef MAX_PATH_LEN
27#define MAX_PATH_LEN 1024
28#endif
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000029 char tclLibPath[MAX_PATH_LEN], tkLibPath[MAX_PATH_LEN];
30 Tcl_Obj* pathPtr;
Jack Jansencb852442001-12-09 23:15:56 +000031
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000032 /* pre- Tcl_Init code copied from tkMacOSXAppInit.c */
33 Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tcllibrary",
34 tclLibPath, MAX_PATH_LEN, 0);
Jack Jansencb852442001-12-09 23:15:56 +000035
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000036 if (tclLibPath[0] != '\0') {
37 Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
38 Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
39 Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
40 }
41
42 if (tclLibPath[0] != '\0') {
43 Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
44 Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
45 Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
46 }
Jack Jansencb852442001-12-09 23:15:56 +000047#endif
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000048 if (Tcl_Init (interp) == TCL_ERROR)
49 return TCL_ERROR;
Jack Jansencb852442001-12-09 23:15:56 +000050
51#ifdef TK_AQUA
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000052 /* pre- Tk_Init code copied from tkMacOSXAppInit.c */
53 Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tklibrary",
54 tkLibPath, MAX_PATH_LEN, 1);
Jack Jansencb852442001-12-09 23:15:56 +000055
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000056 if (tclLibPath[0] != '\0') {
57 pathPtr = Tcl_NewStringObj(tclLibPath, -1);
58 } else {
59 Tcl_Obj *pathPtr = TclGetLibraryPath();
60 }
Jack Jansencb852442001-12-09 23:15:56 +000061
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000062 if (tkLibPath[0] != '\0') {
63 Tcl_Obj *objPtr;
Jack Jansencb852442001-12-09 23:15:56 +000064
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000065 Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
66 objPtr = Tcl_NewStringObj(tkLibPath, -1);
67 Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
68 }
Jack Jansencb852442001-12-09 23:15:56 +000069
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000070 TclSetLibraryPath(pathPtr);
Jack Jansencb852442001-12-09 23:15:56 +000071#endif
72
David Aschere2b4b322004-02-18 05:59:53 +000073#ifdef WITH_XXX
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000074 /* Initialize modules that don't require Tk */
David Aschere2b4b322004-02-18 05:59:53 +000075#endif
76
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000077 _tkinter_skip_tk_init = Tcl_GetVar(interp, "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY);
78 if (_tkinter_skip_tk_init != NULL && strcmp(_tkinter_skip_tk_init, "1") == 0) {
79 return TCL_OK;
80 }
81 if (Tk_Init(interp) == TCL_ERROR)
82 return TCL_ERROR;
Guido van Rossumf7132471994-06-27 08:00:16 +000083
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000084 main_window = Tk_MainWindow(interp);
Guido van Rossume168c651999-11-05 18:11:23 +000085
Jack Jansencb852442001-12-09 23:15:56 +000086#ifdef TK_AQUA
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000087 TkMacOSXInitAppleEvents(interp);
88 TkMacOSXInitMenus(interp);
Jack Jansencb852442001-12-09 23:15:56 +000089#endif
Guido van Rossumf7132471994-06-27 08:00:16 +000090
Antoine Pitrouc7c96a92010-05-09 15:15:40 +000091#ifdef WITH_MOREBUTTONS
92 {
93 extern Tcl_CmdProc studButtonCmd;
94 extern Tcl_CmdProc triButtonCmd;
95
96 Tcl_CreateCommand(interp, "studbutton", studButtonCmd,
97 (ClientData) main_window, NULL);
98 Tcl_CreateCommand(interp, "tributton", triButtonCmd,
99 (ClientData) main_window, NULL);
100 }
Guido van Rossumf7132471994-06-27 08:00:16 +0000101#endif
Guido van Rossum1cbdfb91997-05-14 19:22:11 +0000102
103#ifdef WITH_PIL /* 0.2b5 and later -- not yet released as of May 14 */
Antoine Pitrouc7c96a92010-05-09 15:15:40 +0000104 {
105 extern void TkImaging_Init(Tcl_Interp *);
106 TkImaging_Init(interp);
107 /* XXX TkImaging_Init() doesn't have the right return type */
108 /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/
109 }
Guido van Rossum1cbdfb91997-05-14 19:22:11 +0000110#endif
111
112#ifdef WITH_PIL_OLD /* 0.2b4 and earlier */
Antoine Pitrouc7c96a92010-05-09 15:15:40 +0000113 {
114 extern void TkImaging_Init(void);
115 /* XXX TkImaging_Init() doesn't have the right prototype */
116 /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/
117 }
Guido van Rossum1cbdfb91997-05-14 19:22:11 +0000118#endif
119
Guido van Rossumaec74971997-11-19 18:56:17 +0000120#ifdef WITH_TIX
Antoine Pitrouc7c96a92010-05-09 15:15:40 +0000121 {
122 extern int Tix_Init(Tcl_Interp *interp);
123 extern int Tix_SafeInit(Tcl_Interp *interp);
124 Tcl_StaticPackage(NULL, "Tix", Tix_Init, Tix_SafeInit);
125 }
Guido van Rossumaec74971997-11-19 18:56:17 +0000126#endif
127
128#ifdef WITH_BLT
Antoine Pitrouc7c96a92010-05-09 15:15:40 +0000129 {
130 extern int Blt_Init(Tcl_Interp *);
131 extern int Blt_SafeInit(Tcl_Interp *);
132 Tcl_StaticPackage(NULL, "Blt", Blt_Init, Blt_SafeInit);
133 }
Guido van Rossum7a206c81997-11-22 17:34:41 +0000134#endif
135
136#ifdef WITH_TOGL
Antoine Pitrouc7c96a92010-05-09 15:15:40 +0000137 {
138 /* XXX I've heard rumors that this doesn't work */
139 extern int Togl_Init(Tcl_Interp *);
140 /* XXX Is there no Togl_SafeInit? */
141 Tcl_StaticPackage(NULL, "Togl", Togl_Init, NULL);
142 }
Guido van Rossumaec74971997-11-19 18:56:17 +0000143#endif
144
Guido van Rossumf7132471994-06-27 08:00:16 +0000145#ifdef WITH_XXX
146
147#endif
Antoine Pitrouc7c96a92010-05-09 15:15:40 +0000148 return TCL_OK;
Guido van Rossumf7132471994-06-27 08:00:16 +0000149}