Configtool: add heater modify button.

Also turn PWM by default on.
This commit is contained in:
Markus Hitter 2015-05-30 22:22:52 +02:00
parent 0f5990b2eb
commit b813df95ff
2 changed files with 55 additions and 8 deletions

View File

@ -4,7 +4,8 @@ from configtool.data import BSIZESMALL, offsetChLabel, offsetTcLabel
class AddHeaterDlg(wx.Dialog):
def __init__(self, parent, names, pins, font):
def __init__(self, parent, names, pins, font,
name = "", pin = "", pwm = "1"):
wx.Dialog.__init__(self, parent, wx.ID_ANY, "Add heater", size = (400, 204))
self.SetFont(font)
self.Bind(wx.EVT_CLOSE, self.onCancel)
@ -12,7 +13,7 @@ class AddHeaterDlg(wx.Dialog):
self.names = names
self.choices = pins
self.nameValid = False
self.nameValid = (name != "")
sz = wx.BoxSizer(wx.VERTICAL)
gsz = wx.GridBagSizer()
@ -24,9 +25,10 @@ class AddHeaterDlg(wx.Dialog):
st.SetFont(font)
lsz.Add(st, 1, wx.TOP, offsetTcLabel)
self.tcName = wx.TextCtrl(self, wx.ID_ANY, "")
self.tcName = wx.TextCtrl(self, wx.ID_ANY, name)
self.tcName.SetFont(font)
self.tcName.SetBackgroundColour("pink")
if not name:
self.tcName.SetBackgroundColour("pink")
self.tcName.Bind(wx.EVT_TEXT, self.onNameEntry)
lsz.Add(self.tcName)
self.tcName.SetToolTipString("Enter a unique name for this heater.")
@ -42,7 +44,11 @@ class AddHeaterDlg(wx.Dialog):
self.chPin = wx.Choice(self, wx.ID_ANY, choices = pins)
self.chPin.SetFont(font)
self.chPin.Bind(wx.EVT_CHOICE, self.onChoice)
self.chPin.SetSelection(0)
i = self.chPin.FindString(pin)
if i == wx.NOT_FOUND:
self.chPin.SetSelection(0)
else:
self.chPin.SetSelection(i)
lsz.Add(self.chPin)
self.chPin.SetToolTipString("Choose a pin for this heater.")
@ -50,6 +56,7 @@ class AddHeaterDlg(wx.Dialog):
self.cbPwm = wx.CheckBox(self, wx.ID_ANY, "PWM")
self.cbPwm.SetFont(font)
self.cbPwm.SetValue(int(pwm) != 0)
self.cbPwm.SetToolTipString("Use Pulse Width Modulation in case the "
"choosen pin allows to do so.")
@ -66,7 +73,6 @@ class AddHeaterDlg(wx.Dialog):
self.bSave.SetFont(font)
self.bSave.Bind(wx.EVT_BUTTON, self.onSave)
bsz.Add(self.bSave)
self.bSave.Enable(False)
bsz.AddSpacer(30, 100)
@ -79,6 +85,7 @@ class AddHeaterDlg(wx.Dialog):
sz.AddSpacer((10, 10))
self.SetSizer(sz)
self.checkDlgValidity()
self.Fit()
def onNameEntry(self, evt):

View File

@ -25,23 +25,34 @@ class HeatersPage(wx.Panel, Page):
sz.AddSpacer((20, 20), pos = (1, 2))
bsz = wx.BoxSizer(wx.VERTICAL)
self.bAdd = wx.Button(self, wx.ID_ANY, "Add", size = BSIZESMALL)
self.bAdd.SetBackgroundColour(self.deco.getBackgroundColour())
self.bAdd.SetFont(font)
self.Bind(wx.EVT_BUTTON, self.doAdd, self.bAdd)
self.bAdd.SetToolTipString("Add a heater to the configuration.")
bsz.Add(self.bAdd)
bsz.AddSpacer((10, 10))
self.bModify = wx.Button(self, wx.ID_ANY, "Modify", size = BSIZESMALL)
self.bModify.SetBackgroundColour(self.deco.getBackgroundColour())
self.bModify.SetFont(font)
self.bModify.Enable(False)
self.Bind(wx.EVT_BUTTON, self.doModify, self.bModify)
self.bModify.SetToolTipString("Modify the selected heater.")
bsz.Add(self.bModify)
bsz.AddSpacer((10, 10))
self.bDelete = wx.Button(self, wx.ID_ANY, "Delete", size = BSIZESMALL)
self.bDelete.SetBackgroundColour(self.deco.getBackgroundColour())
self.bDelete.SetFont(font)
self.bDelete.Enable(False)
self.Bind(wx.EVT_BUTTON, self.doDelete, self.bDelete)
bsz.Add(self.bDelete)
self.bDelete.SetToolTipString("Remove the selected heater from the "
"configuration.")
bsz.Add(self.bDelete)
sz.Add(bsz, pos = (1, 3))
@ -56,8 +67,10 @@ class HeatersPage(wx.Panel, Page):
self.selection = n
if n is None:
self.bDelete.Enable(False)
self.bModify.Enable(False)
else:
self.bDelete.Enable(True)
self.bModify.Enable(True)
def doAdd(self, evt):
nm = []
@ -80,6 +93,33 @@ class HeatersPage(wx.Panel, Page):
self.parent.setHeaters(self.heaters)
self.assertModified(True)
def doModify(self, evt):
if self.selection is None:
return
nm = []
for s in self.heaters:
nm.append(s[0])
h = self.heaters[self.selection]
dlg = AddHeaterDlg(self, nm, self.validPins, self.font,
name = h[0], pin = h[1], pwm = h[2])
rc = dlg.ShowModal()
if rc == wx.ID_OK:
ht = dlg.getValues()
dlg.Destroy()
if rc != wx.ID_OK:
return
self.heaters[self.selection] = ht
self.lb.updateList(self.heaters)
self.validateTable()
self.parent.setHeaters(self.heaters)
self.assertModified(True)
def doDelete(self, evt):
if self.selection is None:
return