From 69267f365ce126029d012b4d4fef2e5806761264 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 14 Apr 2024 22:54:44 +0200 Subject: [PATCH] Only enable the device selection OK button of validator is OK While the combobox validator prevents "QValidator.Invalid" characters to be entered, the user could still get away with any string that is considered "QValidator.Intermediate". In that caes, disable the OK button of the button box so the (intermediate) result could not be passed on. --- src/python/adgui.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/python/adgui.py b/src/python/adgui.py index c79c1666..a8c6f99f 100755 --- a/src/python/adgui.py +++ b/src/python/adgui.py @@ -434,13 +434,15 @@ class FusePopup(): class listValidator(QValidator): - def __init__(self, liste): + def __init__(self, liste, buttonbox): super().__init__() self.list = liste + self.buttonbox = buttonbox def validate(self, string, position): if string == "": # empty string could always become a real match + self.buttonbox.button(QDialogButtonBox.Ok).setEnabled(False) return QValidator.Intermediate, string, position s = string.lower() @@ -450,13 +452,16 @@ class listValidator(QValidator): if i == s: # exact match + self.buttonbox.button(QDialogButtonBox.Ok).setEnabled(True) return QValidator.Acceptable, string, position if i.find(s) != -1: # could become a real match some day + self.buttonbox.button(QDialogButtonBox.Ok).setEnabled(False) return QValidator.Intermediate, string, position # no match at all, invalid input + self.buttonbox.button(QDialogButtonBox.Ok).setEnabled(False) return QValidator.Invalid, string, position def fixup(self, string): @@ -793,7 +798,7 @@ class adgui(QObject): for d in self.devices[f]: self.device.devices.addItem(d) l.append(d) - self.dev_validator = listValidator(l) + self.dev_validator = listValidator(l, self.device.buttonBox) self.device.devices.setValidator(self.dev_validator) def update_programmer_cb(self):