chiark / gitweb /
Add language selection.
[cura.git] / Cura / gui / preferencesDialog.py
index 10c946a5c7b773c1ce56292c1c4aa727a68bc90b..8dc0199d0a1f23774db7593944b8b77af58b9300 100644 (file)
-from __future__ import absolute_import\r
-import __init__\r
-\r
-import wx, os, platform, types, string\r
-import ConfigParser\r
-\r
-from gui import configBase\r
-from gui import validators\r
-from util import machineCom\r
-from util import profile\r
-\r
-class preferencesDialog(configBase.configWindowBase):\r
-       def __init__(self, parent):\r
-               super(preferencesDialog, self).__init__(title="Preferences")\r
-               \r
-               wx.EVT_CLOSE(self, self.OnClose)\r
-               \r
-               self.oldExtruderAmount = int(profile.getPreference('extruder_amount'))\r
-               \r
-               left, right, main = self.CreateConfigPanel(self)\r
-               configBase.TitleRow(left, 'Machine settings')\r
-               c = configBase.SettingRow(left, 'Steps per E', 'steps_per_e', '0', 'Amount of steps per mm filament extrusion', type = 'preference')\r
-               validators.validFloat(c, 0.1)\r
-               c = configBase.SettingRow(left, 'Machine width (mm)', 'machine_width', '205', 'Size of the machine in mm', type = 'preference')\r
-               validators.validFloat(c, 10.0)\r
-               c = configBase.SettingRow(left, 'Machine depth (mm)', 'machine_depth', '205', 'Size of the machine in mm', type = 'preference')\r
-               validators.validFloat(c, 10.0)\r
-               c = configBase.SettingRow(left, 'Machine height (mm)', 'machine_height', '200', 'Size of the machine in mm', type = 'preference')\r
-               validators.validFloat(c, 10.0)\r
-               c = configBase.SettingRow(left, 'Extruder count', 'extruder_amount', ['1', '2', '3', '4'], 'Amount of extruders in your machine.', type = 'preference')\r
-               \r
-               for i in xrange(1, self.oldExtruderAmount):\r
-                       configBase.TitleRow(left, 'Extruder %d' % (i+1))\r
-                       c = configBase.SettingRow(left, 'Offset X', 'extruder_offset_x%d' % (i), '0.0', 'The offset of your secondary extruder compared to the primary.', type = 'preference')\r
-                       validators.validFloat(c)\r
-                       c = configBase.SettingRow(left, 'Offset Y', 'extruder_offset_y%d' % (i), '0.0', 'The offset of your secondary extruder compared to the primary.', type = 'preference')\r
-                       validators.validFloat(c)\r
-\r
-               configBase.TitleRow(right, 'Filament settings')\r
-               c = configBase.SettingRow(right, 'Filament density (kg/m3)', 'filament_density', '1300', 'Weight of the filament per m3. Around 1300 for PLA. And around 1040 for ABS. This value is used to estimate the weight if the filament used for the print.', type = 'preference')\r
-               validators.validFloat(c, 500.0, 3000.0)\r
-               c = configBase.SettingRow(right, 'Filament cost (price/kg)', 'filament_cost_kg', '0', 'Cost of your filament per kg, to estimate the cost of the final print.', type = 'preference')\r
-               validators.validFloat(c, 0.0)\r
-               c = configBase.SettingRow(right, 'Filament cost (price/m)', 'filament_cost_meter', '0', 'Cost of your filament per meter, to estimate the cost of the final print.', type = 'preference')\r
-               validators.validFloat(c, 0.0)\r
-               \r
-               configBase.TitleRow(right, 'Communication settings')\r
-               c = configBase.SettingRow(right, 'Serial port', 'serial_port', ['AUTO'] + machineCom.serialList(), 'Serial port to use for communication with the printer', type = 'preference')\r
-               c = configBase.SettingRow(right, 'Baudrate', 'serial_baud', ['AUTO'] + map(str, machineCom.baudrateList()), 'Speed of the serial port communication\nNeeds to match your firmware settings\nCommon values are 250000, 115200, 57600', type = 'preference')\r
-\r
-               configBase.TitleRow(right, 'Slicer settings')\r
-               #c = configBase.SettingRow(right, 'Slicer selection', 'slicer', ['Cura (Skeinforge based)', 'Slic3r'], 'Which slicer to use to slice objects. Usually the Cura engine produces the best results. But Slic3r is developing fast and is faster with slicing.', type = 'preference')\r
-               c = configBase.SettingRow(right, 'Save profile on slice', 'save_profile', False, 'When slicing save the profile as [stl_file]_profile.ini next to the model.', type = 'preference')\r
-\r
-               configBase.TitleRow(right, 'SD Card settings')\r
-               if len(getDrives()) > 1:\r
-                       c = configBase.SettingRow(right, 'SD card drive', 'sdpath', getDrives(), 'Location of your SD card, when using the copy to SD feature.', type = 'preference')\r
-               else:\r
-                       c = configBase.SettingRow(right, 'SD card path', 'sdpath', '', 'Location of your SD card, when using the copy to SD feature.', type = 'preference')\r
-               c = configBase.SettingRow(right, 'Copy to SD with 8.3 names', 'sdshortnames', False, 'Save the gcode files in short filenames, so they are properly shown on the UltiController', type = 'preference')\r
-\r
-               self.okButton = wx.Button(left, -1, 'Ok')\r
-               left.GetSizer().Add(self.okButton, (left.GetSizer().GetRows(), 1))\r
-               self.okButton.Bind(wx.EVT_BUTTON, self.OnClose)\r
-               \r
-               self.MakeModal(True)\r
-               main.Fit()\r
-               self.Fit()\r
-\r
-       def OnClose(self, e):\r
-               if self.oldExtruderAmount != int(profile.getPreference('extruder_amount')):\r
-                       wx.MessageBox('After changing the amount of extruders you need to restart Cura for full effect.', 'Extruder amount warning.', wx.OK | wx.ICON_INFORMATION)\r
-               self.MakeModal(False)\r
-               self.Destroy()\r
-\r
-def getDrives():\r
-       drives = ['']\r
-       if platform.system() == "Windows":\r
-               from ctypes import windll\r
-               bitmask = windll.kernel32.GetLogicalDrives()\r
-               for letter in string.uppercase:\r
-                       if bitmask & 1:\r
-                               drives.append(letter + ':/')\r
-                       bitmask >>= 1\r
-       return drives\r
+from __future__ import absolute_import
+__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
+
+import wx
+
+from Cura.gui import configWizard
+from Cura.gui import configBase
+from Cura.util import machineCom
+from Cura.util import profile
+from Cura.util import resources
+
+class preferencesDialog(wx.Dialog):
+       def __init__(self, parent):
+               super(preferencesDialog, self).__init__(None, title="Preferences")
+
+               wx.EVT_CLOSE(self, self.OnClose)
+
+               self.parent = parent
+               extruderCount = int(profile.getMachineSetting('extruder_amount'))
+
+               self.panel = configBase.configPanelBase(self)
+
+               left, right, main = self.panel.CreateConfigPanel(self)
+
+               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(left, _("Language"))
+               configBase.SettingRow(left, 'language', map(lambda n: n[1], resources.getLanguageOptions()))
+
+               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, 'Slicer settings')
+               #configBase.SettingRow(right, 'save_profile')
+
+               #configBase.TitleRow(right, 'SD Card settings')
+
+               configBase.TitleRow(right, _("Cura settings"))
+               configBase.SettingRow(right, 'auto_detect_sd')
+               configBase.SettingRow(right, 'check_for_updates')
+               configBase.SettingRow(right, 'submit_slice_information')
+
+               self.okButton = wx.Button(right, -1, 'Ok')
+               right.GetSizer().Add(self.okButton, (right.GetSizer().GetRows(), 0), flag=wx.BOTTOM, 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()
+
+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).title())
+
+               self.nb.SetSelection(int(profile.getPreferenceFloat('active_machine')))
+
+               self.buttonPanel = wx.Panel(self.panel)
+               self.panel.GetSizer().Add(self.buttonPanel)
+
+               self.buttonPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
+               self.okButton = wx.Button(self.buttonPanel, -1, 'Ok')
+               self.okButton.Bind(wx.EVT_BUTTON, lambda e: self.Close())
+               self.buttonPanel.GetSizer().Add(self.okButton, flag=wx.ALL, border=5)
+
+               self.addButton = wx.Button(self.buttonPanel, -1, 'Add new machine')
+               self.addButton.Bind(wx.EVT_BUTTON, self.OnAddMachine)
+               self.buttonPanel.GetSizer().Add(self.addButton, flag=wx.ALL, border=5)
+
+               self.remButton = wx.Button(self.buttonPanel, -1, 'Remove machine')
+               self.remButton.Bind(wx.EVT_BUTTON, self.OnRemoveMachine)
+               self.buttonPanel.GetSizer().Add(self.remButton, flag=wx.ALL, border=5)
+
+               main.Fit()
+               self.Fit()
+
+       def OnAddMachine(self, e):
+               self.Hide()
+               self.parent.Hide()
+               profile.setActiveMachine(profile.getMachineCount())
+               configWizard.configWizard(True)
+               self.parent.Show()
+               self.parent.reloadSettingPanels()
+               self.parent.updateMachineMenu()
+
+               prefDialog = machineSettingsDialog(self.parent)
+               prefDialog.Centre()
+               prefDialog.Show()
+               wx.CallAfter(self.Close)
+
+       def OnRemoveMachine(self, e):
+               if profile.getMachineCount() < 2:
+                       wx.MessageBox(_("Cannot remove the last machine configuration in Cura"), _("Machine remove error"), wx.OK | wx.ICON_ERROR)
+                       return
+
+               self.Hide()
+               profile.removeMachine(self.nb.GetSelection())
+               self.parent.reloadSettingPanels()
+               self.parent.updateMachineMenu()
+
+               prefDialog = machineSettingsDialog(self.parent)
+               prefDialog.Centre()
+               prefDialog.Show()
+               wx.CallAfter(self.Close)
+
+       def OnClose(self, e):
+               self.parent.reloadSettingPanels()
+               self.Destroy()