From 374f474b1404fd646d9f0f66974727ba7fcccd3e Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 4 Mar 2016 22:03:20 +0300 Subject: [PATCH] some updates: ui - messages #2, test fix --- src/list_items.py | 15 +++++++-------- src/menu.py | 10 +++++----- src/profile.py | 43 ++++++++++++++++++++++++++++++++++++++----- tests/tests.py | 6 ------ 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/list_items.py b/src/list_items.py index f059be5..53f89f0 100644 --- a/src/list_items.py +++ b/src/list_items.py @@ -25,9 +25,9 @@ class MessageEdit(QtGui.QPlainTextEdit): except: print 'updateSize failed' print 'lines ', lines - self.setFixedHeight(lines * 17) - self.setMinimumHeight(lines * 17) - self.setMaximumHeight(lines * 17) + self.setFixedHeight(max(lines * 18, 30)) + self.setMinimumHeight(max(lines * 18, 30)) + self.setMaximumHeight(max(lines * 18, 30)) self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse) @@ -59,10 +59,10 @@ class MessageItem(QtGui.QListWidget): self.time.setText(time) self.message = MessageEdit(text, self) - print parent.width() - print self.message.height() self.message.setGeometry(QtCore.QRect(50, 0, parent.width() - 100, self.message.height())) self.h = self.message.height() + self.setFixedHeight(self.getHeight()) + self.message.setFrameShape(QtGui.QFrame.NoFrame) self.time.setFrameShape(QtGui.QFrame.NoFrame) self.name.setFrameShape(QtGui.QFrame.NoFrame) @@ -81,7 +81,6 @@ class MessageItem(QtGui.QListWidget): return max(self.h, 30) - class ContactItem(QtGui.QListWidget): """ Contact in friends list @@ -119,7 +118,7 @@ class StatusCircle(QtGui.QWidget): """ Connection status """ - + # TODO: rewrite with showing unread messages def __init__(self, parent): QtGui.QWidget.__init__(self, parent) self.setGeometry(0, 0, 32, 32) @@ -148,4 +147,4 @@ class StatusCircle(QtGui.QWidget): center = QtCore.QPoint(k, k) paint.setBrush(color) paint.drawEllipse(center, rad_x, rad_y) - paint.end() \ No newline at end of file + paint.end() diff --git a/src/menu.py b/src/menu.py index fce30d7..2e1fdcb 100644 --- a/src/menu.py +++ b/src/menu.py @@ -61,9 +61,9 @@ class ProfileSettings(QtGui.QWidget): def initUI(self): self.setObjectName("ProfileSettingsForm") self.resize(600, 400) - self.setMinimumSize(QtCore.QSize(600, 400)) - self.setMaximumSize(QtCore.QSize(600, 400)) - self.setBaseSize(QtCore.QSize(600, 400)) + self.setMinimumSize(QtCore.QSize(700, 400)) + self.setMaximumSize(QtCore.QSize(700, 400)) + self.setBaseSize(QtCore.QSize(700, 400)) self.nick = QtGui.QLineEdit(self) self.nick.setGeometry(QtCore.QRect(30, 60, 351, 27)) self.nick.setObjectName("nick") @@ -253,10 +253,10 @@ class NotificationsSettings(QtGui.QWidget): self.enableNotifications.setObjectName("enableNotifications") self.soundNotifications = QtGui.QCheckBox(self) self.soundNotifications.setGeometry(QtCore.QRect(30, 100, 231, 22)) - self.soundNotifications.setObjectName("checkBox_2") + self.soundNotifications.setObjectName("sound_notifications") self.callsSound = QtGui.QCheckBox(self) self.callsSound.setGeometry(QtCore.QRect(30, 60, 231, 22)) - self.callsSound.setObjectName("checkBox_3") + self.callsSound.setObjectName("calls_sound") s = Settings.get_instance() self.enableNotifications.setChecked(s['notifications']) self.soundNotifications.setChecked(s['sound_notifications']) diff --git a/src/profile.py b/src/profile.py index 3d550c1..969adff 100644 --- a/src/profile.py +++ b/src/profile.py @@ -62,6 +62,10 @@ class Contact(object): widget.name.setText(name) widget.status_message.setText(status_message) + # ----------------------------------------------------------------------------------------------------------------- + # name - current name or alias of user + # ----------------------------------------------------------------------------------------------------------------- + def get_name(self): return self._name @@ -72,6 +76,10 @@ class Contact(object): name = property(get_name, set_name) + # ----------------------------------------------------------------------------------------------------------------- + # Status message + # ----------------------------------------------------------------------------------------------------------------- + def get_status_message(self): return self._status_message @@ -82,6 +90,10 @@ class Contact(object): status_message = property(get_status_message, set_status_message) + # ----------------------------------------------------------------------------------------------------------------- + # Status + # ----------------------------------------------------------------------------------------------------------------- + def get_status(self): return self._status @@ -103,6 +115,14 @@ class Friend(Contact): self._new_messages = False self._visible = True + def __del__(self): + self.set_visibility(False) + del self._widget + + # ----------------------------------------------------------------------------------------------------------------- + # Visibility in friends' list + # ----------------------------------------------------------------------------------------------------------------- + def get_visibility(self): return self._visible @@ -112,6 +132,10 @@ class Friend(Contact): visibility = property(get_visibility, set_visibility) + # ----------------------------------------------------------------------------------------------------------------- + # Unread messages from friend + # ----------------------------------------------------------------------------------------------------------------- + def get_messages(self): return self._new_messages @@ -120,15 +144,16 @@ class Friend(Contact): messages = property(get_messages, set_messages) + # ----------------------------------------------------------------------------------------------------------------- + # Friend's number (can be used in toxcore) + # ----------------------------------------------------------------------------------------------------------------- + def get_number(self): return self._number number = property(get_number) # TODO: check if setNumber needed - def __del__(self): - del self._widget - class Profile(Contact): """ @@ -158,6 +183,10 @@ class Profile(Contact): def get_instance(): return Profile._instance + # ----------------------------------------------------------------------------------------------------------------- + # Edit current user's data + # ----------------------------------------------------------------------------------------------------------------- + def change_status(self): if self._status is not None: status = (self._status + 1) % 3 @@ -172,6 +201,10 @@ class Profile(Contact): super(self.__class__, self).set_status_message(value) self.tox.self_set_status_message(self._status_message.encode('utf-8')) + # ----------------------------------------------------------------------------------------------------------------- + # Filtration + # ----------------------------------------------------------------------------------------------------------------- + def filtration(self, show_online=True, filter_str=''): # TODO: hide elements in list filter_str = filter_str.lower() @@ -193,6 +226,7 @@ class Profile(Contact): try: visible_friends = filter(lambda elem: elem[1].visibility, enumerate(self._friends)) self._active_friend = visible_friends[value][0] + self.friends[self._active_friend].set_messages(False) self._messages.clear() self._messages.repaint() # TODO: load history @@ -227,7 +261,6 @@ class Profile(Contact): 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) - print 'item height', item.height() elem.setSizeHint(QtCore.QSize(500, item.getHeight())) self._messages.addItem(elem) self._messages.setItemWidget(elem, item) @@ -247,7 +280,6 @@ class Profile(Contact): self.tox.friend_send_message(self._active_friend, message_type, text.encode('utf-8')) item = MessageItem(text, curr_time(), self._name, message_type, self._messages) elem = QtGui.QListWidgetItem(self._messages) - print 'item height', item.height() elem.setSizeHint(QtCore.QSize(500, item.getHeight())) self._messages.addItem(elem) self._messages.setItemWidget(elem, item) @@ -261,6 +293,7 @@ class Profile(Contact): # Work with friends (add, remove) # ----------------------------------------------------------------------------------------------------------------- + # TODO: add friends def delete_friend(self, num): self.tox.friend_delete(num) friend = filter(lambda x: x.number == num, self._friends)[0] diff --git a/tests/tests.py b/tests/tests.py index 78160ff..a4f1540 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -12,12 +12,6 @@ class TestSettings(): assert s['ipv6_enabled'] is not None assert s['notifications'] is not None - def test_with_delete(self): - path = Settings.get_default_path() + 'toxygen.json' - os.remove(path) - Settings() - assert os.path.exists(path) - class TestProfile():