From 1ea919bdc2975df598dc85de73a9ddb294b6559d Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 18 Jul 2017 23:36:40 +0300 Subject: [PATCH] tab && bug fix --- toxygen/group_chat.py | 6 +++++- toxygen/mainscreen_widgets.py | 4 ++++ toxygen/profile.py | 20 +++++++++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/toxygen/group_chat.py b/toxygen/group_chat.py index 9b505ce..0ee4b35 100644 --- a/toxygen/group_chat.py +++ b/toxygen/group_chat.py @@ -32,11 +32,15 @@ class GroupChat(contact.Contact): def remove_invalid_unsent_files(self): pass - def get_full_status(self): + def get_names(self): peers_count = self._tox.group_number_peers(self._number) names = [] for i in range(peers_count): name = self._tox.group_peername(self._number, i) names.append(name) names = sorted(names, key=lambda n: n.lower()) + return names + + def get_full_status(self): + names = self.get_names() return '\n'.join(names) diff --git a/toxygen/mainscreen_widgets.py b/toxygen/mainscreen_widgets.py index b6d4b0c..700f16b 100644 --- a/toxygen/mainscreen_widgets.py +++ b/toxygen/mainscreen_widgets.py @@ -34,6 +34,10 @@ class MessageArea(QtWidgets.QPlainTextEdit): self.parent.send_message() elif event.key() == QtCore.Qt.Key_Up and not self.toPlainText(): self.appendPlainText(Profile.get_instance().get_last_message()) + elif event.key() == QtCore.Qt.Key_Tab and not self.parent.profile.is_active_a_friend(): + text = self.toPlainText() + pos = self.textCursor().position() + self.insertPlainText(Profile.get_instance().get_gc_peer_name(text[:pos])) else: self.parent.profile.send_typing(True) if self.timer.isActive(): diff --git a/toxygen/profile.py b/toxygen/profile.py index 63cf09b..c54220b 100644 --- a/toxygen/profile.py +++ b/toxygen/profile.py @@ -17,6 +17,7 @@ import items_factory import cv2 import threading from group_chat import * +import re class Profile(basecontact.BaseContact, Singleton): @@ -130,6 +131,7 @@ class Profile(basecontact.BaseContact, Singleton): filter_str = filter_str.lower() settings = Settings.get_instance() 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) @@ -165,7 +167,7 @@ class Profile(basecontact.BaseContact, Singleton): self._sorting, self._filter_string = sorting, filter_str settings['sorting'] = self._sorting settings.save() - self.set_active_by_number(number) + self.set_active_by_number_and_type(number, is_friend) def update_filtration(self): """ @@ -291,9 +293,10 @@ class Profile(basecontact.BaseContact, Singleton): log('Error in set active: ' + str(ex)) raise - def set_active_by_number(self, number): + def set_active_by_number_and_type(self, number, is_friend): for i in range(len(self._contacts)): - if self._contacts[i].number == number: + c = self._contacts[i] + if c.number == number and (type(c) is Friend == is_friend): self._active_friend = i break @@ -1402,6 +1405,17 @@ class Profile(basecontact.BaseContact, Singleton): friend = self._contacts[friend_num] self._tox.invite_friend(friend.number, group_number) + def get_gc_peer_name(self, text): + gc = self.get_curr_friend() + if type(gc) is not GroupChat: + return '\t' + names = gc.get_names() + name = re.split("\s+", text)[-1] + suggested_names = list(filter(lambda x: x.startswith(name), names)) + if not len(suggested_names): + return '\t' + return suggested_names[0][len(name):] + def tox_factory(data=None, settings=None): """