chiark / gitweb /
Tell user to connect and power on 3D printer before attempting to flash firmware
[cura.git] / Cura / gui / simpleMode.py
1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
2
3 import wx
4 import ConfigParser as configparser
5 import os.path
6
7 from Cura.util import profile
8 from Cura.util import resources
9
10 class simpleModePanel(wx.Panel):
11         "Main user interface window for Quickprint mode"
12         def __init__(self, parent, callback):
13                 super(simpleModePanel, self).__init__(parent)
14                 self._callback = callback
15
16                 self._print_material_options = []
17                 self._print_profile_options = []
18                 self._print_other_options = []
19
20                 materials = resources.getSimpleModeMaterials()
21
22                 # Create material buttons
23                 self.printMaterialPanel = wx.Panel(self)
24                 selectedMaterial = None
25                 for material in materials:
26                         if material.disabled:
27                                 continue
28                         button = wx.RadioButton(self.printMaterialPanel, -1, material.name.replace('&', '&&'),
29                                                                         style=wx.RB_GROUP if len(self._print_material_options) == 0 else 0)
30                         button.profile = material
31                         self._print_material_options.append(button)
32                         if profile.getProfileSetting('simpleModeMaterial') == material.name:
33                                 selectedMaterial = button
34
35                 # Decide on the default selected material
36                 if selectedMaterial is None:
37                         for button in self._print_material_options:
38                                 if button.profile.default:
39                                         selectedMaterial = button
40                                         break
41
42                 if selectedMaterial is None and len(self._print_material_options) > 0:
43                         selectedMaterial = self._print_material_options[0]
44
45                 # Decide to show the panel or not
46                 if len(self._print_material_options) < 2:
47                         self.printMaterialPanel.Show(len(self._print_material_options) > 1 and \
48                                                                                  self._print_material_options[0].profile.always_visible)
49
50                 self.printTypePanel = wx.Panel(self)
51
52                 sizer = wx.GridBagSizer()
53                 self.SetSizer(sizer)
54
55                 sb = wx.StaticBox(self.printMaterialPanel, label=_("Material:"))
56                 boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
57                 boxsizer.SetMinSize((80, 20))
58                 for button in self._print_material_options:
59                         boxsizer.Add(button)
60                 self.printMaterialPanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
61                 self.printMaterialPanel.GetSizer().Add(boxsizer, flag=wx.EXPAND)
62                 sizer.Add(self.printMaterialPanel, (0,0), border=10, flag=wx.EXPAND|wx.RIGHT|wx.LEFT|wx.TOP)
63
64                 sb = wx.StaticBox(self.printTypePanel, label=_("Select a quickprint profile:"))
65                 boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
66                 boxsizer.SetMinSize((180, 20))
67                 self.printTypePanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
68                 self.printTypePanel.GetSizer().Add(boxsizer, flag=wx.EXPAND)
69                 sizer.Add(self.printTypePanel, (1,0), border=10, flag=wx.EXPAND|wx.RIGHT|wx.LEFT|wx.TOP)
70
71
72                 self.printOptionsBox = wx.StaticBox(self, label=_("Other options:"))
73                 boxsizer = wx.StaticBoxSizer(self.printOptionsBox, wx.VERTICAL)
74                 boxsizer.SetMinSize((100, 20))
75                 sizer.Add(boxsizer, (2,0), border=10, flag=wx.EXPAND|wx.RIGHT|wx.LEFT|wx.TOP)
76                 self.printOptionsSizer = boxsizer
77
78                 for button in self._print_material_options:
79                         button.Bind(wx.EVT_RADIOBUTTON, self._materialSelected)
80
81                 if selectedMaterial:
82                         selectedMaterial.SetValue(True)
83                         self._materialSelected(None)
84                 self.Layout()
85
86         def _materialSelected(self, e):
87                 material = None
88                 for button in self._print_material_options:
89                         if button.GetValue():
90                                 material = button.profile
91
92                 # Delete profile options
93                 boxsizer = self.printTypePanel.GetSizer().GetItem(0).GetSizer()
94                 boxsizer.Clear(True)
95                 self._print_profile_options = []
96
97                 # Add new profiles
98                 selectedProfile = None
99                 for print_profile in material.profiles:
100                         if print_profile.disabled:
101                                 continue
102                         button = wx.RadioButton(self.printTypePanel, -1, print_profile.name.replace('&', '&&'),
103                                                                         style=wx.RB_GROUP if len(self._print_profile_options) == 0 else 0)
104                         button.profile = print_profile
105                         self._print_profile_options.append(button)
106                         if profile.getProfileSetting('simpleModeProfile') == print_profile.name:
107                                 selectedProfile = button
108
109                 # Decide on the profile to be selected by default
110                 if selectedProfile is None:
111                         for button in self._print_profile_options:
112                                 if button.profile.default:
113                                         selectedProfile = button
114                                         break
115
116                 if selectedProfile is None and len(self._print_profile_options) > 0:
117                         selectedProfile = self._print_profile_options[0]
118
119                 # Decide if we show the profile panel or not
120                 if len(self._print_profile_options) < 2:
121                         self.printTypePanel.Show(len(self._print_profile_options) > 0 and \
122                                                                          self._print_profile_options[0].profile.always_visible)
123
124                 if selectedProfile:
125                         selectedProfile.SetValue(True)
126
127                 # Add profiles to the UI
128                 for button in self._print_profile_options:
129                         boxsizer.Add(button)
130                         button.Bind(wx.EVT_RADIOBUTTON, self._update)
131
132                 # Save current selected options
133                 selected_options = []
134                 deselected_options = []
135                 for button in self._print_other_options:
136                         if button.GetValue():
137                                 selected_options.append(button.profile.name)
138                         else:
139                                 deselected_options.append(button.profile.name)
140
141                 # Delete profile options
142                 boxsizer = self.printOptionsSizer
143                 boxsizer.Clear(True)
144                 self._print_other_options = []
145
146                 # Create new options
147                 for option in material.options:
148                         if option.disabled:
149                                 continue
150                         button = wx.CheckBox(self, -1, option.name.replace('&', '&&'))
151                         button.profile = option
152                         self._print_other_options.append(button)
153                         # Restore selection on similarly named options
154                         if option.name in selected_options or \
155                            ((not option.name in deselected_options) and option.default):
156                                 button.SetValue(True)
157
158                 # Decide if we show the profile panel or not
159                 # The always_visible doesn't make sense for options since they are checkboxes, and not radio buttons
160                 self.printOptionsBox.Show(len(self._print_other_options) > 0)
161
162                 # Add profiles to the UI
163                 for button in self._print_other_options:
164                         boxsizer.Add(button)
165                         button.Bind(wx.EVT_CHECKBOX, self._update)
166                 self.Layout()
167                 self.GetParent().Fit()
168
169                 # Do not call the callback on the initial UI build
170                 if e is not None:
171                         self._update(e)
172
173         def _update(self, e):
174                 for button in self._print_material_options:
175                         if button.GetValue():
176                                 profile.putProfileSetting('simpleModeMaterial', button.profile.name)
177                 for button in self._print_profile_options:
178                         if button.GetValue():
179                                 profile.putProfileSetting('simpleModeProfile', button.profile.name)
180                 self._callback()
181
182         def getSettingOverrides(self):
183                 settings = {}
184                 for setting in profile.settingsList:
185                         if setting.isProfile() or setting.isAlteration():
186                                 settings[setting.getName()] = setting.getDefault()
187
188                 # Apply materials, profile, then options
189                 for button in self._print_material_options:
190                         if button.GetValue():
191                                 settings.update(button.profile.getProfileDict())
192                 for button in self._print_profile_options:
193                         if button.GetValue():
194                                 settings.update(button.profile.getProfileDict())
195                 for button in self._print_other_options:
196                         if button.GetValue():
197                                 settings.update(button.profile.getProfileDict())
198
199                 return settings
200
201         def updateProfileToControls(self):
202                 pass