Skip to content

Commit

Permalink
Allow for getting/setting item by index in menu widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
jwlodek committed Apr 20, 2023
1 parent 6f89afb commit f250ef5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions py_cui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,41 @@ def set_selected_item(self, selected_item: Any):
self._view_items[self._selected_item] = selected_item


def get_item_index(self, index: int):
"""Function that returns reference to item at given index
Paramters
---------
index : int
Index of object
Returns
-------
item : Any
Item at specified index in the list, or None if index is invalid.
"""

try:
return self._view_items[index]
except IndexError:
return None


def set_item_index(self, item: Any, index: int):
"""Function that sets the item at the specified index of the menu
Parameters
----------
item: Any
Item to put in menu at given index
index: int
Index at which to put the specified item.
"""

if item is not None and len(self._view_items) > index and index >= 0:
self._view_items[index] = item


class CheckBoxMenuImplementation(MenuImplementation):
"""Class representing checkbox menu ui implementation
Expand Down

0 comments on commit f250ef5

Please sign in to comment.