filtering fixed
This commit is contained in:
parent
10a77960dc
commit
f38df24947
@ -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):
|
||||
"""
|
||||
|
@ -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():
|
||||
|
@ -57,7 +57,7 @@
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>50</y>
|
||||
<width>23</width>
|
||||
<width>20</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
94
toxygen/ui/views/ms_left_column.ui
Normal file
94
toxygen/ui/views/ms_left_column.ui
Normal file
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>270</width>
|
||||
<height>500</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QLabel" name="avatarLabel">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>5</x>
|
||||
<y>5</y>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="searchLineEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>75</y>
|
||||
<width>150</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="contactsFilterComboBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>150</x>
|
||||
<y>75</y>
|
||||
<width>120</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="searchLabel">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>77</y>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QListWidget" name="friendsListWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>100</y>
|
||||
<width>270</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="groupInvitesPushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>100</y>
|
||||
<width>270</width>
|
||||
<height>30</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user