Adds the ipaddr module to the standard library. Issue #3959.
[python.git] / Modules / tkappinit.c
blobcfbd20c4f4099ddeaa5c93ec51035d50d91ad536
1 /* appinit.c -- Tcl and Tk application initialization.
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.
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").
15 #include <string.h>
16 #include <tcl.h>
17 #include <tk.h>
19 #include "tkinter.h"
21 #ifdef TKINTER_PROTECT_LOADTK
22 /* See Tkapp_TkInit in _tkinter.c for the usage of tk_load_faile */
23 static int tk_load_failed;
24 #endif
26 int
27 Tcl_AppInit(Tcl_Interp *interp)
29 Tk_Window main_window;
30 const char *_tkinter_skip_tk_init;
31 #ifdef TKINTER_PROTECT_LOADTK
32 const char *_tkinter_tk_failed;
33 #endif
35 #ifdef TK_AQUA
36 #ifndef MAX_PATH_LEN
37 #define MAX_PATH_LEN 1024
38 #endif
39 char tclLibPath[MAX_PATH_LEN], tkLibPath[MAX_PATH_LEN];
40 Tcl_Obj* pathPtr;
42 /* pre- Tcl_Init code copied from tkMacOSXAppInit.c */
43 Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tcllibrary",
44 tclLibPath, MAX_PATH_LEN, 0);
46 if (tclLibPath[0] != '\0') {
47 Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
48 Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
49 Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
52 if (tclLibPath[0] != '\0') {
53 Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
54 Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
55 Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
57 #endif
58 if (Tcl_Init (interp) == TCL_ERROR)
59 return TCL_ERROR;
61 #ifdef TK_AQUA
62 /* pre- Tk_Init code copied from tkMacOSXAppInit.c */
63 Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tklibrary",
64 tkLibPath, MAX_PATH_LEN, 1);
66 if (tclLibPath[0] != '\0') {
67 pathPtr = Tcl_NewStringObj(tclLibPath, -1);
68 } else {
69 Tcl_Obj *pathPtr = TclGetLibraryPath();
72 if (tkLibPath[0] != '\0') {
73 Tcl_Obj *objPtr;
75 Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
76 objPtr = Tcl_NewStringObj(tkLibPath, -1);
77 Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
80 TclSetLibraryPath(pathPtr);
81 #endif
83 #ifdef WITH_XXX
84 /* Initialize modules that don't require Tk */
85 #endif
87 _tkinter_skip_tk_init = Tcl_GetVar(interp,
88 "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY);
89 if (_tkinter_skip_tk_init != NULL &&
90 strcmp(_tkinter_skip_tk_init, "1") == 0) {
91 return TCL_OK;
94 #ifdef TKINTER_PROTECT_LOADTK
95 _tkinter_tk_failed = Tcl_GetVar(interp,
96 "_tkinter_tk_failed", TCL_GLOBAL_ONLY);
98 if (tk_load_failed || (
99 _tkinter_tk_failed != NULL &&
100 strcmp(_tkinter_tk_failed, "1") == 0)) {
101 Tcl_SetResult(interp, TKINTER_LOADTK_ERRMSG, TCL_STATIC);
102 return TCL_ERROR;
104 #endif
106 if (Tk_Init(interp) == TCL_ERROR) {
107 #ifdef TKINTER_PROTECT_LOADTK
108 tk_load_failed = 1;
109 Tcl_SetVar(interp, "_tkinter_tk_failed", "1", TCL_GLOBAL_ONLY);
110 #endif
111 return TCL_ERROR;
114 main_window = Tk_MainWindow(interp);
116 #ifdef TK_AQUA
117 TkMacOSXInitAppleEvents(interp);
118 TkMacOSXInitMenus(interp);
119 #endif
121 #ifdef WITH_MOREBUTTONS
123 extern Tcl_CmdProc studButtonCmd;
124 extern Tcl_CmdProc triButtonCmd;
126 Tcl_CreateCommand(interp, "studbutton", studButtonCmd,
127 (ClientData) main_window, NULL);
128 Tcl_CreateCommand(interp, "tributton", triButtonCmd,
129 (ClientData) main_window, NULL);
131 #endif
133 #ifdef WITH_PIL /* 0.2b5 and later -- not yet released as of May 14 */
135 extern void TkImaging_Init(Tcl_Interp *);
136 TkImaging_Init(interp);
137 /* XXX TkImaging_Init() doesn't have the right return type */
138 /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/
140 #endif
142 #ifdef WITH_PIL_OLD /* 0.2b4 and earlier */
144 extern void TkImaging_Init(void);
145 /* XXX TkImaging_Init() doesn't have the right prototype */
146 /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/
148 #endif
150 #ifdef WITH_TIX
152 extern int Tix_Init(Tcl_Interp *interp);
153 extern int Tix_SafeInit(Tcl_Interp *interp);
154 Tcl_StaticPackage(NULL, "Tix", Tix_Init, Tix_SafeInit);
156 #endif
158 #ifdef WITH_BLT
160 extern int Blt_Init(Tcl_Interp *);
161 extern int Blt_SafeInit(Tcl_Interp *);
162 Tcl_StaticPackage(NULL, "Blt", Blt_Init, Blt_SafeInit);
164 #endif
166 #ifdef WITH_TOGL
168 /* XXX I've heard rumors that this doesn't work */
169 extern int Togl_Init(Tcl_Interp *);
170 /* XXX Is there no Togl_SafeInit? */
171 Tcl_StaticPackage(NULL, "Togl", Togl_Init, NULL);
173 #endif
175 #ifdef WITH_XXX
177 #endif
178 return TCL_OK;