forked from albertz/music-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifications.py
38 lines (32 loc) · 1.02 KB
/
notifications.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def macNotificationsMain():
from State import state
from player import PlayerEventCallbacks
import AppKit
import utils
pool = AppKit.NSAutoreleasePool.alloc().init()
appDelegate = AppKit.NSApplication.sharedApplication().delegate()
notifCenter = AppKit.NSUserNotificationCenter.defaultUserNotificationCenter()
notifCenter.setDelegate_(appDelegate)
def notifyCurSong():
notif = AppKit.NSUserNotification.alloc().init()
notif.setTitle_("MusicPlayer")
song = state.curSong
s = None
try:
s = utils.convertToUnicode(song.userString)
except: pass
notif.setInformativeText_(s)
notifCenter.deliverNotification_(notif)
#print "notification:", notif
for ev,args,kwargs in state.updates.read():
if ev is PlayerEventCallbacks.onSongChange:
notifyCurSong()
elif ev is PlayerEventCallbacks.onPlayingStateChange and kwargs["newState"] == True:
notifyCurSong()
del pool
def notificationsMain():
import sys
if sys.platform == "darwin":
macNotificationsMain()
else:
print "no notification implementation"