chiark / gitweb /
Merge pull request #1113 from pmsimard/15.01_RC10_SDFolderStructure
[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__(None, 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']
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__(None, 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_amount', index=idx)
119                         configBase.SettingRow(left, 'has_heated_bed', index=idx)
120                         configBase.SettingRow(left, 'machine_center_is_zero', index=idx)
121                         configBase.SettingRow(left, 'machine_shape', index=idx)
122                         configBase.SettingRow(left, 'gcode_flavor', index=idx)
123
124                         configBase.TitleRow(right, _("Printer head size"))
125                         configBase.SettingRow(right, 'extruder_head_size_min_x', index=idx)
126                         configBase.SettingRow(right, 'extruder_head_size_min_y', index=idx)
127                         configBase.SettingRow(right, 'extruder_head_size_max_x', index=idx)
128                         configBase.SettingRow(right, 'extruder_head_size_max_y', index=idx)
129                         configBase.SettingRow(right, 'extruder_head_size_height', index=idx)
130
131                         for i in xrange(1, extruderCount):
132                                 configBase.TitleRow(left, _("Extruder %d") % (i+1))
133                                 configBase.SettingRow(left, 'extruder_offset_x%d' % (i), index=idx)
134                                 configBase.SettingRow(left, 'extruder_offset_y%d' % (i), index=idx)
135
136                         configBase.TitleRow(right, _("Communication settings"))
137                         configBase.SettingRow(right, 'serial_port', ['AUTO'] + machineCom.serialList(), index=idx)
138                         configBase.SettingRow(right, 'serial_baud', ['AUTO'] + map(str, machineCom.baudrateList()), index=idx)
139
140                         self.nb.AddPage(main, profile.getMachineSetting('machine_name', idx).title())
141
142                 self.nb.SetSelection(int(profile.getPreferenceFloat('active_machine')))
143
144                 self.buttonPanel = wx.Panel(self.panel)
145                 self.panel.GetSizer().Add(self.buttonPanel)
146
147                 self.buttonPanel.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
148                 self.okButton = wx.Button(self.buttonPanel, -1, _('Ok'))
149                 self.okButton.Bind(wx.EVT_BUTTON, lambda e: self.Close())
150                 self.buttonPanel.GetSizer().Add(self.okButton, flag=wx.ALL, border=5)
151
152                 self.addButton = wx.Button(self.buttonPanel, -1, _('Add new machine'))
153                 self.addButton.Bind(wx.EVT_BUTTON, self.OnAddMachine)
154                 self.buttonPanel.GetSizer().Add(self.addButton, flag=wx.ALL, border=5)
155
156                 self.remButton = wx.Button(self.buttonPanel, -1, _('Remove machine'))
157                 self.remButton.Bind(wx.EVT_BUTTON, self.OnRemoveMachine)
158                 self.buttonPanel.GetSizer().Add(self.remButton, flag=wx.ALL, border=5)
159
160                 self.renButton = wx.Button(self.buttonPanel, -1, _('Change machine name'))
161                 self.renButton.Bind(wx.EVT_BUTTON, self.OnRenameMachine)
162                 self.buttonPanel.GetSizer().Add(self.renButton, flag=wx.ALL, border=5)
163
164                 main.Fit()
165                 self.Fit()
166
167         def OnAddMachine(self, e):
168                 self.Hide()
169                 self.parent.Hide()
170                 configWizard.ConfigWizard(True)
171                 self.parent.Show()
172                 self.parent.reloadSettingPanels()
173                 self.parent.updateMachineMenu()
174
175                 prefDialog = machineSettingsDialog(self.parent)
176                 prefDialog.Centre()
177                 prefDialog.Show()
178                 wx.CallAfter(self.Close)
179
180         def OnRemoveMachine(self, e):
181                 if profile.getMachineCount() < 2:
182                         wx.MessageBox(_("Cannot remove the last machine configuration in Cura"), _("Machine remove error"), wx.OK | wx.ICON_ERROR)
183                         return
184
185                 self.Hide()
186                 profile.removeMachine(self.nb.GetSelection())
187                 self.parent.reloadSettingPanels()
188                 self.parent.updateMachineMenu()
189
190                 prefDialog = machineSettingsDialog(self.parent)
191                 prefDialog.Centre()
192                 prefDialog.Show()
193                 wx.CallAfter(self.Close)
194
195         def OnRenameMachine(self, e):
196                 dialog = wx.TextEntryDialog(self, _("Enter the new name:"), _("Change machine name"), self.nb.GetPageText(self.nb.GetSelection()))
197                 if dialog.ShowModal() != wx.ID_OK:
198                         return
199                 self.nb.SetPageText(self.nb.GetSelection(), dialog.GetValue())
200                 profile.putMachineSetting('machine_name', dialog.GetValue(), self.nb.GetSelection())
201                 self.parent.updateMachineMenu()
202
203         def OnClose(self, e):
204                 self.parent.reloadSettingPanels()
205                 self.Destroy()