diff --git a/nion/utils/ListModel.py b/nion/utils/ListModel.py index bb1f63d..0426114 100644 --- a/nion/utils/ListModel.py +++ b/nion/utils/ListModel.py @@ -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 @@ -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