forked from baraltech/Pomodoro-Timer-PyGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutubemain.py
86 lines (73 loc) · 3.75 KB
/
youtubemain.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
import pygame
import sys
from button import Button
pygame.init()
WIDTH, HEIGHT = 900, 600
SCREEN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Pomodoro Timer")
CLOCK = pygame.time.Clock()
BACKDROP = pygame.image.load("assets/backdrop.png")
WHITE_BUTTON = pygame.image.load("assets/button.png")
FONT = pygame.font.Font("assets/ArialRoundedMTBold.ttf", 120)
timer_text = FONT.render("25:00", True, "white")
timer_text_rect = timer_text.get_rect(center=(WIDTH/2, HEIGHT/2-25))
START_STOP_BUTTON = Button(WHITE_BUTTON, (WIDTH/2, HEIGHT/2+100), 170, 60, "START",
pygame.font.Font("assets/ArialRoundedMTBold.ttf", 20), "#c97676", "#9ab034")
POMODORO_BUTTON = Button(None, (WIDTH/2-150, HEIGHT/2-140), 120, 30, "Pomodoro",
pygame.font.Font("assets/ArialRoundedMTBold.ttf", 20), "#FFFFFF", "#9ab034")
SHORT_BREAK_BUTTON = Button(None, (WIDTH/2, HEIGHT/2-140), 120, 30, "Short Break",
pygame.font.Font("assets/ArialRoundedMTBold.ttf", 20), "#FFFFFF", "#9ab034")
LONG_BREAK_BUTTON = Button(None, (WIDTH/2+150, HEIGHT/2-140), 120, 30, "Long Break",
pygame.font.Font("assets/ArialRoundedMTBold.ttf", 20), "#FFFFFF", "#9ab034")
POMODORO_LENGTH = 1500 # 1500 secs / 25 mins
SHORT_BREAK_LENGTH = 300 # 300 secs / 5 mins
LONG_BREAK_LENGTH = 900 # 900 secs / 15 mins
current_seconds = POMODORO_LENGTH
pygame.time.set_timer(pygame.USEREVENT, 1000)
started = False
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if START_STOP_BUTTON.check_for_input(pygame.mouse.get_pos()):
if started:
started = False
else:
started = True
if POMODORO_BUTTON.check_for_input(pygame.mouse.get_pos()):
current_seconds = POMODORO_LENGTH
started = False
if SHORT_BREAK_BUTTON.check_for_input(pygame.mouse.get_pos()):
current_seconds = SHORT_BREAK_LENGTH
started = False
if LONG_BREAK_BUTTON.check_for_input(pygame.mouse.get_pos()):
current_seconds = LONG_BREAK_LENGTH
started = False
if started:
START_STOP_BUTTON.text_input = "STOP"
START_STOP_BUTTON.text = pygame.font.Font("assets/ArialRoundedMTBold.ttf", 20).render(
START_STOP_BUTTON.text_input, True, START_STOP_BUTTON.base_color)
else:
START_STOP_BUTTON.text_input = "START"
START_STOP_BUTTON.text = pygame.font.Font("assets/ArialRoundedMTBold.ttf", 20).render(
START_STOP_BUTTON.text_input, True, START_STOP_BUTTON.base_color)
if event.type == pygame.USEREVENT and started:
current_seconds -= 1
SCREEN.fill("#ba4949")
SCREEN.blit(BACKDROP, BACKDROP.get_rect(center=(WIDTH/2, HEIGHT/2)))
START_STOP_BUTTON.update(SCREEN)
START_STOP_BUTTON.change_color(pygame.mouse.get_pos())
POMODORO_BUTTON.update(SCREEN)
POMODORO_BUTTON.change_color(pygame.mouse.get_pos())
SHORT_BREAK_BUTTON.update(SCREEN)
SHORT_BREAK_BUTTON.change_color(pygame.mouse.get_pos())
LONG_BREAK_BUTTON.update(SCREEN)
LONG_BREAK_BUTTON.change_color(pygame.mouse.get_pos())
if current_seconds >= 0:
display_seconds = current_seconds % 60
display_minutes = int(current_seconds / 60) % 60
timer_text = FONT.render(f"{display_minutes:02}:{display_seconds:02}", True, "white")
SCREEN.blit(timer_text, timer_text_rect)
pygame.display.update()