chiark / gitweb /
Merge tag '15.02.1' into upstream
[cura.git] / Cura / gui / mainWindow.py
index d6e75b4b63c7eb16eea27e01b17404af86dfa50e..fbab3ac25ca6561221dc71b7af06c245857a7388 100644 (file)
@@ -25,7 +25,11 @@ from Cura.util import version
 import platform
 from Cura.util import meshLoader
 
-from wx.lib.pubsub import Publisher
+try:
+       #MacOS release currently lacks some wx components, like the Publisher.
+       from wx.lib.pubsub import Publisher
+except:
+       Publisher = None
 
 class mainWindow(wx.Frame):
        def __init__(self):
@@ -89,6 +93,10 @@ class mainWindow(wx.Frame):
                i = self.fileMenu.Append(-1, _("Save Profile..."))
                self.normalModeOnlyItems.append(i)
                self.Bind(wx.EVT_MENU, self.OnSaveProfile, i)
+               if version.isDevVersion():
+                       i = self.fileMenu.Append(-1, "Save difference from default...")
+                       self.normalModeOnlyItems.append(i)
+                       self.Bind(wx.EVT_MENU, self.OnSaveDifferences, i)
                i = self.fileMenu.Append(-1, _("Load Profile from GCode..."))
                self.normalModeOnlyItems.append(i)
                self.Bind(wx.EVT_MENU, self.OnLoadProfileFromGcode, i)
@@ -138,8 +146,8 @@ class mainWindow(wx.Frame):
                        i = toolsMenu.Append(-1, _("Auto Firmware Update..."))
                        self.Bind(wx.EVT_MENU, self.OnAutoFirmwareUpdate, i)
 
-               i = toolsMenu.Append(-1, _("Copy profile to clipboard"))
-               self.Bind(wx.EVT_MENU, self.onCopyProfileClipboard,i)
+               #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)
@@ -237,7 +245,7 @@ class mainWindow(wx.Frame):
                #Timer set; used to check if profile is on the clipboard
                self.timer = wx.Timer(self)
                self.Bind(wx.EVT_TIMER, self.onTimer)
-               self.timer.Start(1000)
+               #self.timer.Start(1000)
                self.lastTriedClipboard = profile.getProfileString()
 
                # Restore the window position, size & state from the preferences file
@@ -274,7 +282,15 @@ class mainWindow(wx.Frame):
                self.updateSliceMode()
                self.scene.SetFocus()
                self.dialogframe = None
-               Publisher().subscribe(self.onPluginUpdate, "pluginupdate")
+               if Publisher is not None:
+                       Publisher().subscribe(self.onPluginUpdate, "pluginupdate")
+
+               pluginCount = self.normalSettingsPanel.pluginPanel.GetActivePluginCount()
+               if pluginCount == 1:
+                       self.scene.notification.message("Warning: 1 plugin from the previous session is still active.")
+
+               if pluginCount > 1:
+                       self.scene.notification.message("Warning: %i plugins from the previous session are still active." % pluginCount)
 
        def onPluginUpdate(self,msg): #receives commands from the plugin thread
                cmd = str(msg.data).split(";")
@@ -330,7 +346,7 @@ class mainWindow(wx.Frame):
                        print "Unable to read from clipboard"
 
 
-       def updateSliceMode(self):
+       def updateSliceMode(self, changedMode = True):
                isSimple = profile.getPreference('startMode') == 'Simple'
 
                self.normalSettingsPanel.Show(not isSimple)
@@ -346,8 +362,10 @@ class mainWindow(wx.Frame):
 
                # Set splitter sash position & size
                if isSimple:
-                       # Save normal mode sash
-                       self.normalSashPos = self.splitter.GetSashPosition()
+                       # Save normal mode sash (only if we changed mode from normal
+                       # to simple)
+                       if changedMode:
+                               self.normalSashPos = self.splitter.GetSashPosition()
 
                        # Change location of sash to width of quick mode pane
                        (width, height) = self.simpleSettingsPanel.GetSizer().GetSize()
@@ -356,11 +374,14 @@ class mainWindow(wx.Frame):
                        # Disable sash
                        self.splitter.SetSashSize(0)
                else:
-                       self.splitter.SetSashPosition(self.normalSashPos, True)
+                       # Only change the sash position if we changed mode from simple
+                       if changedMode:
+                               self.splitter.SetSashPosition(self.normalSashPos, True)
                        # Enabled sash
                        self.splitter.SetSashSize(4)
                self.defaultFirmwareInstallMenuItem.Enable(firmwareInstall.getDefaultFirmware() is not None)
-               if profile.getMachineSetting('machine_type') == 'ultimaker2' or profile.getMachineSetting('machine_type') == 'lulzbot_mini' or profile.getMachineSetting('machine_type') == 'lulzbot_TAZ':
+               if profile.getMachineSetting('machine_type').startswith('ultimaker2') or \
+                  profile.getMachineSetting('machine_type').startswith('lulzbot_'):
                        self.bedLevelWizardMenuItem.Enable(False)
                        self.headOffsetWizardMenuItem.Enable(False)
                else:
@@ -384,7 +405,6 @@ class mainWindow(wx.Frame):
                prefDialog.Centre()
                prefDialog.Show()
                prefDialog.Raise()
-               wx.CallAfter(prefDialog.Show)
 
        def OnMachineSettings(self, e):
                prefDialog = preferencesDialog.machineSettingsDialog(self)
@@ -393,8 +413,6 @@ class mainWindow(wx.Frame):
                prefDialog.Raise()
 
        def OnDropFiles(self, files):
-               if len(files) > 0:
-                       self.updateProfileToAllControls()
                self.scene.loadFiles(files)
 
        def OnModelMRU(self, e):
@@ -439,7 +457,7 @@ class mainWindow(wx.Frame):
                self.normalSettingsPanel.updateProfileToControls()
                self.simpleSettingsPanel.updateProfileToControls()
 
-       def reloadSettingPanels(self):
+       def reloadSettingPanels(self, changedSliceMode = False):
                self.leftSizer.Detach(self.simpleSettingsPanel)
                self.leftSizer.Detach(self.normalSettingsPanel)
                self.simpleSettingsPanel.Destroy()
@@ -448,7 +466,7 @@ class mainWindow(wx.Frame):
                self.normalSettingsPanel = normalSettingsPanel(self.leftPane, lambda : self.scene.sceneUpdated())
                self.leftSizer.Add(self.simpleSettingsPanel, 1)
                self.leftSizer.Add(self.normalSettingsPanel, 1, wx.EXPAND)
-               self.updateSliceMode()
+               self.updateSliceMode(changedSliceMode)
                self.updateProfileToAllControls()
 
        def updateMachineMenu(self):
@@ -513,10 +531,20 @@ class mainWindow(wx.Frame):
                dlg=wx.FileDialog(self, _("Select profile file to save"), os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_SAVE)
                dlg.SetWildcard("ini files (*.ini)|*.ini")
                if dlg.ShowModal() == wx.ID_OK:
-                       profileFile = dlg.GetPath()
-                       if not profileFile.lower().endswith('.ini'): #hack for linux, as for some reason the .ini is not appended.
-                               profileFile += '.ini'
-                       profile.saveProfile(profileFile)
+                       profile_filename = dlg.GetPath()
+                       if not profile_filename.lower().endswith('.ini'): #hack for linux, as for some reason the .ini is not appended.
+                               profile_filename += '.ini'
+                       profile.saveProfile(profile_filename)
+               dlg.Destroy()
+
+       def OnSaveDifferences(self, e):
+               dlg=wx.FileDialog(self, _("Select profile file to save"), os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_SAVE)
+               dlg.SetWildcard("ini files (*.ini)|*.ini")
+               if dlg.ShowModal() == wx.ID_OK:
+                       profile_filename = dlg.GetPath()
+                       if not profile_filename.lower().endswith('.ini'): #hack for linux, as for some reason the .ini is not appended.
+                               profile_filename += '.ini'
+                       profile.saveProfileDifferenceFromDefault(profile_filename)
                dlg.Destroy()
 
        def OnResetProfile(self, e):
@@ -533,6 +561,14 @@ class mainWindow(wx.Frame):
 
        def OnNormalSwitch(self, e):
                profile.putPreference('startMode', 'Normal')
+               dlg = wx.MessageDialog(self, _("Copy the settings from quickprint to your full settings?\n(This will overwrite any full setting modifications you have)"), _("Profile copy"), wx.YES_NO | wx.ICON_QUESTION)
+               result = dlg.ShowModal() == wx.ID_YES
+               dlg.Destroy()
+               if result:
+                       profile.resetProfile()
+                       for k, v in self.simpleSettingsPanel.getSettingOverrides().items():
+                               profile.putProfileSetting(k, v)
+                       self.updateProfileToAllControls()
                self.updateSliceMode()
 
        def OnDefaultMarlinFirmware(self, e):
@@ -553,15 +589,16 @@ class mainWindow(wx.Frame):
 
        def OnAddNewMachine(self, e):
                self.Hide()
-               profile.setActiveMachine(profile.getMachineCount())
-               configWizard.configWizard(True)
+               wasSimple = profile.getPreference('startMode') == 'Simple'
+               configWizard.ConfigWizard(True)
+               isSimple = profile.getPreference('startMode') == 'Simple'
                self.Show()
-               self.reloadSettingPanels()
+               self.reloadSettingPanels(isSimple != wasSimple)
                self.updateMachineMenu()
 
        def OnSelectMachine(self, index):
                profile.setActiveMachine(index)
-               self.reloadSettingPanels()
+               self.reloadSettingPanels(False)
 
        def OnBedLevelWizard(self, e):
                configWizard.bedLevelWizard()
@@ -617,9 +654,10 @@ class mainWindow(wx.Frame):
                        wx.MessageBox(_("You are running the latest version of Cura!"), _("Awesome!"), wx.ICON_INFORMATION)
 
        def OnAbout(self, e):
-               aboutBox = aboutWindow.aboutWindow()
+               aboutBox = aboutWindow.aboutWindow(self)
                aboutBox.Centre()
                aboutBox.Show()
+               aboutBox.Raise()
 
        def OnClose(self, e):
                profile.saveProfile(profile.getDefaultProfilePath(), True)
@@ -643,7 +681,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._engine.cleanup()
+               self.scene.cleanup()
                self.Destroy()
 
        def OnQuit(self, e):