| 1 |
import sys, os |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
try: |
| 15 |
import ctypes |
| 16 |
ctypes.windll.kernel32.GetFinalPathNameByHandleW |
| 17 |
except (ImportError, AttributeError): |
| 18 |
def convert_path(s): |
| 19 |
return s |
| 20 |
else: |
| 21 |
def convert_path(s): |
| 22 |
assert isinstance(s, str) |
| 23 |
udir = s.decode("mbcs") |
| 24 |
hdir = ctypes.windll.kernel32.\ |
| 25 |
CreateFileW(udir, 0x80, |
| 26 |
1, |
| 27 |
None, 3, |
| 28 |
0x02000000, |
| 29 |
None) |
| 30 |
if hdir == -1: |
| 31 |
|
| 32 |
return s |
| 33 |
buf = ctypes.create_unicode_buffer(u"", 32768) |
| 34 |
res = ctypes.windll.kernel32.\ |
| 35 |
GetFinalPathNameByHandleW(hdir, buf, len(buf), |
| 36 |
0) |
| 37 |
ctypes.windll.kernel32.CloseHandle(hdir) |
| 38 |
if res == 0: |
| 39 |
|
| 40 |
return s |
| 41 |
s = buf[:res].encode("mbcs") |
| 42 |
|
| 43 |
if s.startswith("\\\\?\\"): |
| 44 |
s = s[4:] |
| 45 |
if s.startswith("UNC"): |
| 46 |
s = "\\" + s[3:] |
| 47 |
return s |
| 48 |
|
| 49 |
prefix = os.path.join(sys.prefix,"tcl") |
| 50 |
if not os.path.exists(prefix): |
| 51 |
|
| 52 |
tcltk = 'tcltk' |
| 53 |
if sys.maxsize > 2**31 - 1: |
| 54 |
tcltk = 'tcltk64' |
| 55 |
prefix = os.path.join(sys.prefix, "externals", tcltk, "lib") |
| 56 |
prefix = os.path.abspath(prefix) |
| 57 |
|
| 58 |
if os.path.exists(prefix): |
| 59 |
prefix = convert_path(prefix) |
| 60 |
if "TCL_LIBRARY" not in os.environ: |
| 61 |
for name in os.listdir(prefix): |
| 62 |
if name.startswith("tcl"): |
| 63 |
tcldir = os.path.join(prefix,name) |
| 64 |
if os.path.isdir(tcldir): |
| 65 |
os.environ["TCL_LIBRARY"] = tcldir |
| 66 |
|
| 67 |
|
| 68 |
import _tkinter |
| 69 |
ver = str(_tkinter.TCL_VERSION) |
| 70 |
if "TK_LIBRARY" not in os.environ: |
| 71 |
v = os.path.join(prefix, 'tk'+ver) |
| 72 |
if os.path.exists(os.path.join(v, "tclIndex")): |
| 73 |
os.environ['TK_LIBRARY'] = v |
| 74 |
|
| 75 |
|
| 76 |
if "TIX_LIBRARY" not in os.environ: |
| 77 |
for name in os.listdir(prefix): |
| 78 |
if name.startswith("tix"): |
| 79 |
tixdir = os.path.join(prefix,name) |
| 80 |
if os.path.isdir(tixdir): |
| 81 |
os.environ["TIX_LIBRARY"] = tixdir |