Skip to content

Commit

Permalink
main : small improvements to listbox example
Browse files Browse the repository at this point in the history
  • Loading branch information
my1e5 committed Mar 21, 2023
1 parent 9128bd5 commit 54fb9ac
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions listbox/listbox_custom_with_keypress.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def _key_press_handler(sender, app_data, user_data):
listbox_ids, items = user_data
letter = ascii_dict.get(app_data)
if letter and dpg.is_item_hovered(tag):
for idx, item_id in enumerate(listbox_ids):
if dpg.get_value(item_id) is True:
start_index = idx
start_index = next(i for i, item_id in enumerate(listbox_ids) if dpg.get_value(item_id))
for idx, item in enumerate(items[start_index+1:]):
if item.startswith(letter):
_selection(listbox_ids[start_index+1+idx], None, listbox_ids)
Expand All @@ -46,13 +44,12 @@ def _selection(sender, app_data, user_data):

for item in user_data:
dpg.set_value(item, False)
dpg.bind_item_theme(item, theme_item_normal)

dpg.set_value(sender, True)
dpg.bind_item_theme(sender, theme_item_selected)


for item in user_data:
if dpg.get_value(item) is True:
dpg.bind_item_theme(item, theme_item_selected)
else:
dpg.bind_item_theme(item, theme_item_normal)

with dpg.child_window(tag=tag, height=height, width=width):
for item in items:
Expand Down

0 comments on commit 54fb9ac

Please sign in to comment.