Skip to content

Commit

Permalink
Add pop_item to ListModel and item_count to FilteredListModel.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeyer committed Nov 27, 2024
1 parent 0e5dbc4 commit 256a725
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions nion/utils/ListModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ def insert_item(self, index: int, value: T) -> None:
self.notify_insert_item(self.__key if self.__key else "items", value, index)

def remove_item(self, index: int) -> None:
value = self.__items[index]
del self.__items[index]
self.notify_remove_item(self.__key if self.__key else "items", value, index)
self.pop_item(index)

def append_item(self, value: T) -> None:
self.insert_item(len(self.__items), value)

def pop_item(self, index: int) -> T:
value = self.__items[index]
del self.__items[index]
self.notify_remove_item(self.__key if self.__key else "items", value, index)
return value

@property
def items(self) -> typing.Sequence[T]:
return self.__items
Expand Down Expand Up @@ -397,6 +401,11 @@ def items(self) -> typing.Sequence[typing.Any]:
with self._update_mutex:
return copy.copy(self.__items)

@property
def item_count(self) -> int:
""" Return the number of items. """
return len(self.__items)

def __getattr__(self, item: str) -> typing.Any:
if item == self.__items_key:
return self.items
Expand Down

0 comments on commit 256a725

Please sign in to comment.