ยปCore Development>Code coverage>Modules/tkappinit.c

Python code coverage for Modules/tkappinit.c

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