chiark / gitweb /
Merge pull request #601 from CapnBry/reloadscene
[cura.git] / Cura / gui / mainWindow.py
index 7efb631dce2ce73df98b788b3a9ff4c366071e8a..d193bd4692a846ffb0c103c0d8f3421b0629bbba 100644 (file)
@@ -1,9 +1,10 @@
-from __future__ import absolute_import
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import wx
 import os
 import webbrowser
+import sys
+
 
 from Cura.gui import configBase
 from Cura.gui import expertConfig
@@ -32,6 +33,16 @@ class mainWindow(wx.Frame):
                # allow dropping any file, restrict later
                self.SetDropTarget(dropTarget.FileDropTarget(self.OnDropFiles))
 
+               # TODO: wxWidgets 2.9.4 has a bug when NSView does not register for dragged types when wx drop target is set. It was fixed in 2.9.5
+               if sys.platform.startswith('darwin'):
+                       try:
+                               import objc
+                               nswindow = objc.objc_object(c_void_p=self.MacGetTopLevelWindowRef())
+                               view = nswindow.contentView()
+                               view.registerForDraggedTypes_([u'NSFilenamesPboardType'])
+                       except:
+                               pass
+
                self.normalModeOnlyItems = []
 
                mruFile = os.path.join(profile.getBasePath(), 'mru_filelist.ini')
@@ -55,16 +66,18 @@ class mainWindow(wx.Frame):
                self.Bind(wx.EVT_MENU, lambda e: self.scene.showLoadModel(), i)
                i = self.fileMenu.Append(-1, _("Save model...\tCTRL+S"))
                self.Bind(wx.EVT_MENU, lambda e: self.scene.showSaveModel(), i)
+               i = self.fileMenu.Append(-1, _("Reload platform\tF5"))
+               self.Bind(wx.EVT_MENU, lambda e: self.scene.reloadScene(e), i)
                i = self.fileMenu.Append(-1, _("Clear platform"))
                self.Bind(wx.EVT_MENU, lambda e: self.scene.OnDeleteAll(e), i)
 
                self.fileMenu.AppendSeparator()
                i = self.fileMenu.Append(-1, _("Print...\tCTRL+P"))
-               self.Bind(wx.EVT_MENU, lambda e: self.scene.showPrintWindow(), i)
+               self.Bind(wx.EVT_MENU, lambda e: self.scene.OnPrintButton(1), i)
                i = self.fileMenu.Append(-1, _("Save GCode..."))
                self.Bind(wx.EVT_MENU, lambda e: self.scene.showSaveGCode(), i)
                i = self.fileMenu.Append(-1, _("Show slice engine log..."))
-               self.Bind(wx.EVT_MENU, lambda e: self.scene._showSliceLog(), i)
+               self.Bind(wx.EVT_MENU, lambda e: self.scene._showEngineLog(), i)
 
                self.fileMenu.AppendSeparator()
                i = self.fileMenu.Append(-1, _("Open Profile..."))
@@ -122,6 +135,17 @@ class mainWindow(wx.Frame):
 
                i = toolsMenu.Append(-1, _("Copy profile to clipboard"))
                self.Bind(wx.EVT_MENU, self.onCopyProfileClipboard,i)
+
+               toolsMenu.AppendSeparator()
+               self.allAtOnceItem = toolsMenu.Append(-1, _("Print all at once"), kind=wx.ITEM_RADIO)
+               self.Bind(wx.EVT_MENU, self.onOneAtATimeSwitch, self.allAtOnceItem)
+               self.oneAtATime = toolsMenu.Append(-1, _("Print one at a time"), kind=wx.ITEM_RADIO)
+               self.Bind(wx.EVT_MENU, self.onOneAtATimeSwitch, self.oneAtATime)
+               if profile.getPreference('oneAtATime') == 'True':
+                       self.oneAtATime.Check(True)
+               else:
+                       self.allAtOnceItem.Check(True)
+
                self.menubar.Append(toolsMenu, _("Tools"))
 
                #Machine menu for machine configuration/tooling
@@ -245,6 +269,7 @@ class mainWindow(wx.Frame):
                        self.Centre()
 
                self.updateSliceMode()
+               self.scene.SetFocus()
 
        def onTimer(self, e):
                #Check if there is something in the clipboard
@@ -309,6 +334,15 @@ class mainWindow(wx.Frame):
                if int(profile.getMachineSetting('extruder_amount')) < 2:
                        self.headOffsetWizardMenuItem.Enable(False)
                self.scene.updateProfileToControls()
+               self.scene._scene.pushFree()
+
+       def onOneAtATimeSwitch(self, e):
+               profile.putPreference('oneAtATime', self.oneAtATime.IsChecked())
+               if self.oneAtATime.IsChecked() and profile.getMachineSettingFloat('extruder_head_size_height') < 1:
+                       wx.MessageBox(_('For "One at a time" printing, you need to have entered the correct head size and gantry height in the machine settings'), _('One at a time warning'), wx.OK | wx.ICON_WARNING)
+               self.scene.updateProfileToControls()
+               self.scene._scene.pushFree()
+               self.scene.sceneUpdated()
 
        def OnPreferences(self, e):
                prefDialog = preferencesDialog.preferencesDialog(self)
@@ -325,7 +359,6 @@ class mainWindow(wx.Frame):
 
        def OnDropFiles(self, files):
                if len(files) > 0:
-                       profile.setPluginConfig([])
                        self.updateProfileToAllControls()
                self.scene.loadFiles(files)
 
@@ -535,7 +568,7 @@ class mainWindow(wx.Frame):
                aboutBox.Show()
 
        def OnClose(self, e):
-               profile.saveProfile(profile.getDefaultProfilePath())
+               profile.saveProfile(profile.getDefaultProfilePath(), True)
 
                # Save the window position, size & state from the preferences file
                profile.putPreference('window_maximized', self.IsMaximized())
@@ -556,7 +589,7 @@ class mainWindow(wx.Frame):
                #HACK: Set the paint function of the glCanvas to nothing so it won't keep refreshing. Which can keep wxWidgets from quiting.
                print "Closing down"
                self.scene.OnPaint = lambda e : e
-               self.scene._slicer.cleanup()
+               self.scene._engine.cleanup()
                self.Destroy()
 
        def OnQuit(self, e):