chiark / gitweb /
plugins: Support user configuration of default values
[cura.git] / Cura / gui / preferencesDialog.py
1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
2
3 import wx
4 import os
5
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
12
13 class preferencesDialog(wx.Dialog):
14         def __init__(self, parent):
15                 super(preferencesDialog, self).__init__(parent, title=_("Preferences"))
16
17                 wx.EVT_CLOSE(self, self.OnClose)
18
19                 self.parent = parent
20                 extruderCount = int(profile.getMachineSetting('extruder_amount'))
21
22                 self.panel = configBase.configPanelBase(self)
23
24                 left, right, main = self.panel.CreateConfigPanel(self)
25
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)
30
31                 if len(resources.getLanguageOptions()) > 1:
32                         configBase.TitleRow(left, _("Language"))
33                         configBase.SettingRow(left, 'language', map(lambda n: n[1], resources.getLanguageOptions()))
34
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')
39
40                 #configBase.TitleRow(right, 'Slicer settings')
41                 #configBase.SettingRow(right, 'save_profile')
42
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)
51
52                 configBase.TitleRow(right, _("Cura settings"))
53                 configBase.SettingRow(right, 'check_for_updates')
54                 #configBase.SettingRow(right, 'submit_slice_information')
55
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())
59
60                 main.Fit()
61                 self.Fit()
62
63         def OnClose(self, e):
64                 #self.parent.reloadSettingPanels()
65                 self.Destroy()
66
67         def OnBrowseSDRootFolder(self, e):
68                 path = profile.getPreference('sdcard_rootfolder')
69                 if path == '':
70                         path = os.path.expanduser('~/Documents')
71                         if not os.path.exists(path):
72                                 path = ''
73
74                 dlg=wx.DirDialog(self, _("Select replication root folder"), path)
75                 if dlg.ShowModal() != wx.ID_OK:
76                         dlg.Destroy()
77                         return
78
79                 profile.putPreference('sdcard_rootfolder', dlg.GetPath())
80                 dlg.Destroy()
81                 self.Close()
82                 self.parent.OnPreferences(None)
83
84
85
86
87
88
89 class machineSettingsDialog(wx.Dialog):
90         def __init__(self, parent):
91                 super(machineSettingsDialog, self).__init__(parent, title=_("Machine settings"))
92
93                 wx.EVT_CLOSE(self, self.OnClose)
94
95                 self.parent = parent
96
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)
103
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)
118
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)
124
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)
131
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)
136
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)
140
141                         self.nb.AddPage(main, profile.getMachineName(idx).title())
142
143                 self.nb.SetSelection(int(profile.getPreferenceFloat('active_machine')))
144
145                 self.buttonPanel = wx.Panel(self.panel)
146                 self.panel.GetSizer().Add(self.buttonPanel)
147
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)
152
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)
156
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)
160
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)
164
165                 main.Fit()
166                 self.Fit()
167
168         def OnChangeToolheadButton(self, e):
169                 self.Hide()
170                 self.parent.Hide()
171                 old_active = int(profile.getPreferenceFloat('active_machine'))
172                 profile.setActiveMachine(self.nb.GetSelection())
173                 configWizard.LulzbotChangeToolheadWizard()
174                 profile.setActiveMachine(old_active)
175                 self.parent.Show()
176                 self.parent.reloadSettingPanels()
177                 self.parent.updateMachineMenu()
178
179                 prefDialog = machineSettingsDialog(self.parent)
180                 prefDialog.Centre()
181                 prefDialog.Show()
182                 wx.CallAfter(self.Close)
183
184         def OnAddMachine(self, e):
185                 self.Hide()
186                 self.parent.Hide()
187                 configWizard.ConfigWizard(True)
188                 self.parent.Show()
189                 self.parent.reloadSettingPanels()
190                 self.parent.updateMachineMenu()
191
192                 prefDialog = machineSettingsDialog(self.parent)
193                 prefDialog.Centre()
194                 prefDialog.Show()
195                 wx.CallAfter(self.Close)
196
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)
200                         return
201
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
207                 dlg.Destroy()
208                 if remove:
209                         self.Hide()
210                         profile.removeMachine(self.nb.GetSelection())
211                         self.parent.reloadSettingPanels()
212                         self.parent.updateMachineMenu()
213
214                         prefDialog = machineSettingsDialog(self.parent)
215                         prefDialog.Centre()
216                         prefDialog.Show()
217                         wx.CallAfter(self.Close)
218
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:
223                         return
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()
227
228         def OnClose(self, e):
229                 self.parent.reloadSettingPanels()
230                 self.Destroy()