home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2004 #2 / K-CD-2-2004.ISO / OpenOffice Sv / f_0397 / python-core-2.2.2 / lib / lib-tk / FixTk.py < prev    next >
Encoding:
Python Source  |  2003-07-18  |  1.2 KB  |  33 lines

  1. import sys, os
  2.  
  3. # Delay import _tkinter until we have set TCL_LIBRARY,
  4. # so that Tcl_FindExecutable has a chance to locate its
  5. # encoding directory.
  6.  
  7. # Unfortunately, we cannot know the TCL_LIBRARY directory
  8. # if we don't know the tcl version, which we cannot find out
  9. # without import Tcl. Fortunately, Tcl will itself look in
  10. # <TCL_LIBRARY>\..\tcl<TCL_VERSION>, so anything close to
  11. # the real Tcl library will do.
  12.  
  13. prefix = os.path.join(sys.prefix,"tcl")
  14. # if this does not exist, no further search is needed
  15. if os.path.exists(prefix):
  16.     if not os.environ.has_key("TCL_LIBRARY"):
  17.         for name in os.listdir(prefix):
  18.             if name.startswith("tcl"):
  19.                 tcldir = os.path.join(prefix,name)
  20.                 if os.path.isdir(tcldir):
  21.                     os.environ["TCL_LIBRARY"] = tcldir
  22.     # Now set the other variables accordingly
  23.     import _tkinter
  24.     ver = str(_tkinter.TCL_VERSION)
  25.     for t in "tk", "tix":
  26.         key = t.upper() + "_LIBRARY"
  27.         try:
  28.             v = os.environ[key]
  29.         except KeyError:
  30.             v = os.path.join(sys.prefix, "tcl", t+ver)
  31.             if os.path.exists(os.path.join(v, "tclIndex")):
  32.                 os.environ[key] = v
  33.