-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleMPDVoteMain.py
66 lines (50 loc) · 1.56 KB
/
SimpleMPDVoteMain.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
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
import urllib
import threading
import signal
import QtTrayMenu
from BallotServer import BallotServer
import SimpleMPDVoteWebServer as WebServer
# Host name, for localhost leave name empty
VOTE_HOST_NAME = ''
VOTE_PORT_NUMBER = 6601
MPD_HOST = "leifs-air"
MPD_PORT = 6600
class SimpleMPDVoteApp():
mpd_host = MPD_HOST
mpd_port = MPD_PORT
web_host = VOTE_HOST_NAME
web_port = VOTE_PORT_NUMBER
bs = None
httpd = None
stm = None
def connect_mpd(self):
try:
self.bs = BallotServer(self.mpd_host, self.mpd_port)
print ("Connect to MPD at {0}:{1}".format(self.mpd_host, self.mpd_port))
except:
print ("Could not connect to MPD at {0}:{1}".format(self.mpd_host, self.mpd_port))
def start_web_server(self):
self.httpd_th = threading.Thread(target=self.httpd.run, args=(self.web_host, self.web_port, self.bs))
self.httpd_th.start()
def stop_web_server(self):
th_q = threading.Thread(target=self.httpd.close)
th_q.start()
th_q.join()
def __init__(self):
self.stm = QtTrayMenu.SystemTrayIcon()
self.connect_mpd()
self.httpd = WebServer.SimpleMPDVoteWebServer()
def run(self):
self.start_web_server();
self.stm.run(self)
def quit(self):
if self.bs:
self.bs.close()
self.stop_web_server()
self.stm.exit()
if __name__ == '__main__':
# catch ctrl-c signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
app = SimpleMPDVoteApp()
# start main loop
app.run()