chiark / gitweb /
Improve the startup a bit, hide the splashscreen at a better timing and do not reload...
authordaid303 <daid303@gmail.com>
Thu, 25 Apr 2013 07:39:21 +0000 (09:39 +0200)
committerdaid303 <daid303@gmail.com>
Thu, 25 Apr 2013 07:39:21 +0000 (09:39 +0200)
Cura/cura.py
Cura/gui/app.py
Cura/gui/mainWindow.py
Cura/gui/sceneView.py
Cura/util/sliceEngine.py

index 73907642eff8eb18717d8978a5ebfb8126f7798f..e796e4b2b11b1d0918387371cdcd99b9bf49d7ca 100644 (file)
@@ -76,14 +76,8 @@ def main():
                        scene.add(m)
                slicer.runSlicer(scene)
        else:
-               #Place any unused arguments as last file, so Cura starts with opening those files.
-               if len(args) > 0:
-                       profile.putPreference('lastFile', ';'.join(args))
-                       profile.setPluginConfig([])
-
-               #Do not import anything from Cura.gui before this spot, as the above code also needs to run in pypy.
                from Cura.gui import app
-               app.CuraApp().MainLoop()
+               app.CuraApp(args).MainLoop()
 
 if __name__ == '__main__':
        main()
index c1618de70e76b176d13a14d3d93e4f9ea5357b89..02e84b712bee7b2b37cbaaf7af254a7a2a9df042 100644 (file)
@@ -11,7 +11,7 @@ import warnings
 import wx._core
 
 class CuraApp(wx.App):
-       def __init__(self):
+       def __init__(self, files):
                if platform.system() == "Windows" and not 'PYCHARM_HOSTED' in os.environ:
                        super(CuraApp, self).__init__(redirect = True, filename = 'output.txt')
                else:
@@ -19,6 +19,7 @@ class CuraApp(wx.App):
 
                self.mainWindow = None
                self.splash = None
+               self.loadFiles = files
 
                if sys.platform.startswith('darwin'):
                        #Do not show a splashscreen on OSX, as by Apple guidelines
@@ -29,7 +30,7 @@ class CuraApp(wx.App):
 
        def MacOpenFile(self, path):
                try:
-                       self.mainWindow._loadModels([path])
+                       self.mainWindow.OnDropFiles([path])
                except Exception as e:
                        warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e)))
 
@@ -44,7 +45,9 @@ class CuraApp(wx.App):
 
                #If we haven't run it before, run the configuration wizard.
                if profile.getPreference('machine_type') == 'unknown':
-                       if platform.system() == "Darwin":
+                       if platform.system() == "Windows":
+                               exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'UltimakerRobot_support.stl'))
+                       else:
                                #Check if we need to copy our examples
                                exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
                                if not os.path.isfile(exampleFile):
@@ -54,19 +57,24 @@ class CuraApp(wx.App):
                                                pass
                                        for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
                                                shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
-                                       profile.putPreference('lastFile', exampleFile)
+                       self.loadFiles = [exampleFile]
+                       if self.splash is not None:
+                               self.splash.Show(False)
                        configWizard.configWizard()
 
-               #Hide the splashscreen before showing the main window.
-               if self.splash is not None:
-                       self.splash.Show(False)
                if profile.getPreference('check_for_updates') == 'True':
                        newVersion = version.checkForNewerVersion()
                        if newVersion is not None:
+                               if self.splash is not None:
+                                       self.splash.Show(False)
                                if wx.MessageBox('A new version of Cura is available, would you like to download?', 'New version available', wx.YES_NO | wx.ICON_INFORMATION) == wx.YES:
                                        webbrowser.open(newVersion)
                                        return
                self.mainWindow = mainWindow.mainWindow()
+               if self.splash is not None:
+                       self.splash.Show(False)
+               self.mainWindow.Show()
+               self.mainWindow.OnDropFiles(self.loadFiles)
 
                setFullScreenCapable(self.mainWindow)
 
index 3aeadb703b7fc9b752971690819e118ef72a8b4d..f2790865da1d35b67edbf00a7516d4d88f451caf 100644 (file)
@@ -141,11 +141,6 @@ class mainWindow(wx.Frame):
                self.menubar.Append(helpMenu, 'Help')
                self.SetMenuBar(self.menubar)
 
-               if profile.getPreference('lastFile') != '':
-                       self.filelist = profile.getPreference('lastFile').split(';')
-               else:
-                       self.filelist = []
-
                self.splitter = wx.SplitterWindow(self, style = wx.SP_3D | wx.SP_LIVE_UPDATE)
                self.leftPane = wx.Panel(self.splitter, style=wx.BORDER_NONE)
                self.rightPane = wx.Panel(self.splitter, style=wx.BORDER_NONE)
@@ -175,13 +170,6 @@ class mainWindow(wx.Frame):
                sizer.Layout()
                self.sizer = sizer
 
-               if len(self.filelist) > 0:
-                       self.scene.loadScene(self.filelist)
-
-                       # Update the Model MRU
-                       for idx in xrange(0, len(self.filelist)):
-                               self.addToModelMRU(self.filelist[idx])
-
                self.updateProfileToControls()
 
                self.SetBackgroundColour(self.normalSettingsPanel.GetBackgroundColour())
@@ -226,8 +214,6 @@ class mainWindow(wx.Frame):
 
                self.updateSliceMode()
 
-               self.Show(True)
-
        def updateSliceMode(self):
                isSimple = profile.getPreference('startMode') == 'Simple'
 
index cfde7ff2e50445a7f9d9509c5ec343cccac17a88..be6cf6dff0de81754466f7536b552d0c3bfa11c6 100644 (file)
@@ -362,6 +362,9 @@ class SceneView(openglGui.glGuiPanel):
                                        self.glReleaseList.append(vbo)
                        self._gcodeVBOs = []
                if ready:
+                       print self._slicer.getFilamentAmount()
+                       print self._slicer.getPrintTime()
+                       print self._slicer.getFilamentCost()
                        self._gcode = gcodeInterpreter.gcode()
                        self._gcode.progressCallback = self._gcodeLoadCallback
                        self._thread = threading.Thread(target=self._loadGCode)
index 348822cafbb7c14881d08c04943013c1d24ce306..10d697fda88ccbad16fa763e6b68960d6479ea44 100644 (file)
@@ -1,5 +1,6 @@
 import subprocess
 import time
+import math
 import numpy
 import os
 import warnings
@@ -35,6 +36,8 @@ class Slicer(object):
                self._progressSteps = ['inset', 'skin', 'export']
                self._objCount = 0
                self._sliceLog = []
+               self._printTimeSeconds = None
+               self._filamentMM = None
 
        def cleanup(self):
                self.abortSlicer()
@@ -61,6 +64,29 @@ class Slicer(object):
        def getSliceLog(self):
                return self._sliceLog
 
+       def getFilamentWeight(self):
+               #Calculates the weight of the filament in kg
+               radius = float(profile.getProfileSetting('filament_diameter')) / 2
+               volumeM3 = (self._filamentMM * (math.pi * radius * radius)) / (1000*1000*1000)
+               return volumeM3 * profile.getPreferenceFloat('filament_physical_density')
+
+       def getFilamentCost(self):
+               cost_kg = profile.getPreferenceFloat('filament_cost_kg')
+               cost_meter = profile.getPreferenceFloat('filament_cost_meter')
+               if cost_kg > 0.0 and cost_meter > 0.0:
+                       return "%.2f / %.2f" % (self.getFilamentWeight() * cost_kg, self._filamentMM / 1000.0 * cost_meter)
+               elif cost_kg > 0.0:
+                       return "%.2f" % (self.getFilamentWeight() * cost_kg)
+               elif cost_meter > 0.0:
+                       return "%.2f" % (self._filamentMM / 1000.0 * cost_meter)
+               return None
+
+       def getPrintTime(self):
+               return '%02d:%02d' % (int(self._printTimeSeconds / 60 / 60), int(self._printTimeSeconds / 60) % 60)
+
+       def getFilamentAmount(self):
+               return '%0.2fm' % (float(self._filamentMM) / 1000.0)
+
        def runSlicer(self, scene):
                self.abortSlicer()
                self._callback(0.0, False)
@@ -118,6 +144,9 @@ class Slicer(object):
        def _watchProcess(self):
                self._callback(0.0, False)
                self._sliceLog = []
+               self._printTimeSeconds = None
+               self._filamentMM = None
+
                line = self._process.stdout.readline()
                objectNr = 0
                while len(line):
@@ -137,6 +166,10 @@ class Slicer(object):
                                                self._callback(progressValue, False)
                                        except:
                                                pass
+                       elif line.startswith('Print time:'):
+                               self._printTimeSeconds = int(line.split(':')[1].strip())
+                       elif line.startswith('Filament:'):
+                               self._filamentMM = int(line.split(':')[1].strip())
                        else:
                                self._sliceLog.append(line.strip())
                        line = self._process.stdout.readline()