Commit ae7bac41 authored by Guillaume Seguin's avatar Guillaume Seguin

More cleanup of buttons handling, sanitize custom buttons

parent d01cb51a
...@@ -61,17 +61,17 @@ class LeftPane(wx.GridBagSizer): ...@@ -61,17 +61,17 @@ class LeftPane(wx.GridBagSizer):
self.Add(self.xyzsizer, pos = (1, 0), span = (1, 8), flag = wx.ALIGN_CENTER) self.Add(self.xyzsizer, pos = (1, 0), span = (1, 8), flag = wx.ALIGN_CENTER)
for i in root.cpbuttons: for i in root.cpbuttons:
btn = make_button(root.panel, i[0], root.procbutton, i[5], style = wx.BU_EXACTFIT) btn = make_button(root.panel, i.label, root.procbutton, i.tooltip, style = wx.BU_EXACTFIT)
btn.SetBackgroundColour(i[3]) btn.SetBackgroundColour(i.background)
btn.SetForegroundColour("black") btn.SetForegroundColour("black")
btn.properties = i btn.properties = i
root.btndict[i[1]] = btn root.btndict[i.command] = btn
root.printerControls.append(btn) root.printerControls.append(btn)
if i[2] == None: if i.pos == None:
if i[4] == 0: if i.span == 0:
llts.Add(btn) llts.Add(btn)
else: else:
self.Add(btn, pos = i[2], span = i[4]) self.Add(btn, pos = i.pos, span = i.span)
root.xyfeedc = wx.SpinCtrl(root.panel,-1, str(root.settings.xy_feedrate), min = 0, max = 50000, size = (70,-1)) root.xyfeedc = wx.SpinCtrl(root.panel,-1, str(root.settings.xy_feedrate), min = 0, max = 50000, size = (70,-1))
root.xyfeedc.SetToolTip(wx.ToolTip("Set Maximum Speed for X & Y axes (mm/min)")) root.xyfeedc.SetToolTip(wx.ToolTip("Set Maximum Speed for X & Y axes (mm/min)"))
...@@ -90,9 +90,7 @@ class LeftPane(wx.GridBagSizer): ...@@ -90,9 +90,7 @@ class LeftPane(wx.GridBagSizer):
self.Add(wx.StaticText(root.panel,-1, _("Heat:")), pos = (2, 0), span = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT) self.Add(wx.StaticText(root.panel,-1, _("Heat:")), pos = (2, 0), span = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
htemp_choices = [root.temps[i]+" ("+i+")" for i in sorted(root.temps.keys(), key = lambda x:root.temps[x])] htemp_choices = [root.temps[i]+" ("+i+")" for i in sorted(root.temps.keys(), key = lambda x:root.temps[x])]
root.settoff = wx.Button(root.panel,-1, _("Off"), size = (36,-1), style = wx.BU_EXACTFIT) root.settoff = make_button(root.panel, _("Off"), lambda e: root.do_settemp("off"), _("Switch Hotend Off"), size = (36,-1), style = wx.BU_EXACTFIT)
root.settoff.SetToolTip(wx.ToolTip("Switch Hotend Off"))
root.settoff.Bind(wx.EVT_BUTTON, lambda e:root.do_settemp("off"))
root.printerControls.append(root.settoff) root.printerControls.append(root.settoff)
self.Add(root.settoff, pos = (2, 1), span = (1, 1)) self.Add(root.settoff, pos = (2, 1), span = (1, 1))
...@@ -104,18 +102,14 @@ class LeftPane(wx.GridBagSizer): ...@@ -104,18 +102,14 @@ class LeftPane(wx.GridBagSizer):
root.htemp.Bind(wx.EVT_COMBOBOX, root.htemp_change) root.htemp.Bind(wx.EVT_COMBOBOX, root.htemp_change)
self.Add(root.htemp, pos = (2, 2), span = (1, 2)) self.Add(root.htemp, pos = (2, 2), span = (1, 2))
root.settbtn = wx.Button(root.panel,-1, _("Set"), size = (38,-1), style = wx.BU_EXACTFIT) root.settbtn = make_button(root.panel, _("Set"), root.do_settemp, _("Switch Hotend On"), size = (38, -1), style = wx.BU_EXACTFIT)
root.settbtn.SetToolTip(wx.ToolTip("Switch Hotend On"))
root.settbtn.Bind(wx.EVT_BUTTON, root.do_settemp)
root.printerControls.append(root.settbtn) root.printerControls.append(root.settbtn)
self.Add(root.settbtn, pos = (2, 4), span = (1, 1)) self.Add(root.settbtn, pos = (2, 4), span = (1, 1))
self.Add(wx.StaticText(root.panel,-1, _("Bed:")), pos = (3, 0), span = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT) self.Add(wx.StaticText(root.panel,-1, _("Bed:")), pos = (3, 0), span = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
btemp_choices = [root.bedtemps[i]+" ("+i+")" for i in sorted(root.bedtemps.keys(), key = lambda x:root.temps[x])] btemp_choices = [root.bedtemps[i]+" ("+i+")" for i in sorted(root.bedtemps.keys(), key = lambda x:root.temps[x])]
root.setboff = wx.Button(root.panel,-1, _("Off"), size = (36,-1), style = wx.BU_EXACTFIT) root.setboff = make_button(root.panel, _("Off"), lambda e:root.do_bedtemp("off"), _("Switch Heated Bed Off"), size = (36,-1), style = wx.BU_EXACTFIT)
root.setboff.SetToolTip(wx.ToolTip("Switch Heated Bed Off"))
root.setboff.Bind(wx.EVT_BUTTON, lambda e:root.do_bedtemp("off"))
root.printerControls.append(root.setboff) root.printerControls.append(root.setboff)
self.Add(root.setboff, pos = (3, 1), span = (1, 1)) self.Add(root.setboff, pos = (3, 1), span = (1, 1))
...@@ -127,9 +121,7 @@ class LeftPane(wx.GridBagSizer): ...@@ -127,9 +121,7 @@ class LeftPane(wx.GridBagSizer):
root.btemp.Bind(wx.EVT_COMBOBOX, root.btemp_change) root.btemp.Bind(wx.EVT_COMBOBOX, root.btemp_change)
self.Add(root.btemp, pos = (3, 2), span = (1, 2)) self.Add(root.btemp, pos = (3, 2), span = (1, 2))
root.setbbtn = wx.Button(root.panel,-1, _("Set"), size = (38,-1), style = wx.BU_EXACTFIT) root.setbbtn = make_button(root.panel, _("Set"), root.do_bedtemp, ("Switch Heated Bed On"), size = (38, -1), style = wx.BU_EXACTFIT)
root.setbbtn.SetToolTip(wx.ToolTip("Switch Heated Bed On"))
root.setbbtn.Bind(wx.EVT_BUTTON, root.do_bedtemp)
root.printerControls.append(root.setbbtn) root.printerControls.append(root.setbbtn)
self.Add(root.setbbtn, pos = (3, 4), span = (1, 1)) self.Add(root.setbbtn, pos = (3, 4), span = (1, 1))
...@@ -232,11 +224,8 @@ class LogPane(wx.BoxSizer): ...@@ -232,11 +224,8 @@ class LogPane(wx.BoxSizer):
root.commandbox.histindex = 1 root.commandbox.histindex = 1
#root.printerControls.append(root.commandbox) #root.printerControls.append(root.commandbox)
lbrs.Add(root.commandbox, 1) lbrs.Add(root.commandbox, 1)
root.sendbtn = wx.Button(root.panel,-1, _("Send"), style = wx.BU_EXACTFIT) root.sendbtn = make_button(root.panel, _("Send"), root.sendline, _("Send Command to Printer"), style = wx.BU_EXACTFIT, container = lbrs)
root.sendbtn.SetToolTip(wx.ToolTip("Send Command to Printer"))
root.sendbtn.Bind(wx.EVT_BUTTON, root.sendline)
#root.printerControls.append(root.sendbtn) #root.printerControls.append(root.sendbtn)
lbrs.Add(root.sendbtn)
self.Add(lbrs, 0, wx.EXPAND) self.Add(lbrs, 0, wx.EXPAND)
class MainToolbar(wx.BoxSizer): class MainToolbar(wx.BoxSizer):
......
...@@ -316,3 +316,22 @@ class TempGauge(wx.Panel): ...@@ -316,3 +316,22 @@ class TempGauge(wx.Panel):
gc.SetFont(gc.CreateFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))) gc.SetFont(gc.CreateFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)))
gc.DrawText(self.title, x0+18, y0+3) gc.DrawText(self.title, x0+18, y0+3)
gc.DrawText(text, x0+118, y0+3) gc.DrawText(text, x0+118, y0+3)
class SpecialButton(object):
label = None
command = None
background = None
pos = None
span = None
tooltip = None
custom = None
def __init__(self, label, command, background = None, pos = None, span = None, tooltip = None, custom = False):
self.label = label
self.command = command
self.pos = pos
self.background = background
self.span = span
self.tooltip = tooltip
self.custom = custom
...@@ -115,10 +115,10 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -115,10 +115,10 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.paused = False self.paused = False
self.sentlines = Queue.Queue(30) self.sentlines = Queue.Queue(30)
self.cpbuttons = [ self.cpbuttons = [
[_("Motors off"), ("M84"), None, (250, 250, 250), 0, _("Switch all motors off")], SpecialButton(_("Motors off"), ("M84"), (250, 250, 250), None, 0, _("Switch all motors off")),
[_("Check temp"), ("M105"), (2, 5), (225, 200, 200), (1, 1), _("Check current hotend temperature")], SpecialButton(_("Check temp"), ("M105"), (225, 200, 200), (2, 5), (1, 1), _("Check current hotend temperature")),
[_("Extrude"), ("extrude"), (4, 0), (225, 200, 200), (1, 2), _("Advance extruder by set length")], SpecialButton(_("Extrude"), ("extrude"), (225, 200, 200), (4, 0), (1, 2), _("Advance extruder by set length")),
[_("Reverse"), ("reverse"), (5, 0), (225, 200, 200), (1, 2), _("Reverse extruder by set length")], SpecialButton(_("Reverse"), ("reverse"), (225, 200, 200), (5, 0), (1, 2), _("Reverse extruder by set length")),
] ]
self.custombuttons = [] self.custombuttons = []
self.btndict = {} self.btndict = {}
...@@ -649,16 +649,16 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -649,16 +649,16 @@ class PronterWindow(MainWindow, pronsole.pronsole):
for i in xrange(len(self.custombuttons)): for i in xrange(len(self.custombuttons)):
btndef = self.custombuttons[i] btndef = self.custombuttons[i]
try: try:
b = wx.Button(self.panel,-1, btndef[0], style = wx.BU_EXACTFIT) b = wx.Button(self.panel, -1, btndef.label, style = wx.BU_EXACTFIT)
b.SetToolTip(wx.ToolTip(_("Execute command: ")+btndef[1])) b.SetToolTip(wx.ToolTip(_("Execute command: ")+btndef.command))
if len(btndef)>2: if btndef.background:
b.SetBackgroundColour(btndef[2]) b.SetBackgroundColour(btndef.background)
rr, gg, bb = b.GetBackgroundColour().Get() rr, gg, bb = b.GetBackgroundColour().Get()
if 0.3*rr+0.59*gg+0.11*bb < 60: if 0.3*rr+0.59*gg+0.11*bb < 60:
b.SetForegroundColour("#ffffff") b.SetForegroundColour("#ffffff")
except: except:
if i == newbuttonbuttonindex: if i == newbuttonbuttonindex:
self.newbuttonbutton = b = wx.Button(self.panel,-1, "+", size = (19, 18), style = wx.BU_EXACTFIT) self.newbuttonbutton = b = wx.Button(self.panel, -1, "+", size = (19, 18), style = wx.BU_EXACTFIT)
#b.SetFont(wx.Font(12, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)) #b.SetFont(wx.Font(12, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
b.SetForegroundColour("#4444ff") b.SetForegroundColour("#4444ff")
b.SetToolTip(wx.ToolTip(_("click to add new custom button"))) b.SetToolTip(wx.ToolTip(_("click to add new custom button")))
...@@ -712,10 +712,10 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -712,10 +712,10 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.webInterface.AddLog("Custom button number should be between 0 and 63") self.webInterface.AddLog("Custom button number should be between 0 and 63")
return return
while num >= len(self.custombuttons): while num >= len(self.custombuttons):
self.custombuttons+=[None] self.custombuttons.append(None)
self.custombuttons[num]=[title, command] self.custombuttons[num] = SpecialButton(title, command)
if colour is not None: if colour is not None:
self.custombuttons[num]+=[colour] self.custombuttons[num].background = colour
if not self.processing_rc: if not self.processing_rc:
self.cbuttons_reload() self.cbuttons_reload()
#except Exception, x: #except Exception, x:
...@@ -726,8 +726,8 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -726,8 +726,8 @@ class PronterWindow(MainWindow, pronsole.pronsole):
if new_n is None: new_n = n if new_n is None: new_n = n
if bdef is None or bdef == "": if bdef is None or bdef == "":
self.save_in_rc(("button %d" % n),'') self.save_in_rc(("button %d" % n),'')
elif len(bdef)>2: elif bdef.background:
colour = bdef[2] colour = bdef.background
if type(colour) not in (str, unicode): if type(colour) not in (str, unicode):
#print type(colour), map(type, colour) #print type(colour), map(type, colour)
if type(colour) == tuple and tuple(map(type, colour)) == (int, int, int): if type(colour) == tuple and tuple(map(type, colour)) == (int, int, int):
...@@ -735,18 +735,18 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -735,18 +735,18 @@ class PronterWindow(MainWindow, pronsole.pronsole):
colour = wx.Colour(*colour).GetAsString(wx.C2S_NAME|wx.C2S_HTML_SYNTAX) colour = wx.Colour(*colour).GetAsString(wx.C2S_NAME|wx.C2S_HTML_SYNTAX)
else: else:
colour = wx.Colour(colour).GetAsString(wx.C2S_NAME|wx.C2S_HTML_SYNTAX) colour = wx.Colour(colour).GetAsString(wx.C2S_NAME|wx.C2S_HTML_SYNTAX)
self.save_in_rc(("button %d" % n),'button %d "%s" /c "%s" %s' % (new_n, bdef[0], colour, bdef[1])) self.save_in_rc(("button %d" % n),'button %d "%s" /c "%s" %s' % (new_n, bdef.label, colour, bdef.command))
else: else:
self.save_in_rc(("button %d" % n),'button %d "%s" %s' % (new_n, bdef[0], bdef[1])) self.save_in_rc(("button %d" % n),'button %d "%s" %s' % (new_n, bdef.label, bdef.command))
def cbutton_edit(self, e, button = None): def cbutton_edit(self, e, button = None):
bedit = ButtonEdit(self) bedit = ButtonEdit(self)
if button is not None: if button is not None:
n = button.custombutton n = button.custombutton
bedit.name.SetValue(button.properties[0]) bedit.name.SetValue(button.label)
bedit.command.SetValue(button.properties[1]) bedit.command.SetValue(button.command)
if len(button.properties)>2: if button.background:
colour = button.properties[2] colour = button.background
if type(colour) not in (str, unicode): if type(colour) not in (str, unicode):
#print type(colour) #print type(colour)
if type(colour) == tuple and tuple(map(type, colour)) == (int, int, int): if type(colour) == tuple and tuple(map(type, colour)) == (int, int, int):
...@@ -762,9 +762,9 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -762,9 +762,9 @@ class PronterWindow(MainWindow, pronsole.pronsole):
if bedit.ShowModal() == wx.ID_OK: if bedit.ShowModal() == wx.ID_OK:
if n == len(self.custombuttons): if n == len(self.custombuttons):
self.custombuttons+=[None] self.custombuttons+=[None]
self.custombuttons[n]=[bedit.name.GetValue().strip(), bedit.command.GetValue().strip()] self.custombuttons[n]=SpecialButton(bedit.name.GetValue().strip(), bedit.command.GetValue().strip(), custom = True)
if bedit.color.GetValue().strip()!="": if bedit.color.GetValue().strip()!="":
self.custombuttons[n]+=[bedit.color.GetValue()] self.custombuttons[n].background = bedit.color.GetValue()
self.cbutton_save(n, self.custombuttons[n]) self.cbutton_save(n, self.custombuttons[n])
bedit.Destroy() bedit.Destroy()
self.cbuttons_reload() self.cbuttons_reload()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment