chiark / gitweb /
Make a new wizard for changing the toolhead and call it from machine settings
authorYouness Alaoui <kakaroto@kakaroto.homelinux.net>
Wed, 29 Jul 2015 21:21:09 +0000 (17:21 -0400)
committerYouness Alaoui <kakaroto@kakaroto.homelinux.net>
Wed, 29 Jul 2015 21:21:09 +0000 (17:21 -0400)
Cura/gui/configWizard.py
Cura/gui/preferencesDialog.py

index 31de48591f4c86a4b4f6a247f40bd66bc8e1711a..085bbd59f30813d4a6c1f1dfc704f1fde016c761 100644 (file)
@@ -1203,9 +1203,10 @@ class LulzbotToolheadSelectPage(InfoPage):
                webbrowser.open(LulzbotMiniToolheadSelectPage.url)
 
 class LulzbotMiniToolheadSelectPage(LulzbotToolheadSelectPage):
-       def __init__(self, parent):
+       def __init__(self, parent, allowBack = True):
                super(LulzbotMiniToolheadSelectPage, self).__init__(parent, _("LulzBot Mini Toolhead Selection"))
 
+               self.allowBack = allowBack
                self.panel = self.AddPanel()
                image_size=(LulzbotMachineSelectPage.IMAGE_WIDTH, LulzbotMachineSelectPage.IMAGE_HEIGHT)
                self.standard = self.AddImageButton(self.panel, 0, 0, _('Single Extruder v2'),
@@ -1215,6 +1216,9 @@ class LulzbotMiniToolheadSelectPage(LulzbotToolheadSelectPage):
                                                                                        'Lulzbot_Toolhead_Mini_Flexystruder.jpg', image_size)
                self.standard.SetValue(True)
 
+       def AllowBack(self):
+               return self.allowBack
+
        def StoreData(self):
                if self.standard.GetValue():
                        profile.putProfileSetting('nozzle_size', '0.5')
@@ -1316,9 +1320,10 @@ class LulzbotTazToolheadSelectPage(LulzbotToolheadSelectPage):
 
 
 class LulzbotHotendSelectPage(LulzbotToolheadSelectPage):
-       def __init__(self, parent):
+       def __init__(self, parent, allowBack = True):
                super(LulzbotHotendSelectPage, self).__init__(parent, _("LulzBot Toolhead Hotend Selection"))
 
+               self.allowBack = allowBack
                self.panel = self.AddPanel()
                image_size=(LulzbotMachineSelectPage.IMAGE_WIDTH, LulzbotMachineSelectPage.IMAGE_HEIGHT)
                self.v1 = self.AddImageButton(self.panel, 0, 0, _('v1 (Budaschnozzle Hotends)'),
@@ -1328,6 +1333,9 @@ class LulzbotHotendSelectPage(LulzbotToolheadSelectPage):
                                                                                        'Lulzbot_Toolhead_v2.jpg', image_size)
                self.v1.SetValue(True)
 
+       def AllowBack(self):
+               return self.allowBack
+
        def StoreData(self):
                self.GetParent().lulzbotTazToolheadPage.SetVersion(1 if self.v1.GetValue() else 2)
 
@@ -1366,6 +1374,53 @@ class LulzbotTaz5NozzleSelectPage(LulzbotToolheadSelectPage):
                        profile.putMachineSetting('machine_name', 'LulzBot TAZ 5 (0.5 nozzle)')
                        profile.putMachineSetting('machine_type', 'lulzbot_TAZ_5_05nozzle')
 
+class LulzbotChangeToolheadWizard(wx.wizard.Wizard):
+       def __init__(self):
+               super(LulzbotChangeToolheadWizard, self).__init__(None, -1, _("Change Lulzbot Toolhead Wizard"))
+
+               self._nozzle_size = profile.getProfileSettingFloat('nozzle_size')
+               self._machine_name = profile.getMachineSetting('machine_name')
+               self._machine_type = profile.getMachineSetting('machine_type')
+               self._extruder_amount = int(profile.getMachineSettingFloat('extruder_amount'))
+
+               self.Bind(wx.wizard.EVT_WIZARD_PAGE_CHANGED, self.OnPageChanged)
+               self.Bind(wx.wizard.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging)
+               self.Bind(wx.wizard.EVT_WIZARD_CANCEL, self.OnCancel)
+
+               self.lulzbotReadyPage = LulzbotReadyPage(self)
+               self.lulzbotMiniToolheadPage = LulzbotMiniToolheadSelectPage(self, False)
+               self.lulzbotTazToolheadPage = LulzbotTazToolheadSelectPage(self)
+               self.lulzbotTazHotendPage = LulzbotHotendSelectPage(self, False)
+               self.lulzbotTaz5NozzleSelectPage = LulzbotTaz5NozzleSelectPage(self)
+
+               wx.wizard.WizardPageSimple.Chain(self.lulzbotMiniToolheadPage, self.lulzbotReadyPage)
+               wx.wizard.WizardPageSimple.Chain(self.lulzbotTazHotendPage, self.lulzbotTazToolheadPage)
+
+               if profile.getMachineSetting('machine_type').startswith('lulzbot_mini'):
+                       self.RunWizard(self.lulzbotMiniToolheadPage)
+               else:
+                       self.RunWizard(self.lulzbotTazHotendPage)
+               self.Destroy()
+
+       def OnPageChanging(self, e):
+               e.GetPage().StoreData()
+
+       def OnPageChanged(self, e):
+               if e.GetPage().AllowNext():
+                       self.FindWindowById(wx.ID_FORWARD).Enable()
+               else:
+                       self.FindWindowById(wx.ID_FORWARD).Disable()
+               if e.GetPage().AllowBack():
+                       self.FindWindowById(wx.ID_BACKWARD).Enable()
+               else:
+                       self.FindWindowById(wx.ID_BACKWARD).Disable()
+
+       def OnCancel(self, e):
+               profile.putProfileSetting('nozzle_size', self._nozzle_size)
+               profile.putMachineSetting('machine_name', self._machine_name)
+               profile.putMachineSetting('machine_type', self._machine_type)
+               profile.putMachineSetting('extruder_amount', self._extruder_amount)
+
 class ConfigWizard(wx.wizard.Wizard):
        def __init__(self, addNew = False):
                super(ConfigWizard, self).__init__(None, -1, _("Configuration Wizard"))
index fa7564aa67e6c56148ba7d281d68d1f095368208..883ce8eb4524b61a81670466ea44d5ecc08a2928 100644 (file)
@@ -125,7 +125,8 @@ class machineSettingsDialog(wx.Dialog):
                        printer_type = profile.getMachineSetting('machine_type', idx)
                        if printer_type.startswith('lulzbot_'):
                                configBase.TitleRow(right, _("Toolhead"))
-                               configBase.ToolheadRow(right, 'toolhead', index=idx)
+                               row = configBase.ToolheadRow(right, 'toolhead', index=idx)
+                               row.button.Bind(wx.EVT_BUTTON, self.OnChangeToolheadButton)
 
                        configBase.TitleRow(right, _("Printer head size"))
                        configBase.SettingRow(right, 'extruder_head_size_min_x', index=idx)
@@ -170,6 +171,22 @@ class machineSettingsDialog(wx.Dialog):
                main.Fit()
                self.Fit()
 
+       def OnChangeToolheadButton(self, e):
+               self.Hide()
+               self.parent.Hide()
+               old_active = int(profile.getPreferenceFloat('active_machine'))
+               profile.setActiveMachine(self.nb.GetSelection())
+               configWizard.LulzbotChangeToolheadWizard()
+               profile.setActiveMachine(old_active)
+               self.parent.Show()
+               self.parent.reloadSettingPanels()
+               self.parent.updateMachineMenu()
+
+               prefDialog = machineSettingsDialog(self.parent)
+               prefDialog.Centre()
+               prefDialog.Show()
+               wx.CallAfter(self.Close)
+
        def OnAddMachine(self, e):
                self.Hide()
                self.parent.Hide()