1 | n/a | import sys, os |
---|
2 | n/a | |
---|
3 | n/a | # Delay import _tkinter until we have set TCL_LIBRARY, |
---|
4 | n/a | # so that Tcl_FindExecutable has a chance to locate its |
---|
5 | n/a | # encoding directory. |
---|
6 | n/a | |
---|
7 | n/a | # Unfortunately, we cannot know the TCL_LIBRARY directory |
---|
8 | n/a | # if we don't know the tcl version, which we cannot find out |
---|
9 | n/a | # without import Tcl. Fortunately, Tcl will itself look in |
---|
10 | n/a | # <TCL_LIBRARY>\..\tcl<TCL_VERSION>, so anything close to |
---|
11 | n/a | # the real Tcl library will do. |
---|
12 | n/a | |
---|
13 | n/a | # Expand symbolic links on Vista |
---|
14 | n/a | try: |
---|
15 | n/a | import ctypes |
---|
16 | n/a | ctypes.windll.kernel32.GetFinalPathNameByHandleW |
---|
17 | n/a | except (ImportError, AttributeError): |
---|
18 | n/a | def convert_path(s): |
---|
19 | n/a | return s |
---|
20 | n/a | else: |
---|
21 | n/a | def convert_path(s): |
---|
22 | n/a | if isinstance(s, bytes): |
---|
23 | n/a | s = s.decode("mbcs") |
---|
24 | n/a | hdir = ctypes.windll.kernel32.\ |
---|
25 | n/a | CreateFileW(s, 0x80, # FILE_READ_ATTRIBUTES |
---|
26 | n/a | 1, # FILE_SHARE_READ |
---|
27 | n/a | None, 3, # OPEN_EXISTING |
---|
28 | n/a | 0x02000000, # FILE_FLAG_BACKUP_SEMANTICS |
---|
29 | n/a | None) |
---|
30 | n/a | if hdir == -1: |
---|
31 | n/a | # Cannot open directory, give up |
---|
32 | n/a | return s |
---|
33 | n/a | buf = ctypes.create_unicode_buffer("", 32768) |
---|
34 | n/a | res = ctypes.windll.kernel32.\ |
---|
35 | n/a | GetFinalPathNameByHandleW(hdir, buf, len(buf), |
---|
36 | n/a | 0) # VOLUME_NAME_DOS |
---|
37 | n/a | ctypes.windll.kernel32.CloseHandle(hdir) |
---|
38 | n/a | if res == 0: |
---|
39 | n/a | # Conversion failed (e.g. network location) |
---|
40 | n/a | return s |
---|
41 | n/a | s = buf[:res] |
---|
42 | n/a | # Ignore leading \\?\ |
---|
43 | n/a | if s.startswith("\\\\?\\"): |
---|
44 | n/a | s = s[4:] |
---|
45 | n/a | if s.startswith("UNC"): |
---|
46 | n/a | s = "\\" + s[3:] |
---|
47 | n/a | return s |
---|
48 | n/a | |
---|
49 | n/a | prefix = os.path.join(sys.base_prefix,"tcl") |
---|
50 | n/a | if not os.path.exists(prefix): |
---|
51 | n/a | # devdir/../tcltk/lib |
---|
52 | n/a | prefix = os.path.join(sys.base_prefix, os.path.pardir, "tcltk", "lib") |
---|
53 | n/a | prefix = os.path.abspath(prefix) |
---|
54 | n/a | # if this does not exist, no further search is needed |
---|
55 | n/a | if os.path.exists(prefix): |
---|
56 | n/a | prefix = convert_path(prefix) |
---|
57 | n/a | if "TCL_LIBRARY" not in os.environ: |
---|
58 | n/a | for name in os.listdir(prefix): |
---|
59 | n/a | if name.startswith("tcl"): |
---|
60 | n/a | tcldir = os.path.join(prefix,name) |
---|
61 | n/a | if os.path.isdir(tcldir): |
---|
62 | n/a | os.environ["TCL_LIBRARY"] = tcldir |
---|
63 | n/a | # Compute TK_LIBRARY, knowing that it has the same version |
---|
64 | n/a | # as Tcl |
---|
65 | n/a | import _tkinter |
---|
66 | n/a | ver = str(_tkinter.TCL_VERSION) |
---|
67 | n/a | if "TK_LIBRARY" not in os.environ: |
---|
68 | n/a | v = os.path.join(prefix, 'tk'+ver) |
---|
69 | n/a | if os.path.exists(os.path.join(v, "tclIndex")): |
---|
70 | n/a | os.environ['TK_LIBRARY'] = v |
---|
71 | n/a | # We don't know the Tix version, so we must search the entire |
---|
72 | n/a | # directory |
---|
73 | n/a | if "TIX_LIBRARY" not in os.environ: |
---|
74 | n/a | for name in os.listdir(prefix): |
---|
75 | n/a | if name.startswith("tix"): |
---|
76 | n/a | tixdir = os.path.join(prefix,name) |
---|
77 | n/a | if os.path.isdir(tixdir): |
---|
78 | n/a | os.environ["TIX_LIBRARY"] = tixdir |
---|