Configtool: provide heater names as temp sensor names.
Formerly, both names were arbitrary and the user had to know that only heaters ans sensors with matching names would work together. Accordingly, temp sensors can have only names matching those of existing heaters. With the exception of "noheater", which is also provided. This kind of solves issue #143.
This commit is contained in:
parent
ada9450807
commit
2f8ed0dbeb
|
|
@ -15,8 +15,8 @@ labelWidth = 160
|
||||||
|
|
||||||
|
|
||||||
class AddSensorDlg(wx.Dialog):
|
class AddSensorDlg(wx.Dialog):
|
||||||
def __init__(self, parent, names, pins, font, name = "", stype = "",
|
def __init__(self, parent, names, pins, heatersPage, font, name = "",
|
||||||
pin = "", params = [], modify = False):
|
stype = "", pin = "", params = [], modify = False):
|
||||||
if modify:
|
if modify:
|
||||||
title = "Modify temperature sensor"
|
title = "Modify temperature sensor"
|
||||||
else:
|
else:
|
||||||
|
|
@ -27,6 +27,7 @@ class AddSensorDlg(wx.Dialog):
|
||||||
|
|
||||||
self.names = names
|
self.names = names
|
||||||
self.choices = pins
|
self.choices = pins
|
||||||
|
self.heatersPage = heatersPage
|
||||||
self.modify = modify
|
self.modify = modify
|
||||||
|
|
||||||
if len(params) == 0:
|
if len(params) == 0:
|
||||||
|
|
@ -57,18 +58,34 @@ class AddSensorDlg(wx.Dialog):
|
||||||
csz.AddSpacer((10, 10))
|
csz.AddSpacer((10, 10))
|
||||||
|
|
||||||
lsz = wx.BoxSizer(wx.HORIZONTAL)
|
lsz = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
st = wx.StaticText(self, wx.ID_ANY, "Sensor Name:", size = (labelWidth, -1),
|
st = wx.StaticText(self, wx.ID_ANY, "Heater Name:", size = (labelWidth, -1),
|
||||||
style = wx.ALIGN_RIGHT)
|
style = wx.ALIGN_RIGHT)
|
||||||
st.SetFont(font)
|
st.SetFont(font)
|
||||||
lsz.Add(st, 1, wx.TOP, offsetTcLabel)
|
lsz.Add(st, 1, wx.TOP, offsetTcLabel)
|
||||||
|
|
||||||
self.tcName = wx.TextCtrl(self, wx.ID_ANY, name)
|
nameList = ["noheater"] + self.heatersPage.heaterNames()
|
||||||
|
for alreadyDefinedName in names:
|
||||||
|
try:
|
||||||
|
nameList.remove(alreadyDefinedName)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
if modify:
|
||||||
|
nameList.insert(0, name)
|
||||||
|
|
||||||
|
if len(nameList) == 0:
|
||||||
|
nameList = ["<no free heater name available>"]
|
||||||
|
self.nameValid = False
|
||||||
|
else:
|
||||||
|
self.nameValid = True
|
||||||
|
|
||||||
|
self.tcName = wx.Choice(self, wx.ID_ANY, choices = nameList)
|
||||||
self.tcName.SetFont(font)
|
self.tcName.SetFont(font)
|
||||||
if not modify:
|
self.tcName.Bind(wx.EVT_CHOICE, self.onHeaterName)
|
||||||
self.tcName.SetBackgroundColour("pink")
|
|
||||||
self.tcName.Bind(wx.EVT_TEXT, self.onNameEntry)
|
|
||||||
lsz.Add(self.tcName)
|
lsz.Add(self.tcName)
|
||||||
self.tcName.SetToolTipString("Enter a unique name for this sensor.")
|
self.tcName.SetToolTipString("Choose the name of the corresponding heater. "
|
||||||
|
"This may require to define that heater "
|
||||||
|
"first.")
|
||||||
|
self.tcName.SetSelection(0)
|
||||||
|
|
||||||
csz.Add(lsz)
|
csz.Add(lsz)
|
||||||
csz.AddSpacer((10, 10))
|
csz.AddSpacer((10, 10))
|
||||||
|
|
@ -305,27 +322,15 @@ class AddSensorDlg(wx.Dialog):
|
||||||
self.selectSensorType(stStart)
|
self.selectSensorType(stStart)
|
||||||
self.validateFields()
|
self.validateFields()
|
||||||
|
|
||||||
def onNameEntry(self, evt):
|
def onHeaterName(self, evt):
|
||||||
tc = evt.GetEventObject()
|
s = self.tcName.GetSelection()
|
||||||
self.validateName(tc)
|
label = self.tcName.GetString(s)
|
||||||
self.checkDlgValidity()
|
if label.startswith("<"):
|
||||||
evt.Skip()
|
|
||||||
|
|
||||||
def validateName(self, tc):
|
|
||||||
w = tc.GetValue().strip()
|
|
||||||
if w == "":
|
|
||||||
self.nameValid = False
|
self.nameValid = False
|
||||||
else:
|
else:
|
||||||
if w in self.names and not self.modify:
|
self.nameValid = True
|
||||||
self.nameValid = False
|
|
||||||
else:
|
|
||||||
self.nameValid = True
|
|
||||||
|
|
||||||
if self.nameValid:
|
evt.Skip()
|
||||||
tc.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
|
|
||||||
else:
|
|
||||||
tc.SetBackgroundColour("pink")
|
|
||||||
tc.Refresh()
|
|
||||||
|
|
||||||
def onMethodSelect(self, evt):
|
def onMethodSelect(self, evt):
|
||||||
rb = evt.GetEventObject()
|
rb = evt.GetEventObject()
|
||||||
|
|
@ -652,7 +657,6 @@ class AddSensorDlg(wx.Dialog):
|
||||||
evt.Skip()
|
evt.Skip()
|
||||||
|
|
||||||
def validateFields(self):
|
def validateFields(self):
|
||||||
self.validateName(self.tcName)
|
|
||||||
self.onParam0Entry(None)
|
self.onParam0Entry(None)
|
||||||
self.onParam1Entry(None)
|
self.onParam1Entry(None)
|
||||||
self.onParam2Entry(None)
|
self.onParam2Entry(None)
|
||||||
|
|
@ -662,7 +666,7 @@ class AddSensorDlg(wx.Dialog):
|
||||||
self.onParam6Entry(None)
|
self.onParam6Entry(None)
|
||||||
|
|
||||||
def getValues(self):
|
def getValues(self):
|
||||||
nm = self.tcName.GetValue()
|
nm = self.tcName.GetString(self.tcName.GetSelection())
|
||||||
pin = self.choices[self.chPin.GetSelection()]
|
pin = self.choices[self.chPin.GetSelection()]
|
||||||
stype = self.chType.GetString(self.chType.GetSelection())
|
stype = self.chType.GetString(self.chType.GetSelection())
|
||||||
if self.currentMode == MODE_THERMISTOR:
|
if self.currentMode == MODE_THERMISTOR:
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ class BoardPanel(wx.Panel):
|
||||||
self.pageModified.append(False)
|
self.pageModified.append(False)
|
||||||
self.pageValid.append(True)
|
self.pageValid.append(True)
|
||||||
|
|
||||||
self.pgSensors = SensorsPage(self, self.nb, len(self.pages),
|
self.pgSensors = SensorsPage(self, self.nb, len(self.pages), self.pgHeaters,
|
||||||
self.settings.font)
|
self.settings.font)
|
||||||
text = "Temperature Sensors"
|
text = "Temperature Sensors"
|
||||||
self.nb.AddPage(self.pgSensors, text)
|
self.nb.AddPage(self.pgSensors, text)
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,11 @@ from addsensordlg import AddSensorDlg
|
||||||
|
|
||||||
|
|
||||||
class SensorsPage(wx.Panel, Page):
|
class SensorsPage(wx.Panel, Page):
|
||||||
def __init__(self, parent, nb, idPg, font):
|
def __init__(self, parent, nb, idPg, heatersPage, font):
|
||||||
wx.Panel.__init__(self, nb, wx.ID_ANY)
|
wx.Panel.__init__(self, nb, wx.ID_ANY)
|
||||||
Page.__init__(self, font)
|
Page.__init__(self, font)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
self.heatersPage = heatersPage
|
||||||
self.font = font
|
self.font = font
|
||||||
self.id = idPg
|
self.id = idPg
|
||||||
|
|
||||||
|
|
@ -78,7 +79,7 @@ class SensorsPage(wx.Panel, Page):
|
||||||
for s in self.sensors:
|
for s in self.sensors:
|
||||||
nm.append(s[0])
|
nm.append(s[0])
|
||||||
|
|
||||||
dlg = AddSensorDlg(self, nm, self.validPins, self.font)
|
dlg = AddSensorDlg(self, nm, self.validPins, self.heatersPage, self.font)
|
||||||
rc = dlg.ShowModal()
|
rc = dlg.ShowModal()
|
||||||
if rc == wx.ID_OK:
|
if rc == wx.ID_OK:
|
||||||
tt = dlg.getValues()
|
tt = dlg.getValues()
|
||||||
|
|
@ -106,7 +107,7 @@ class SensorsPage(wx.Panel, Page):
|
||||||
else:
|
else:
|
||||||
params = s[3]
|
params = s[3]
|
||||||
|
|
||||||
dlg = AddSensorDlg(self, nm, self.validPins, self.font,
|
dlg = AddSensorDlg(self, nm, self.validPins, self.heatersPage, self.font,
|
||||||
name = s[0], stype = s[1], pin = s[2],
|
name = s[0], stype = s[1], pin = s[2],
|
||||||
params = params, modify = True)
|
params = params, modify = True)
|
||||||
rc = dlg.ShowModal()
|
rc = dlg.ShowModal()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue