-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimerbar.py
132 lines (104 loc) · 4.2 KB
/
timerbar.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/python
# -*- coding: utf-8 -*-
""" Simple OSX Bar with Countdown Timer """
import os
import sys
import rumps # uses the rumps library from http://github.com/tito/rumps
import parsedatetime # natural language expressions for parsing https://github.com/bear/parsedatetime
from datetime import datetime, timedelta # temporal objects
__author__ = "Alexander O'Connor <[email protected]>"
__copyright__ = "Copyright 2014, Alexander O'Connor <[email protected]>"
__credits__ = ["Alexander O'Connor <[email protected]>"]
__license__ = "Copyright"
__version__ = "1.5"
__email__ = "Alexander O'Connor <[email protected]>"
__status__ = "Release"
target_time = None
notify = False
@rumps.timer(1)
def tick(sender):
""" Called automatically every second """
global target_time
global notify
global app
if target_time:
notify = True
timeleft = target_time[0] - datetime.now()
app.title = "(%02d:%02d:%02d)" % (timeleft.total_seconds()//3600,(timeleft.seconds % 3600)//60, timeleft.seconds%60)
if (timeleft.total_seconds() < 1) and notify:
app.title = "Done!"
rumps.notification(title="Countdown Done!", subtitle="TimerBar", sound=True, message="The Timer has Completed!")
target_time.pop(0)
notify = False
def startcount(target):
"""start a counter for num mins"""
global target_time
global notify
print 'target: %s' % target
target_time = target
notify = True
rumps.notification(title="Countdown has begun.", subtitle="TimerBar", message="Ends at %s"%target.strftime('%X on %x'))
@rumps.clicked("Pomodoro")
def pomodoro(sender):
""" start a 25/5 cycle"""
time_now = datetime.now()
target = [time_now + timedelta(minutes=25), time_now + timedelta(minutes=30)]
startcount(target)
@rumps.clicked("Start Timer", "5:00")
def fivemincall(sender):
""" start a counter for five mins"""
target = [datetime.now() + timedelta(minutes=5)]
startcount(target)
@rumps.clicked("Start Timer", "10:00")
def tenmincall(sender):
""" start a counter for ten mins"""
target = [datetime.now() + timedelta(minutes=10)]
startcount(target)
@rumps.clicked("Start Timer", "15:00")
def fifteenmincall(sender):
""" start a counter for fifteen mins"""
target = [datetime.now() + timedelta(minutes=15)]
startcount(target)
@rumps.clicked("Start Timer", "25:00")
def fifteenmincall(sender):
""" start a counter for twenty-five mins"""
target = [datetime.now() + timedelta(minutes=25)]
startcount(target)
@rumps.clicked("Start Timer", "Custom...")
def customcall(sender):
response = rumps.Window("Enters number of minutes").run()
p = parsedatetime.Calendar(parsedatetime.Constants())
print response
if response.clicked:
try:
print(datetime(*p.parse(response.text)[0][:6]))
startcount([datetime(*p.parse(response.text)[0][:6])])
except Exception, e:
print e
@rumps.clicked("Stop")
def stoptimer(sender):
global target_time
"""Set the time left to zero"""
target_time = [datetime.now()]
@rumps.clicked("About TimerBar")
def aboutButton(sender):
rumps.Window(title="TimerBar, by Alexander O'Connor", message="Thanks for using TimerBar! Please feel free to send feedback on twitter to @uberalex", default_text="To use it, just run the app and select the time limit you would like to count down to. You can click the stop button any time.\n\nThe Custom... box will take a variety of input such as '5 minutes' or 'at 4pm' or 'tomorrow' (see https://code.google.com/p/parsedatetime/ for more examples).").run()
#App Definition
app = rumps.App("Timebar", title="(00:00:00)\t", icon="data/rooster-128.png")
#The Menu
app.menu = [
rumps.MenuItem("About TimerBar"),
None,
rumps.MenuItem("Pomodoro", icon="data/tomato-100.png", dimensions=(16,16)),
None,
[rumps.MenuItem("Start Timer",icon="data/alarm_clock-128.png", dimensions=(16,16)),
[rumps.MenuItem("5:00"),
rumps.MenuItem("10:00"),
rumps.MenuItem("15:00"),
rumps.MenuItem("25:00"),
rumps.MenuItem("Custom...")]],
None,
rumps.MenuItem("Stop")
]
if __name__ == "__main__":
app.run()