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