some todo implemented. profile filtering added, support of action messages added
This commit is contained in:
parent
7329f5f46c
commit
d7f1f15b04
@ -52,11 +52,10 @@ def main():
|
||||
if not _login.t:
|
||||
return
|
||||
elif _login.t == 1: # create new profile
|
||||
# TODO: test
|
||||
name = _login.name if _login.name else 'toxygen_user'
|
||||
tox = tox_factory()
|
||||
tox.self_set_name('Toxygen User')
|
||||
tox.self_set_status('Toxing on Toxygen')
|
||||
tox.self_set_name(_login.name if _login.name else 'Toxygen User')
|
||||
tox.self_set_status_message('Toxing on Toxygen')
|
||||
ProfileHelper.save_profile(tox.get_savedata(), name)
|
||||
else: # load existing profile
|
||||
path, name = _login.get_data()
|
||||
@ -71,7 +70,6 @@ def main():
|
||||
tox = tox_factory(data, settings)
|
||||
|
||||
ms = MainWindow(tox)
|
||||
#ms.setup_info_from_tox()
|
||||
ms.show()
|
||||
# bootstrap
|
||||
for data in node_generator():
|
||||
|
@ -10,10 +10,11 @@ from util import curr_time
|
||||
|
||||
class MessageItem(QtGui.QListWidget):
|
||||
|
||||
def __init__(self, text, time, user='', parent=None):
|
||||
def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
|
||||
QtGui.QListWidget.__init__(self, parent)
|
||||
self.name = QtGui.QLabel(self)
|
||||
self.name.setGeometry(QtCore.QRect(0, 0, 50, 25))
|
||||
self.name.setTextFormat(QtCore.Qt.PlainText)
|
||||
font = QtGui.QFont()
|
||||
font.setFamily("Times New Roman")
|
||||
font.setPointSize(12)
|
||||
@ -37,6 +38,10 @@ class MessageItem(QtGui.QListWidget):
|
||||
self.message.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse)
|
||||
self.message.setPlainText(text)
|
||||
|
||||
if message_type == TOX_MESSAGE_TYPE['ACTION']:
|
||||
self.name.setStyleSheet("QLabel { color: blue; }")
|
||||
self.message.setStyleSheet("QPlainTextEdit { color: blue; }")
|
||||
|
||||
|
||||
class ContactItem(QtGui.QListWidget):
|
||||
|
||||
@ -323,7 +328,6 @@ class MainWindow(QtGui.QMainWindow):
|
||||
# self.connection_status.repaint()
|
||||
|
||||
def setup_info_from_tox(self):
|
||||
# TODO: remove - use Profile()
|
||||
self.name.setText(self.profile.name)
|
||||
self.status_message.setText(self.profile.status_message)
|
||||
|
||||
@ -379,9 +383,9 @@ class MainWindow(QtGui.QMainWindow):
|
||||
print 'row:', index.row()
|
||||
num = index.row()
|
||||
self.profile.setActive(num)
|
||||
friend = self.profile.friends[num]
|
||||
self.account_name.setText(friend.name)
|
||||
self.account_status.setText(friend.status_message)
|
||||
friend = self.profile.getActiveFriendData()
|
||||
self.account_name.setText(friend[0])
|
||||
self.account_status.setText(friend[1])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -5,7 +5,7 @@ import os
|
||||
from tox import Tox
|
||||
from toxcore_enums_and_consts import *
|
||||
from ctypes import *
|
||||
from util import curr_time
|
||||
from util import curr_time, log
|
||||
|
||||
|
||||
class ProfileHelper(object):
|
||||
@ -56,9 +56,8 @@ class Contact(object):
|
||||
number - unique number of friend in list, widget - widget for update
|
||||
"""
|
||||
|
||||
def __init__(self, name, status_message, number, widget):
|
||||
# TODO: remove number
|
||||
self._name, self._status_message, self._number = name, status_message, number
|
||||
def __init__(self, name, status_message, widget):
|
||||
self._name, self._status_message= name, status_message
|
||||
self._status, self._widget = None, widget
|
||||
widget.name.setText(name)
|
||||
widget.status_message.setText(status_message)
|
||||
@ -96,12 +95,20 @@ class Friend(Contact):
|
||||
Friend in list of friends. Can be hidden, unread messages added
|
||||
"""
|
||||
|
||||
def __init__(self, *args):
|
||||
def __init__(self, number, *args):
|
||||
super(Friend, self).__init__(*args)
|
||||
self._number = number
|
||||
self._new_messages = False
|
||||
self._visible = True
|
||||
|
||||
def getVisibility(self):
|
||||
return self._visible
|
||||
|
||||
def setVisibility(self, value):
|
||||
self._widget.setVisibility(value)
|
||||
self._visible = value
|
||||
|
||||
visibility = property(getVisibility, setVisibility)
|
||||
|
||||
def setMessages(self, value):
|
||||
self._new_messages = value
|
||||
@ -119,8 +126,7 @@ class Profile(Contact):
|
||||
"""
|
||||
Profile of current toxygen user. Contains friends list, tox instance
|
||||
"""
|
||||
# TODO: add slices
|
||||
# TODO: add unicode support
|
||||
# TODO: add unicode support in messages
|
||||
def __init__(self, tox, widgets, widget, messages_list):
|
||||
self._widget = widget
|
||||
self._messages = messages_list
|
||||
@ -131,9 +137,9 @@ class Profile(Contact):
|
||||
data = tox.self_get_friend_list()
|
||||
self.friends, num, self._active_friend = [], 0, -1
|
||||
for i in data:
|
||||
name = tox.friend_get_name(i) or 'Tox user' # tox.friend_get_public_key(i)
|
||||
name = tox.friend_get_name(i) or tox.friend_get_public_key(i)
|
||||
status_message = tox.friend_get_status_message(i)
|
||||
self.friends.append(Friend(name, status_message, i, widgets[num]))
|
||||
self.friends.append(Friend(i, name, status_message, widgets[num]))
|
||||
num += 1
|
||||
Profile._instance = self
|
||||
|
||||
@ -145,16 +151,25 @@ class Profile(Contact):
|
||||
return self._active_friend
|
||||
|
||||
def setActive(self, value):
|
||||
if 0 <= value < self.tox.self_get_friend_list_size():
|
||||
self._active_friend = value
|
||||
try:
|
||||
visible_friends = filter(lambda num, friend: friend.visibility, enumerate(self.friends))
|
||||
self._active_friend = visible_friends[value][0]
|
||||
self._messages.clear()
|
||||
# TODO: load history
|
||||
except: # no friend found. ignore
|
||||
log('Incorrect friend value: ' + str(value))
|
||||
|
||||
active_friend = property(getActive, setActive)
|
||||
|
||||
def getActiveFriendData(self):
|
||||
friend = self.friends[self._active_friend]
|
||||
return friend.name, friend.status_message
|
||||
|
||||
def getActiveNumber(self):
|
||||
return self.friends[self._active_friend].getNumber()
|
||||
return self.friends[self._active_friend].number
|
||||
|
||||
def getActiveName(self):
|
||||
return self.friends[self._active_friend].getName()
|
||||
return self.friends[self._active_friend].name
|
||||
|
||||
def isActiveOnline(self):
|
||||
if not self._active_friend + 1: # no active friend
|
||||
@ -162,16 +177,18 @@ class Profile(Contact):
|
||||
else:
|
||||
# TODO: callbacks!
|
||||
return True
|
||||
status = self.friends[self._active_friend].getStatus()
|
||||
status = self.friends[self._active_friend].status
|
||||
return status is not None
|
||||
|
||||
def filtration(self, show_online=True, filter_str=''):
|
||||
for friend in self.friends:
|
||||
friend.visibility = (friend.status is not None or not show_online) and (filter_str in friend.name)
|
||||
|
||||
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)
|
||||
item = mainscreen.MessageItem(message, curr_time(), user_name, message_type)
|
||||
elem = QtGui.QListWidgetItem(self._messages)
|
||||
print item.sizeHint()
|
||||
elem.setSizeHint(QtCore.QSize(500, 100))
|
||||
self._messages.addItem(elem)
|
||||
self._messages.setItemWidget(elem, item)
|
||||
@ -183,8 +200,13 @@ class Profile(Contact):
|
||||
|
||||
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)
|
||||
if text.startswith('/me'):
|
||||
message_type = TOX_MESSAGE_TYPE['ACTION']
|
||||
text = text[3:]
|
||||
else:
|
||||
message_type = TOX_MESSAGE_TYPE['NORMAL']
|
||||
self.tox.friend_send_message(self._active_friend, message_type, text)
|
||||
item = mainscreen.MessageItem(text, curr_time(), self._name, message_type)
|
||||
elem = QtGui.QListWidgetItem(self._messages)
|
||||
elem.setSizeHint(QtCore.QSize(500, 100))
|
||||
self._messages.addItem(elem)
|
||||
|
Loading…
Reference in New Issue
Block a user