From f38df2494798a414507b0d7f23bec77186036c92 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sun, 29 Jul 2018 11:16:03 +0300 Subject: [PATCH] filtering fixed --- toxygen/contacts/contacts_manager.py | 71 +++++++++++---------- toxygen/ui/main_screen.py | 16 ++--- toxygen/ui/views/gc_invite_item.ui | 2 +- toxygen/ui/views/ms_left_column.ui | 94 ++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 44 deletions(-) create mode 100644 toxygen/ui/views/ms_left_column.ui diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index ca9e00d..3499f42 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -25,7 +25,7 @@ class ContactsManager(ToxSave): self._sorting = settings['sorting'] self._filter_string = '' self._friend_item_height = 40 if settings['compact_mode'] else 70 - #screen.online_contacts.setCurrentIndex(int(self._sorting)) + screen.contacts_filter.setCurrentIndex(int(self._sorting)) self._history = history self._load_contacts() @@ -163,50 +163,55 @@ class ContactsManager(ToxSave): def filtration_and_sorting(self, sorting=0, filter_str=''): """ Filtration of friends list - :param sorting: 0 - no sorting, 1 - online only, 2 - online first, 4 - by name + :param sorting: 0 - no sorting, 1 - online only, 2 - online first, 3 - by name, + 4 - online and by name, 5 - online first and by name :param filter_str: show contacts which name contains this substring """ - # TODO: simplify? filter_str = filter_str.lower() - number = self.get_active_number() - is_friend = self.is_active_a_friend() - if sorting > 1: - if sorting & 2: - self._contacts = sorted(self._contacts, key=lambda x: int(x.status is not None), reverse=True) - if sorting & 4: - if not sorting & 2: - self._contacts = sorted(self._contacts, key=lambda x: x.name.lower()) - else: # save results of prev sorting - online_friends = filter(lambda x: x.status is not None, self._contacts) - count = len(list(online_friends)) - part1 = self._contacts[:count] - part2 = self._contacts[count:] - part1 = sorted(part1, key=lambda x: x.name.lower()) - part2 = sorted(part2, key=lambda x: x.name.lower()) - self._contacts = part1 + part2 - else: # sort by number - online_friends = filter(lambda x: x.status is not None, self._contacts) - count = len(list(online_friends)) - part1 = self._contacts[:count] - part2 = self._contacts[count:] - part1 = sorted(part1, key=lambda x: x.number) - part2 = sorted(part2, key=lambda x: x.number) - self._contacts = part1 + part2 - 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) + contact = self.get_curr_contact() + + if sorting > 5 or sorting < 0: + sorting = 0 + + if sorting in (1, 2, 4, 5): # online first + self._contacts = sorted(self._contacts, key=lambda x: int(x.status is not None), reverse=True) + sort_by_name = sorting in (4, 5) + # save results of previous sorting + online_friends = filter(lambda x: x.status is not None, self._contacts) + online_friends_count = len(list(online_friends)) + part1 = self._contacts[:online_friends_count] + part2 = self._contacts[online_friends_count:] + key_lambda = lambda x: x.name.lower() if sort_by_name else x.number + part1 = sorted(part1, key=key_lambda) + part2 = sorted(part2, key=key_lambda) + self._contacts = part1 + part2 + elif sorting == 0: + self._contacts = sorted(self._contacts, key=lambda x: x.number) + else: + self._contacts = sorted(self._contacts, key=lambda x: x.name.lower()) + + # change item widgets + 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()) + filtered_by_name = filter_str in friend.name.lower() + friend.visibility = (friend.status is not None or sorting not in (1, 4)) and filtered_by_name + # show friend even if it's hidden when there any unread messages/actions friend.visibility = friend.visibility or friend.messages or friend.actions if friend.visibility: self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, self._friend_item_height)) else: self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, 0)) + # save soring results self._sorting, self._filter_string = sorting, filter_str self._settings['sorting'] = self._sorting self._settings.save() - self.set_active_by_number_and_type(number, is_friend) + # update active contact + index = self._contacts.index(contact) + self.set_active(index) def update_filtration(self): """ diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index 43a6b19..d57667b 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -166,6 +166,8 @@ class MainWindow(QtWidgets.QMainWindow): self.audioSettings.setText(util_ui.tr("Audio")) self.videoSettings.setText(util_ui.tr("Video")) self.updateSettings.setText(util_ui.tr("Updates")) + self.importPlugin.setText(util_ui.tr("Import plugin")) + self.reloadPlugins.setText(util_ui.tr("Reload plugins")) self.searchLineEdit.setPlaceholderText(util_ui.tr("Search")) self.sendMessageButton.setToolTip(util_ui.tr("Send message")) @@ -178,12 +180,6 @@ class MainWindow(QtWidgets.QMainWindow): self.contactsFilterComboBox.addItem(util_ui.tr("Online and by name")) self.contactsFilterComboBox.addItem(util_ui.tr("Online first and by name")) - ind = self._settings['sorting'] - d = {0: 0, 1: 1, 2: 2, 3: 4, 4: 3, 1 | 4: 4, 2 | 4: 5} - self.contactsFilterComboBox.setCurrentIndex(d[ind]) - self.importPlugin.setText(util_ui.tr("Import plugin")) - self.reloadPlugins.setText(util_ui.tr("Reload plugins")) - def setup_right_bottom(self, Form): Form.resize(650, 60) self.messageEdit = MessageArea(Form, self) @@ -238,7 +234,7 @@ class MainWindow(QtWidgets.QMainWindow): self.avatar_label = left_column.avatarLabel self.searchLineEdit = left_column.searchLineEdit - self.contactsFilterComboBox = left_column.contactsFilterComboBox + self.contacts_filter = self.contactsFilterComboBox = left_column.contactsFilterComboBox self.groupInvitesPushButton = left_column.groupInvitesPushButton @@ -691,9 +687,9 @@ class MainWindow(QtWidgets.QMainWindow): super().mouseReleaseEvent(event) def _filtering(self): - ind = self.contactsFilterComboBox.currentIndex() - d = {0: 0, 1: 1, 2: 2, 3: 4, 4: 1 | 4, 5: 2 | 4} - self._contacts_manager.filtration_and_sorting(d[ind], self.searchLineEdit.text()) + index = self.contactsFilterComboBox.currentIndex() + search_text = self.searchLineEdit.text() + self._contacts_manager.filtration_and_sorting(index, search_text) def show_search_field(self): if hasattr(self, 'search_field') and self.search_field.isVisible(): diff --git a/toxygen/ui/views/gc_invite_item.ui b/toxygen/ui/views/gc_invite_item.ui index dc077a7..6eddbeb 100644 --- a/toxygen/ui/views/gc_invite_item.ui +++ b/toxygen/ui/views/gc_invite_item.ui @@ -57,7 +57,7 @@ 40 50 - 23 + 20 23 diff --git a/toxygen/ui/views/ms_left_column.ui b/toxygen/ui/views/ms_left_column.ui new file mode 100644 index 0000000..ffbff71 --- /dev/null +++ b/toxygen/ui/views/ms_left_column.ui @@ -0,0 +1,94 @@ + + + Form + + + + 0 + 0 + 270 + 500 + + + + PointingHandCursor + + + Form + + + + + 5 + 5 + 64 + 64 + + + + PointingHandCursor + + + TextLabel + + + + + + 0 + 75 + 150 + 25 + + + + + + + 150 + 75 + 120 + 25 + + + + + + + 0 + 77 + 20 + 20 + + + + TextLabel + + + + + + 0 + 100 + 270 + 400 + + + + + + + 0 + 100 + 270 + 30 + + + + PushButton + + + + + +