From 1a1769cbe1a62e5735ef976b28cef61b7699a5d5 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Wed, 9 Mar 2016 21:45:38 +0300 Subject: [PATCH] profile filtering --- src/callbacks.py | 4 +++- src/mainscreen.py | 4 ++-- src/profile.py | 23 +++++++++++++++-------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index 0bcc917..e485e9e 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -4,7 +4,6 @@ from settings import Settings from profile import Profile from toxcore_enums_and_consts import * from tox import bin_to_string -# TODO: add all callbacks (use wrappers) class InvokeEvent(QtCore.QEvent): @@ -116,6 +115,9 @@ def friend_message(window): def friend_request(tox, public_key, message, message_size, user_data): + """ + Called when user get new friend request + """ profile = Profile.get_instance() tox_id = bin_to_string(public_key, TOX_PUBLIC_KEY_SIZE) invoke_in_main_thread(profile.process_friend_request, tox_id, message.decode('utf-8')) diff --git a/src/mainscreen.py b/src/mainscreen.py index a09a122..551e3d9 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -177,7 +177,7 @@ class MainWindow(QtGui.QMainWindow): self.callButton.setText(QtGui.QApplication.translate("Form", "Start call", None, QtGui.QApplication.UnicodeUTF8)) QtCore.QMetaObject.connectSlotsByName(Form) - def setup_left_center(self, widget, profile_widget): + def setup_left_center(self, widget): self.friends_list = QtGui.QListWidget(widget) self.friends_list.setGeometry(0, 0, 250, 250) self.friends_list.clicked.connect(self.friend_click) @@ -209,7 +209,7 @@ class MainWindow(QtGui.QMainWindow): self.setup_right_bottom(message_buttons) grid.addWidget(message_buttons, 2, 1) main_list = QtGui.QWidget() - self.setup_left_center(main_list, name) + self.setup_left_center(main_list) grid.addWidget(main_list, 1, 0) grid.setColumnMinimumWidth(1, 500) grid.setColumnMinimumWidth(0, 250) diff --git a/src/profile.py b/src/profile.py index 0134212..4e628aa 100644 --- a/src/profile.py +++ b/src/profile.py @@ -164,7 +164,11 @@ class Friend(Contact): def set_visibility(self, value): self._visible = value - self._widget.setVisible(value) + # #self._widget.setVisible(value) + # if value: + # self._widget.parent().setSizeHint(250, 70) + # else: + # self._widget.parent().setSizeHint(250, 0) visibility = property(get_visibility, set_visibility) @@ -258,10 +262,13 @@ class Profile(Contact, Singleton): # ----------------------------------------------------------------------------------------------------------------- def filtration(self, show_online=True, filter_str=''): - # TODO: hide elements in list filter_str = filter_str.lower() - for friend in self._friends: + for index, friend in enumerate(self._friends): friend.visibility = (friend.status is not None or not show_online) and (filter_str in friend.name.lower()) + if friend.visibility: + self.screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, 70)) + else: + self.screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, 0)) self.show_online, self.filter_string = show_online, filter_str settings = Settings.get_instance() settings['show_online_friends'] = self.show_online @@ -284,11 +291,11 @@ class Profile(Contact, Singleton): """ :param value: number of new active friend in friend's list or None to update active user's data """ - # TODO: rewrite to work with filtering + if value is None and self._active_friend == -1: # nothing to update + return try: if value is not None: - visible_friends = filter(lambda elem: elem[1].visibility, enumerate(self._friends)) - self._active_friend = visible_friends[value][0] + self._active_friend = value self._friends[self._active_friend].set_messages(False) self.screen.messages.clear() self.screen.messageEdit.clear() @@ -325,10 +332,10 @@ class Profile(Contact, Singleton): """ Current user gets new message :param friend_num: friend_num of friend who sent message - :param message_type: message type - plain text or actionmessage + :param message_type: message type - plain text or action message (/me) :param message: text of message """ - if friend_num == self._friends[self._active_friend].number: # add message to list + if friend_num == self.get_active_number(): # add message to list user_name = Profile.get_instance().get_active_name() item = MessageItem(message.decode('utf-8'), curr_time(), user_name, message_type, self._messages) elem = QtGui.QListWidgetItem(self._messages)