blob: 42b6bb883046847be634cb452e278f8460965c36 [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
15#include <tcl.h>
16#include <tk.h>
17
18int
Peter Schneider-Kampfaaad372000-07-10 09:26:41 +000019Tcl_AppInit(Tcl_Interp *interp)
Guido van Rossumf7132471994-06-27 08:00:16 +000020{
Moshe Zadka6a078ed2000-08-04 15:53:06 +000021 Tk_Window main_window;
David Aschere2b4b322004-02-18 05:59:53 +000022 const char * _tkinter_skip_tk_init;
Guido van Rossumf7132471994-06-27 08:00:16 +000023
Jack Jansencb852442001-12-09 23:15:56 +000024#ifdef TK_AQUA
25#ifndef MAX_PATH_LEN
26#define MAX_PATH_LEN 1024
27#endif
28 char tclLibPath[MAX_PATH_LEN], tkLibPath[MAX_PATH_LEN];
29 Tcl_Obj* pathPtr;
30
31 /* pre- Tcl_Init code copied from tkMacOSXAppInit.c */
32 Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tcllibrary",
33 tclLibPath, MAX_PATH_LEN, 0);
34
35 if (tclLibPath[0] != '\0') {
36 Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
37 Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
38 Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
39 }
40
41 if (tclLibPath[0] != '\0') {
42 Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
43 Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
44 Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
45 }
46#endif
Barry Warsaw845a4c61997-01-14 17:36:36 +000047 if (Tcl_Init (interp) == TCL_ERROR)
48 return TCL_ERROR;
Jack Jansencb852442001-12-09 23:15:56 +000049
50#ifdef TK_AQUA
51 /* pre- Tk_Init code copied from tkMacOSXAppInit.c */
52 Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tklibrary",
53 tkLibPath, MAX_PATH_LEN, 1);
54
55 if (tclLibPath[0] != '\0') {
56 pathPtr = Tcl_NewStringObj(tclLibPath, -1);
57 } else {
58 Tcl_Obj *pathPtr = TclGetLibraryPath();
59 }
60
61 if (tkLibPath[0] != '\0') {
62 Tcl_Obj *objPtr;
63
64 Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
65 objPtr = Tcl_NewStringObj(tkLibPath, -1);
66 Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
67 }
68
69 TclSetLibraryPath(pathPtr);
70#endif
71
David Aschere2b4b322004-02-18 05:59:53 +000072#ifdef WITH_XXX
73 // Initialize modules that don't require Tk
74#endif
75
76 _tkinter_skip_tk_init = Tcl_GetVar(interp, "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY);
77 if (_tkinter_skip_tk_init != NULL && strcmp(_tkinter_skip_tk_init, "1") == 0) {
78 return TCL_OK;
79 }
80 if (Tk_Init(interp) == TCL_ERROR)
Barry Warsaw845a4c61997-01-14 17:36:36 +000081 return TCL_ERROR;
Guido van Rossumf7132471994-06-27 08:00:16 +000082
Moshe Zadka6a078ed2000-08-04 15:53:06 +000083 main_window = Tk_MainWindow(interp);
Guido van Rossume168c651999-11-05 18:11:23 +000084
Jack Jansencb852442001-12-09 23:15:56 +000085#ifdef TK_AQUA
86 TkMacOSXInitAppleEvents(interp);
87 TkMacOSXInitMenus(interp);
88#endif
89
Guido van Rossumf7132471994-06-27 08:00:16 +000090#ifdef WITH_MOREBUTTONS
Barry Warsaw845a4c61997-01-14 17:36:36 +000091 {
92 extern Tcl_CmdProc studButtonCmd;
93 extern Tcl_CmdProc triButtonCmd;
Guido van Rossumf7132471994-06-27 08:00:16 +000094
Barry Warsaw845a4c61997-01-14 17:36:36 +000095 Tcl_CreateCommand(interp, "studbutton", studButtonCmd,
Moshe Zadka6a078ed2000-08-04 15:53:06 +000096 (ClientData) main_window, NULL);
Barry Warsaw845a4c61997-01-14 17:36:36 +000097 Tcl_CreateCommand(interp, "tributton", triButtonCmd,
Moshe Zadka6a078ed2000-08-04 15:53:06 +000098 (ClientData) main_window, NULL);
Barry Warsaw845a4c61997-01-14 17:36:36 +000099 }
Guido van Rossumf7132471994-06-27 08:00:16 +0000100#endif
Guido van Rossum1cbdfb91997-05-14 19:22:11 +0000101
102#ifdef WITH_PIL /* 0.2b5 and later -- not yet released as of May 14 */
103 {
Guido van Rossum7a206c81997-11-22 17:34:41 +0000104 extern void TkImaging_Init(Tcl_Interp *);
Guido van Rossum1cbdfb91997-05-14 19:22:11 +0000105 TkImaging_Init(interp);
Guido van Rossum7a206c81997-11-22 17:34:41 +0000106 /* XXX TkImaging_Init() doesn't have the right return type */
107 /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/
Guido van Rossum1cbdfb91997-05-14 19:22:11 +0000108 }
109#endif
110
111#ifdef WITH_PIL_OLD /* 0.2b4 and earlier */
112 {
113 extern void TkImaging_Init(void);
Guido van Rossum7a206c81997-11-22 17:34:41 +0000114 /* XXX TkImaging_Init() doesn't have the right prototype */
115 /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/
Guido van Rossum1cbdfb91997-05-14 19:22:11 +0000116 }
117#endif
118
Guido van Rossumaec74971997-11-19 18:56:17 +0000119#ifdef WITH_TIX
Guido van Rossumf259a8e1997-12-02 20:38:38 +0000120 {
121 extern int Tix_Init(Tcl_Interp *interp);
122 extern int Tix_SafeInit(Tcl_Interp *interp);
123 Tcl_StaticPackage(NULL, "Tix", Tix_Init, Tix_SafeInit);
124 }
Guido van Rossumaec74971997-11-19 18:56:17 +0000125#endif
126
127#ifdef WITH_BLT
Guido van Rossum7a206c81997-11-22 17:34:41 +0000128 {
129 extern int Blt_Init(Tcl_Interp *);
130 extern int Blt_SafeInit(Tcl_Interp *);
131 Tcl_StaticPackage(NULL, "Blt", Blt_Init, Blt_SafeInit);
Guido van Rossumaec74971997-11-19 18:56:17 +0000132 }
Guido van Rossum7a206c81997-11-22 17:34:41 +0000133#endif
134
135#ifdef WITH_TOGL
136 {
137 /* XXX I've heard rumors that this doesn't work */
138 extern int Togl_Init(Tcl_Interp *);
139 /* XXX Is there no Togl_SafeInit? */
140 Tcl_StaticPackage(NULL, "Togl", Togl_Init, NULL);
141 }
Guido van Rossumaec74971997-11-19 18:56:17 +0000142#endif
143
Guido van Rossumf7132471994-06-27 08:00:16 +0000144#ifdef WITH_XXX
145
146#endif
Barry Warsaw845a4c61997-01-14 17:36:36 +0000147 return TCL_OK;
Guido van Rossumf7132471994-06-27 08:00:16 +0000148}