1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
import wx
import ConfigParser as configparser
import os.path
from Cura.util import profile
from Cura.util import resources
class simpleModePanel(wx.Panel):
"Main user interface window for Quickprint mode"
def __init__(self, parent, callback):
super(simpleModePanel, self).__init__(parent)
self._callback = callback
self._print_material_options = []
self._print_profile_options = []
self._print_other_options = []
self._print_material_types = {}
self._all_print_materials = []
materials = resources.getSimpleModeMaterials()
other_print_material_types = []
for material in materials:
if material.disabled:
continue
if len(material.types) == 0:
other_print_material_types.append(material)
else:
for type in material.types:
if self._print_material_types.has_key(type):
self._print_material_types[type].append(material)
else:
self._print_material_types[type] = [material]
if len(self._print_material_types) == 0:
self._print_material_types = None
# Create material buttons
self.printMaterialPanel = wx.Panel(self)
selectedMaterial = None
for material in materials:
if material.disabled:
continue
# Show radio buttons if there are no material types
if self._print_material_types is None:
button = wx.RadioButton(self.printMaterialPanel, -1, material.name.replace('&', '&&'),
style=wx.RB_GROUP if len(self._print_material_options) == 0 else 0)
button.profile = material
button.Bind(wx.EVT_RADIOBUTTON, self._materialSelected)
self._print_material_options.append(button)
self._all_print_materials.append(material)
if profile.getProfileSetting('simpleModeMaterial') == material.name:
selectedMaterial = material
# Decide on the default selected material
if selectedMaterial is None:
for material in self._all_print_materials:
if material.default:
selectedMaterial = material
break
if selectedMaterial is None and len(self._all_print_materials) > 0:
selectedMaterial = self._all_print_materials[0]
# Decide to show the panel or not
if self._print_material_types is None and len(self._print_material_options) < 2:
self.printMaterialPanel.Show(len(self._print_material_options) > 1 and \
self._print_material_options[0].always_visible)
# Create material types combobox
self.printMaterialTypesPanel = wx.Panel(self)
selectedMaterialType = None
if self._print_material_types is not None:
for material_type in self._print_material_types:
if profile.getProfileSetting('simpleModeMaterialType') == material_type and \
selectedMaterial in self._print_material_types[material_type]:
selectedMaterialType = material_type
if selectedMaterialType is None:
if selectedMaterial is None or len(selectedMaterial.types) == 0:
selectedMaterialType = _("Others")
else:
selectedMaterialType = selectedMaterial.types[0]
# Decide to show the material types or not
if self._print_material_types is None:
self.printMaterialTypesPanel.Show(False)
self.printTypePanel = wx.Panel(self)
sizer = wx.GridBagSizer()
self.SetSizer(sizer)
boxsizer = wx.BoxSizer(wx.VERTICAL)
boxsizer.SetMinSize((80, 20))
if self._print_material_types is None:
self.materialTypeCombo = None
else:
choices = self._print_material_types.keys()
choices.sort(key=lambda type: sum([mat.order for mat in self._print_material_types[type]]))
# Now we can add Others, so it appears towards the end
if len(other_print_material_types) > 0:
self._print_material_types[_("Others")] = other_print_material_types
choices.append(_("Others"))
choices.append(_("All"))
label = wx.StaticText(self.printMaterialTypesPanel, label=_("Material ease of use:"))
self.materialTypeCombo = wx.ComboBox(self.printMaterialTypesPanel, -1, selectedMaterialType,
choices=choices, style=wx.CB_READONLY)
self.materialTypeCombo.Bind(wx.EVT_COMBOBOX, self._materialTypeSelected)
boxsizer.Add(label, flag=wx.EXPAND)
boxsizer.Add(self.materialTypeCombo, border=5, flag=wx.BOTTOM|wx.TOP|wx.EXPAND)
self.printMaterialTypesPanel.SetSizer(boxsizer)
sizer.Add(self.printMaterialTypesPanel, (0,0), border=10, flag=wx.EXPAND|wx.RIGHT|wx.LEFT|wx.TOP)
if self._print_material_types is None:
sb = wx.StaticBox(self.printMaterialPanel, label=_("Material:"))
boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
boxsizer.SetMinSize((80, 20))
for button in self._print_material_options:
# wxpython 2.8 gives a 13 pixel high radio/checkbutton but wxpython 3.0
# gives it a 25 pixels height, so we add a border to compensate for the ugliness
if button.GetBestSize()[1] < 20:
border = 5
else:
border = 0
boxsizer.Add(button, border=border, flag=wx.ALL)
self.printMaterialPanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
self.printMaterialPanel.GetSizer().Add(boxsizer, flag=wx.EXPAND)
self.materialCombo = None
else:
boxsizer = wx.BoxSizer(wx.VERTICAL)
boxsizer.SetMinSize((80, 20))
label = wx.StaticText(self.printMaterialPanel, label=_("Material:"))
self.materialCombo = wx.ComboBox(self.printMaterialPanel, -1, selectedMaterial.name,
choices=[], style=wx.CB_READONLY)
self.materialCombo.Bind(wx.EVT_COMBOBOX, self._materialSelected)
boxsizer.Add(label, flag=wx.EXPAND)
boxsizer.Add(self.materialCombo, border=5, flag=wx.BOTTOM|wx.TOP|wx.EXPAND)
self.printMaterialPanel.SetSizer(boxsizer)
self.materialHyperlink = wx.HyperlinkCtrl(self.printMaterialPanel, -1, label=_('Material Information'), url='',
style=wx.HL_ALIGN_LEFT|wx.BORDER_NONE|wx.HL_CONTEXTMENU)
self.materialHyperlink.Show(False)
self.materialDescription = wx.StaticText(self.printMaterialPanel, -1, '')
self.materialDescription.Show(False)
boxsizer.Add(self.materialDescription, border=5, flag=wx.BOTTOM|wx.TOP|wx.EXPAND)
boxsizer.Add(self.materialHyperlink, border=5, flag=wx.BOTTOM|wx.TOP|wx.EXPAND)
sizer.Add(self.printMaterialPanel, (1,0), border=10, flag=wx.EXPAND|wx.RIGHT|wx.LEFT|wx.TOP)
sb = wx.StaticBox(self.printTypePanel, label=_("Select a quickprint profile:"))
boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
boxsizer.SetMinSize((180, 20))
self.printTypePanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
self.printTypePanel.GetSizer().Add(boxsizer, flag=wx.EXPAND)
sizer.Add(self.printTypePanel, (2,0), border=10, flag=wx.EXPAND|wx.RIGHT|wx.LEFT|wx.TOP)
self.printOptionsBox = wx.StaticBox(self, label=_("Other options:"))
boxsizer = wx.StaticBoxSizer(self.printOptionsBox, wx.VERTICAL)
boxsizer.SetMinSize((100, 20))
sizer.Add(boxsizer, (3,0), border=10, flag=wx.EXPAND|wx.RIGHT|wx.LEFT|wx.TOP)
self.printOptionsSizer = boxsizer
if selectedMaterialType:
self.materialTypeCombo.SetValue(selectedMaterialType)
self._materialTypeSelected(None)
if selectedMaterial:
if self.materialCombo:
self.materialCombo.SetValue(selectedMaterial.name)
else:
for button in self._print_material_options:
if button.profile == selectedMaterial:
button.SetValue(True)
break
self._materialSelected(None)
self.Layout()
def _materialTypeSelected(self, e):
materialType = self.materialTypeCombo.GetValue()
selection = self.materialTypeCombo.GetSelection()
choices = []
if selection >= len(self._print_material_types.keys()):
materials = self._all_print_materials
for material in materials:
choices.append(material.full_name)
else:
materials = self._print_material_types[materialType]
for material in materials:
choices.append(material.name)
# Decide on the default selected material
selectedMaterial = None
for material in materials:
if material.default:
selectedMaterial = material
break
if selectedMaterial is None and len(materials) > 0:
selectedMaterial = materials[0]
self.materialCombo.Clear()
self.materialCombo.AppendItems(choices)
if len(materials) == 0:
self.printMaterialTypesPanel.Show(False)
else:
self.printMaterialTypesPanel.Show(True)
self.materialCombo.SetValue(selectedMaterial.name)
self.materialCombo.Layout()
self.printMaterialPanel.Layout()
self._materialSelected(e)
def _getSelectedMaterial(self):
if self.materialCombo:
materialType = self.materialTypeCombo.GetValue()
selection = self.materialTypeCombo.GetSelection()
if selection >= len(self._print_material_types.keys()):
materials = self._all_print_materials
else:
materials = self._print_material_types[materialType]
selection = self.materialCombo.GetSelection()
# This is needed to avoid a wxpython 2.8 bug which returns -1
# when the selection is made with SetValue
if selection == -1:
material_name = self.materialCombo.GetValue()
for material in materials:
if material.name == material_name:
return material
return materials[selection]
else:
for button in self._print_material_options:
if button.GetValue():
return button.profile
return None
def _materialSelected(self, e):
material = self._getSelectedMaterial()
# Delete profile options
boxsizer = self.printTypePanel.GetSizer().GetItem(0).GetSizer()
boxsizer.Clear(True)
self._print_profile_options = []
if material is None:
self.printOptionsBox.Show(False)
self.printTypePanel.Show(False)
return
self.printOptionsBox.Show(True)
self.printTypePanel.Show(True)
self.materialHyperlink.Show(material.url is not None)
if material.url:
self.materialHyperlink.SetURL(material.url)
self.materialDescription.Show(material.description is not None)
if material.description:
self.materialDescription.SetLabel(material.description)
# Add new profiles
selectedProfile = None
for print_profile in material.profiles:
if print_profile.disabled:
continue
button = wx.RadioButton(self.printTypePanel, -1, print_profile.name.replace('&', '&&'),
style=wx.RB_GROUP if len(self._print_profile_options) == 0 else 0)
button.profile = print_profile
self._print_profile_options.append(button)
if profile.getProfileSetting('simpleModeProfile') == print_profile.name:
selectedProfile = button
# Decide on the profile to be selected by default
if selectedProfile is None:
for button in self._print_profile_options:
if button.profile.default:
selectedProfile = button
break
if selectedProfile is None and len(self._print_profile_options) > 0:
selectedProfile = self._print_profile_options[0]
# Decide if we show the profile panel or not
if len(self._print_profile_options) < 2:
self.printTypePanel.Show(len(self._print_profile_options) > 0 and \
self._print_profile_options[0].profile.always_visible)
if selectedProfile:
selectedProfile.SetValue(True)
# Add profiles to the UI
for button in self._print_profile_options:
# wxpython 2.8 gives a 13 pixel high radio/checkbutton but wxpython 3.0
# gives it a 25 pixels height, so we add a border to compensate for the ugliness
if button.GetBestSize()[1] < 20:
border = 5
else:
border = 0
boxsizer.Add(button, border=border, flag=wx.ALL)
button.Bind(wx.EVT_RADIOBUTTON, self._update)
# Save current selected options
selected_options = []
deselected_options = []
for button in self._print_other_options:
if button.GetValue():
selected_options.append(button.profile.name)
else:
deselected_options.append(button.profile.name)
# Delete profile options
boxsizer = self.printOptionsSizer
boxsizer.Clear(True)
self._print_other_options = []
# Create new options
for option in material.options:
if option.disabled:
continue
button = wx.CheckBox(self, -1, option.name.replace('&', '&&'))
button.profile = option
self._print_other_options.append(button)
# Restore selection on similarly named options
if option.name in selected_options or \
((not option.name in deselected_options) and option.default):
button.SetValue(True)
# Decide if we show the profile panel or not
# The always_visible doesn't make sense for options since they are checkboxes, and not radio buttons
self.printOptionsBox.Show(len(self._print_other_options) > 0)
# Add profiles to the UI
for button in self._print_other_options:
# wxpython 2.8 gives a 13 pixel high radio/checkbutton but wxpython 3.0
# gives it a 25 pixels height, so we add a border to compensate for the ugliness
if button.GetBestSize()[1] < 20:
border = 5
else:
border = 0
boxsizer.Add(button, border=border, flag=wx.ALL)
button.Bind(wx.EVT_CHECKBOX, self._update)
self.printTypePanel.Layout()
self.Layout()
self.GetParent().Fit()
# Do not call the callback on the initial UI build
if e is not None:
self._update(e)
def _update(self, e):
material = self._getSelectedMaterial()
if material:
profile.putProfileSetting('simpleModeMaterial', material.name)
for button in self._print_profile_options:
if button.GetValue():
profile.putProfileSetting('simpleModeProfile', button.profile.name)
self._callback()
def getSettingOverrides(self):
settings = {}
for setting in profile.settingsList:
if setting.isProfile() or setting.isAlteration():
settings[setting.getName()] = setting.getDefault()
# Apply materials, profile, then options
material = self._getSelectedMaterial()
if material:
settings.update(material.getProfileDict())
for button in self._print_profile_options:
if button.GetValue():
settings.update(button.profile.getProfileDict())
for button in self._print_other_options:
if button.GetValue():
settings.update(button.profile.getProfileDict())
return settings
def updateProfileToControls(self):
pass
|