import platform
from optparse import OptionParser
+from util import profile
from util import sliceRun
__author__ = 'Daid'
__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:
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)
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
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)
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()
self.Close()
def OnClose(self, e):
- profile.saveGlobalProfile(profile.getDefaultProfilePath())
self.Destroy()
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:
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 = []
#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
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'):
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]