-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
74 lines (64 loc) · 1.92 KB
/
main.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
66
67
68
69
70
71
72
73
74
import rumps
import os
import schedule
import time
import threading
class TwentyTwentyTwenty(rumps.App):
def __init__(self):
super(TwentyTwentyTwenty, self).__init__("20Twenty20",icon="data/icon.tiff")
self.time = 20
self.escapable = False
self.fontsize = 50
self.quotefile = "data/quotes.txt"
self.start = rumps.MenuItem("Start Timer")
self.stop = rumps.MenuItem("Stop Timer",callback=self.stopTimer)
self.menu = [self.start,self.stop,None]
self.timerRunning = True
self.startTimer(None)
self.mainloopStart()
def startTimer(self,_):
self.timerRunning = True
#print "Start"
for i in range(0,24):
strh = str(i)
if i<10:
strh = "0"+strh
for j in [0,20,40]:
strm = str(j)
if j<10:
strm = "0"+strm
time = strh+":"+strm
schedule.every().day.at(time).do(self.runTimer).tag("202020timer")
self.start.set_callback(None)
self.stop.set_callback(self.stopTimer)
def stopTimer(self,_):
self.timerRunning = False
#print "Stop"
schedule.clear("202020timer")
self.stop.set_callback(None)
self.start.title = "Start Timer"
self.start.set_callback(self.startTimer)
def runTimer(self):
os.system("python2 runtimer.py "+str(self.time)+" "+str(self.quotefile)+" "+str(self.escapable)+" "+str(self.fontsize))
def mainloopStart(self):
job_thread = threading.Thread(target=self.mainloop)
job_thread.start()
def mainloop(self):
while True:
if self.timerRunning:
d = schedule.next_run()
strd = d.strftime("Next break at %H:%M")
self.start.title = strd
schedule.run_pending()
time.sleep(1)
#@rumps.clicked("Preferences")
#def prefs(self, _):
# rumps.alert("jk! no preferences available!")
#@rumps.clicked("Silly button")
#def onoff(self, sender):
# sender.state = not sender.state
#@rumps.clicked("Say hi")
#def sayhi(self, _):
# rumps.notification("Awesome title", "amazing subtitle", "hi!!1")
if __name__ == "__main__":
TwentyTwentyTwenty().run()