def append(self, element: str) -> None: if not element.lower() in self: super().append(element.lower()) if not self._custom_sort: self.sort() SAVE_NEEDED.set() LIST_SIGNALS.category_list_changed.emit()
def add_new_article(self, name: str, category: str) -> ShoppingArticle: article = ShoppingArticle(name, category) self.append_silent(article) self.shopping_articles_list.append(article) article.selection += 1 self.sort_by_shop() SAVE_NEEDED.set() LIST_SIGNALS.list_changed.emit() return article
def move_bottom(self, element: str): index = self.index(element) if index == len(self) - 1: raise AttributeError( f'Attribute {element} is already at the bottom of the list') self.append(self.pop(index)) self._custom_sort = True SAVE_NEEDED.set() LIST_SIGNALS.category_list_changed.emit()
def move_top(self, element: str): index = self.index(element) if index == 0: raise AttributeError( f'Attribute {element} is already at the top of the list') self.insert(0, self.pop(index)) self._custom_sort = True SAVE_NEEDED.set() LIST_SIGNALS.category_list_changed.emit()
def add_button_pressed(self): selected_to_add = self.combobox_layout.category_combobox.currentText() selected_on_list = self.category_list_layout.category_list_widget.currentIndex( ).row() if selected_to_add in self._shops_list.selected_shop.category_list: raise RuntimeError(f'Category {selected_to_add} already in shop') if selected_on_list: self._shops_list.selected_shop.category_list.insert( selected_on_list + 1, selected_to_add) SAVE_NEEDED.set() LIST_SIGNALS.category_list_changed.emit()
def remove_article(self, name: str): self.remove_silent(self.get_article_by_name(name)) self.sort_by_shop() SAVE_NEEDED.set() LIST_SIGNALS.list_changed.emit()
def add_existing_article(self, element: ShoppingArticle): self.append_silent(element) element.selection += 1 self.sort_by_shop() SAVE_NEEDED.set() LIST_SIGNALS.list_changed.emit()
def clear(self): self.clear_silent() SAVE_NEEDED.set() LIST_SIGNALS.list_changed.emit()
def remove(self, item) -> None: self.remove_silent(item) SAVE_NEEDED.set() LIST_SIGNALS.list_changed.emit()
def __setitem__(self, key, value): super(ShoppingListWithoutDuplicates, self).__setitem__(key, value) SAVE_NEEDED.set() LIST_SIGNALS.list_changed.emit()
def append(self, element: Union['ShoppingArticle', 'Shop']) -> None: self.append_silent(element) SAVE_NEEDED.set() LIST_SIGNALS.list_changed.emit()
def remove(self, item) -> None: super(StringListWithoutDuplicates, self).remove(item) SAVE_NEEDED.set() LIST_SIGNALS.category_list_changed.emit()
def __setattr__(self, key, value): super(ShoppingArticle, self).__setattr__(key, value) SAVE_NEEDED.set()
def selected_shop(self, value): if value not in self: raise AttributeError(f'Shop {value} does not exist') self._selected_shop = value SAVE_NEEDED.set() LIST_SIGNALS.shop_changed.emit()