notifications added, some fixes
This commit is contained in:
parent
568609dfcb
commit
35cf74eff8
4 changed files with 24 additions and 32 deletions
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
10
src/notifications.py
Normal file
10
src/notifications.py
Normal file
|
@ -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)
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue