chiark / gitweb /
Add multiple tabs for multiple machine configurations in the machine-settings dialog.
authordaid <daid303@gmail.com>
Wed, 25 Sep 2013 06:53:08 +0000 (08:53 +0200)
committerdaid <daid303@gmail.com>
Wed, 25 Sep 2013 06:53:08 +0000 (08:53 +0200)
Cura/gui/configBase.py
Cura/gui/mainWindow.py
Cura/gui/preferencesDialog.py
Cura/util/machineCom.py
Cura/util/profile.py

index 6411d9928b43c217977430ccbb5ef1175b1cdb25..042ca3888f1c848cf97fc648bd000c8f7b51820c 100644 (file)
@@ -144,7 +144,7 @@ class TitleRow(object):
                sizer.SetRows(x + 2)
 
 class SettingRow(object):
-       def __init__(self, panel, configName, valueOverride = None):
+       def __init__(self, panel, configName, valueOverride = None, index = None):
                "Add a setting to the configuration panel"
                sizer = panel.GetSizer()
                x = sizer.GetRows()
@@ -152,6 +152,7 @@ class SettingRow(object):
                flag = 0
 
                self.setting = profile.settingsDictionary[configName]
+               self.settingIndex = index
                self.validationMsg = ''
                self.panel = panel
 
@@ -168,14 +169,14 @@ class SettingRow(object):
                #       flag = wx.EXPAND
                if self.setting.getType() is types.BooleanType:
                        self.ctrl = wx.CheckBox(panel, -1, style=wx.ALIGN_RIGHT)
-                       self.SetValue(self.setting.getValue())
+                       self.SetValue(self.setting.getValue(self.settingIndex))
                        self.ctrl.Bind(wx.EVT_CHECKBOX, self.OnSettingChange)
                elif valueOverride is not None and valueOverride is wx.Colour:
                        self.ctrl = wx.ColourPickerCtrl(panel, -1)
-                       self.SetValue(self.setting.getValue())
+                       self.SetValue(self.setting.getValue(self.settingIndex))
                        self.ctrl.Bind(wx.EVT_COLOURPICKER_CHANGED, self.OnSettingChange)
                elif type(self.setting.getType()) is list or valueOverride is not None:
-                       value = self.setting.getValue()
+                       value = self.setting.getValue(self.settingIndex)
                        choices = self.setting.getType()
                        if valueOverride is not None:
                                choices = valueOverride
@@ -186,7 +187,7 @@ class SettingRow(object):
                        self.ctrl.Bind(wx.EVT_LEFT_DOWN, self.OnMouseExit)
                        flag = wx.EXPAND
                else:
-                       self.ctrl = wx.TextCtrl(panel, -1, self.setting.getValue())
+                       self.ctrl = wx.TextCtrl(panel, -1, self.setting.getValue(self.settingIndex))
                        self.ctrl.Bind(wx.EVT_TEXT, self.OnSettingChange)
                        flag = wx.EXPAND
 
@@ -213,7 +214,7 @@ class SettingRow(object):
                e.Skip()
 
        def OnSettingChange(self, e):
-               self.setting.setValue(self.GetValue())
+               self.setting.setValue(self.GetValue(), self.settingIndex)
                self.panel.main._validate()
 
        def _validate(self):
index 97a871f2ba1de1404d6627af5b6662f8186f95ff..4edb45dec192c0f376e44bd5110990b84ee980fe 100644 (file)
@@ -84,6 +84,8 @@ class mainWindow(wx.Frame):
                self.fileMenu.AppendSeparator()
                i = self.fileMenu.Append(-1, _("Preferences...\tCTRL+,"))
                self.Bind(wx.EVT_MENU, self.OnPreferences, i)
+               i = self.fileMenu.Append(-1, _("Machine settings..."))
+               self.Bind(wx.EVT_MENU, self.OnMachineSettings, i)
                self.fileMenu.AppendSeparator()
 
                # Model MRU list
@@ -307,6 +309,11 @@ class mainWindow(wx.Frame):
                prefDialog.Centre()
                prefDialog.Show()
 
+       def OnMachineSettings(self, e):
+               prefDialog = preferencesDialog.machineSettingsDialog(self)
+               prefDialog.Centre()
+               prefDialog.Show()
+
        def OnDropFiles(self, files):
                if len(files) > 0:
                        profile.setPluginConfig([])
@@ -443,10 +450,7 @@ class mainWindow(wx.Frame):
 
        def OnAddNewMachine(self, e):
                self.Hide()
-               n = 0
-               while profile.getMachineSetting('machine_name', n) != '':
-                       n += 1
-               profile.setActiveMachine(n)
+               profile.setActiveMachine(profile.getMachineCount())
                configWizard.configWizard(True)
                self.Show()
                self.reloadSettingPanels()
@@ -564,7 +568,7 @@ class normalSettingsPanel(configBase.configPanelBase):
                #Plugin page
                self.pluginPanel = pluginPanel.pluginPanel(self.nb, callback)
                if len(self.pluginPanel.pluginList) > 0:
-                       self.nb.AddPage(self.pluginPanel, "Plugins")
+                       self.nb.AddPage(self.pluginPanel, _("Plugins"))
                else:
                        self.pluginPanel.Show(False)
 
index b650f993b3740fcf27b77f9ee5a9e3b8ee5da8b1..17b30ec5a4accfe21fa54661684fe77ad0a20b54 100644 (file)
@@ -14,46 +14,22 @@ class preferencesDialog(wx.Dialog):
                wx.EVT_CLOSE(self, self.OnClose)
 
                self.parent = parent
-               self.oldExtruderAmount = int(profile.getMachineSetting('extruder_amount'))
+               extruderCount = int(profile.getMachineSetting('extruder_amount'))
 
                self.panel = configBase.configPanelBase(self)
 
                left, right, main = self.panel.CreateConfigPanel(self)
-               configBase.TitleRow(left, _("Machine settings"))
-               configBase.SettingRow(left, 'steps_per_e')
-               configBase.SettingRow(left, 'machine_width')
-               configBase.SettingRow(left, 'machine_depth')
-               configBase.SettingRow(left, 'machine_height')
-               configBase.SettingRow(left, 'extruder_amount')
-               configBase.SettingRow(left, 'has_heated_bed')
-               configBase.SettingRow(left, 'gcode_flavor')
-
-               configBase.TitleRow(left, _("Printer head size"))
-               configBase.SettingRow(left, 'extruder_head_size_min_x')
-               configBase.SettingRow(left, 'extruder_head_size_min_y')
-               configBase.SettingRow(left, 'extruder_head_size_max_x')
-               configBase.SettingRow(left, 'extruder_head_size_max_y')
-               configBase.SettingRow(left, 'extruder_head_size_height')
-
-               for i in xrange(1, self.oldExtruderAmount):
-                       configBase.TitleRow(left, _("Extruder %d") % (i+1))
-                       configBase.SettingRow(left, 'extruder_offset_x%d' % (i))
-                       configBase.SettingRow(left, 'extruder_offset_y%d' % (i))
-
-               configBase.TitleRow(right, _("Colours"))
-               configBase.SettingRow(right, 'model_colour', wx.Colour)
-               for i in xrange(1, self.oldExtruderAmount):
-                       configBase.SettingRow(right, 'model_colour%d' % (i+1), wx.Colour)
+
+               configBase.TitleRow(left, _("Colours"))
+               configBase.SettingRow(left, 'model_colour', wx.Colour)
+               for i in xrange(1, extruderCount):
+                       configBase.SettingRow(left, 'model_colour%d' % (i+1), wx.Colour)
 
                configBase.TitleRow(right, _("Filament settings"))
                configBase.SettingRow(right, 'filament_physical_density')
                configBase.SettingRow(right, 'filament_cost_kg')
                configBase.SettingRow(right, 'filament_cost_meter')
 
-               configBase.TitleRow(right, _("Communication settings"))
-               configBase.SettingRow(right, 'serial_port', ['AUTO'] + machineCom.serialList())
-               configBase.SettingRow(right, 'serial_baud', ['AUTO'] + map(str, machineCom.baudrateList()))
-
                #configBase.TitleRow(right, 'Slicer settings')
                #configBase.SettingRow(right, 'save_profile')
 
@@ -71,6 +47,62 @@ class preferencesDialog(wx.Dialog):
                main.Fit()
                self.Fit()
 
+       def OnClose(self, e):
+               #self.parent.reloadSettingPanels()
+               self.Destroy()
+
+class machineSettingsDialog(wx.Dialog):
+       def __init__(self, parent):
+               super(machineSettingsDialog, self).__init__(None, title="Machine settings")
+
+               wx.EVT_CLOSE(self, self.OnClose)
+
+               self.parent = parent
+               extruderCount = int(profile.getMachineSetting('extruder_amount'))
+
+               self.panel = configBase.configPanelBase(self)
+               self.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
+               self.GetSizer().Add(self.panel, 1, wx.EXPAND)
+               self.nb = wx.Notebook(self.panel)
+               self.panel.SetSizer(wx.BoxSizer(wx.VERTICAL))
+               self.panel.GetSizer().Add(self.nb, 1, wx.EXPAND)
+
+               for idx in xrange(0, profile.getMachineCount()):
+                       left, right, main = self.panel.CreateConfigPanel(self.nb)
+                       configBase.TitleRow(left, _("Machine settings"))
+                       configBase.SettingRow(left, 'steps_per_e', index=idx)
+                       configBase.SettingRow(left, 'machine_width', index=idx)
+                       configBase.SettingRow(left, 'machine_depth', index=idx)
+                       configBase.SettingRow(left, 'machine_height', index=idx)
+                       configBase.SettingRow(left, 'extruder_amount', index=idx)
+                       configBase.SettingRow(left, 'has_heated_bed', index=idx)
+                       configBase.SettingRow(left, 'gcode_flavor', index=idx)
+
+                       configBase.TitleRow(right, _("Printer head size"))
+                       configBase.SettingRow(right, 'extruder_head_size_min_x', index=idx)
+                       configBase.SettingRow(right, 'extruder_head_size_min_y', index=idx)
+                       configBase.SettingRow(right, 'extruder_head_size_max_x', index=idx)
+                       configBase.SettingRow(right, 'extruder_head_size_max_y', index=idx)
+                       configBase.SettingRow(right, 'extruder_head_size_height', index=idx)
+
+                       for i in xrange(1, extruderCount):
+                               configBase.TitleRow(left, _("Extruder %d") % (i+1))
+                               configBase.SettingRow(left, 'extruder_offset_x%d' % (i), index=idx)
+                               configBase.SettingRow(left, 'extruder_offset_y%d' % (i), index=idx)
+
+                       configBase.TitleRow(right, _("Communication settings"))
+                       configBase.SettingRow(right, 'serial_port', ['AUTO'] + machineCom.serialList(), index=idx)
+                       configBase.SettingRow(right, 'serial_baud', ['AUTO'] + map(str, machineCom.baudrateList()), index=idx)
+
+                       self.nb.AddPage(main, profile.getMachineSetting('machine_name', idx))
+
+               self.okButton = wx.Button(self.panel, -1, 'Ok')
+               self.panel.GetSizer().Add(self.okButton, flag=wx.ALL, border=5)
+               self.okButton.Bind(wx.EVT_BUTTON, lambda e: self.Close())
+
+               main.Fit()
+               self.Fit()
+
        def OnClose(self, e):
                self.parent.reloadSettingPanels()
                self.Destroy()
index 9df8d72142880f4f98fbe844509683d0278c54ad..a47f8f31b93f408382ceb2fa1219bb8dcd41869e 100644 (file)
@@ -41,12 +41,12 @@ def serialList(forAutoDetect=False):
        if forAutoDetect:
                baselist = baselist + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/cu.usb*")
                baselist = filter(lambda s: not 'Bluetooth' in s, baselist)
+               prev = profile.getMachineSetting('serial_port_auto')
+               if prev in baselist:
+                       baselist.remove(prev)
+                       baselist.insert(0, prev)
        else:
                baselist = baselist + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/rfcomm*")
-       prev = profile.getMachineSetting('serial_port_auto')
-       if prev in baselist:
-               baselist.remove(prev)
-               baselist.insert(0, prev)
        if version.isDevVersion() and not forAutoDetect:
                baselist.append('VIRTUAL')
        return baselist
index 1177bcf378f9a6735dde58916e80e1b090c88ae8..bd360e1e9562952fe7fa15d61fe8dfdbae3973b4 100644 (file)
@@ -360,14 +360,14 @@ setting('machine_height', '200', float, 'machine', 'hidden').setLabel('Maximum h
 setting('machine_center_is_zero', 'False', bool, 'machine', 'hidden')
 setting('ultimaker_extruder_upgrade', 'False', bool, 'machine', 'hidden')
 setting('has_heated_bed', 'False', bool, 'machine', 'hidden').setLabel('Heated bed', 'If you have an heated bed, this enabled heated bed settings (requires restart)')
-setting('gcode_flavor', 'RepRap (Marlin/Sprinter)', ['RepRap (Marlin/Sprinter)', 'UltiGCode'], 'machine', 'hidden').setLabel('GCode Flavor', 'Flavor of generated GCode.\nRepRap...')
+setting('gcode_flavor', 'RepRap (Marlin/Sprinter)', ['RepRap (Marlin/Sprinter)', 'UltiGCode'], 'machine', 'hidden').setLabel('GCode Flavor', 'Flavor of generated GCode.\nRepRap is normal 5D GCode which works on Marlin/Sprinter based firmwares.\nUltiGCode is a variation of the RepRap GCode which puts more settings in the machine instead of the slicer.')
 setting('extruder_amount', '1', ['1','2','3','4'], 'machine', 'hidden').setLabel('Extruder count', 'Amount of extruders in your machine.')
 setting('extruder_offset_x1', '-21.6', float, 'machine', 'hidden').setLabel('Offset X', 'The offset of your secondary extruder compared to the primary.')
 setting('extruder_offset_y1', '0.0', float, 'machine', 'hidden').setLabel('Offset Y', 'The offset of your secondary extruder compared to the primary.')
-setting('extruder_offset_x2', '0.0', float, 'machine', 'hidden').setLabel('Offset X', 'The offset of your secondary extruder compared to the primary.')
-setting('extruder_offset_y2', '0.0', float, 'machine', 'hidden').setLabel('Offset Y', 'The offset of your secondary extruder compared to the primary.')
-setting('extruder_offset_x3', '0.0', float, 'machine', 'hidden').setLabel('Offset X', 'The offset of your secondary extruder compared to the primary.')
-setting('extruder_offset_y3', '0.0', float, 'machine', 'hidden').setLabel('Offset Y', 'The offset of your secondary extruder compared to the primary.')
+setting('extruder_offset_x2', '0.0', float, 'machine', 'hidden').setLabel('Offset X', 'The offset of your tertiary extruder compared to the primary.')
+setting('extruder_offset_y2', '0.0', float, 'machine', 'hidden').setLabel('Offset Y', 'The offset of your tertiary extruder compared to the primary.')
+setting('extruder_offset_x3', '0.0', float, 'machine', 'hidden').setLabel('Offset X', 'The offset of your forth extruder compared to the primary.')
+setting('extruder_offset_y3', '0.0', float, 'machine', 'hidden').setLabel('Offset Y', 'The offset of your forth extruder compared to the primary.')
 setting('steps_per_e', '0', float, 'machine', 'hidden').setLabel('E-Steps per 1mm filament', 'Amount of steps per mm filament extrusion. If set to 0 then this value is ignored and the value in your firmware is used.')
 setting('serial_port', 'AUTO', str, 'machine', 'hidden').setLabel('Serial port', 'Serial port to use for communication with the printer')
 setting('serial_port_auto', '', str, 'machine', 'hidden')
@@ -726,10 +726,8 @@ def checkAndUpdateMachineName():
        index = None
        if name == '':
                name = getMachineSetting('machine_type')
-       n = 0
-       while getMachineSetting('machine_name', n) != '':
+       for n in xrange(0, getMachineCount()):
                if n == _selectedMachineIndex:
-                       n += 1
                        continue
                print name, index, getMachineSetting('machine_name', n)
                if index is None:
@@ -738,12 +736,19 @@ def checkAndUpdateMachineName():
                else:
                        if '%s (%d)' % (name, index) == getMachineSetting('machine_name', n):
                                index += 1
-               n += 1
        if index is not None:
                name = '%s (%d)' % (name, index)
        putMachineSetting('machine_name', name)
        putPreference('active_machine', _selectedMachineIndex)
 
+def getMachineCount():
+       n = 0
+       while getMachineSetting('machine_name', n) != '':
+               n += 1
+       if n < 1:
+               return 1
+       return n
+
 def setActiveMachine(index):
        global _selectedMachineIndex
        _selectedMachineIndex = index