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 configBase.TitleRow(left, _("Colours"))
27 configBase.SettingRow(left, 'model_colour', wx.Colour)
28 for i in xrange(1, extruderCount):
29 configBase.SettingRow(left, 'model_colour%d' % (i+1), wx.Colour)
31 if len(resources.getLanguageOptions()) > 1:
32 configBase.TitleRow(left, _("Language"))
33 configBase.SettingRow(left, 'language', map(lambda n: n[1], resources.getLanguageOptions()))
35 configBase.TitleRow(right, _("Filament settings"))
36 configBase.SettingRow(right, 'filament_physical_density')
37 configBase.SettingRow(right, 'filament_cost_kg')
38 configBase.SettingRow(right, 'filament_cost_meter')
40 #configBase.TitleRow(right, 'Slicer settings')
41 #configBase.SettingRow(right, 'save_profile')
43 configBase.TitleRow(right, 'SD Card settings')
44 configBase.SettingRow(right, 'auto_detect_sd')
45 configBase.SettingRow(right, 'sdcard_rootfolder')
46 #same as the expert settings button.
47 self.browseButton = wx.Button(right, -1, '...', style=wx.BU_EXACTFIT)
48 self.browseButton.SetFont(wx.Font(wx.SystemSettings.GetFont(wx.SYS_ANSI_VAR_FONT).GetPointSize() * 0.8, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_NORMAL))
49 self.browseButton.Bind(wx.EVT_BUTTON, self.OnBrowseSDRootFolder)
50 right.GetSizer().Add(self.browseButton, (right.GetSizer().GetRows()-1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
52 configBase.TitleRow(right, _("Cura settings"))
53 configBase.SettingRow(right, 'check_for_updates')
54 #configBase.SettingRow(right, 'submit_slice_information')
56 self.okButton = wx.Button(right, -1, _('Ok'))
57 right.GetSizer().Add(self.okButton, (right.GetSizer().GetRows(), 0), flag=wx.BOTTOM, border=5)
58 self.okButton.Bind(wx.EVT_BUTTON, lambda e: self.Close())
64 #self.parent.reloadSettingPanels()
67 def OnBrowseSDRootFolder(self, e):
68 path = profile.getPreference('sdcard_rootfolder')
70 path = os.path.expanduser('~/Documents')
71 if not os.path.exists(path):
74 dlg=wx.DirDialog(self, _("Select replication root folder"), path)
75 if dlg.ShowModal() != wx.ID_OK:
79 profile.putPreference('sdcard_rootfolder', dlg.GetPath())
82 self.parent.OnPreferences(None)
89 class machineSettingsDialog(wx.Dialog):
90 def __init__(self, parent):
91 super(machineSettingsDialog, self).__init__(parent, title=_("Machine settings"))
93 wx.EVT_CLOSE(self, self.OnClose)
97 self.panel = configBase.configPanelBase(self)
98 self.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
99 self.GetSizer().Add(self.panel, 1, wx.EXPAND)
100 self.nb = wx.Notebook(self.panel)
101 self.panel.SetSizer(wx.BoxSizer(wx.VERTICAL))
102 self.panel.GetSizer().Add(self.nb, 1, wx.EXPAND)
104 for idx in xrange(0, profile.getMachineCount()):
105 extruderCount = int(profile.getMachineSetting('extruder_amount', idx))
106 left, right, main = self.panel.CreateConfigPanel(self.nb)
107 configBase.TitleRow(left, _("Machine settings"))
108 configBase.SettingRow(left, 'steps_per_e', index=idx)
109 configBase.SettingRow(left, 'machine_width', index=idx)
110 configBase.SettingRow(left, 'machine_depth', index=idx)
111 configBase.SettingRow(left, 'machine_height', index=idx)
112 configBase.SettingRow(left, 'extruder_z_offset', index=idx)
113 configBase.SettingRow(left, 'extruder_amount', index=idx)
114 configBase.SettingRow(left, 'has_heated_bed', index=idx)
115 configBase.SettingRow(left, 'machine_center_is_zero', index=idx)
116 configBase.SettingRow(left, 'machine_shape', index=idx)
117 configBase.SettingRow(left, 'gcode_flavor', index=idx)
119 printer_type = profile.getMachineSetting('machine_type', idx)
120 if printer_type.startswith('lulzbot_'):
121 configBase.TitleRow(right, _("Tool Head"))
122 row = configBase.ToolHeadRow(right, 'toolhead', index=idx)
123 row.button.Bind(wx.EVT_BUTTON, self.OnChangeToolheadButton)
125 configBase.TitleRow(right, _("Printer head size"))
126 configBase.SettingRow(right, 'extruder_head_size_min_x', index=idx)
127 configBase.SettingRow(right, 'extruder_head_size_min_y', index=idx)
128 configBase.SettingRow(right, 'extruder_head_size_max_x', index=idx)
129 configBase.SettingRow(right, 'extruder_head_size_max_y', index=idx)
130 configBase.SettingRow(right, 'extruder_head_size_height', index=idx)
132 for i in xrange(1, extruderCount):
133 configBase.TitleRow(left, _("Extruder %d") % (i+1))
134 configBase.SettingRow(left, 'extruder_offset_x%d' % (i), index=idx)
135 configBase.SettingRow(left, 'extruder_offset_y%d' % (i), index=idx)
137 configBase.TitleRow(right, _("Communication settings"))
138 configBase.SettingRow(right, 'serial_port', ['AUTO'] + machineCom.serialList(), index=idx)
139 configBase.SettingRow(right, 'serial_baud', ['AUTO'] + map(str, machineCom.baudrateList()), index=idx)
141 self.nb.AddPage(main, profile.getMachineName(idx).title())
143 self.nb.SetSelection(int(profile.getPreferenceFloat('active_machine')))
145 self.buttonPanel = wx.Panel(self.panel)
146 self.panel.GetSizer().Add(self.buttonPanel)
148 self.buttonPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
149 self.okButton = wx.Button(self.buttonPanel, -1, _('Ok'))
150 self.okButton.Bind(wx.EVT_BUTTON, lambda e: self.Close())
151 self.buttonPanel.GetSizer().Add(self.okButton, flag=wx.ALL, border=5)
153 self.addButton = wx.Button(self.buttonPanel, -1, _('Add new machine'))
154 self.addButton.Bind(wx.EVT_BUTTON, self.OnAddMachine)
155 self.buttonPanel.GetSizer().Add(self.addButton, flag=wx.ALL, border=5)
157 self.remButton = wx.Button(self.buttonPanel, -1, _('Remove machine'))
158 self.remButton.Bind(wx.EVT_BUTTON, self.OnRemoveMachine)
159 self.buttonPanel.GetSizer().Add(self.remButton, flag=wx.ALL, border=5)
161 self.renButton = wx.Button(self.buttonPanel, -1, _('Change machine name'))
162 self.renButton.Bind(wx.EVT_BUTTON, self.OnRenameMachine)
163 self.buttonPanel.GetSizer().Add(self.renButton, flag=wx.ALL, border=5)
168 def OnChangeToolheadButton(self, e):
171 old_active = int(profile.getPreferenceFloat('active_machine'))
172 profile.setActiveMachine(self.nb.GetSelection())
173 configWizard.LulzbotChangeToolheadWizard()
174 profile.setActiveMachine(old_active)
176 self.parent.reloadSettingPanels()
177 self.parent.updateMachineMenu()
179 prefDialog = machineSettingsDialog(self.parent)
182 wx.CallAfter(self.Close)
184 def OnAddMachine(self, e):
187 configWizard.ConfigWizard(True)
189 self.parent.reloadSettingPanels()
190 self.parent.updateMachineMenu()
192 prefDialog = machineSettingsDialog(self.parent)
195 wx.CallAfter(self.Close)
197 def OnRemoveMachine(self, e):
198 if profile.getMachineCount() < 2:
199 wx.MessageBox(_("Cannot remove the last machine configuration in Cura"), _("Machine remove error"), wx.OK | wx.ICON_ERROR)
202 dlg = wx.MessageDialog(self,
203 _("Are you sure you want to remove the selected machine?"),
204 _('Remove machine?'),
205 wx.YES_NO | wx.ICON_EXCLAMATION)
206 remove = dlg.ShowModal() == wx.ID_YES
210 profile.removeMachine(self.nb.GetSelection())
211 self.parent.reloadSettingPanels()
212 self.parent.updateMachineMenu()
214 prefDialog = machineSettingsDialog(self.parent)
217 wx.CallAfter(self.Close)
219 def OnRenameMachine(self, e):
220 dialog = wx.TextEntryDialog(self, _("Enter the new name:"), _("Change machine name"),
221 profile.getMachineSetting('machine_name', self.nb.GetSelection()))
222 if dialog.ShowModal() != wx.ID_OK:
224 profile.putMachineSetting('machine_name', dialog.GetValue(), self.nb.GetSelection())
225 self.nb.SetPageText(self.nb.GetSelection(), profile.getMachineName(self.nb.GetSelection()))
226 self.parent.updateMachineMenu()
228 def OnClose(self, e):
229 self.parent.reloadSettingPanels()