From: daid Date: Tue, 29 May 2012 11:42:33 +0000 (+0200) Subject: Use a function to generate the "_export.xxx" filename X-Git-Tag: 12.07~44^2~13 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=eb449630791c94fae4d8b74feaf70a43bdacbe88;p=cura.git Use a function to generate the "_export.xxx" filename --- diff --git a/Cura/gui/mainWindow.py b/Cura/gui/mainWindow.py index d4b8f55f..450e2272 100644 --- a/Cura/gui/mainWindow.py +++ b/Cura/gui/mainWindow.py @@ -18,6 +18,7 @@ from gui import projectPlanner from gui import icon from util import profile from util import version +from util import sliceRun def main(): app = wx.App(False) @@ -333,10 +334,10 @@ class mainWindow(configBase.configWindowBase): if len(self.filelist) < 1: wx.MessageBox('You need to load a file and slice it before you can print it.', 'Print error', wx.OK | wx.ICON_INFORMATION) return - if not os.path.exists(self.filelist[0][: self.filelist[0].rfind('.')] + "_export.gcode"): + if not os.path.exists(sliceRun.getExportFilename(self.filelist[0])): wx.MessageBox('You need to slice the file to GCode before you can print it.', 'Print error', wx.OK | wx.ICON_INFORMATION) return - printWindow.printFile(self.filelist[0][: self.filelist[0].rfind('.')] + "_export.gcode") + printWindow.printFile(sliceRun.getExportFilename(self.filelist[0])) def OnExpertOpen(self, e): ecw = expertConfig.expertConfigWindow() diff --git a/Cura/gui/preview3d.py b/Cura/gui/preview3d.py index 43cb8c98..e9c73783 100644 --- a/Cura/gui/preview3d.py +++ b/Cura/gui/preview3d.py @@ -21,6 +21,7 @@ from util import profile from util import gcodeInterpreter from util import stl from util import util3d +from util import sliceRun class previewObject(): def __init__(self): @@ -207,8 +208,8 @@ class previewPanel(wx.Panel): self.logFileTime = None obj.filename = filelist[idx] - self.gcodeFilename = filelist[0][: filelist[0].rfind('.')] + "_export.gcode" - self.logFilename = filelist[0][: filelist[0].rfind('.')] + "_export.log" + self.gcodeFilename = sliceRun.getExportFilename(filelist[0]) + self.logFilename = sliceRun.getExportFilename(filelist[0], "log") #Do the STL file loading in a background thread so we don't block the UI. if self.loadThread != None and self.loadThread.isAlive(): self.loadThread.join() diff --git a/Cura/gui/projectPlanner.py b/Cura/gui/projectPlanner.py index 054fbe71..8096129c 100644 --- a/Cura/gui/projectPlanner.py +++ b/Cura/gui/projectPlanner.py @@ -893,7 +893,7 @@ class ProjectSliceProgressWindow(wx.Frame): profile.resetTempOverride() if not action.usePreviousSlice: - f = open(action.filename[: action.filename.rfind('.')] + "_export.project_tmp", "r") + f = open(sliceRun.getExportFilename(action.filename, "project_tmp"), "r") data = f.read(4096) while data != '': resultFile.write(data) @@ -902,7 +902,7 @@ class ProjectSliceProgressWindow(wx.Frame): savedCenterX = action.centerX savedCenterY = action.centerY else: - f = open(action.filename[: action.filename.rfind('.')] + "_export.project_tmp", "r") + f = open(sliceRun.getExportFilename(action.filename, "project_tmp"), "r") for line in f: if line[0] != ';': if 'X' in line: @@ -913,7 +913,7 @@ class ProjectSliceProgressWindow(wx.Frame): f.close() if not action.leaveResultForNextSlice: - os.remove(action.filename[: action.filename.rfind('.')] + "_export.project_tmp") + os.remove(sliceRun.getExportFilename(action.filename, "project_tmp")) wx.CallAfter(self.progressGauge.SetValue, 10000) self.totalDoneFactor = 0.0 diff --git a/Cura/gui/simpleMode.py b/Cura/gui/simpleMode.py index ffd2ac7c..ed885d67 100644 --- a/Cura/gui/simpleMode.py +++ b/Cura/gui/simpleMode.py @@ -14,6 +14,7 @@ from gui import printWindow from gui import icon from util import profile from util import version +from util import sliceRun class simpleModeWindow(configBase.configWindowBase): "Main user interface window for Quickprint mode" @@ -276,10 +277,10 @@ class simpleModeWindow(configBase.configWindowBase): if len(self.filelist) < 1: wx.MessageBox('You need to load a file and slice it before you can print it.', 'Print error', wx.OK | wx.ICON_INFORMATION) return - if not os.path.exists(self.filelist[0][: self.filelist[0].rfind('.')] + "_export.gcode"): + if not os.path.exists(sliceRun.getExportFilename(self.filelist[0])): wx.MessageBox('You need to slice the file to GCode before you can print it.', 'Print error', wx.OK | wx.ICON_INFORMATION) return - printWindow.printFile(self.filelist[0][: self.filelist[0].rfind('.')] + "_export.gcode") + printWindow.printFile(sliceRun.getExportFilename(self.filelist[0])) def OnNormalSwitch(self, e): from gui import mainWindow diff --git a/Cura/gui/sliceProgessPanel.py b/Cura/gui/sliceProgessPanel.py index d2240a56..344ea642 100644 --- a/Cura/gui/sliceProgessPanel.py +++ b/Cura/gui/sliceProgessPanel.py @@ -68,7 +68,7 @@ class sliceProgessPanel(wx.Panel): LogWindow('\n'.join(self.progressLog)) def OnOpenFileLocation(self, e): - exporer.openExporer(self.filelist[0][: self.filelist[0].rfind('.')] + "_export.gcode") + exporer.openExporer(sliceRun.getExportFilename(self.filelist[0])) def OnSliceDone(self, result): self.progressGauge.Destroy() @@ -145,7 +145,7 @@ class WorkerThread(threading.Thread): return line = p.stdout.readline() self.returnCode = p.wait() - logfile = open(self.filelist[self.fileIdx][: self.filelist[self.fileIdx].rfind('.')] + "_export.log", "w") + logfile = open(sliceRun.getExportFilename(self.filelist[self.fileIdx], "log"), "w") for logLine in self.progressLog: logfile.write(logLine) logfile.write('\n') @@ -155,19 +155,19 @@ class WorkerThread(threading.Thread): if len(self.filelist) > 1: self._stitchMultiExtruder() self.gcode = gcodeInterpreter.gcode() - self.gcode.load(self.filelist[0][:self.filelist[0].rfind('.')]+'_export.gcode') + self.gcode.load(sliceRun.getExportFilename(self.filelist[0])) wx.CallAfter(self.notifyWindow.OnSliceDone, self) else: self.run() def _stitchMultiExtruder(self): files = [] - resultFile = open(self.filelist[0][:self.filelist[0].rfind('.')]+'_export.gcode', "w") + resultFile = open(sliceRun.getExportFilename(self.filelist[0]), "w") resultFile.write(';TYPE:CUSTOM\n') resultFile.write(profile.getAlterationFileContents('start.gcode')) for filename in self.filelist: - if os.path.isfile(filename[:filename.rfind('.')]+'_export.multi_extrude_tmp'): - files.append(open(filename[:filename.rfind('.')]+'_export.multi_extrude_tmp', "r")) + if os.path.isfile(sliceRun.getExportFilename(filename, 'multi_extrude_tmp')): + files.append(open(sliceRun.getExportFilename(filename, 'multi_extrude_tmp'), "r")) else: return @@ -201,7 +201,7 @@ class WorkerThread(threading.Thread): for f in files: f.close() for filename in self.filelist: - os.remove(filename[:filename.rfind('.')]+'_export.multi_extrude_tmp') + os.remove(sliceRun.getExportFilename(filename, 'multi_extrude_tmp')) resultFile.write(';TYPE:CUSTOM\n') resultFile.write(profile.getAlterationFileContents('end.gcode')) resultFile.close() diff --git a/Cura/util/sliceRun.py b/Cura/util/sliceRun.py index 7c2ca547..47f585d0 100644 --- a/Cura/util/sliceRun.py +++ b/Cura/util/sliceRun.py @@ -83,6 +83,9 @@ def runSlice(fileNames): 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]) +def getExportFilename(filename, ext = "gcode"): + return "%s_export.%s" % (filename[: filename.rfind('.')], ext) + def getSliceCommand(filename): if profile.getPreference('slicer').startswith('Slic3r') and getSlic3rExe() != False: slic3rExe = getSlic3rExe()