toxygen/src/notifications.py

32 lines
851 B
Python
Raw Normal View History

2016-02-24 23:01:25 +03:00
from PySide import QtGui
from PySide.phonon import Phonon
2016-02-25 11:32:40 +03:00
from util import curr_directory
2016-02-26 23:14:22 +03:00
# TODO: make app icon active
2016-03-18 16:50:32 +03:00
# TODO: add all sound notifications
2016-02-24 21:38:36 +03:00
SOUND_NOTIFICATION = {
'MESSAGE': 0,
'FRIEND_CONNECTION_STATUS': 1,
'FILE_TRANSFER': 2
}
2016-03-15 22:12:37 +03:00
def tray_notification(title, text, tray):
2016-02-24 21:38:36 +03:00
if QtGui.QSystemTrayIcon.isSystemTrayAvailable():
2016-02-25 11:32:40 +03:00
if len(text) > 30:
2016-02-25 23:40:00 +03:00
text = text[:27] + '...'
2016-02-25 11:32:40 +03:00
tray.showMessage(title, text, QtGui.QSystemTrayIcon.NoIcon, 3000)
def sound_notification(t):
if t == SOUND_NOTIFICATION['MESSAGE']:
f = curr_directory() + '/sounds/message.wav'
2016-03-18 16:50:32 +03:00
elif t == SOUND_NOTIFICATION['FILE_TRANSFER']:
f = curr_directory() + '/sounds/file.wav'
else:
return
m = Phonon.MediaSource(f)
player = Phonon.createPlayer(Phonon.MusicCategory, m)
player.play()