bug fixes

This commit is contained in:
ingvar1995 2016-03-15 22:12:37 +03:00
parent c90822bf57
commit ab419eddda
5 changed files with 22 additions and 23 deletions

View File

@ -89,9 +89,10 @@ def friend_status_message(tox, friend_num, status_message, size, user_data):
invoke_in_main_thread(profile.set_active)
def friend_message(window):
def friend_message(window, tray):
"""
:param window: main window
:param tray: tray
:return: function for tox.callback_friend_message. Adds new message to list
"""
def wrapped(tox, friend_number, message_type, message, size, user_data):
@ -102,7 +103,7 @@ def friend_message(window):
if not window.isActiveWindow():
friend = profile.get_friend_by_number(friend_number)
if settings['notifications']:
invoke_in_main_thread(tray_notification, friend.name, message.decode('utf8'))
invoke_in_main_thread(tray_notification, friend.name, message.decode('utf8'), tray)
if settings['sound_notifications']:
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
return wrapped
@ -117,14 +118,14 @@ def friend_request(tox, public_key, message, message_size, user_data):
invoke_in_main_thread(profile.process_friend_request, tox_id, message.decode('utf-8'))
def init_callbacks(tox, window):
def init_callbacks(tox, window, tray):
"""
Initialization of all callbacks.
:param tox: tox instance
:param window: main window
"""
tox.callback_friend_status(friend_status, 0)
tox.callback_friend_message(friend_message(window), 0)
tox.callback_friend_message(friend_message(window, tray), 0)
tox.callback_self_connection_status(self_connection_status(tox), 0)
tox.callback_friend_connection_status(friend_connection_status, 0)
tox.callback_friend_name(friend_name, 0)

View File

@ -55,12 +55,17 @@ class Toxygen(object):
data = ProfileHelper.open_profile(path, name)
self.tox = tox_factory(data, settings)
# tray icon
self.tray = QtGui.QSystemTrayIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
self.tray.setContextMenu(QtGui.QMenu())
self.tray.show()
self.ms = MainWindow(self.tox, self.reset)
self.ms.show()
QtGui.QApplication.setStyle(get_style(settings['theme'])) # set application style
# init thread
self.init = self.InitThread(self.tox, self.ms)
self.init = self.InitThread(self.tox, self.ms, self.tray)
self.init.start()
# starting thread for tox iterate
@ -83,14 +88,12 @@ class Toxygen(object):
self.mainloop.wait()
self.init.terminate()
data = self.tox.get_savedata()
length = self.tox.get_savedata_size()
savedata = ''.join('{}'.format(data[i]) for i in xrange(length))
ProfileHelper.save_profile(savedata)
ProfileHelper.save_profile(data)
del self.tox
# create new tox instance
self.tox = tox_factory(savedata, Settings.get_instance())
self.tox = tox_factory(data, Settings.get_instance())
# init thread
self.init = self.InitThread(self.tox, self.ms)
self.init = self.InitThread(self.tox, self.ms, self.tray)
self.init.start()
# starting thread for tox iterate
@ -104,13 +107,13 @@ class Toxygen(object):
class InitThread(QtCore.QThread):
def __init__(self, tox, ms):
def __init__(self, tox, ms, tray):
QtCore.QThread.__init__(self)
self.tox, self.ms = tox, ms
self.tox, self.ms, self.tray = tox, ms, tray
def run(self):
# initializing callbacks
init_callbacks(self.tox, self.ms)
init_callbacks(self.tox, self.ms, self.tray)
# bootstrap
for data in node_generator():
self.tox.bootstrap(*data)

View File

@ -11,11 +11,8 @@ SOUND_NOTIFICATION = {
}
def tray_notification(title, text):
def tray_notification(title, text, tray):
if QtGui.QSystemTrayIcon.isSystemTrayAvailable():
tray = QtGui.QSystemTrayIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
tray.setContextMenu(QtGui.QMenu())
tray.show()
if len(text) > 30:
text = text[:27] + '...'
tray.showMessage(title, text, QtGui.QSystemTrayIcon.NoIcon, 3000)

View File

@ -428,10 +428,10 @@ class Profile(Contact, Singleton):
active_friend = property(get_active, set_active)
def get_active_number(self):
return self._friends[self._active_friend].number
return self._friends[self._active_friend].number if self._active_friend + 1 else -1
def get_active_name(self):
return self._friends[self._active_friend].name
return self._friends[self._active_friend].name if self._active_friend + 1 else ''
def is_active_online(self):
return self._active_friend + 1 and self._friends[self._active_friend].status is not None
@ -451,7 +451,7 @@ class Profile(Contact, Singleton):
user_name = Profile.get_instance().get_active_name()
self.create_message_item(message.decode('utf-8'), curr_time(), user_name, message_type)
self._messages.scrollToBottom()
self._friends[self._active_friend].append_message((message,
self._friends[self._active_friend].append_message((message.decode('utf-8'),
MESSAGE_OWNER['FRIEND'],
time.time(),
message_type))

View File

@ -56,10 +56,8 @@ class TestTox():
tox.self_set_name(name)
tox.self_set_status_message(status_message)
data = tox.get_savedata()
length = tox.get_savedata_size()
savedata = ''.join('{}'.format(data[i]) for i in xrange(length))
del tox
tox = tox_factory(savedata)
tox = tox_factory(data)
assert tox.self_get_name() == name
assert tox.self_get_status_message() == status_message