chiark / gitweb /
Fixed a few issues with a frozen executable. Slicing now works, and images work....
authordaid <daid303@gmail.com>
Thu, 31 May 2012 16:37:59 +0000 (18:37 +0200)
committerdaid <daid303@gmail.com>
Thu, 31 May 2012 16:37:59 +0000 (18:37 +0200)
Cura/gui/preview3d.py
Cura/gui/toolbarUtil.py
Cura/setup.py
Cura/util/profile.py
Cura/util/sliceRun.py

index e9c73783ed8e762081a4923daea80bbbb9934812..49659d8510651eda137ceaa4f59dc3a31ddc026f 100644 (file)
@@ -361,6 +361,8 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
                        else:\r
                                self.offsetX += float(e.GetX() - self.oldX) * self.zoom / self.GetSize().GetHeight() * 2\r
                                self.offsetY -= float(e.GetY() - self.oldY) * self.zoom / self.GetSize().GetHeight() * 2\r
+                       \r
+                       #Workaround for buggy ATI cards.\r
                        size = self.GetSizeTuple()\r
                        self.SetSize((size[0]+1, size[1]))\r
                        self.SetSize((size[0], size[1]))\r
index a609aa6e8f42230d2136017541ba0c9457a1bc77..e49d77c45f39211d7cad3c33d3967c93e1a716d2 100644 (file)
@@ -12,6 +12,13 @@ from util import profile
 # toolbar buttons.
 #######################################################
 
+def getBitmapImage(filename):
+       #The frozen executable has the script files in a zip, so we need to exit another level to get to our images.
+       if hasattr(sys, 'frozen'):
+               return wx.Bitmap(os.path.normpath(os.path.join(os.path.split(__file__)[0], "../../images", filename)))
+       else:
+               return wx.Bitmap(os.path.normpath(os.path.join(os.path.split(__file__)[0], "../images", filename)))
+
 class Toolbar(wx.ToolBar):
        def __init__(self, parent):
                super(Toolbar, self).__init__(parent, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER)
@@ -52,8 +59,8 @@ class Toolbar(wx.ToolBar):
 class ToggleButton(buttons.GenBitmapToggleButton):
        def __init__(self, parent, profileSetting, bitmapFilenameOn, bitmapFilenameOff,
                                 helpText='', id=-1, callback=None, size=(20,20)):
-               self.bitmapOn = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOn))
-               self.bitmapOff = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOff))
+               self.bitmapOn = getBitmapImage(bitmapFilenameOn)
+               self.bitmapOff = getBitmapImage(bitmapFilenameOff)
 
                super(ToggleButton, self).__init__(parent, id, self.bitmapOff, size=size)
 
@@ -114,8 +121,8 @@ class ToggleButton(buttons.GenBitmapToggleButton):
 class RadioButton(buttons.GenBitmapButton):
        def __init__(self, parent, group, bitmapFilenameOn, bitmapFilenameOff,
                                 helpText='', id=-1, callback=None, size=(20,20)):
-               self.bitmapOn = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOn))
-               self.bitmapOff = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOff))
+               self.bitmapOn = getBitmapImage(bitmapFilenameOn)
+               self.bitmapOff = getBitmapImage(bitmapFilenameOff)
 
                super(RadioButton, self).__init__(parent, id, self.bitmapOff, size=size)
 
@@ -176,7 +183,7 @@ class RadioButton(buttons.GenBitmapButton):
 class NormalButton(buttons.GenBitmapButton):
        def __init__(self, parent, callback, bitmapFilename,
                                 helpText='', id=-1, size=(20,20)):
-               self.bitmap = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilename))
+               self.bitmap = getBitmapImage(bitmapFilename)
                super(NormalButton, self).__init__(parent, id, self.bitmap, size=size)
 
                self.helpText = helpText
index 104c1debae0f6d1dda56514c79a2229fd1318ca2..daca547fcfa4739feedad29f577d0cb3ab82a807 100644 (file)
@@ -7,7 +7,13 @@ sys.path.append('./cura_sf/')
 build_exe_options = {"packages": [
        'encodings.utf_8',
        "OpenGL", "OpenGL.arrays", "OpenGL.platform",
-], "excludes": [], "optimize": 0}
+], "excludes": [], "optimize": 0, "include_files": [
+       ('images', 'images'),
+       ('cura.py', 'cura.py'),
+       ('__init__.py', '__init__.py'),
+       ('util', 'util'),
+       ('cura_sf', 'cura_sf')
+]}
 
 # GUI applications require a different base on Windows (the default is for a
 # console application).
index 23e2888a0f005c02e227136cb04a671ef7cdea71..f223fef87efa261581cb3afd5e36be7d6f2e1e50 100644 (file)
@@ -3,7 +3,7 @@ from __future__ import division
 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.\r
 import __init__\r
 \r
-import ConfigParser, os, traceback, math, re, zlib, base64, time\r
+import ConfigParser, os, traceback, math, re, zlib, base64, time, sys\r
 \r
 #########################################################\r
 ## Default settings when none are found.\r
@@ -170,7 +170,11 @@ preferencesDefaultSettings = {
 \r
 ## Profile functions\r
 def getDefaultProfilePath():\r
-       return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../current_profile.ini"))\r
+       basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))\r
+       #If we have a frozen python install, we need to step out of the library.zip\r
+       if hasattr(sys, 'frozen'):\r
+               basePath = os.path.normpath(os.path.join(basePath, ".."))\r
+       return os.path.normpath(os.path.join(basePath, "current_profile.ini"))\r
 \r
 def loadGlobalProfile(filename):\r
        #Read a configuration file as global config\r
@@ -273,7 +277,8 @@ globalPreferenceParser = None
 \r
 def getPreferencePath():\r
        basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))\r
-       if os.path.basename(basePath) == 'library.zip':\r
+       #If we have a frozen python install, we need to step out of the library.zip\r
+       if hasattr(sys, 'frozen'):\r
                basePath = os.path.normpath(os.path.join(basePath, ".."))\r
        return os.path.normpath(os.path.join(basePath, "preferences.ini"))\r
 \r
index bc3b98f78e7ab6ca77962b9358b520d6f3d555f5..221003677458ba42c4458995dbf07716a70976cd 100644 (file)
@@ -85,7 +85,7 @@ def runSlice(fileNames):
                        print "* Failed to find pypy, so sliced with python!  *"
                        print "************************************************"
                else:
-                       subprocess.call([pypyExe, os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", os.path.split(sys.argv[0])[1])), '-p', profile.getGlobalProfileString(), fileName])
+                       subprocess.call(getSliceCommand(fileName))
 
 def getExportFilename(filename, ext = "gcode"):
        return "%s_export.%s" % (filename[: filename.rfind('.')], ext)
@@ -146,7 +146,13 @@ def getSliceCommand(filename):
                pypyExe = getPyPyExe()
                if pypyExe == False:
                        pypyExe = sys.executable
-               cmd = [pypyExe, os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", os.path.split(sys.argv[0])[1])), '-p', profile.getGlobalProfileString()]
+               
+               #In case we have a frozen exe, then argv[0] points to the executable, but we want to give pypy a real script file.
+               if hasattr(sys, 'frozen'):
+                       mainScriptFile = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "cura.py"))
+               else:
+                       mainScriptFile = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", os.path.split(sys.argv[0])[1]))
+               cmd = [pypyExe, mainScriptFile, '-p', profile.getGlobalProfileString()]
                cmd.append(filename)
                return cmd