diff --git a/py_cui/ui.py b/py_cui/ui.py index 06ae250..56d3d1c 100644 --- a/py_cui/ui.py +++ b/py_cui/ui.py @@ -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