-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpd-applet
94 lines (79 loc) · 2.19 KB
/
mpd-applet
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
import os, signal, gi
gi.require_version('Gtk', '3.0')
gi.require_version('AppIndicator3', '0.1')
gi.require_version('Notify', '0.7')
from gi.repository import Gtk as gtk, AppIndicator3 as appindicator, Notify as notify
from mpd import MPDClient
HOST = 'localhost'
PORT = 6600
ICON = '/usr/share/icons/Papirus/64x64/devices/audio-headphones.svg'
APPINDICATOR_ID = 'mpd-applet'
client = MPDClient()
client.connect(HOST, PORT)
curSongInfo = client.currentsong()
current = curSongInfo['artist'] + " - " + curSongInfo['title']
TXPOPUP = "Artist : "+curSongInfo['artist']+ " \nTitle : " +curSongInfo['title']+ " \nAlbum : " +curSongInfo['album']
def popup(self):
notify.Notification.new("Now Playing",TXPOPUP,"audio-headphones").show()
def play(self):
try:
client.play()
except:
client.connect(HOST,PORT)
client.play()
def pause(self):
try:
client.pause(1)
except:
client.connect(HOST,PORT)
client.pause(1)
def stop(self):
try:
client.stop()
except:
client.connect(HOST,PORT)
client.stop()
def next(self):
try:
client.next()
except:
client.connect(HOST,PORT)
client.next()
def prev(self):
try:
client.previous()
except:
client.connect(HOST,PORT)
client.previous()
def build_menu():
item_play = gtk.MenuItem('Play')
item_play.connect('activate', play)
menu.append(item_play)
item_pause = gtk.MenuItem('Pause')
item_pause.connect('activate', pause)
menu.append(item_pause)
item_stop = gtk.MenuItem('Stop')
item_stop.connect('activate', stop)
menu.append(item_stop)
item_next = gtk.MenuItem('Next')
item_next.connect('activate', next)
menu.append(item_next)
item_prev = gtk.MenuItem('Previous')
item_prev.connect('activate', prev)
menu.append(item_prev)
item_quit = gtk.MenuItem('Exit Applet')
item_quit.connect('activate', quit)
menu.append(item_quit)
menu.show_all()
return menu
def main():
indicator = appindicator.Indicator.new(APPINDICATOR_ID, os.path.abspath(ICON), appindicator.IndicatorCategory.SYSTEM_SERVICES)
indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
indicator.set_menu(build_menu())
notify.init(APPINDICATOR_ID)
gtk.main()
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal.SIG_DFL)
while(True):
main()