From 4597fd0c513c59c298bbde3cc0eb18b6891ce7ea Mon Sep 17 00:00:00 2001 From: jbernardis Date: Sat, 30 May 2015 21:54:37 -0400 Subject: [PATCH] Configtool: reset/restore thermistor presets. The sensor dialog now checks present values against the list of presets. This means, if a preset is used and then modified, the preset choice jumps to . It also means presets are recognized when modifying a temperature sensor. This should solve issue #155. --- configtool/addsensordlg.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/configtool/addsensordlg.py b/configtool/addsensordlg.py index f3f4ad1..6eceed7 100644 --- a/configtool/addsensordlg.py +++ b/configtool/addsensordlg.py @@ -262,8 +262,8 @@ class AddSensorDlg(wx.Dialog): st.SetFont(font) lsz.Add(st, 1, wx.TOP, offsetTcLabel) - choices = [""] + sorted(thermistorPresets.keys()) - ch = wx.Choice(self, wx.ID_ANY, choices = choices) + self.thermistorChoices = [""] + sorted(thermistorPresets.keys()) + ch = wx.Choice(self, wx.ID_ANY, choices = self.thermistorChoices) ch.SetFont(font) ch.Enable(False) ch.SetSelection(0) @@ -400,6 +400,7 @@ class AddSensorDlg(wx.Dialog): def onParam0Entry(self, evt): if self.currentMode == MODE_THERMISTOR: self.param0Valid = self.onTextCtrlInteger(self.param0, True) + self.checkValuesForPreset() else: self.param0Valid = True @@ -410,6 +411,7 @@ class AddSensorDlg(wx.Dialog): def onParam1Entry(self, evt): if self.currentMode == MODE_THERMISTOR: self.param1Valid = self.onTextCtrlInteger(self.param1, True) + self.checkValuesForPreset() else: self.param1Valid = True @@ -420,6 +422,7 @@ class AddSensorDlg(wx.Dialog): def onParam2Entry(self, evt): if self.currentMode == MODE_THERMISTOR: self.param2Valid = self.onTextCtrlInteger(self.param2, True) + self.checkValuesForPreset() else: self.param2Valid = True @@ -433,6 +436,7 @@ class AddSensorDlg(wx.Dialog): self.param3Valid = self.onTextCtrlFloat(self.param3, True) else: self.param3Valid = self.onTextCtrlInteger(self.param3, True) + self.checkValuesForPreset() else: self.param3Valid = True @@ -446,6 +450,7 @@ class AddSensorDlg(wx.Dialog): self.param4Valid = True else: self.param4Valid = self.onTextCtrlInteger(self.param4, True) + self.checkValuesForPreset() else: self.param4Valid = True @@ -459,6 +464,7 @@ class AddSensorDlg(wx.Dialog): self.param5Valid = True else: self.param5Valid = self.onTextCtrlInteger(self.param5, True) + self.checkValuesForPreset() else: self.param5Valid = True @@ -472,6 +478,7 @@ class AddSensorDlg(wx.Dialog): self.param6Valid = True else: self.param6Valid = self.onTextCtrlInteger(self.param6, True) + self.checkValuesForPreset() else: self.param6Valid = True @@ -479,6 +486,28 @@ class AddSensorDlg(wx.Dialog): if evt is not None: evt.Skip() + def checkValuesForPreset(self): + p = [] + p.append(self.param0.GetValue().strip()) + p.append(self.param1.GetValue().strip()) + p.append(self.param2.GetValue().strip()) + p.append(self.param3.GetValue().strip()) + if self.currentMethod != METHOD_BETA: + p.append(self.param4.GetValue().strip()) + p.append(self.param5.GetValue().strip()) + p.append(self.param6.GetValue().strip()) + + for k in thermistorPresets.keys(): + if p == thermistorPresets[k]: + try: + i = self.thermistorChoices.index(k) + except: + i = 0 + self.chPresets.SetSelection(i) + return + + self.chPresets.SetSelection(0) + def selectSensorType(self, lbl): if lbl == "Thermistor": self.currentMode = MODE_THERMISTOR