-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpomodoro.py
343 lines (276 loc) · 17.5 KB
/
pomodoro.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
from init_and_funcs import *
# main loop
while running:
iTime = time.time()
for event in pygame.event.get(): # event loop
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_l:
colorIndex = not colorIndex
screen.fill(BG[colorIndex])
if colorIndex == 0:
pygame.mixer.Sound.play(birds_chirps, fade_ms = 2000)
else:
pygame.mixer.Sound.play(owl_hooting, fade_ms = 2000)
elif event.key == pygame.K_m:
if not paused:
pygame.mixer.music.pause()
paused = True
else:
pygame.mixer.music.unpause()
paused = False
pygame.display.flip()
mouse = pygame.mouse.get_pos()
match status:
case "begin":
rectCoordinates = (width // 2 - 30, 200, 70, 20)
textCoordinates = (width // 2 - 20, 202)
mainFont = header_font.render("Pomodoro Timer", False, TEXT[colorIndex])
noteFont = note_font.render("Press 'M' to mute music during sessions, and 'L' to switch color modes.", False, TEXT[colorIndex])
if not startScreenFaded:
fade((mainFont, (178, 128)))
pygame.time.delay(1000)
displayButton(b = ((BUTTON[colorIndex], rectCoordinates), (button_font, "Ready?", TEXT[colorIndex], textCoordinates, True)))
fade((noteFont, (150, 400)))
startScreenFaded = True
elif (width // 2) - 30 <= mouse[0] <= (width // 2) + 40 and 200 <= mouse[1] <= 220:
displayButton(b = ((BUTTON_FOCUS[colorIndex], rectCoordinates), (button_font, "Ready?", BUTTON_TEXT[not colorIndex], textCoordinates, False)))
screen.blit(noteFont, (150, 400))
screen.blit(mainFont, (178, 128))
if event.type == pygame.MOUSEBUTTONDOWN:
pygame.mixer.Sound.play(button_select)
current_music_queue = list(random.sample(music_queue, 10))
pygame.mixer.music.load(current_music_queue.pop(0))
pygame.mixer.music.play(fade_ms= 3000)
pygame.mixer.music.queue(current_music_queue.pop(0))
headerBG = pygame.Surface((450, 50))
buttonBG = pygame.Surface((70, 20))
noteBG = pygame.Surface((500, 20))
headerBG.fill(BG[colorIndex])
buttonBG.fill(BG[colorIndex])
noteBG.fill(BG[colorIndex])
displayButton(b = ((BUTTON[colorIndex], rectCoordinates), (button_font, "Begin!", TEXT[colorIndex], textCoordinates, False)))
fade((headerBG, (178, 128)), (buttonBG, (width // 2 - 30, 200)), (noteBG, (150, 400)))
status = "ticking"
else:
displayButton(b = ((BUTTON[colorIndex], (width // 2 - 30, 200, 70, 20)), (button_font, "Ready?", TEXT[colorIndex], (width // 2 - 20, 202), False)))
screen.blit(noteFont, (150, 400))
screen.blit(mainFont, (178, 128))
case "ticking":
dt = int(time.time() - iTime)
mainTimer[1] = mainTimer[1] - dt if dt > 1 and dt <= mainTimer[1] else (-1 if dt > mainTimer[1] else mainTimer[1])
if firstTick:
minute, seconds = mainTimer
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, TEXT[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
mainTimer[0] = mainTimer[0] - 1 if mainTimer[0] > 1 and mainTimer[1] == 0 else (0 if mainTimer[0] == 0 else mainTimer[0])
mainTimer[1] = 59 if mainTimer[1] == 0 else mainTimer[1] - 1
firstTick = False
lastTime = time.time()
elif time.time() - lastTime >= 0.990:
if mainTimer[0] == 0 and mainTimer[1] == -1:
minute, seconds = mainTimer
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, BG[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
screen.fill(BG[colorIndex])
pygame.mixer.music.load(working_dir + r"assets\sound_effects\argon.mp3")
pygame.mixer.music.play(5)
firstTick = True
mainTimer = [25, 0]
totalSessionPeriod += mainTimer[0]
status = "big_break" if totalSessionPeriod >= 115 else "break"
else:
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, BG[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
minute, seconds = mainTimer
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, TEXT[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
mainTimer[1] = mainTimer[1] - 1
lastTime = time.time()
if mainTimer[0] != 0 and mainTimer[1] == -1:
mainTimer[0] -= 1
mainTimer[1] = 59
elif mainTimer[0] == 0 and mainTimer[1] == 3:
pygame.mixer.music.fadeout(3000)
if not pygame.mixer.music.get_busy() and len(current_music_queue) >= 1:
pygame.mixer.music.queue(current_music_queue.pop(0))
case "break":
rectCoordinates = (318, 218, 150, 20)
textCoordinates = (340, 220)
finishedText = subheader_font_medium.render("Session Completed!", False, TEXT[colorIndex])
if not breakScreenFaded:
fade((finishedText, (width - 725, height - 300)))
pygame.time.delay(1500)
displayButton(b = ((BUTTON[colorIndex], rectCoordinates), (button_font, "Begin Break?", TEXT[colorIndex], textCoordinates, True)))
breakScreenFaded = True
elif 318 <= mouse[0] <= 468 and 218 <= mouse[1] <= 238:
displayButton(b = ((BUTTON_FOCUS[colorIndex], rectCoordinates), (button_font, "Begin Break?", BUTTON_TEXT[not colorIndex], textCoordinates, False)))
screen.blit(finishedText, (width - 725, height - 300))
if event.type == pygame.MOUSEBUTTONDOWN:
pygame.mixer.music.stop()
pygame.mixer.Sound.play(button_select)
current_music_queue = list(random.sample(music_queue, 10))
pygame.mixer.music.load(current_music_queue.pop(0))
pygame.mixer.music.play(fade_ms= 3000)
pygame.mixer.music.queue(current_music_queue.pop(0))
buttonBG = pygame.Surface((150, 20))
headerBG = pygame.Surface((750, 60))
buttonBG.fill(BG[colorIndex])
headerBG.fill(BG[colorIndex])
displayButton(b = ((BUTTON[colorIndex], rectCoordinates), (button_font, "Begin the chill!", TEXT[colorIndex], textCoordinates, False)))
fade((buttonBG, (318, 218)), (headerBG, (30, 145)))
status = "break_timer"
else:
displayButton(b = ((BUTTON[colorIndex], rectCoordinates), (button_font, "Begin Break?", TEXT[colorIndex], textCoordinates, False)))
screen.blit(finishedText, (width - 725, height - 300))
case "break_timer":
dt = int(time.time() - iTime)
breakTimer[1] = breakTimer[1] - dt if dt > 1 and dt <= breakTimer[1] else (-1 if dt > breakTimer[1] else breakTimer[1])
if firstTick:
firstTick = False
minute, seconds = breakTimer
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, TEXT[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
breakTimer[0] = breakTimer[0] - 1 if breakTimer[0] > 1 and breakTimer[1] == 0 else(0 if breakTimer[0] == 0 else breakTimer[0])
breakTimer[1] = 59 if breakTimer[1] == 0 else breakTimer[1] - 1
lastTime = time.time()
elif time.time() - lastTime >= 0.990:
if breakTimer[0] == 0 and breakTimer[1] == -1:
minute, seconds = breakTimer
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, BG[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
screen.fill(BG[colorIndex])
pygame.mixer.music.load(working_dir + r"assets\sound_effects\argon.mp3")
pygame.mixer.music.play(5)
firstTick = True
breakTimer = [5, 0]
totalSessionPeriod += breakTimer[0]
status = "end"
else:
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, BG[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
minute, seconds = breakTimer
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, TEXT[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
breakTimer[1] = breakTimer[1] - 1
lastTime = time.time()
if breakTimer[0] != 0 and breakTimer[1] == -1:
breakTimer[0] -= 1
breakTimer[1] = 59
elif breakTimer[0] == 0 and breakTimer[1] == 3:
pygame.mixer.music.fadeout(3000)
if not pygame.mixer.music.get_busy() and len(current_music_queue) >= 1:
pygame.mixer.music.queue(current_music_queue.pop(0))
case "big_break":
rectCoordinates = (318, 248, 164, 20)
textCoordinates = (324, 250)
if not bigBreakScreenFaded:
workedBigFont = subheader_font_medium.render("You worked ", False, TEXT[colorIndex])
breakBigFont = basic_font.render("So have a break that's", False, TEXT[colorIndex])
bigFont = bold_font.render("BIG!", False, TEXT[colorIndex])
fade((workedBigFont, (20, 120)), (breakBigFont, (30, 192)), (bigFont, (420, 90)))
displayButton(b = ((BUTTON[colorIndex], rectCoordinates), (button_font, "Begin the Big Break?", TEXT[colorIndex], textCoordinates, True)))
bigBreakScreenFaded = True
elif 318 <= mouse[0] <= 482 and 248 <= mouse[1] <= 268:
displayButton(b = ((BUTTON_FOCUS[colorIndex], rectCoordinates), (button_font, "Begin the Big Break?", BUTTON_TEXT[not colorIndex], textCoordinates, False)))
screen.blit(workedBigFont, (20, 120))
screen.blit(breakBigFont, (20, 192))
screen.blit(bigFont, (420, 90))
if event.type == pygame.MOUSEBUTTONDOWN:
pygame.mixer.music.stop()
pygame.mixer.Sound.play(button_select)
current_music_queue = list(random.sample(music_queue, 10))
pygame.mixer.music.load(current_music_queue.pop(0))
pygame.mixer.music.play(fade_ms= 3000)
pygame.mixer.music.queue(current_music_queue.pop(0))
buttonBG = pygame.Surface((180, 30))
headerBG = pygame.Surface((750, 120))
buttonBG.fill(BG[colorIndex])
headerBG.fill(BG[colorIndex])
displayButton(b = ((BUTTON[colorIndex], rectCoordinates), (button_font, "Begin the BIG CHILL!", TEXT[colorIndex], textCoordinates, False)))
fade((buttonBG, (318, 248)), (headerBG, (24, 120)))
status = "big_break_timer"
else:
displayButton(b = ((BUTTON[colorIndex], rectCoordinates), (button_font, "Begin the Big Break?", TEXT[colorIndex], textCoordinates, False)))
screen.blit(workedBigFont, (20, 120))
screen.blit(breakBigFont, (20, 192))
screen.blit(bigFont, (420, 90))
case "big_break_timer":
dt = int(time.time() - iTime)
bigBreakTimer[1] = bigBreakTimer[1] - dt if dt > 1 and dt <= bigBreakTimer[1] else (-1 if dt > bigBreakTimer[1] else bigBreakTimer[1])
if firstTick:
firstTick = False
minute, seconds = bigBreakTimer
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, TEXT[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
bigBreakTimer[0] = bigBreakTimer[0] - 1 if bigBreakTimer[0] > 1 and bigBreakTimer[1] == 0 else(0 if bigBreakTimer[0] == 0 else bigBreakTimer[0])
bigBreakTimer[1] = 59 if bigBreakTimer[1] == 0 else bigBreakTimer[1] - 1
lastTime = time.time()
elif time.time() - lastTime >= 0.990:
if bigBreakTimer[0] == 0 and bigBreakTimer[1] == -1:
minute, seconds = bigBreakTimer
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, BG[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
screen.fill(BG[colorIndex])
pygame.mixer.music.load(working_dir + r"assets\sound_effects\argon.mp3")
pygame.mixer.music.play(5)
firstTick = True
bigBreakTimer = [20, 0]
totalSessionPeriod = 0
status = "end"
else:
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, BG[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
minute, seconds = bigBreakTimer
timeText = timer_font.render(f"{minute:02d}:{seconds:02d}", False, TEXT[colorIndex])
screen.blit(timeText, (timeWidth, timeHeight))
bigBreakTimer[1] = bigBreakTimer[1] - 1
lastTime = time.time()
if bigBreakTimer[0] != 0 and bigBreakTimer[1] == -1:
bigBreakTimer[0] -= 1
bigBreakTimer[1] = 59
elif bigBreakTimer[0] == 0 and bigBreakTimer[1] == 3:
pygame.mixer.music.fadeout(3000)
if not pygame.mixer.music.get_busy() and len(current_music_queue) >= 1:
pygame.mixer.music.queue(current_music_queue.pop(0))
case "end":
rectCoordinates_Button1 = (200, 245, 130, 20)
textCoordinates_Button1 = (210, 247)
rectCoordinates_Button2 = (500, 245, 70, 20)
textCoordinates_Button2 = (515, 247)
screenDummy = pygame.Surface((width, height))
screenDummy.fill(BG[colorIndex])
endFont1 = subheader_font_small.render("Pomodoro Session", False, TEXT[colorIndex])
endFont2 = subheader_font_large.render("Complete!", False, TEXT[colorIndex])
if not endScreenFaded:
fade((endFont1, (160, 100)), (endFont2, (140, 130)))
displayButton(b1 = ((BUTTON[colorIndex], rectCoordinates_Button1), (button_font, "Home Screen?", TEXT[colorIndex], textCoordinates_Button1, True)), b2 = ((BUTTON[colorIndex], rectCoordinates_Button2), (button_font, "Quit?", TEXT[colorIndex], textCoordinates_Button2, True)))
endScreenFaded = True
elif 200 <= mouse[0] <= 330 and 245 <= mouse[1] <= 265:
displayButton(b = ((BUTTON_FOCUS[colorIndex], rectCoordinates_Button1), (button_font, "Home Screen?", BUTTON_TEXT[not colorIndex], textCoordinates_Button1, False)))
screen.blit(endFont1, (160, 100))
screen.blit(endFont2, (140, 130))
if event.type == pygame.MOUSEBUTTONDOWN:
pygame.mixer.music.stop()
pygame.mixer.Sound.play(button_select)
startScreenFaded = False
breakScreenFaded = False
endScreenFaded = False
status = "begin"
fade((screenDummy, (0,0)))
elif 500 <= mouse[0] <= 570 and 245 <= mouse[1] <= 265:
displayButton(b =((BUTTON_FOCUS[colorIndex], rectCoordinates_Button2),(button_font, "Quit?", BUTTON_TEXT[not colorIndex], textCoordinates_Button2, False)))
screen.blit(endFont1, (160, 100))
screen.blit(endFont2, (140, 130))
if event.type == pygame.MOUSEBUTTONDOWN:
pygame.mixer.music.stop()
pygame.mixer.Sound.play(button_select)
fade((screenDummy, (0, 0)))
pygame.time.delay(500)
running = False
else:
displayButton(b1 = ((BUTTON[colorIndex], rectCoordinates_Button1), (button_font, "Home Screen?", TEXT[colorIndex], textCoordinates_Button1, False)), b2 = ((BUTTON[colorIndex], rectCoordinates_Button2), (button_font, "Quit?", TEXT[colorIndex], textCoordinates_Button2, False)))
screen.blit(endFont1, (160, 100))
screen.blit(endFont2, (140, 130))
pygame.quit()