profile filtering
This commit is contained in:
parent
5cfffd1dee
commit
1a1769cbe1
@ -4,7 +4,6 @@ from settings import Settings
|
|||||||
from profile import Profile
|
from profile import Profile
|
||||||
from toxcore_enums_and_consts import *
|
from toxcore_enums_and_consts import *
|
||||||
from tox import bin_to_string
|
from tox import bin_to_string
|
||||||
# TODO: add all callbacks (use wrappers)
|
|
||||||
|
|
||||||
|
|
||||||
class InvokeEvent(QtCore.QEvent):
|
class InvokeEvent(QtCore.QEvent):
|
||||||
@ -116,6 +115,9 @@ def friend_message(window):
|
|||||||
|
|
||||||
|
|
||||||
def friend_request(tox, public_key, message, message_size, user_data):
|
def friend_request(tox, public_key, message, message_size, user_data):
|
||||||
|
"""
|
||||||
|
Called when user get new friend request
|
||||||
|
"""
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
tox_id = bin_to_string(public_key, TOX_PUBLIC_KEY_SIZE)
|
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'))
|
invoke_in_main_thread(profile.process_friend_request, tox_id, message.decode('utf-8'))
|
||||||
|
@ -177,7 +177,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
self.callButton.setText(QtGui.QApplication.translate("Form", "Start call", None, QtGui.QApplication.UnicodeUTF8))
|
self.callButton.setText(QtGui.QApplication.translate("Form", "Start call", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
QtCore.QMetaObject.connectSlotsByName(Form)
|
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 = QtGui.QListWidget(widget)
|
||||||
self.friends_list.setGeometry(0, 0, 250, 250)
|
self.friends_list.setGeometry(0, 0, 250, 250)
|
||||||
self.friends_list.clicked.connect(self.friend_click)
|
self.friends_list.clicked.connect(self.friend_click)
|
||||||
@ -209,7 +209,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
self.setup_right_bottom(message_buttons)
|
self.setup_right_bottom(message_buttons)
|
||||||
grid.addWidget(message_buttons, 2, 1)
|
grid.addWidget(message_buttons, 2, 1)
|
||||||
main_list = QtGui.QWidget()
|
main_list = QtGui.QWidget()
|
||||||
self.setup_left_center(main_list, name)
|
self.setup_left_center(main_list)
|
||||||
grid.addWidget(main_list, 1, 0)
|
grid.addWidget(main_list, 1, 0)
|
||||||
grid.setColumnMinimumWidth(1, 500)
|
grid.setColumnMinimumWidth(1, 500)
|
||||||
grid.setColumnMinimumWidth(0, 250)
|
grid.setColumnMinimumWidth(0, 250)
|
||||||
|
@ -164,7 +164,11 @@ class Friend(Contact):
|
|||||||
|
|
||||||
def set_visibility(self, value):
|
def set_visibility(self, value):
|
||||||
self._visible = 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)
|
visibility = property(get_visibility, set_visibility)
|
||||||
|
|
||||||
@ -258,10 +262,13 @@ class Profile(Contact, Singleton):
|
|||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def filtration(self, show_online=True, filter_str=''):
|
def filtration(self, show_online=True, filter_str=''):
|
||||||
# TODO: hide elements in list
|
|
||||||
filter_str = filter_str.lower()
|
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())
|
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
|
self.show_online, self.filter_string = show_online, filter_str
|
||||||
settings = Settings.get_instance()
|
settings = Settings.get_instance()
|
||||||
settings['show_online_friends'] = self.show_online
|
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
|
: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:
|
try:
|
||||||
if value is not None:
|
if value is not None:
|
||||||
visible_friends = filter(lambda elem: elem[1].visibility, enumerate(self._friends))
|
self._active_friend = value
|
||||||
self._active_friend = visible_friends[value][0]
|
|
||||||
self._friends[self._active_friend].set_messages(False)
|
self._friends[self._active_friend].set_messages(False)
|
||||||
self.screen.messages.clear()
|
self.screen.messages.clear()
|
||||||
self.screen.messageEdit.clear()
|
self.screen.messageEdit.clear()
|
||||||
@ -325,10 +332,10 @@ class Profile(Contact, Singleton):
|
|||||||
"""
|
"""
|
||||||
Current user gets new message
|
Current user gets new message
|
||||||
:param friend_num: friend_num of friend who sent 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
|
: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()
|
user_name = Profile.get_instance().get_active_name()
|
||||||
item = MessageItem(message.decode('utf-8'), curr_time(), user_name, message_type, self._messages)
|
item = MessageItem(message.decode('utf-8'), curr_time(), user_name, message_type, self._messages)
|
||||||
elem = QtGui.QListWidgetItem(self._messages)
|
elem = QtGui.QListWidgetItem(self._messages)
|
||||||
|
Loading…
Reference in New Issue
Block a user