Skip to content

Commit

Permalink
Improve the device selection list
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
dl8dtl committed Apr 16, 2024
1 parent 1b74b0f commit 5d7d073
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/python/adgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,11 @@ def get_entries(self):

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 == "":
Expand All @@ -455,9 +456,21 @@ def validate(self, string, position):
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
Expand Down Expand Up @@ -798,7 +811,7 @@ def update_device_cb(self):
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):
Expand Down

0 comments on commit 5d7d073

Please sign in to comment.