-
Notifications
You must be signed in to change notification settings - Fork 0
/
Show.py
51 lines (37 loc) · 1.12 KB
/
Show.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
from threading import Thread
from flask_caching import Cache
import os
import sys
sys.path.insert(0, "./lightshowpi/py")
os.environ["SYNCHRONIZED_LIGHTS_HOME"] = "{}/lightshowpi".format(os.curdir)
from lightshowpi.py.synchronized_lights import Lightshow
class Show(object):
def __init__(self, cache: Cache):
self.cache = cache
self.cache.set("showRunning", False)
self._thread = None
self.ls = Lightshow()
def canIRun(self):
if (self.cache.get("showRunning")):
return False
else:
self.cache.set("showRunning", True)
return True
def setConfig(self, configName):
self.ls.configPath = "{}.cfg".format(configName)
self.ls.loadHC()
def startShow(self, songPath, callback=None):
if (self.canIRun()):
self.ls.filepath = songPath
self._thread = Thread(target=self.showWatcher, args=[callback])
self._thread.start()
return True
else:
return False
def showWatcher(self, callback):
self.ls.play_song()
self.cache.set("showRunning", False)
if callback:
callback()
def isRunning(self):
return self.cache.get("showRunning")