1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
6 from Cura.gui import configWizard
7 from Cura.gui import configBase
8 from Cura.util import machineCom
9 from Cura.util import profile
10 from Cura.util import pluginInfo
11 from Cura.util import resources
13 class preferencesDialog(wx.Dialog):
14 def __init__(self, parent):
15 super(preferencesDialog, self).__init__(parent, title=_("Preferences"))
17 wx.EVT_CLOSE(self, self.OnClose)
20 extruderCount = int(profile.getMachineSetting('extruder_amount'))
22 self.panel = configBase.configPanelBase(self)
24 left, right, main = self.panel.CreateConfigPanel(self)
26 printWindowTypes = ['Basic']
27 for p in pluginInfo.getPluginList('printwindow'):
28 printWindowTypes.append(p.getName())
29 configBase.TitleRow(left, _("Print window"))
30 configBase.SettingRow(left, 'printing_window', printWindowTypes)
32 configBase.TitleRow(left, _("Colours"))
33 configBase.SettingRow(left, 'model_colour', wx.Colour)
34 for i in xrange(1, extruderCount):
35 configBase.SettingRow(left, 'model_colour%d' % (i+1), wx.Colour)
37 if len(resources.getLanguageOptions()) > 1:
38 configBase.TitleRow(left, _("Language"))
39 configBase.SettingRow(left, 'language', map(lambda n: n[1], resources.getLanguageOptions()))
41 configBase.TitleRow(right, _("Filament settings"))
42 configBase.SettingRow(right, 'filament_physical_density')
43 configBase.SettingRow(right, 'filament_cost_kg')
44 configBase.SettingRow(right, 'filament_cost_meter')
46 #configBase.TitleRow(right, 'Slicer settings')
47 #configBase.SettingRow(right, 'save_profile')
49 configBase.TitleRow(right, 'SD Card settings')
50 configBase.SettingRow(right, 'auto_detect_sd')
51 configBase.SettingRow(right, 'sdcard_rootfolder')
52 #same as the expert settings button.
53 self.browseButton = wx.Button(right, -1, '...', style=wx.BU_EXACTFIT)
54 self.browseButton.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize() * 0.8, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_NORMAL))
55 self.browseButton.Bind(wx.EVT_BUTTON, self.OnBrowseSDRootFolder)
56 right.GetSizer().Add(self.browseButton, (right.GetSizer().GetRows()-1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
58 configBase.TitleRow(right, _("Cura settings"))
59 configBase.SettingRow(right, 'check_for_updates')
60 #configBase.SettingRow(right, 'submit_slice_information')
62 self.okButton = wx.Button(right, -1, _('Ok'))
63 right.GetSizer().Add(self.okButton, (right.GetSizer().GetRows(), 0), flag=wx.BOTTOM, border=5)
64 self.okButton.Bind(wx.EVT_BUTTON, lambda e: self.Close())
70 #self.parent.reloadSettingPanels()
73 def OnBrowseSDRootFolder(self, e):
74 path = profile.getPreference('sdcard_rootfolder')
76 path = os.path.expanduser('~/Documents')
77 if not os.path.exists(path):
80 dlg=wx.DirDialog(self, _("Select replication root folder"), path)
81 if dlg.ShowModal() != wx.ID_OK:
85 profile.putPreference('sdcard_rootfolder', dlg.GetPath())
88 self.parent.OnPreferences(None)
95 class machineSettingsDialog(wx.Dialog):
96 def __init__(self, parent):
97 super(machineSettingsDialog, self).__init__(parent, title=_("Machine settings"))
99 wx.EVT_CLOSE(self, self.OnClose)
103 self.panel = configBase.configPanelBase(self)
104 self.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
105 self.GetSizer().Add(self.panel, 1, wx.EXPAND)
106 self.nb = wx.Notebook(self.panel)
107 self.panel.SetSizer(wx.BoxSizer(wx.VERTICAL))
108 self.panel.GetSizer().Add(self.nb, 1, wx.EXPAND)
110 for idx in xrange(0, profile.getMachineCount()):
111 extruderCount = int(profile.getMachineSetting('extruder_amount', idx))
112 left, right, main = self.panel.CreateConfigPanel(self.nb)
113 configBase.TitleRow(left, _("Machine settings"))
114 configBase.SettingRow(left, 'steps_per_e', index=idx)
115 configBase.SettingRow(left, 'machine_width', index=idx)
116 configBase.SettingRow(left, 'machine_depth', index=idx)
117 configBase.SettingRow(left, 'machine_height', index=idx)
118 configBase.SettingRow(left, 'extruder_z_offset', index=idx)
119 configBase.SettingRow(left, 'extruder_amount', index=idx)
120 configBase.SettingRow(left, 'has_heated_bed', index=idx)
121 configBase.SettingRow(left, 'machine_center_is_zero', index=idx)
122 configBase.SettingRow(left, 'machine_shape', index=idx)
123 configBase.SettingRow(left, 'gcode_flavor', index=idx)
125 printer_type = profile.getMachineSetting('machine_type', idx)
126 if printer_type.startswith('lulzbot_'):
127 configBase.TitleRow(right, _("Tool Head"))
128 row = configBase.ToolHeadRow(right, 'toolhead', index=idx)
129 row.button.Bind(wx.EVT_BUTTON, self.OnChangeToolheadButton)
131 configBase.TitleRow(right, _("Printer head size"))
132 configBase.SettingRow(right, 'extruder_head_size_min_x', index=idx)
133 configBase.SettingRow(right, 'extruder_head_size_min_y', index=idx)
134 configBase.SettingRow(right, 'extruder_head_size_max_x', index=idx)
135 configBase.SettingRow(right, 'extruder_head_size_max_y', index=idx)
136 configBase.SettingRow(right, 'extruder_head_size_height', index=idx)
138 for i in xrange(1, extruderCount):
139 configBase.TitleRow(left, _("Extruder %d") % (i+1))
140 configBase.SettingRow(left, 'extruder_offset_x%d' % (i), index=idx)
141 configBase.SettingRow(left, 'extruder_offset_y%d' % (i), index=idx)
143 configBase.TitleRow(right, _("Communication settings"))
144 configBase.SettingRow(right, 'serial_port', ['AUTO'] + machineCom.serialList(), index=idx)
145 configBase.SettingRow(right, 'serial_baud', ['AUTO'] + map(str, machineCom.baudrateList()), index=idx)
147 self.nb.AddPage(main, profile.getMachineName(idx).title())
149 self.nb.SetSelection(int(profile.getPreferenceFloat('active_machine')))
151 self.buttonPanel = wx.Panel(self.panel)
152 self.panel.GetSizer().Add(self.buttonPanel)
154 self.buttonPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
155 self.okButton = wx.Button(self.buttonPanel, -1, _('Ok'))
156 self.okButton.Bind(wx.EVT_BUTTON, lambda e: self.Close())
157 self.buttonPanel.GetSizer().Add(self.okButton, flag=wx.ALL, border=5)
159 self.addButton = wx.Button(self.buttonPanel, -1, _('Add new machine'))
160 self.addButton.Bind(wx.EVT_BUTTON, self.OnAddMachine)
161 self.buttonPanel.GetSizer().Add(self.addButton, flag=wx.ALL, border=5)
163 self.remButton = wx.Button(self.buttonPanel, -1, _('Remove machine'))
164 self.remButton.Bind(wx.EVT_BUTTON, self.OnRemoveMachine)
165 self.buttonPanel.GetSizer().Add(self.remButton, flag=wx.ALL, border=5)
167 self.renButton = wx.Button(self.buttonPanel, -1, _('Change machine name'))
168 self.renButton.Bind(wx.EVT_BUTTON, self.OnRenameMachine)
169 self.buttonPanel.GetSizer().Add(self.renButton, flag=wx.ALL, border=5)
174 def OnChangeToolheadButton(self, e):
177 old_active = int(profile.getPreferenceFloat('active_machine'))
178 profile.setActiveMachine(self.nb.GetSelection())
179 configWizard.LulzbotChangeToolheadWizard()
180 profile.setActiveMachine(old_active)
182 self.parent.reloadSettingPanels()
183 self.parent.updateMachineMenu()
185 prefDialog = machineSettingsDialog(self.parent)
188 wx.CallAfter(self.Close)
190 def OnAddMachine(self, e):
193 configWizard.ConfigWizard(True)
195 self.parent.reloadSettingPanels()
196 self.parent.updateMachineMenu()
198 prefDialog = machineSettingsDialog(self.parent)
201 wx.CallAfter(self.Close)
203 def OnRemoveMachine(self, e):
204 if profile.getMachineCount() < 2:
205 wx.MessageBox(_("Cannot remove the last machine configuration in Cura"), _("Machine remove error"), wx.OK | wx.ICON_ERROR)
209 profile.removeMachine(self.nb.GetSelection())
210 self.parent.reloadSettingPanels()
211 self.parent.updateMachineMenu()
213 prefDialog = machineSettingsDialog(self.parent)
216 wx.CallAfter(self.Close)
218 def OnRenameMachine(self, e):
219 dialog = wx.TextEntryDialog(self, _("Enter the new name:"), _("Change machine name"),
220 profile.getMachineSetting('machine_name', self.nb.GetSelection()))
221 if dialog.ShowModal() != wx.ID_OK:
223 profile.putMachineSetting('machine_name', dialog.GetValue(), self.nb.GetSelection())
224 self.nb.SetPageText(self.nb.GetSelection(), profile.getMachineName(self.nb.GetSelection()))
225 self.parent.updateMachineMenu()
227 def OnClose(self, e):
228 self.parent.reloadSettingPanels()