printrun-src/printrun/gui/widgets.py

changeset 46
cce0af6351f0
parent 26
5c98c7e24b02
child 48
3c27b4ee6fec
equal deleted inserted replaced
45:c82943fb205f 46:cce0af6351f0
118 118
119 SETTINGS_GROUPS = {"Printer": _("Printer settings"), 119 SETTINGS_GROUPS = {"Printer": _("Printer settings"),
120 "UI": _("User interface"), 120 "UI": _("User interface"),
121 "Viewer": _("Viewer"), 121 "Viewer": _("Viewer"),
122 "Colors": _("Colors"), 122 "Colors": _("Colors"),
123 "External": _("External commands"), 123 "External": _("External commands")}
124 "Laser": "Lasercut options"}
125 124
126 class PronterOptionsDialog(wx.Dialog): 125 class PronterOptionsDialog(wx.Dialog):
127 """Options editor""" 126 """Options editor"""
128 def __init__(self, pronterface): 127 def __init__(self, pronterface):
129 wx.Dialog.__init__(self, parent = None, title = _("Edit settings"), 128 wx.Dialog.__init__(self, parent = None, title = _("Edit settings"),
130 size = (400, 500), style = wx.DEFAULT_DIALOG_STYLE) 129 size = (400, 500), style = wx.DEFAULT_DIALOG_STYLE)
131 panel = wx.Panel(self) 130 panel = wx.Panel(self)
132 header = wx.StaticBox(panel, label = _("Settings")) 131 header = wx.StaticBox(panel, label = _("Settings"))
133 sbox = wx.StaticBoxSizer(header, wx.VERTICAL) 132 sbox = wx.StaticBoxSizer(header, wx.VERTICAL)
134 notebook = wx.Notebook(panel) 133 self.notebook = notebook = wx.Notebook(panel)
135 all_settings = pronterface.settings._all_settings() 134 all_settings = pronterface.settings._all_settings()
136 group_list = [] 135 group_list = []
137 groups = {} 136 groups = {}
138 for group in ["Printer", "UI", "Viewer", "Colors", "External", "Laser"]: 137 for group in ["Printer", "UI", "Viewer", "Colors", "External"]:
139 group_list.append(group) 138 group_list.append(group)
140 groups[group] = [] 139 groups[group] = []
141 for setting in all_settings: 140 for setting in all_settings:
142 if setting.group not in group_list: 141 if setting.group not in group_list:
143 group_list.append(setting.group) 142 group_list.append(setting.group)
160 font = label.GetFont() 159 font = label.GetFont()
161 font.SetWeight(wx.BOLD) 160 font.SetWeight(wx.BOLD)
162 label.SetFont(font) 161 label.SetFont(font)
163 grid.Add(label, pos = (current_row, 0), 162 grid.Add(label, pos = (current_row, 0),
164 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) 163 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
164 expand = 0 if isinstance(widget, (wx.SpinCtrlDouble, wx.Choice, wx.ComboBox)) else wx.EXPAND
165 grid.Add(widget, pos = (current_row, 1), 165 grid.Add(widget, pos = (current_row, 1),
166 flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND) 166 flag = wx.ALIGN_CENTER_VERTICAL | expand)
167 if hasattr(label, "set_default"): 167 if hasattr(label, "set_default"):
168 label.Bind(wx.EVT_MOUSE_EVENTS, label.set_default) 168 label.Bind(wx.EVT_MOUSE_EVENTS, label.set_default)
169 if hasattr(widget, "Bind"): 169 if hasattr(widget, "Bind"):
170 widget.Bind(wx.EVT_MOUSE_EVENTS, label.set_default) 170 widget.Bind(wx.EVT_MOUSE_EVENTS, label.set_default)
171 current_row += 1 171 current_row += 1
173 grouppanel.SetSizer(grid) 173 grouppanel.SetSizer(grid)
174 sbox.Add(notebook, 1, wx.EXPAND) 174 sbox.Add(notebook, 1, wx.EXPAND)
175 panel.SetSizer(sbox) 175 panel.SetSizer(sbox)
176 topsizer = wx.BoxSizer(wx.VERTICAL) 176 topsizer = wx.BoxSizer(wx.VERTICAL)
177 topsizer.Add(panel, 1, wx.ALL | wx.EXPAND) 177 topsizer.Add(panel, 1, wx.ALL | wx.EXPAND)
178 topsizer.Add(self.CreateButtonSizer(wx.OK | wx.CANCEL), 0, wx.ALIGN_RIGHT) 178 topsizer.Add(self.CreateButtonSizer(wx.OK | wx.CANCEL), 0, wx.ALIGN_CENTER)
179 self.SetSizerAndFit(topsizer) 179 self.SetSizerAndFit(topsizer)
180 self.SetMinSize(self.GetSize()) 180 self.SetMinSize(self.GetSize())
181 181
182 self.notebook = notebook 182 notebookSelection = 0
183 self.group_list = group_list 183 def PronterOptions(pronterface):
184
185 def setPage(self, name):
186 self.notebook.ChangeSelection(self.group_list.index(name))
187
188 def PronterOptions(pronterface, defaulttab = None):
189 dialog = PronterOptionsDialog(pronterface) 184 dialog = PronterOptionsDialog(pronterface)
190 if defaulttab: 185 global notebookSelection
191 # set the active tab before open dialog 186 dialog.notebook.Selection = notebookSelection
192 dialog.setPage(defaulttab)
193
194 if dialog.ShowModal() == wx.ID_OK: 187 if dialog.ShowModal() == wx.ID_OK:
188 changed_settings = []
195 for setting in pronterface.settings._all_settings(): 189 for setting in pronterface.settings._all_settings():
196 old_value = setting.value 190 old_value = setting.value
197 setting.update() 191 setting.update()
198 if setting.value != old_value: 192 if setting.value != old_value:
199 pronterface.set(setting.name, setting.value) 193 pronterface.set(setting.name, setting.value)
194 changed_settings.append(setting)
195 pronterface.on_settings_change(changed_settings)
196 notebookSelection = dialog.notebook.Selection
200 dialog.Destroy() 197 dialog.Destroy()
201 198
202 class ButtonEdit(wx.Dialog): 199 class ButtonEdit(wx.Dialog):
203 """Custom button edit dialog""" 200 """Custom button edit dialog"""
204 def __init__(self, pronterface): 201 def __init__(self, pronterface):
234 try: 231 try:
235 if macro == "": 232 if macro == "":
236 valid = True 233 valid = True
237 elif macro in self.pronterface.macros: 234 elif macro in self.pronterface.macros:
238 valid = True 235 valid = True
239 elif hasattr(self.pronterface.__class__, u"do_" + macro): 236 elif hasattr(self.pronterface.__class__, "do_" + macro):
240 valid = False 237 valid = False
241 elif len([c for c in macro if not c.isalnum() and c != "_"]): 238 elif len([c for c in macro if not c.isalnum() and c != "_"]):
242 valid = False 239 valid = False
243 else: 240 else:
244 valid = True 241 valid = True
266 maxval = 240, gaugeColour = None, bgcolor = "#FFFFFF"): 263 maxval = 240, gaugeColour = None, bgcolor = "#FFFFFF"):
267 wx.Panel.__init__(self, parent, -1, size = size) 264 wx.Panel.__init__(self, parent, -1, size = size)
268 self.Bind(wx.EVT_PAINT, self.paint) 265 self.Bind(wx.EVT_PAINT, self.paint)
269 self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) 266 self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
270 self.bgcolor = wx.Colour() 267 self.bgcolor = wx.Colour()
271 self.bgcolor.SetFromName(bgcolor) 268 self.bgcolor.Set(bgcolor)
272 self.width, self.height = size 269 self.width, self.height = size
273 self.title = title 270 self.title = title
274 self.max = maxval 271 self.max = maxval
275 self.gaugeColour = gaugeColour 272 self.gaugeColour = gaugeColour
276 self.value = 0 273 self.value = 0
297 lo, hi, val, valhi = cmin, cmid, val - vmin, vmid - vmin 294 lo, hi, val, valhi = cmin, cmid, val - vmin, vmid - vmin
298 else: 295 else:
299 lo, hi, val, valhi = cmid, cmax, val - vmid, vmax - vmid 296 lo, hi, val, valhi = cmid, cmax, val - vmid, vmax - vmid
300 vv = float(val) / valhi 297 vv = float(val) / valhi
301 rgb = lo.Red() + (hi.Red() - lo.Red()) * vv, lo.Green() + (hi.Green() - lo.Green()) * vv, lo.Blue() + (hi.Blue() - lo.Blue()) * vv 298 rgb = lo.Red() + (hi.Red() - lo.Red()) * vv, lo.Green() + (hi.Green() - lo.Green()) * vv, lo.Blue() + (hi.Blue() - lo.Blue()) * vv
302 rgb = map(lambda x: x * 0.8, rgb) 299 rgb = (int(x * 0.8) for x in rgb)
303 return wx.Colour(*map(int, rgb)) 300 return wx.Colour(*rgb)
304 301
305 def paint(self, ev): 302 def paint(self, ev):
306 self.width, self.height = self.GetClientSizeTuple() 303 self.width, self.height = self.GetClientSize()
307 self.recalc() 304 self.recalc()
308 x0, y0, x1, y1, xE, yE = 1, 1, self.ypt + 1, 1, self.width + 1 - 2, 20 305 x0, y0, x1, y1, xE, yE = 1, 1, self.ypt + 1, 1, self.width + 1 - 2, 20
309 dc = wx.PaintDC(self) 306 dc = wx.PaintDC(self)
310 dc.SetBackground(wx.Brush(self.bgcolor)) 307 dc.SetBackground(wx.Brush(self.bgcolor))
311 dc.Clear() 308 dc.Clear()
312 cold, medium, hot = wx.Colour(0, 167, 223), wx.Colour(239, 233, 119), wx.Colour(210, 50.100) 309 cold, medium, hot = wx.Colour(0, 167, 223), wx.Colour(239, 233, 119), wx.Colour(210, 50, 0)
313 # gauge1, gauge2 = wx.Colour(255, 255, 210), (self.gaugeColour or wx.Colour(234, 82, 0)) 310 # gauge1, gauge2 = wx.Colour(255, 255, 210), (self.gaugeColour or wx.Colour(234, 82, 0))
314 gauge1 = wx.Colour(255, 255, 210) 311 gauge1 = wx.Colour(255, 255, 210)
315 shadow1, shadow2 = wx.Colour(110, 110, 110), self.bgcolor 312 shadow1, shadow2 = wx.Colour(110, 110, 110), self.bgcolor
316 gc = wx.GraphicsContext.Create(dc) 313 gc = wx.GraphicsContext.Create(dc)
317 # draw shadow first 314 # draw shadow first
359 setp_path.MoveToPoint(setpoint - 4, yE) 356 setp_path.MoveToPoint(setpoint - 4, yE)
360 setp_path.AddLineToPoint(setpoint + 4, yE) 357 setp_path.AddLineToPoint(setpoint + 4, yE)
361 setp_path.AddLineToPoint(setpoint, yE - 5) 358 setp_path.AddLineToPoint(setpoint, yE - 5)
362 gc.DrawPath(setp_path) 359 gc.DrawPath(setp_path)
363 # draw readout 360 # draw readout
364 text = u"T\u00B0 %u/%u" % (self.value, self.setpoint) 361 text = "T\u00B0 %u/%u" % (self.value, self.setpoint)
365 # gc.SetFont(gc.CreateFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD), wx.WHITE)) 362 # gc.SetFont(gc.CreateFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD), wx.WHITE))
366 # gc.DrawText(text, 29,-2) 363 # gc.DrawText(text, 29,-2)
367 gc.SetFont(gc.CreateFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD), wx.WHITE)) 364 gc.SetFont(gc.CreateFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD), wx.WHITE))
368 gc.DrawText(self.title, x0 + 19, y0 + 4) 365 gc.DrawText(self.title, x0 + 19, y0 + 4)
369 gc.DrawText(text, x0 + 119, y0 + 4) 366 gc.DrawText(text, x0 + 119, y0 + 4)
370 gc.SetFont(gc.CreateFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))) 367 gc.SetFont(gc.CreateFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)))
371 gc.DrawText(self.title, x0 + 18, y0 + 3) 368 gc.DrawText(self.title, x0 + 18, y0 + 3)
372 gc.DrawText(text, x0 + 118, y0 + 3) 369 gc.DrawText(text, x0 + 118, y0 + 3)
373 370
374 class SpecialButton(object): 371 class SpecialButton:
375 372
376 label = None 373 label = None
377 command = None 374 command = None
378 background = None 375 background = None
379 tooltip = None 376 tooltip = None

mercurial