user can set new name and status message in settings

This commit is contained in:
ingvar1995 2016-02-29 19:39:43 +03:00
parent 79cae779e7
commit ff7aa1794c
4 changed files with 40 additions and 31 deletions

View file

@ -3,7 +3,7 @@ from notifications import *
from settings import Settings from settings import Settings
from profile import Profile from profile import Profile
from toxcore_enums_and_consts import * from toxcore_enums_and_consts import *
# TODO: add all callbacks (remove test callbacks and use wrappers) # TODO: add all callbacks (use wrappers)
class InvokeEvent(QtCore.QEvent): class InvokeEvent(QtCore.QEvent):
@ -29,7 +29,7 @@ def invoke_in_main_thread(fn, *args, **kwargs):
QtCore.QCoreApplication.postEvent(_invoker, InvokeEvent(fn, *args, **kwargs)) QtCore.QCoreApplication.postEvent(_invoker, InvokeEvent(fn, *args, **kwargs))
def self_connection_status(st, tox_link): def self_connection_status(tox_link):
""" """
:param st: widget on mainscreen which shows status :param st: widget on mainscreen which shows status
:param tox_link: tox instance :param tox_link: tox instance
@ -80,7 +80,8 @@ def friend_name(window):
friend = profile.get_friend_by_number(friend_num) friend = profile.get_friend_by_number(friend_num)
print 'New name: ', str(friend_num), str(name) print 'New name: ', str(friend_num), str(name)
invoke_in_main_thread(friend.set_name, name) invoke_in_main_thread(friend.set_name, name)
invoke_in_main_thread(window.update_active_friend) if profile.get_active_number() == friend_num:
invoke_in_main_thread(window.update_active_friend)
return wrapped return wrapped
@ -95,7 +96,8 @@ def friend_status_message(window):
friend = profile.get_friend_by_number(friend_num) friend = profile.get_friend_by_number(friend_num)
invoke_in_main_thread(friend.set_status_message, status_message) invoke_in_main_thread(friend.set_status_message, status_message)
print 'User #{} has new status: {}'.format(friend_num, status_message) print 'User #{} has new status: {}'.format(friend_num, status_message)
invoke_in_main_thread(window.update_active_friend) if profile.get_active_number() == friend_num:
invoke_in_main_thread(window.update_active_friend)
return wrapped return wrapped
@ -122,7 +124,7 @@ def init_callbacks(tox, window):
""" """
tox.callback_friend_status(friend_status, 0) tox.callback_friend_status(friend_status, 0)
tox.callback_friend_message(friend_message(window), 0) tox.callback_friend_message(friend_message(window), 0)
tox.callback_self_connection_status(self_connection_status(window.connection_status, tox), 0) tox.callback_self_connection_status(self_connection_status(tox), 0)
tox.callback_friend_connection_status(friend_connection_status, 0) tox.callback_friend_connection_status(friend_connection_status, 0)
tox.callback_friend_name(friend_name(window), 0) tox.callback_friend_name(friend_name(window), 0)
tox.callback_friend_status_message(friend_status_message(window), 0) tox.callback_friend_status_message(friend_status_message(window), 0)

View file

@ -9,7 +9,9 @@ from toxcore_enums_and_consts import *
# TODO: move list items to new file # TODO: move list items to new file
class MessageItem(QtGui.QListWidget): class MessageItem(QtGui.QListWidget):
"""
Message in messages list
"""
def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None): def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
QtGui.QListWidget.__init__(self, parent) QtGui.QListWidget.__init__(self, parent)
self.name = QtGui.QLabel(self) self.name = QtGui.QLabel(self)
@ -44,7 +46,9 @@ class MessageItem(QtGui.QListWidget):
class ContactItem(QtGui.QListWidget): class ContactItem(QtGui.QListWidget):
"""
Contact in friends list
"""
def __init__(self, parent=None): def __init__(self, parent=None):
QtGui.QListWidget.__init__(self, parent) QtGui.QListWidget.__init__(self, parent)
# self.setMinimumSize(QtCore.QSize(250, 50)) # self.setMinimumSize(QtCore.QSize(250, 50))
@ -75,6 +79,9 @@ class ContactItem(QtGui.QListWidget):
class StatusCircle(QtGui.QWidget): class StatusCircle(QtGui.QWidget):
"""
Connection status
"""
def __init__(self, parent): def __init__(self, parent):
QtGui.QWidget.__init__(self, parent) QtGui.QWidget.__init__(self, parent)
@ -272,7 +279,7 @@ class MainWindow(QtGui.QMainWindow):
def setup_left_center(self, widget, profile_widget): def setup_left_center(self, widget, profile_widget):
self.friends_list = QtGui.QListWidget(widget) self.friends_list = QtGui.QListWidget(widget)
self.friends_list.setGeometry(0, 0, 250, 300) self.friends_list.setGeometry(0, 0, 250, 150)
count = self.tox.self_get_friend_list_size() count = self.tox.self_get_friend_list_size()
widgets = [] widgets = []
for i in xrange(count): for i in xrange(count):
@ -288,7 +295,7 @@ class MainWindow(QtGui.QMainWindow):
def setup_right_center(self, widget): def setup_right_center(self, widget):
self.messages = QtGui.QListWidget(widget) self.messages = QtGui.QListWidget(widget)
self.messages.setGeometry(0, 0, 500, 500) self.messages.setGeometry(0, 0, 500, 200)
def initUI(self): def initUI(self):
self.setMinimumSize(800, 400) self.setMinimumSize(800, 400)
@ -321,12 +328,8 @@ class MainWindow(QtGui.QMainWindow):
self.setup_menu(self) self.setup_menu(self)
def mouseReleaseEvent(self, event): def mouseReleaseEvent(self, event):
# TODO: process click
self.profile.change_status() self.profile.change_status()
# if self.connection_status.status != TOX_USER_CONNECTION_STATUS['OFFLINE']:
# self.connection_status.status += 1
# self.connection_status.status %= TOX_USER_CONNECTION_STATUS['OFFLINE']
# self.tox.self_set_status(self.connection_status.status)
# self.connection_status.repaint()
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Functions which called when user click in menu # Functions which called when user click in menu
@ -386,3 +389,4 @@ class MainWindow(QtGui.QMainWindow):
num = index.row() num = index.row()
self.profile.set_active(num) self.profile.set_active(num)
self.update_active_friend() self.update_active_friend()
self.messageEdit.clear()

View file

@ -1,5 +1,6 @@
from PySide import QtCore, QtGui from PySide import QtCore, QtGui
from settings import Settings from settings import Settings
from profile import Profile
class AddContact(QtGui.QWidget): class AddContact(QtGui.QWidget):
@ -97,7 +98,7 @@ class ProfileSettings(QtGui.QWidget):
self.tox_id = QtGui.QLabel(self) self.tox_id = QtGui.QLabel(self)
self.tox_id.setGeometry(QtCore.QRect(10, 210, self.width(), 21)) self.tox_id.setGeometry(QtCore.QRect(10, 210, self.width(), 21))
font = QtGui.QFont() font = QtGui.QFont()
font.setPointSize(12) font.setPointSize(10)
#font.setWeight(75) #font.setWeight(75)
font.setBold(True) font.setBold(True)
self.tox_id.setFont(font) self.tox_id.setFont(font)
@ -132,9 +133,14 @@ class ProfileSettings(QtGui.QWidget):
def copy(self): def copy(self):
clipboard = QtGui.QApplication.clipboard() clipboard = QtGui.QApplication.clipboard()
id = bin_to_string(self.tox.self_get_address().value) id = self.tox.self_get_address()
clipboard.setText(id) clipboard.setText(id)
def closeEvent(self, event):
profile = Profile.get_instance()
profile.name = self.nick.text()
profile.status_message = self.status.text()
class NetworkSettings(QtGui.QWidget): class NetworkSettings(QtGui.QWidget):
"""Network settings form: UDP, Ipv6 and proxy""" """Network settings form: UDP, Ipv6 and proxy"""
@ -294,12 +300,3 @@ class InterfaceSettings(QtGui.QWidget):
def retranslateUi(self): def retranslateUi(self):
self.setWindowTitle(QtGui.QApplication.translate("interfaceForm", "Interface settings", None, QtGui.QApplication.UnicodeUTF8)) self.setWindowTitle(QtGui.QApplication.translate("interfaceForm", "Interface settings", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("interfaceForm", "Theme:", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("interfaceForm", "Theme:", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
ex = NetworkSettings()
ex.show()
app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
app.exec_()

View file

@ -158,11 +158,17 @@ class Profile(Contact):
def change_status(self): def change_status(self):
if self._status is not None: if self._status is not None:
self._status += 1 status = (self._status + 1) % 3
self._status %= 3 super(self.__class__, self).set_status(status)
self.tox.self_set_status(self._status) self.tox.self_set_status(status)
self._widget.connection_status.data = self._status
self._widget.connection_status.repaint() def set_name(self, value):
super(self.__class__, self).set_name(value)
self.tox.self_set_name(value)
def set_status_message(self, value):
super(self.__class__, self).set_status_message(value)
self.tox.self_set_status_message(value)
def filtration(self, show_online=True, filter_str=''): def filtration(self, show_online=True, filter_str=''):
for friend in self._friends: for friend in self._friends:
@ -195,7 +201,7 @@ class Profile(Contact):
friend = self._friends[self._active_friend] friend = self._friends[self._active_friend]
return friend.name, friend.status_message return friend.name, friend.status_message
else: else:
return '', '' log('Something is wrong in get_active_friend_data')
def get_active_number(self): def get_active_number(self):
return self._friends[self._active_friend].number return self._friends[self._active_friend].number