chiark / gitweb /
Add Advanced print window to the preferences and change default
[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                 printWindowTypes = ['Basic', 'Advanced']
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)
31
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)
36
37                 if len(resources.getLanguageOptions()) > 1:
38                         configBase.TitleRow(left, _("Language"))
39                         configBase.SettingRow(left, 'language', map(lambda n: n[1], resources.getLanguageOptions()))
40
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')
45
46                 #configBase.TitleRow(right, 'Slicer settings')
47                 #configBase.SettingRow(right, 'save_profile')
48
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)
57
58                 configBase.TitleRow(right, _("Cura settings"))
59                 configBase.SettingRow(right, 'check_for_updates')
60                 #configBase.SettingRow(right, 'submit_slice_information')
61
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())
65
66                 main.Fit()
67                 self.Fit()
68
69         def OnClose(self, e):
70                 #self.parent.reloadSettingPanels()
71                 self.Destroy()
72
73         def OnBrowseSDRootFolder(self, e):
74                 path = profile.getPreference('sdcard_rootfolder')
75                 if path == '':
76                         path = os.path.expanduser('~/Documents')
77                         if not os.path.exists(path):
78                                 path = ''
79
80                 dlg=wx.DirDialog(self, _("Select replication root folder"), path)
81                 if dlg.ShowModal() != wx.ID_OK:
82                         dlg.Destroy()
83                         return
84
85                 profile.putPreference('sdcard_rootfolder', dlg.GetPath())
86                 dlg.Destroy()
87                 self.Close()
88                 self.parent.OnPreferences(None)
89
90
91
92
93
94
95 class machineSettingsDialog(wx.Dialog):
96         def __init__(self, parent):
97                 super(machineSettingsDialog, self).__init__(parent, title=_("Machine settings"))
98
99                 wx.EVT_CLOSE(self, self.OnClose)
100
101                 self.parent = parent
102
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)
109
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)
124
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)
130
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)
137
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)
142
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)
146
147                         self.nb.AddPage(main, profile.getMachineName(idx).title())
148
149                 self.nb.SetSelection(int(profile.getPreferenceFloat('active_machine')))
150
151                 self.buttonPanel = wx.Panel(self.panel)
152                 self.panel.GetSizer().Add(self.buttonPanel)
153
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)
158
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)
162
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)
166
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)
170
171                 main.Fit()
172                 self.Fit()
173
174         def OnChangeToolheadButton(self, e):
175                 self.Hide()
176                 self.parent.Hide()
177                 old_active = int(profile.getPreferenceFloat('active_machine'))
178                 profile.setActiveMachine(self.nb.GetSelection())
179                 configWizard.LulzbotChangeToolheadWizard()
180                 profile.setActiveMachine(old_active)
181                 self.parent.Show()
182                 self.parent.reloadSettingPanels()
183                 self.parent.updateMachineMenu()
184
185                 prefDialog = machineSettingsDialog(self.parent)
186                 prefDialog.Centre()
187                 prefDialog.Show()
188                 wx.CallAfter(self.Close)
189
190         def OnAddMachine(self, e):
191                 self.Hide()
192                 self.parent.Hide()
193                 configWizard.ConfigWizard(True)
194                 self.parent.Show()
195                 self.parent.reloadSettingPanels()
196                 self.parent.updateMachineMenu()
197
198                 prefDialog = machineSettingsDialog(self.parent)
199                 prefDialog.Centre()
200                 prefDialog.Show()
201                 wx.CallAfter(self.Close)
202
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)
206                         return
207
208                 self.Hide()
209                 profile.removeMachine(self.nb.GetSelection())
210                 self.parent.reloadSettingPanels()
211                 self.parent.updateMachineMenu()
212
213                 prefDialog = machineSettingsDialog(self.parent)
214                 prefDialog.Centre()
215                 prefDialog.Show()
216                 wx.CallAfter(self.Close)
217
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:
222                         return
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()
226
227         def OnClose(self, e):
228                 self.parent.reloadSettingPanels()
229                 self.Destroy()