From 776b3dec943bb1a5c34e338ce57bb7041c547c27 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Wed, 1 Jun 2016 21:52:21 +0200 Subject: [PATCH] Configtool: try to repair broken value-#defines. Previously, #defines requiring a value, but configured as boolean, broke GUI code. While Configtool its self should never write such broken #defines, they can happen with manual config file edits. IMHO it's fine to do such repair attempts as long as it doesn't hobble other functionality. Whatever was broken at read time will end up disabled at write time, unless the user changes that value in the GUI. --- configtool/boardpanel.py | 7 ++++++- configtool/printerpanel.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/configtool/boardpanel.py b/configtool/boardpanel.py index 737ac12..e449153 100644 --- a/configtool/boardpanel.py +++ b/configtool/boardpanel.py @@ -396,7 +396,12 @@ class BoardPanel(wx.Panel): m = reDefBool.search(ln) if m: t = m.groups() - if len(t) == 1 and (t[0] in self.cfgNames): + # Accept booleans, but not those for which a value exists already. + # Booleans already existing as values are most likely misconfigured + # manual edits (or result of a bug). + if len(t) == 1 and t[0] in self.cfgNames \ + and not (t[0] in self.cfgValues \ + and isinstance(self.cfgValues[t[0]], tuple)): if reDefBoolBL.search(ln): self.cfgValues[t[0]] = True else: diff --git a/configtool/printerpanel.py b/configtool/printerpanel.py index f976985..08ab132 100644 --- a/configtool/printerpanel.py +++ b/configtool/printerpanel.py @@ -322,7 +322,12 @@ class PrinterPanel(wx.Panel): m = reDefBool.search(ln) if m: t = m.groups() - if len(t) == 1 and (t[0] in self.cfgNames): + # Accept booleans, but not those for which a value exists already. + # Booleans already existing as values are most likely misconfigured + # manual edits (or result of a bug). + if len(t) == 1 and t[0] in self.cfgNames \ + and not (t[0] in self.cfgValues \ + and isinstance(self.cfgValues[t[0]], tuple)): if reDefBoolBL.search(ln): self.cfgValues[t[0]] = True else: