1. Anthony Tuininga
  2. cx_Freeze

Commits

Anthony Tuininga  committed 67c078f

Add support for copying files when modules are included which require data
files to operate properly; add support for copying the necessary files for the
Tkinter module.

  • Participants
  • Parent commits 5c2cb99
  • Branches default

Comments (0)

Files changed (3)

File cx_Freeze/finder.py

View file
  • Ignore whitespace
 
 class ModuleFinder(object):
 
-    def __init__(self, excludes = [], path = None, replacePaths = []):
+    def __init__(self, includeFiles, excludes, path, replacePaths):
+        self.includeFiles = includeFiles
         self.excludes = dict.fromkeys(excludes)
         self.replacePaths = replacePaths
         self.path = path or sys.path
         self._ImportDeferredImports(deferredImports)
         return module
 
+    def IncludeFiles(self, sourcePath, targetPath):
+        """Include the files in the given directory in the target build."""
+        self.includeFiles.append((sourcePath, targetPath))
+
     def IncludeModule(self, name):
         """Include the named module in the frozen executable."""
         deferredImports = []

File cx_Freeze/freezer.py

View file
  • Ignore whitespace
     def _GetModuleFinder(self, argsSource = None):
         if argsSource is None:
             argsSource = self
-        finder = cx_Freeze.ModuleFinder(argsSource.excludes, argsSource.path,
-                argsSource.replacePaths)
+        finder = cx_Freeze.ModuleFinder(self.includeFiles, argsSource.excludes,
+                argsSource.path, argsSource.replacePaths)
         if argsSource.copyDependentFiles:
             finder.IncludeModule("imp")
             finder.IncludeModule("os")

File cx_Freeze/hooks.py

View file
  • Ignore whitespace
             pass
 
 
+def load_Tkinter(finder, module):
+    """the Tkinter module has data files that are required to be loaded so
+       ensure that they are copied into the directory that is expected at
+       runtime."""
+    import Tkinter
+    import _tkinter
+    tk = _tkinter.create()
+    tclDir = os.path.dirname(tk.call("info", "library"))
+    tclSourceDir = os.path.join(tclDir, "tcl%s" % _tkinter.TCL_VERSION)
+    tkSourceDir = os.path.join(tclDir, "tk%s" % _tkinter.TK_VERSION)
+    finder.IncludeFiles(tclSourceDir, "tcl")
+    finder.IncludeFiles(tkSourceDir, "tk")
+
+
 def load_tempfile(finder, module):
     """the tempfile module attempts to load the fcntl and thread modules but
        continues if these modules cannot be found; ignore these modules if they