-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimey.py
executable file
·180 lines (141 loc) · 5.04 KB
/
timey.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
from AppKit import NSSound
class Sound:
def __init__(self, file):
self._sound = NSSound.alloc()
self._sound.initWithContentsOfFile_byReference_(file, True)
def play(self):
self._sound.play()
def stop(self):
self._sound.stop()
def is_playing(self):
return self._sound.isPlaying()
# class CustomView(NSView):
# n = 10
# def X(self, t):
# return (sin(t) + 1) * self.width * 0.5
# def Y(self, t):
# return (cos(t) + 1) * self.height * 0.5
# def drawRect_(self, rect):
# self.width = self.bounds()[1][0]
# self.height = self.bounds()[1][1]
# NSColor.clearColor().set()
# NSRectFill(self.frame())
# class AppDelegate(NSObject):
# def windowWillClose_(self, notification):
# app.terminate_(self)
# class CustomWindow(NSWindow):
# def awakeFromNib(self):
# self.initialLocation = NSPoint()
# def canBecomeKeyWindow(self):
# return True
# def mouseDragged_(self, theEvent):
# screenFrame = NSScreen.mainScreen().frame()
# if screenFrame is None:
# sys.stderr.write('failed to obtain screen\n')
# raise RuntimeError
# windowFrame = self.frame()
# if windowFrame is None:
# sys.stderr.write('failed to obtain frame\n')
# raise RuntimeError
# currentLocation = self.convertBaseToScreen_(self.mouseLocationOutsideOfEventStream())
# newOrigin = NSMakePoint((currentLocation.x - self.initialLocation.x),
# (currentLocation.y - self.initialLocation.y))
# if (newOrigin.y + windowFrame.size.height) > \
# (screenFrame.origin.y + screenFrame.size.height):
# newOrigin.y = screenFrame.origin.y + \
# (screenFrame.size.height + windowFrame.size.height)
# self.setFrameOrigin_(newOrigin)
# def mouseDown_(self, theEvent):
# windowFrame = self.frame()
# if windowFrame is None:
# sys.stderr.write('failed to obtain frame\n')
# raise RuntimeError
# self.initialLocation = \
# self.convertBaseToScreen_(theEvent.locationInWindow())
# self.initialLocation.x -= windowFrame.origin.x
# self.initialLocation.y -= windowFrame.origin.y
# def main():
# global app
# app = NSApplication.sharedApplication()
# graphicsRect = NSMakeRect(100.0, 350.0, 450.0, 400.0)
# myWindow = CustomWindow.alloc().initWithContentRect_styleMask_backing_defer_(
# graphicsRect,
# NSTitledWindowMask
# | NSClosableWindowMask
# | NSResizableWindowMask
# | NSMiniaturizableWindowMask,
# NSBackingStoreBuffered,
# False)
# # myWindow.setAlphaValue_(0.7)
# myWindow.setBackgroundColor_(NSColor.clearColor())
# myWindow.setBackgroundColor_(NSColor.whiteColor().set())
# myWindow.setLevel_(NSStatusWindowLevel)
# # myWindow.setOpaque_(False)
# # myWindow.setHasShadow_(True)
# myWindow.setTitle_('Tiny Application Window')
# myView = CustomView.alloc().initWithFrame_(graphicsRect)
# myWindow.setContentView_(myView)
# myDelegate = AppDelegate.alloc().init()
# myWindow.setDelegate_(myDelegate)
# myWindow.display()
# myWindow.orderFrontRegardless()
# app.run()
# print 'Done'
import rumps
INTERVAL_TIMER = (60) * 45
ICON_ACTIVE = 'statusItemIcon.png'
ICON_NOACTIVE = 'Icon-32.png'
class Pomodorro(object):
"""docstring for Pomodorro"""
def __init__(self):
self.started = False
self.start = None
self.now = None
self.end = 0
def go(self):
self.started = True
self.start = INTERVAL_TIMER + 1
self.now = self.start
self.end = 0
def tick(self):
self.now = self.now - 1
if self.now <= self.end:
self.stop()
return self.end
return self.now
def stop(self):
self.started = False
self.start = None
self.now = None
self.end = 0
pomodorro = Pomodorro()
endTimerSound = Sound("Ship_Brass_Bell-Mike_Koenig-1458750630.mp3")
def timer_string(t):
return "{:02d}:{:02d}".format(*divmod(t, 60))
# create a new thread that calls the decorated function every 1 second
@rumps.timer(1)
def updateUI(sender):
if pomodorro.started:
t = pomodorro.tick()
timey.title = timer_string(t)
if t == 0:
timey.icon = ICON_NOACTIVE
endTimerSound.play()
# rumps.notification("Awesome title", "amazing subtitle", "hi!!1")
@rumps.clicked('Start timer')
def start_timer(_):
pomodorro.go()
timey.icon = ICON_ACTIVE
@rumps.clicked('Stop timer')
def stop_timer(_):
pomodorro.stop()
timey.title = '00:00'
timey.icon = ICON_NOACTIVE
if __name__ == "__main__":
timey = rumps.App("Timey", icon=ICON_NOACTIVE, title='00:00')
timey.menu = [
rumps.MenuItem('Start timer', icon='playback_play.png'),
rumps.MenuItem('Stop timer', icon='playback_stop.png'),
None
]
timey.run()