fix(ui): prevent invalid list selections

This commit is contained in:
2026-08-13 08:58:40 -06:00
parent 3b86a70a4c
commit 18290d9265
+13 -2
View File
@@ -49,10 +49,16 @@ class list(object):
def remove_item(self, pos): def remove_item(self, pos):
""" Deletes an item from the list.""" """ Deletes an item from the list."""
if self.system == "Windows": if self.system == "Windows":
if pos > 0: self.list.Focus(pos-1) if not 0 <= pos < self.list.GetItemCount():
return
if pos > 0:
self.list.Focus(pos-1)
self.list.DeleteItem(pos) self.list.DeleteItem(pos)
else: else:
if pos > 0: self.list.SetSelection(pos-1) if not 0 <= pos < self.list.GetCount():
return
if pos > 0:
self.list.SetSelection(pos-1)
self.list.Delete(pos) self.list.Delete(pos)
def clear(self): def clear(self):
@@ -71,10 +77,15 @@ class list(object):
return self.list.GetSelection() return self.list.GetSelection()
def select_item(self, pos): def select_item(self, pos):
"""Select an existing item without sending invalid native list commands."""
if self.system == "Windows": if self.system == "Windows":
if not 0 <= pos < self.list.GetItemCount():
return
self.list.Focus(pos) self.list.Focus(pos)
self.list.Select(pos) self.list.Select(pos)
else: else:
if not 0 <= pos < self.list.GetCount():
return
self.list.SetSelection(pos) self.list.SetSelection(pos)
def get_count(self): def get_count(self):