1 | n/a | /* appinit.c -- Tcl and Tk application initialization. |
---|
2 | n/a | |
---|
3 | n/a | The function Tcl_AppInit() below initializes various Tcl packages. |
---|
4 | n/a | It is called for each Tcl interpreter created by _tkinter.create(). |
---|
5 | n/a | It needs to be compiled with -DWITH_<package> flags for each package |
---|
6 | n/a | that you are statically linking with. You may have to add sections |
---|
7 | n/a | for packages not yet listed below. |
---|
8 | n/a | |
---|
9 | n/a | Note that those packages for which Tcl_StaticPackage() is called with |
---|
10 | n/a | a NULL first argument are known as "static loadable" packages to |
---|
11 | n/a | Tcl but not actually initialized. To use these, you have to load |
---|
12 | n/a | it explicitly, e.g. tkapp.eval("load {} Blt"). |
---|
13 | n/a | */ |
---|
14 | n/a | |
---|
15 | n/a | #include <string.h> |
---|
16 | n/a | #include <tcl.h> |
---|
17 | n/a | #include <tk.h> |
---|
18 | n/a | |
---|
19 | n/a | #include "tkinter.h" |
---|
20 | n/a | |
---|
21 | n/a | #ifdef TKINTER_PROTECT_LOADTK |
---|
22 | n/a | /* See Tkapp_TkInit in _tkinter.c for the usage of tk_load_faile */ |
---|
23 | n/a | static int tk_load_failed; |
---|
24 | n/a | #endif |
---|
25 | n/a | |
---|
26 | n/a | int |
---|
27 | n/a | Tcl_AppInit(Tcl_Interp *interp) |
---|
28 | n/a | { |
---|
29 | n/a | const char *_tkinter_skip_tk_init; |
---|
30 | n/a | #ifdef TKINTER_PROTECT_LOADTK |
---|
31 | n/a | const char *_tkinter_tk_failed; |
---|
32 | n/a | #endif |
---|
33 | n/a | |
---|
34 | n/a | #ifdef TK_AQUA |
---|
35 | n/a | #ifndef MAX_PATH_LEN |
---|
36 | n/a | #define MAX_PATH_LEN 1024 |
---|
37 | n/a | #endif |
---|
38 | n/a | char tclLibPath[MAX_PATH_LEN], tkLibPath[MAX_PATH_LEN]; |
---|
39 | n/a | Tcl_Obj* pathPtr; |
---|
40 | n/a | |
---|
41 | n/a | /* pre- Tcl_Init code copied from tkMacOSXAppInit.c */ |
---|
42 | n/a | Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tcllibrary", |
---|
43 | n/a | tclLibPath, MAX_PATH_LEN, 0); |
---|
44 | n/a | |
---|
45 | n/a | if (tclLibPath[0] != '\0') { |
---|
46 | n/a | Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY); |
---|
47 | n/a | Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY); |
---|
48 | n/a | Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY); |
---|
49 | n/a | } |
---|
50 | n/a | |
---|
51 | n/a | if (tclLibPath[0] != '\0') { |
---|
52 | n/a | Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY); |
---|
53 | n/a | Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY); |
---|
54 | n/a | Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY); |
---|
55 | n/a | } |
---|
56 | n/a | #endif |
---|
57 | n/a | if (Tcl_Init (interp) == TCL_ERROR) |
---|
58 | n/a | return TCL_ERROR; |
---|
59 | n/a | |
---|
60 | n/a | #ifdef TK_AQUA |
---|
61 | n/a | /* pre- Tk_Init code copied from tkMacOSXAppInit.c */ |
---|
62 | n/a | Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tklibrary", |
---|
63 | n/a | tkLibPath, MAX_PATH_LEN, 1); |
---|
64 | n/a | |
---|
65 | n/a | if (tclLibPath[0] != '\0') { |
---|
66 | n/a | pathPtr = Tcl_NewStringObj(tclLibPath, -1); |
---|
67 | n/a | } else { |
---|
68 | n/a | Tcl_Obj *pathPtr = TclGetLibraryPath(); |
---|
69 | n/a | } |
---|
70 | n/a | |
---|
71 | n/a | if (tkLibPath[0] != '\0') { |
---|
72 | n/a | Tcl_Obj *objPtr; |
---|
73 | n/a | |
---|
74 | n/a | Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY); |
---|
75 | n/a | objPtr = Tcl_NewStringObj(tkLibPath, -1); |
---|
76 | n/a | Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
---|
77 | n/a | } |
---|
78 | n/a | |
---|
79 | n/a | TclSetLibraryPath(pathPtr); |
---|
80 | n/a | #endif |
---|
81 | n/a | |
---|
82 | n/a | #ifdef WITH_XXX |
---|
83 | n/a | /* Initialize modules that don't require Tk */ |
---|
84 | n/a | #endif |
---|
85 | n/a | |
---|
86 | n/a | _tkinter_skip_tk_init = Tcl_GetVar(interp, |
---|
87 | n/a | "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY); |
---|
88 | n/a | if (_tkinter_skip_tk_init != NULL && |
---|
89 | n/a | strcmp(_tkinter_skip_tk_init, "1") == 0) { |
---|
90 | n/a | return TCL_OK; |
---|
91 | n/a | } |
---|
92 | n/a | |
---|
93 | n/a | #ifdef TKINTER_PROTECT_LOADTK |
---|
94 | n/a | _tkinter_tk_failed = Tcl_GetVar(interp, |
---|
95 | n/a | "_tkinter_tk_failed", TCL_GLOBAL_ONLY); |
---|
96 | n/a | |
---|
97 | n/a | if (tk_load_failed || ( |
---|
98 | n/a | _tkinter_tk_failed != NULL && |
---|
99 | n/a | strcmp(_tkinter_tk_failed, "1") == 0)) { |
---|
100 | n/a | Tcl_SetResult(interp, TKINTER_LOADTK_ERRMSG, TCL_STATIC); |
---|
101 | n/a | return TCL_ERROR; |
---|
102 | n/a | } |
---|
103 | n/a | #endif |
---|
104 | n/a | |
---|
105 | n/a | if (Tk_Init(interp) == TCL_ERROR) { |
---|
106 | n/a | #ifdef TKINTER_PROTECT_LOADTK |
---|
107 | n/a | tk_load_failed = 1; |
---|
108 | n/a | Tcl_SetVar(interp, "_tkinter_tk_failed", "1", TCL_GLOBAL_ONLY); |
---|
109 | n/a | #endif |
---|
110 | n/a | return TCL_ERROR; |
---|
111 | n/a | } |
---|
112 | n/a | |
---|
113 | n/a | Tk_MainWindow(interp); |
---|
114 | n/a | |
---|
115 | n/a | #ifdef TK_AQUA |
---|
116 | n/a | TkMacOSXInitAppleEvents(interp); |
---|
117 | n/a | TkMacOSXInitMenus(interp); |
---|
118 | n/a | #endif |
---|
119 | n/a | |
---|
120 | n/a | #ifdef WITH_PIL /* 0.2b5 and later -- not yet released as of May 14 */ |
---|
121 | n/a | { |
---|
122 | n/a | extern void TkImaging_Init(Tcl_Interp *); |
---|
123 | n/a | TkImaging_Init(interp); |
---|
124 | n/a | /* XXX TkImaging_Init() doesn't have the right return type */ |
---|
125 | n/a | /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/ |
---|
126 | n/a | } |
---|
127 | n/a | #endif |
---|
128 | n/a | |
---|
129 | n/a | #ifdef WITH_PIL_OLD /* 0.2b4 and earlier */ |
---|
130 | n/a | { |
---|
131 | n/a | extern void TkImaging_Init(void); |
---|
132 | n/a | /* XXX TkImaging_Init() doesn't have the right prototype */ |
---|
133 | n/a | /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/ |
---|
134 | n/a | } |
---|
135 | n/a | #endif |
---|
136 | n/a | |
---|
137 | n/a | #ifdef WITH_TIX |
---|
138 | n/a | { |
---|
139 | n/a | extern int Tix_Init(Tcl_Interp *interp); |
---|
140 | n/a | extern int Tix_SafeInit(Tcl_Interp *interp); |
---|
141 | n/a | Tcl_StaticPackage(NULL, "Tix", Tix_Init, Tix_SafeInit); |
---|
142 | n/a | } |
---|
143 | n/a | #endif |
---|
144 | n/a | |
---|
145 | n/a | #ifdef WITH_BLT |
---|
146 | n/a | { |
---|
147 | n/a | extern int Blt_Init(Tcl_Interp *); |
---|
148 | n/a | extern int Blt_SafeInit(Tcl_Interp *); |
---|
149 | n/a | Tcl_StaticPackage(NULL, "Blt", Blt_Init, Blt_SafeInit); |
---|
150 | n/a | } |
---|
151 | n/a | #endif |
---|
152 | n/a | |
---|
153 | n/a | #ifdef WITH_TOGL |
---|
154 | n/a | { |
---|
155 | n/a | /* XXX I've heard rumors that this doesn't work */ |
---|
156 | n/a | extern int Togl_Init(Tcl_Interp *); |
---|
157 | n/a | /* XXX Is there no Togl_SafeInit? */ |
---|
158 | n/a | Tcl_StaticPackage(NULL, "Togl", Togl_Init, NULL); |
---|
159 | n/a | } |
---|
160 | n/a | #endif |
---|
161 | n/a | |
---|
162 | n/a | #ifdef WITH_XXX |
---|
163 | n/a | |
---|
164 | n/a | #endif |
---|
165 | n/a | return TCL_OK; |
---|
166 | n/a | } |
---|