From: daid Date: Thu, 31 May 2012 16:37:59 +0000 (+0200) Subject: Fixed a few issues with a frozen executable. Slicing now works, and images work.... X-Git-Tag: 12.07~44^2~9 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a9ed30067535c7f33fab993219568ceb3e96d59d;p=cura.git Fixed a few issues with a frozen executable. Slicing now works, and images work. Will need more testing. --- diff --git a/Cura/gui/preview3d.py b/Cura/gui/preview3d.py index e9c73783..49659d85 100644 --- a/Cura/gui/preview3d.py +++ b/Cura/gui/preview3d.py @@ -361,6 +361,8 @@ class PreviewGLCanvas(glcanvas.GLCanvas): else: self.offsetX += float(e.GetX() - self.oldX) * self.zoom / self.GetSize().GetHeight() * 2 self.offsetY -= float(e.GetY() - self.oldY) * self.zoom / self.GetSize().GetHeight() * 2 + + #Workaround for buggy ATI cards. size = self.GetSizeTuple() self.SetSize((size[0]+1, size[1])) self.SetSize((size[0], size[1])) diff --git a/Cura/gui/toolbarUtil.py b/Cura/gui/toolbarUtil.py index a609aa6e..e49d77c4 100644 --- a/Cura/gui/toolbarUtil.py +++ b/Cura/gui/toolbarUtil.py @@ -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 diff --git a/Cura/setup.py b/Cura/setup.py index 104c1deb..daca547f 100644 --- a/Cura/setup.py +++ b/Cura/setup.py @@ -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). diff --git a/Cura/util/profile.py b/Cura/util/profile.py index 23e2888a..f223fef8 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -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. import __init__ -import ConfigParser, os, traceback, math, re, zlib, base64, time +import ConfigParser, os, traceback, math, re, zlib, base64, time, sys ######################################################### ## Default settings when none are found. @@ -170,7 +170,11 @@ preferencesDefaultSettings = { ## Profile functions def getDefaultProfilePath(): - return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../current_profile.ini")) + basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) + #If we have a frozen python install, we need to step out of the library.zip + if hasattr(sys, 'frozen'): + basePath = os.path.normpath(os.path.join(basePath, "..")) + return os.path.normpath(os.path.join(basePath, "current_profile.ini")) def loadGlobalProfile(filename): #Read a configuration file as global config @@ -273,7 +277,8 @@ globalPreferenceParser = None def getPreferencePath(): basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) - if os.path.basename(basePath) == 'library.zip': + #If we have a frozen python install, we need to step out of the library.zip + if hasattr(sys, 'frozen'): basePath = os.path.normpath(os.path.join(basePath, "..")) return os.path.normpath(os.path.join(basePath, "preferences.ini")) diff --git a/Cura/util/sliceRun.py b/Cura/util/sliceRun.py index bc3b98f7..22100367 100644 --- a/Cura/util/sliceRun.py +++ b/Cura/util/sliceRun.py @@ -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