ui update: messages #1
This commit is contained in:
parent
6c525477d9
commit
7282e20540
@ -50,7 +50,7 @@ def friend_status(tox, friend_num, new_status, user_data):
|
|||||||
"""
|
"""
|
||||||
Check friend's status (none, busy, away)
|
Check friend's status (none, busy, away)
|
||||||
"""
|
"""
|
||||||
print "Friend's #{} status changed! New status: ".format(friend_num, new_status)
|
print "Friend's #{} status changed! New status: {}".format(friend_num, new_status)
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
friend = profile.get_friend_by_number(friend_num)
|
friend = profile.get_friend_by_number(friend_num)
|
||||||
invoke_in_main_thread(friend.set_status, new_status)
|
invoke_in_main_thread(friend.set_status, new_status)
|
||||||
@ -60,7 +60,7 @@ def friend_connection_status(tox, friend_num, new_status, user_data):
|
|||||||
"""
|
"""
|
||||||
Check friend's connection status (offline, udp, tcp)
|
Check friend's connection status (offline, udp, tcp)
|
||||||
"""
|
"""
|
||||||
print "Friend #{} connected! Friend's status: ".format(friend_num, new_status)
|
print "Friend #{} connected! Friend's status: {}".format(friend_num, new_status)
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
friend = profile.get_friend_by_number(friend_num)
|
friend = profile.get_friend_by_number(friend_num)
|
||||||
if new_status == TOX_CONNECTION['NONE']:
|
if new_status == TOX_CONNECTION['NONE']:
|
||||||
|
@ -1,5 +1,34 @@
|
|||||||
from toxcore_enums_and_consts import *
|
from toxcore_enums_and_consts import *
|
||||||
from PySide import QtGui, QtCore
|
from PySide import QtGui, QtCore
|
||||||
|
# TODO: remove some hardcoded values
|
||||||
|
|
||||||
|
|
||||||
|
class MessageEdit(QtGui.QPlainTextEdit):
|
||||||
|
def __init__(self, text='', parent=None):
|
||||||
|
super(MessageEdit, self).__init__(parent)
|
||||||
|
|
||||||
|
self.setWordWrapMode(QtGui.QTextOption.WrapAtWordBoundaryOrAnywhere)
|
||||||
|
self.setPlainText(text)
|
||||||
|
self.document().setTextWidth(parent.width() - 100)
|
||||||
|
font = QtGui.QFont()
|
||||||
|
font.setFamily("Times New Roman")
|
||||||
|
font.setPointSize(10)
|
||||||
|
font.setBold(False)
|
||||||
|
|
||||||
|
self.setFont(font)
|
||||||
|
lines = prev = 0
|
||||||
|
try:
|
||||||
|
for elem in xrange(self.document().blockCount()):
|
||||||
|
pos = self.document().findBlockByLineNumber(elem).position()
|
||||||
|
lines += (pos - prev) // 55 + 1
|
||||||
|
prev = pos
|
||||||
|
except:
|
||||||
|
print 'updateSize failed'
|
||||||
|
print 'lines ', lines
|
||||||
|
self.setFixedHeight(lines * 17)
|
||||||
|
self.setMinimumHeight(lines * 17)
|
||||||
|
self.setMaximumHeight(lines * 17)
|
||||||
|
self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse)
|
||||||
|
|
||||||
|
|
||||||
class MessageItem(QtGui.QListWidget):
|
class MessageItem(QtGui.QListWidget):
|
||||||
@ -29,14 +58,28 @@ class MessageItem(QtGui.QListWidget):
|
|||||||
self.time.setObjectName("time")
|
self.time.setObjectName("time")
|
||||||
self.time.setText(time)
|
self.time.setText(time)
|
||||||
|
|
||||||
self.message = QtGui.QPlainTextEdit(self)
|
self.message = MessageEdit(text, self)
|
||||||
self.message.setGeometry(QtCore.QRect(50, 0, 400, 50))
|
print parent.width()
|
||||||
self.message.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse)
|
print self.message.height()
|
||||||
self.message.setPlainText(text)
|
self.message.setGeometry(QtCore.QRect(50, 0, parent.width() - 100, self.message.height()))
|
||||||
|
self.h = self.message.height()
|
||||||
|
self.message.setFrameShape(QtGui.QFrame.NoFrame)
|
||||||
|
self.time.setFrameShape(QtGui.QFrame.NoFrame)
|
||||||
|
self.name.setFrameShape(QtGui.QFrame.NoFrame)
|
||||||
|
self.setFrameShape(QtGui.QFrame.NoFrame)
|
||||||
|
|
||||||
if message_type == TOX_MESSAGE_TYPE['ACTION']:
|
if message_type == TOX_MESSAGE_TYPE['ACTION']:
|
||||||
self.name.setStyleSheet("QLabel { color: blue; }")
|
self.name.setStyleSheet("QLabel { color: blue; }")
|
||||||
self.message.setStyleSheet("QPlainTextEdit { color: blue; }")
|
self.message.setStyleSheet("QPlainTextEdit { color: blue; }")
|
||||||
|
else:
|
||||||
|
if text[0] == '>':
|
||||||
|
self.message.setStyleSheet("QPlainTextEdit { color: green; }")
|
||||||
|
if text[-1] == '<':
|
||||||
|
self.message.setStyleSheet("QPlainTextEdit { color: red; }")
|
||||||
|
|
||||||
|
def getHeight(self):
|
||||||
|
return max(self.h, 30)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ContactItem(QtGui.QListWidget):
|
class ContactItem(QtGui.QListWidget):
|
||||||
|
@ -225,9 +225,10 @@ class Profile(Contact):
|
|||||||
def new_message(self, id, message_type, message):
|
def new_message(self, id, message_type, message):
|
||||||
if id == self._active_friend: # add message to list
|
if id == self._active_friend: # 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)
|
item = MessageItem(message.decode('utf-8'), curr_time(), user_name, message_type, self._messages)
|
||||||
elem = QtGui.QListWidgetItem(self._messages)
|
elem = QtGui.QListWidgetItem(self._messages)
|
||||||
elem.setSizeHint(QtCore.QSize(500, 100))
|
print 'item height', item.height()
|
||||||
|
elem.setSizeHint(QtCore.QSize(500, item.getHeight()))
|
||||||
self._messages.addItem(elem)
|
self._messages.addItem(elem)
|
||||||
self._messages.setItemWidget(elem, item)
|
self._messages.setItemWidget(elem, item)
|
||||||
self._messages.scrollToBottom()
|
self._messages.scrollToBottom()
|
||||||
@ -240,13 +241,14 @@ class Profile(Contact):
|
|||||||
if self.is_active_online() and text:
|
if self.is_active_online() and text:
|
||||||
if text.startswith('/me '):
|
if text.startswith('/me '):
|
||||||
message_type = TOX_MESSAGE_TYPE['ACTION']
|
message_type = TOX_MESSAGE_TYPE['ACTION']
|
||||||
text = text[3:]
|
text = text[4:]
|
||||||
else:
|
else:
|
||||||
message_type = TOX_MESSAGE_TYPE['NORMAL']
|
message_type = TOX_MESSAGE_TYPE['NORMAL']
|
||||||
self.tox.friend_send_message(self._active_friend, message_type, text.encode('utf-8'))
|
self.tox.friend_send_message(self._active_friend, message_type, text.encode('utf-8'))
|
||||||
item = MessageItem(text, curr_time(), self._name, message_type)
|
item = MessageItem(text, curr_time(), self._name, message_type, self._messages)
|
||||||
elem = QtGui.QListWidgetItem(self._messages)
|
elem = QtGui.QListWidgetItem(self._messages)
|
||||||
elem.setSizeHint(QtCore.QSize(500, 100))
|
print 'item height', item.height()
|
||||||
|
elem.setSizeHint(QtCore.QSize(500, item.getHeight()))
|
||||||
self._messages.addItem(elem)
|
self._messages.addItem(elem)
|
||||||
self._messages.setItemWidget(elem, item)
|
self._messages.setItemWidget(elem, item)
|
||||||
self._messages.scrollToBottom()
|
self._messages.scrollToBottom()
|
||||||
|
Loading…
Reference in New Issue
Block a user