From 35cf74eff8f092b78ced2efcdbdcf21330081714 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Wed, 24 Feb 2016 21:38:36 +0300 Subject: [PATCH] notifications added, some fixes --- src/callbacks.py | 7 ++----- src/mainscreen.py | 27 ++++++++++++--------------- src/notifications.py | 10 ++++++++++ src/toxcore_enums_and_consts.py | 12 ------------ 4 files changed, 24 insertions(+), 32 deletions(-) create mode 100644 src/notifications.py diff --git a/src/callbacks.py b/src/callbacks.py index 3854b2d..0138412 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -1,5 +1,5 @@ from PySide import QtCore -from toxcore_enums_and_consts import TOX_USER_CONNECTION_STATUS, TOX_CONNECTION +from notifications import * # TODO: add all callbacks (replace test callbacks and use wrappers) @@ -33,10 +33,6 @@ def repaint_widget(widget): def self_connection_status(st, tox_link): def wrapped(tox, connection, user_data): print 'Connection status: ', str(connection) - if connection == TOX_CONNECTION['NONE']: - st.status = TOX_USER_CONNECTION_STATUS['OFFLINE'] - else: - st.status = int(tox_link.self_get_status()) invoke_in_main_thread(repaint_widget(st)) return wrapped @@ -47,6 +43,7 @@ def friend_status(a, b, c, d): def friend_message(a, b, c, d, e, f): print 'Message: ', d.decode('utf8') + tray_notification('Message', d.decode('utf8')) def init_callbacks(tox, window): diff --git a/src/mainscreen.py b/src/mainscreen.py index e9931cc..dfe1be3 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -11,32 +11,29 @@ class StatusCircle(QtGui.QWidget): def __init__(self, parent): QtGui.QWidget.__init__(self, parent) self.setGeometry(0, 0, 32, 32) - self.status = TOX_USER_CONNECTION_STATUS['OFFLINE'] self.tox = parent.tox def mouseReleaseEvent(self, event): - if self.status != TOX_USER_CONNECTION_STATUS['OFFLINE']: - self.status += 1 - self.status %= TOX_USER_CONNECTION_STATUS['OFFLINE'] - self.tox.self_set_status(self.status) - self.repaint() + pass def paintEvent(self, event): paint = QtGui.QPainter() paint.begin(self) paint.setRenderHint(QtGui.QPainter.Antialiasing) - paint.setBrush(QtCore.Qt.white) - paint.drawRect(event.rect()) + #paint.setBrush(QtCore.Qt.white) + #paint.drawRect(event.rect()) k = 16 rad_x = rad_y = 10 - if self.status == TOX_USER_CONNECTION_STATUS['OFFLINE']: + if not self.tox.self_get_connection_status(): color = QtCore.Qt.black - elif self.status == TOX_USER_CONNECTION_STATUS['ONLINE']: - color = QtCore.Qt.green - elif self.status == TOX_USER_CONNECTION_STATUS['AWAY']: - color = QtCore.Qt.yellow - else: # self.status == TOX_USER_CONNECTION_STATUS['BUSY']: - color = QtCore.Qt.red + else: + status = self.tox.self_get_status() + if status == TOX_USER_STATUS['NONE']: + color = QtCore.Qt.green + elif status == TOX_USER_STATUS['AWAY']: + color = QtCore.Qt.yellow + else: # self.status == TOX_USER_STATUS['BUSY']: + color = QtCore.Qt.red paint.setPen(color) center = QtCore.QPoint(k, k) diff --git a/src/notifications.py b/src/notifications.py new file mode 100644 index 0000000..51f910a --- /dev/null +++ b/src/notifications.py @@ -0,0 +1,10 @@ +from PySide import QtGui, QtCore +# TODO: add sound notifications + + +def tray_notification(title, text): + if QtGui.QSystemTrayIcon.isSystemTrayAvailable(): + tray = QtGui.QSystemTrayIcon() + tray.setContextMenu(QtGui.QMenu()) + tray.show() + tray.showMessage(title, text) diff --git a/src/toxcore_enums_and_consts.py b/src/toxcore_enums_and_consts.py index 19b3ca5..6a4e471 100644 --- a/src/toxcore_enums_and_consts.py +++ b/src/toxcore_enums_and_consts.py @@ -199,15 +199,3 @@ TOX_MAX_MESSAGE_LENGTH = 1372 TOX_MAX_NAME_LENGTH = 128 TOX_MAX_STATUS_MESSAGE_LENGTH = 1007 - -# ----------------------------------------------------------------------------------------------------------------- -# Other enums -# ----------------------------------------------------------------------------------------------------------------- - - -TOX_USER_CONNECTION_STATUS = { - 'ONLINE': 0, - 'AWAY': 1, - 'BUSY': 2, - 'OFFLINE': 3 -}