From: daid Date: Fri, 30 Mar 2012 11:54:49 +0000 (+0200) Subject: No longer use the current_profile.ini to share the profile between the backend slicer... X-Git-Tag: RC1~14^2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=88337f167546023c6ae0de6065c94a41fbfe7abd;p=cura.git No longer use the current_profile.ini to share the profile between the backend slicer and the frontend. No longer have simple-mode overwrite the current profile from normal mode. --- diff --git a/Cura/cura.py b/Cura/cura.py index 4de0ed12..2d2d7e43 100644 --- a/Cura/cura.py +++ b/Cura/cura.py @@ -16,6 +16,7 @@ import sys import platform from optparse import OptionParser +from util import profile from util import sliceRun __author__ = 'Daid' @@ -43,9 +44,11 @@ Art of Illusion """ __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' def main(): - parser = OptionParser() + parser = OptionParser(usage="usage: %prog [options] .stl") + parser.add_option("-p", "--profile", action="store", type="string", dest="profile", help="Use these profile settings instead of loading current_profile.ini") (options, args) = parser.parse_args() - sys.argv = [sys.argv[0]] + args + if options.profile != None: + profile.loadGlobalProfileFromString(options.profile) if len( args ) > 0: sliceRun.runSlice(args) else: diff --git a/Cura/gui/mainWindow.py b/Cura/gui/mainWindow.py index 9839d409..d0c30d78 100644 --- a/Cura/gui/mainWindow.py +++ b/Cura/gui/mainWindow.py @@ -265,8 +265,6 @@ class mainWindow(configBase.configWindowBase): def OnSlice(self, e): if self.filename == None: return - profile.saveGlobalProfile(profile.getDefaultProfilePath()) - #Create a progress panel and add it to the window. The progress panel will start the Skein operation. spp = sliceProgessPanel.sliceProgessPanel(self, self, self.filename) self.sizer.Add(spp, (len(self.progressPanelList)+2,0), span=(1,4), flag=wx.EXPAND) diff --git a/Cura/gui/simpleMode.py b/Cura/gui/simpleMode.py index 02905c61..e2a6d91e 100644 --- a/Cura/gui/simpleMode.py +++ b/Cura/gui/simpleMode.py @@ -162,6 +162,9 @@ class simpleModeWindow(configBase.configWindowBase): def OnSlice(self, e): if self.filename == None: return + #save the current profile so we can put it back latter + oldProfile = profile.getGlobalProfileString() + put = profile.putProfileSetting get = profile.getProfileSetting @@ -247,8 +250,6 @@ class simpleModeWindow(configBase.configWindowBase): put('enable_raft', 'True') put('skirt_line_count', '0') - profile.saveGlobalProfile(profile.getDefaultProfilePath()) - #Create a progress panel and add it to the window. The progress panel will start the Skein operation. spp = sliceProgessPanel.sliceProgessPanel(self, self, self.filename) self.sizer.Add(spp, (len(self.progressPanelList)+2,0), span=(1,4), flag=wx.EXPAND) @@ -257,6 +258,9 @@ class simpleModeWindow(configBase.configWindowBase): newSize.IncBy(0, spp.GetSize().GetHeight()) self.SetSize(newSize) self.progressPanelList.append(spp) + + #Restore the old profile. + profile.loadGlobalProfileFromString(oldProfile) def OnPrint(self, e): printWindow.printWindow() @@ -286,5 +290,4 @@ class simpleModeWindow(configBase.configWindowBase): self.Close() def OnClose(self, e): - profile.saveGlobalProfile(profile.getDefaultProfilePath()) self.Destroy() diff --git a/Cura/gui/sliceProgessPanel.py b/Cura/gui/sliceProgessPanel.py index 5854060e..bdf2e82e 100644 --- a/Cura/gui/sliceProgessPanel.py +++ b/Cura/gui/sliceProgessPanel.py @@ -57,7 +57,8 @@ class sliceProgessPanel(wx.Panel): self.prevStep = 'start' self.totalDoneFactor = 0.0 self.startTime = time.time() - self.thread = WorkerThread(self, filename) + p = subprocess.Popen(sliceRun.getSliceCommand(self.filename), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + self.thread = WorkerThread(self, filename, p) def OnAbort(self, e): if self.abort: @@ -108,14 +109,15 @@ class sliceProgessPanel(wx.Panel): self.statusText.SetLabel(stepName + " [" + str(layer) + "/" + str(maxLayer) + "]") class WorkerThread(threading.Thread): - def __init__(self, notifyWindow, filename): + def __init__(self, notifyWindow, filename, process): threading.Thread.__init__(self) self.filename = filename self.notifyWindow = notifyWindow + self.process = process self.start() def run(self): - p = subprocess.Popen(sliceRun.getSliceCommand(self.filename), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + p = self.process line = p.stdout.readline() maxValue = 1 self.progressLog = [] diff --git a/Cura/util/profile.py b/Cura/util/profile.py index daa82541..8ab00bd3 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -85,10 +85,23 @@ def saveGlobalProfile(filename): #Save the current profile to an ini file globalProfileParser.write(open(filename, 'w')) -def resetGlobalProfile(): - #Create an empty profile with no settings, so everything gets default settings. +def loadGlobalProfileFromString(options): global globalProfileParser globalProfileParser = ConfigParser.ConfigParser() + globalProfileParser.add_section('profile') + for option in options.split('#'): + (key, value) = option.split('=', 1) + globalProfileParser.set('profile', key, value) + +def getGlobalProfileString(): + global globalProfileParser + if not globals().has_key('globalProfileParser'): + loadGlobalProfile(getDefaultProfilePath()) + + ret = [] + for key in globalProfileParser.options('profile'): + ret.append(key + "=" + globalProfileParser.get('profile', key)) + return '#'.join(ret) def getProfileSetting(name): if name in profileDefaultSettings: diff --git a/Cura/util/sliceRun.py b/Cura/util/sliceRun.py index e18fb98a..4813f359 100644 --- a/Cura/util/sliceRun.py +++ b/Cura/util/sliceRun.py @@ -58,7 +58,7 @@ def runSlice(fileNames): print "* Failed to find pypy, so sliced with python! *" print "************************************************" else: - subprocess.call([pypyExe, os.path.join(sys.path[0], sys.argv[0]), fileName]) + 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 getSliceCommand(filename): if profile.getPreference('slicer').startswith('Slic3r'): @@ -116,5 +116,5 @@ def getSliceCommand(filename): pypyExe = getPyPyExe() if pypyExe == False: pypyExe = sys.executable - return [pypyExe, os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", os.path.split(sys.argv[0])[1])), filename] + return [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]