Commit bbcdf2f3 authored by Guillaume Seguin's avatar Guillaume Seguin

Cleanup factorized button creation, start using it more

parent 8974ada1
...@@ -27,6 +27,20 @@ from printrun.xybuttons import XYButtons ...@@ -27,6 +27,20 @@ from printrun.xybuttons import XYButtons
from printrun.zbuttons import ZButtons from printrun.zbuttons import ZButtons
from printrun.graph import Graph from printrun.graph import Graph
def make_button(parent, label, callback, tooltip, container = None, size = wx.DefaultSize, style = 0):
button = wx.Button(parent, -1, label, style = style, size = size)
button.Bind(wx.EVT_BUTTON, callback)
button.SetToolTip(wx.ToolTip(tooltip))
if container:
container.Add(button)
return button
def make_sized_button(*args):
return make_button(*args, size = buttonSize)
def make_autosize_button(*args):
return make_button(*args, size = (-1, buttonSize[1]), style = wx.BU_EXACTFIT)
class XYZControlsSizer(wx.GridBagSizer): class XYZControlsSizer(wx.GridBagSizer):
def __init__(self, root): def __init__(self, root):
...@@ -47,13 +61,11 @@ class LeftPane(wx.GridBagSizer): ...@@ -47,13 +61,11 @@ 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 = wx.Button(root.panel,-1, i[0], style = wx.BU_EXACTFIT) btn = make_button(root.panel, i[0], root.procbutton, i[5], style = wx.BU_EXACTFIT)
btn.SetToolTip(wx.ToolTip(i[5]))
btn.SetBackgroundColour(i[3]) btn.SetBackgroundColour(i[3])
btn.SetForegroundColour("black") btn.SetForegroundColour("black")
btn.properties = i btn.properties = i
btn.Bind(wx.EVT_BUTTON, root.procbutton) root.btndict[i[1]] = btn
root.btndict[i[1]]=btn
root.printerControls.append(btn) root.printerControls.append(btn)
if i[2] == None: if i[2] == None:
if i[4] == 0: if i[4] == 0:
...@@ -227,23 +239,6 @@ class LogPane(wx.BoxSizer): ...@@ -227,23 +239,6 @@ class LogPane(wx.BoxSizer):
lbrs.Add(root.sendbtn) lbrs.Add(root.sendbtn)
self.Add(lbrs, 0, wx.EXPAND) self.Add(lbrs, 0, wx.EXPAND)
def make_button(parent, label, callback, tooltip, container = None, size = None, style = None):
if style:
button = wx.Button(parent, -1, label, style = style, size = size)
else:
button = wx.Button(parent, -1, label, size = size)
button.Bind(wx.EVT_BUTTON, callback)
button.SetToolTip(wx.ToolTip(tooltip))
if container:
container.Add(button)
return button
def make_sized_button(*args):
return make_button(*args, size = buttonSize)
def make_autosize_button(*args):
return make_button(*args, size = (-1, buttonSize[1]), style = wx.BU_EXACTFIT)
class MainToolbar(wx.BoxSizer): class MainToolbar(wx.BoxSizer):
def __init__(self, root): def __init__(self, root):
......
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