some updates: ui - messages #2, test fix

This commit is contained in:
ingvar1995 2016-03-04 22:03:20 +03:00
parent 7282e20540
commit 374f474b14
4 changed files with 50 additions and 24 deletions

View File

@ -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()
paint.end()

View File

@ -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'])

View File

@ -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]

View File

@ -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():