1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
4 import ConfigParser as configparser
7 from Cura.util import profile
8 from Cura.util import resources
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
16 self._print_material_options = []
17 self._print_profile_options = []
18 self._print_other_options = []
20 materials = resources.getSimpleModeMaterials()
22 # Create material buttons
23 self.printMaterialPanel = wx.Panel(self)
24 selectedMaterial = None
25 for material in materials:
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
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
42 if selectedMaterial is None and len(self._print_material_options) > 0:
43 selectedMaterial = self._print_material_options[0]
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)
50 self.printTypePanel = wx.Panel(self)
52 sizer = wx.GridBagSizer()
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:
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)
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)
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
78 for button in self._print_material_options:
79 button.Bind(wx.EVT_RADIOBUTTON, self._materialSelected)
82 selectedMaterial.SetValue(True)
83 self._materialSelected(None)
86 def _materialSelected(self, e):
88 for button in self._print_material_options:
90 material = button.profile
92 # Delete profile options
93 boxsizer = self.printTypePanel.GetSizer().GetItem(0).GetSizer()
95 self._print_profile_options = []
98 selectedProfile = None
99 for print_profile in material.profiles:
100 if print_profile.disabled:
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
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
116 if selectedProfile is None and len(self._print_profile_options) > 0:
117 selectedProfile = self._print_profile_options[0]
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)
125 selectedProfile.SetValue(True)
127 # Add profiles to the UI
128 for button in self._print_profile_options:
130 button.Bind(wx.EVT_RADIOBUTTON, self._update)
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)
139 deselected_options.append(button.profile.name)
141 # Delete profile options
142 boxsizer = self.printOptionsSizer
144 self._print_other_options = []
147 for option in material.options:
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)
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)
162 # Add profiles to the UI
163 for button in self._print_other_options:
165 button.Bind(wx.EVT_CHECKBOX, self._update)
167 self.GetParent().Fit()
169 # Do not call the callback on the initial UI build
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)
182 def getSettingOverrides(self):
184 for setting in profile.settingsList:
185 if setting.isProfile() or setting.isAlteration():
186 settings[setting.getName()] = setting.getDefault()
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())
201 def updateProfileToControls(self):