Guido van Rossum | 7a206c8 | 1997-11-22 17:34:41 +0000 | [diff] [blame] | 1 | /* 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 Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 14 | |
Neal Norwitz | 0a8266a | 2004-06-13 20:29:55 +0000 | [diff] [blame] | 15 | #include <string.h> |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 16 | #include <tcl.h> |
| 17 | #include <tk.h> |
| 18 | |
| 19 | int |
Peter Schneider-Kamp | faaad37 | 2000-07-10 09:26:41 +0000 | [diff] [blame] | 20 | Tcl_AppInit(Tcl_Interp *interp) |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 21 | { |
Moshe Zadka | 6a078ed | 2000-08-04 15:53:06 +0000 | [diff] [blame] | 22 | Tk_Window main_window; |
David Ascher | e2b4b32 | 2004-02-18 05:59:53 +0000 | [diff] [blame] | 23 | const char * _tkinter_skip_tk_init; |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 24 | |
Jack Jansen | cb85244 | 2001-12-09 23:15:56 +0000 | [diff] [blame] | 25 | #ifdef TK_AQUA |
| 26 | #ifndef MAX_PATH_LEN |
| 27 | #define MAX_PATH_LEN 1024 |
| 28 | #endif |
| 29 | char tclLibPath[MAX_PATH_LEN], tkLibPath[MAX_PATH_LEN]; |
| 30 | Tcl_Obj* pathPtr; |
| 31 | |
| 32 | /* pre- Tcl_Init code copied from tkMacOSXAppInit.c */ |
| 33 | Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tcllibrary", |
| 34 | tclLibPath, MAX_PATH_LEN, 0); |
| 35 | |
| 36 | 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 | } |
| 47 | #endif |
Barry Warsaw | 845a4c6 | 1997-01-14 17:36:36 +0000 | [diff] [blame] | 48 | if (Tcl_Init (interp) == TCL_ERROR) |
| 49 | return TCL_ERROR; |
Jack Jansen | cb85244 | 2001-12-09 23:15:56 +0000 | [diff] [blame] | 50 | |
| 51 | #ifdef TK_AQUA |
| 52 | /* pre- Tk_Init code copied from tkMacOSXAppInit.c */ |
| 53 | Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tklibrary", |
| 54 | tkLibPath, MAX_PATH_LEN, 1); |
| 55 | |
| 56 | if (tclLibPath[0] != '\0') { |
| 57 | pathPtr = Tcl_NewStringObj(tclLibPath, -1); |
| 58 | } else { |
| 59 | Tcl_Obj *pathPtr = TclGetLibraryPath(); |
| 60 | } |
| 61 | |
| 62 | if (tkLibPath[0] != '\0') { |
| 63 | Tcl_Obj *objPtr; |
| 64 | |
| 65 | Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY); |
| 66 | objPtr = Tcl_NewStringObj(tkLibPath, -1); |
| 67 | Tcl_ListObjAppendElement(NULL, pathPtr, objPtr); |
| 68 | } |
| 69 | |
| 70 | TclSetLibraryPath(pathPtr); |
| 71 | #endif |
| 72 | |
David Ascher | e2b4b32 | 2004-02-18 05:59:53 +0000 | [diff] [blame] | 73 | #ifdef WITH_XXX |
Christian Heimes | 1a8501c | 2008-10-02 19:56:01 +0000 | [diff] [blame^] | 74 | /* Initialize modules that don't require Tk */ |
David Ascher | e2b4b32 | 2004-02-18 05:59:53 +0000 | [diff] [blame] | 75 | #endif |
| 76 | |
| 77 | _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) |
Barry Warsaw | 845a4c6 | 1997-01-14 17:36:36 +0000 | [diff] [blame] | 82 | return TCL_ERROR; |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 83 | |
Moshe Zadka | 6a078ed | 2000-08-04 15:53:06 +0000 | [diff] [blame] | 84 | main_window = Tk_MainWindow(interp); |
Guido van Rossum | e168c65 | 1999-11-05 18:11:23 +0000 | [diff] [blame] | 85 | |
Jack Jansen | cb85244 | 2001-12-09 23:15:56 +0000 | [diff] [blame] | 86 | #ifdef TK_AQUA |
| 87 | TkMacOSXInitAppleEvents(interp); |
| 88 | TkMacOSXInitMenus(interp); |
| 89 | #endif |
| 90 | |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 91 | #ifdef WITH_MOREBUTTONS |
Barry Warsaw | 845a4c6 | 1997-01-14 17:36:36 +0000 | [diff] [blame] | 92 | { |
| 93 | extern Tcl_CmdProc studButtonCmd; |
| 94 | extern Tcl_CmdProc triButtonCmd; |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 95 | |
Barry Warsaw | 845a4c6 | 1997-01-14 17:36:36 +0000 | [diff] [blame] | 96 | Tcl_CreateCommand(interp, "studbutton", studButtonCmd, |
Moshe Zadka | 6a078ed | 2000-08-04 15:53:06 +0000 | [diff] [blame] | 97 | (ClientData) main_window, NULL); |
Barry Warsaw | 845a4c6 | 1997-01-14 17:36:36 +0000 | [diff] [blame] | 98 | Tcl_CreateCommand(interp, "tributton", triButtonCmd, |
Moshe Zadka | 6a078ed | 2000-08-04 15:53:06 +0000 | [diff] [blame] | 99 | (ClientData) main_window, NULL); |
Barry Warsaw | 845a4c6 | 1997-01-14 17:36:36 +0000 | [diff] [blame] | 100 | } |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 101 | #endif |
Guido van Rossum | 1cbdfb9 | 1997-05-14 19:22:11 +0000 | [diff] [blame] | 102 | |
| 103 | #ifdef WITH_PIL /* 0.2b5 and later -- not yet released as of May 14 */ |
| 104 | { |
Guido van Rossum | 7a206c8 | 1997-11-22 17:34:41 +0000 | [diff] [blame] | 105 | extern void TkImaging_Init(Tcl_Interp *); |
Guido van Rossum | 1cbdfb9 | 1997-05-14 19:22:11 +0000 | [diff] [blame] | 106 | TkImaging_Init(interp); |
Guido van Rossum | 7a206c8 | 1997-11-22 17:34:41 +0000 | [diff] [blame] | 107 | /* XXX TkImaging_Init() doesn't have the right return type */ |
| 108 | /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/ |
Guido van Rossum | 1cbdfb9 | 1997-05-14 19:22:11 +0000 | [diff] [blame] | 109 | } |
| 110 | #endif |
| 111 | |
| 112 | #ifdef WITH_PIL_OLD /* 0.2b4 and earlier */ |
| 113 | { |
| 114 | extern void TkImaging_Init(void); |
Guido van Rossum | 7a206c8 | 1997-11-22 17:34:41 +0000 | [diff] [blame] | 115 | /* XXX TkImaging_Init() doesn't have the right prototype */ |
| 116 | /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/ |
Guido van Rossum | 1cbdfb9 | 1997-05-14 19:22:11 +0000 | [diff] [blame] | 117 | } |
| 118 | #endif |
| 119 | |
Guido van Rossum | aec7497 | 1997-11-19 18:56:17 +0000 | [diff] [blame] | 120 | #ifdef WITH_TIX |
Guido van Rossum | f259a8e | 1997-12-02 20:38:38 +0000 | [diff] [blame] | 121 | { |
| 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 Rossum | aec7497 | 1997-11-19 18:56:17 +0000 | [diff] [blame] | 126 | #endif |
| 127 | |
| 128 | #ifdef WITH_BLT |
Guido van Rossum | 7a206c8 | 1997-11-22 17:34:41 +0000 | [diff] [blame] | 129 | { |
| 130 | extern int Blt_Init(Tcl_Interp *); |
| 131 | extern int Blt_SafeInit(Tcl_Interp *); |
| 132 | Tcl_StaticPackage(NULL, "Blt", Blt_Init, Blt_SafeInit); |
Guido van Rossum | aec7497 | 1997-11-19 18:56:17 +0000 | [diff] [blame] | 133 | } |
Guido van Rossum | 7a206c8 | 1997-11-22 17:34:41 +0000 | [diff] [blame] | 134 | #endif |
| 135 | |
| 136 | #ifdef WITH_TOGL |
| 137 | { |
| 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 Rossum | aec7497 | 1997-11-19 18:56:17 +0000 | [diff] [blame] | 143 | #endif |
| 144 | |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 145 | #ifdef WITH_XXX |
| 146 | |
| 147 | #endif |
Barry Warsaw | 845a4c6 | 1997-01-14 17:36:36 +0000 | [diff] [blame] | 148 | return TCL_OK; |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 149 | } |