From 7329f5f46c305c30368eabf2a16ab87cee1b3f76 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 27 Feb 2016 20:03:33 +0300 Subject: [PATCH] some ui fixes. todo added --- src/mainscreen.py | 4 +--- src/profile.py | 17 +++++++++++++++++ src/util.py | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/mainscreen.py b/src/mainscreen.py index 3ce48f2..0462342 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -368,9 +368,7 @@ class MainWindow(QtGui.QMainWindow): def send_message(self): text = self.messageEdit.toPlainText() - if self.profile.isActiveOnline() and text: - num = self.profile.getActiveNumber() - self.tox.friend_send_message(num, TOX_MESSAGE_TYPE['NORMAL'], text) + if self.profile.sendMessage(text): self.messageEdit.clear() # ----------------------------------------------------------------------------------------------------------------- diff --git a/src/profile.py b/src/profile.py index c71086f..a7604a0 100644 --- a/src/profile.py +++ b/src/profile.py @@ -120,6 +120,7 @@ class Profile(Contact): Profile of current toxygen user. Contains friends list, tox instance """ # TODO: add slices + # TODO: add unicode support def __init__(self, tox, widgets, widget, messages_list): self._widget = widget self._messages = messages_list @@ -165,6 +166,7 @@ class Profile(Contact): return status is not None def newMessage(self, id, message_type, message): + # TODO: add support of action (/me) messages if id == self._active_friend: # add message to list user_name = Profile.getInstance().getActiveName() item = mainscreen.MessageItem(message, curr_time(), user_name) @@ -173,11 +175,26 @@ class Profile(Contact): elem.setSizeHint(QtCore.QSize(500, 100)) self._messages.addItem(elem) self._messages.setItemWidget(elem, item) + self._messages.scrollToBottom() self._messages.repaint() else: friend = filter(lambda x: x.getNumber() == id, self.friends)[0] friend.setMessages(True) + def sendMessage(self, text): + if self.isActiveOnline() and text: + self.tox.friend_send_message(self._active_friend, TOX_MESSAGE_TYPE['NORMAL'], text) + item = mainscreen.MessageItem(text, curr_time(), self._name) + elem = QtGui.QListWidgetItem(self._messages) + elem.setSizeHint(QtCore.QSize(500, 100)) + self._messages.addItem(elem) + self._messages.setItemWidget(elem, item) + self._messages.scrollToBottom() + self._messages.repaint() + return True + else: + return False + def changeStatus(self): if self._status is not None: self._status += 1 diff --git a/src/util.py b/src/util.py index bc6adbd..0bfdcc2 100644 --- a/src/util.py +++ b/src/util.py @@ -14,7 +14,7 @@ def curr_directory(): def curr_time(): - return time.strftime("%H:%M:") + return time.strftime("%H:%M") class Singleton(object):