From 5d7d0737eb3abecadb535374950723a000a25ec1 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 16 Apr 2024 22:16:27 +0200 Subject: [PATCH] Improve the device selection list While typing the combobox text, the validator adapts the contents of the dropdown menu to only those entries that match the text typed. So one can enter "64", and will only be presented all device that have a 64 in their name (which are a few more than just those with 64 KiB of flash). --- src/python/adgui.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/python/adgui.py b/src/python/adgui.py index d56fa85f..6ac52b98 100755 --- a/src/python/adgui.py +++ b/src/python/adgui.py @@ -434,10 +434,11 @@ class FusePopup(): class listValidator(QValidator): - def __init__(self, liste, buttonbox): + def __init__(self, liste, buttonbox, combobox): super().__init__() self.list = liste self.buttonbox = buttonbox + self.combobox = combobox def validate(self, string, position): if string == "": @@ -455,9 +456,21 @@ class listValidator(QValidator): self.buttonbox.button(QDialogButtonBox.Ok).setEnabled(True) return QValidator.Acceptable, string, position + for i in self.list: + i = i.lower() + if i.find(s) != -1: # could become a real match some day self.buttonbox.button(QDialogButtonBox.Ok).setEnabled(False) + # adjust the elements visible in the dropdown list + self.combobox.setEditable(False) + self.combobox.clear() + for j in self.list: + if j.lower().find(s) != -1: + self.combobox.addItem(j) + self.combobox.setEditable(True) + self.combobox.setEditText(s) + self.combobox.setValidator(self) return QValidator.Intermediate, string, position # no match at all, invalid input @@ -798,7 +811,7 @@ class adgui(QObject): for d in self.devices[f]: self.device.devices.addItem(d) l.append(d) - self.dev_validator = listValidator(l, self.device.buttonBox) + self.dev_validator = listValidator(l, self.device.buttonBox, self.device.devices) self.device.devices.setValidator(self.dev_validator) def update_programmer_cb(self):