chiark / gitweb /
No longer use the current_profile.ini to share the profile between the backend slicer...
authordaid <daid303@gmail.com>
Fri, 30 Mar 2012 11:54:49 +0000 (13:54 +0200)
committerdaid <daid303@gmail.com>
Fri, 30 Mar 2012 11:54:49 +0000 (13:54 +0200)
Cura/cura.py
Cura/gui/mainWindow.py
Cura/gui/simpleMode.py
Cura/gui/sliceProgessPanel.py
Cura/util/profile.py
Cura/util/sliceRun.py

index 4de0ed12122e285797165b350acd414aedade29a..2d2d7e43eb94552ed0d0f93b60732e9ed4f4c5e3 100644 (file)
@@ -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 <http://www.artofillusion.org/>"""
 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
 
 def main():
-       parser = OptionParser()
+       parser = OptionParser(usage="usage: %prog [options] <filename>.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:
index 9839d409c096699e46fbdbc6ae12d6a93f0ec7f0..d0c30d7893c2b62b8b94e3e01048db9b08601653 100644 (file)
@@ -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)
index 02905c615409d593083b491e256ddccfbb92fc08..e2a6d91e0525e424287b813ea7777a9e03d7a75c 100644 (file)
@@ -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()
index 5854060ee48a8fa1dfe8fcd18fb73952a727f601..bdf2e82e0c01a3bd19cecc820aeae7c28bb786e4 100644 (file)
@@ -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 = []
index daa825412f146446cfb190b27e5ccdeac7c02e83..8ab00bd32ca21b22ca68543396f66af4586ecfbb 100644 (file)
@@ -85,10 +85,23 @@ def saveGlobalProfile(filename):
        #Save the current profile to an ini file\r
        globalProfileParser.write(open(filename, 'w'))\r
 \r
-def resetGlobalProfile():\r
-       #Create an empty profile with no settings, so everything gets default settings.\r
+def loadGlobalProfileFromString(options):\r
        global globalProfileParser\r
        globalProfileParser = ConfigParser.ConfigParser()\r
+       globalProfileParser.add_section('profile')\r
+       for option in options.split('#'):\r
+               (key, value) = option.split('=', 1)\r
+               globalProfileParser.set('profile', key, value)\r
+\r
+def getGlobalProfileString():\r
+       global globalProfileParser\r
+       if not globals().has_key('globalProfileParser'):\r
+               loadGlobalProfile(getDefaultProfilePath())\r
+       \r
+       ret = []\r
+       for key in globalProfileParser.options('profile'):\r
+               ret.append(key + "=" + globalProfileParser.get('profile', key))\r
+       return '#'.join(ret)\r
 \r
 def getProfileSetting(name):\r
        if name in profileDefaultSettings:\r
index e18fb98af8d780bdee1d4592dfab5c4f2cc4f27f..4813f359f2cdbcb38390edf6a5b93f4e00fe5660 100644 (file)
@@ -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]