From 41de31549678fc5f28f6f3e26a83ac5df36cdcc4 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sun, 3 Jun 2018 21:18:22 +0300 Subject: [PATCH] Filtration fixed --- toxygen/contacts/contact.py | 8 ++++++++ toxygen/contacts/contacts_manager.py | 9 +++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/toxygen/contacts/contact.py b/toxygen/contacts/contact.py index d7fe35e..fb124dd 100644 --- a/toxygen/contacts/contact.py +++ b/toxygen/contacts/contact.py @@ -320,3 +320,11 @@ class Contact(basecontact.BaseContact): def get_context_menu_generator(self): return BaseContactMenuGenerator(self) + + # ----------------------------------------------------------------------------------------------------------------- + # Filtration support + # ----------------------------------------------------------------------------------------------------------------- + + def set_widget(self, widget): + self._widget = widget + self.init_widget() diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index 74452e1..08ee678 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -154,7 +154,7 @@ class ContactsManager(ToxSave): def filtration_and_sorting(self, sorting=0, filter_str=''): """ Filtration of friends list - :param sorting: 0 - no sort, 1 - online only, 2 - online first, 4 - by name + :param sorting: 0 - no sorting, 1 - online only, 2 - online first, 4 - by name :param filter_str: show contacts which name contains this substring """ # TODO: simplify? @@ -183,9 +183,10 @@ class ContactsManager(ToxSave): part1 = sorted(part1, key=lambda x: x.number) part2 = sorted(part2, key=lambda x: x.number) self._contacts = part1 + part2 - # self._screen.friends_list.clear() - # for contact in self._contacts: - # contact.set_widget(self.create_friend_item()) + for index, contact in enumerate(self._contacts): + list_item = self._screen.friends_list.item(index) + item_widget = self._screen.friends_list.itemWidget(list_item) + contact.set_widget(item_widget) for index, friend in enumerate(self._contacts): friend.visibility = (friend.status is not None or not (sorting & 1)) and (filter_str in friend.name.lower()) friend.visibility = friend.visibility or friend.messages or friend.actions