-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
139 lines (125 loc) · 4.56 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
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
from tkinter import *
import math
import requests
import os
import datetime as dt
# ---------------------------- CONSTANTS ------------------------------- #
PINK = "#ffadad"
RED = "#EA526F"
GREEN = "#25CED1"
YELLOW = "#FCEADE"
BLUE = "#85E9EA"
BG_COLOR = RED
# -- Font of choice: "Dubai", "Bahnschrift", "Ink Free", "Lucida Sans", "Lucida Sans Typewriter", "Maiandra GD",
# "Source Code Pro", "Taipei Sans TC Beta", "Tempus Sans ITC"
FONT_NAME = "Bahnschrift"
WORK_MIN = 25
SHORT_BREAK_MIN = 5
LONG_BREAK_MIN = 30
timer = None
reps = 1
pomo_num = ""
start_time = None
today = dt.datetime.now().strftime("%Y-%m-%d")
# ---------------------------- TIMER RESET ------------------------------- #
def reset_timer():
global timer, reps, pomo_num, start_time
window.after_cancel(timer)
# start_btn.config(bg=BG_COLOR)
# start_btn["state"] = "active"
canvas.itemconfig(timer_text, text="00:00")
canvas.itemconfig(timer_label, text="Timer")
checked_mark.config(text="")
timer = None
start_btn.config(bg=BG_COLOR, state="normal")
now = dt.datetime.now().strftime("%H:%M:%S")
record = pomo_num.replace("⚫", "🍅")
# ------------ Export data to a spreadsheet using sheety api --------
ENDPOINT = os.environ['URL']
header = {
"Content-Type": "application/json"
}
add_row = {
'report': {
'date': today,
'start': start_time,
'end': now,
'pomodoroNumbers': record
}
}
response = requests.post(url=ENDPOINT, json=add_row, headers=header)
response.raise_for_status()
reps = 1
pomo_num = ""
# ---------------------------- TIMER MECHANISM ------------------------------- #
def start_count_down():
global reps, BG_COLOR, start_time
start_time = dt.datetime.now().strftime("%H:%M:%S")
start_btn["state"] = "disable"
if reps%8 == 0:
count_down(LONG_BREAK_MIN * 60)
BG_COLOR = BLUE
canvas.config(bg=BG_COLOR)
window.config(bg=BG_COLOR)
canvas.itemconfig(timer_label, text="BREAK", fill=GREEN)
start_btn.config(bg=BG_COLOR)
reset_btn.config(bg=BG_COLOR)
checked_mark.config(bg=BG_COLOR)
elif reps%2 == 0:
count_down(SHORT_BREAK_MIN * 60)
BG_COLOR = GREEN
canvas.config(bg=BG_COLOR)
window.config(bg=BG_COLOR)
canvas.itemconfig(timer_label, text="Break", fill="white")
start_btn.config(bg=BG_COLOR)
reset_btn.config(bg=BG_COLOR)
checked_mark.config(bg=BG_COLOR)
elif reps%2 == 1:
count_down(WORK_MIN * 60)
BG_COLOR = RED
canvas.config(bg=BG_COLOR)
window.config(bg=BG_COLOR)
canvas.itemconfig(timer_label, text="Work", fill=PINK)
start_btn.config(bg=BG_COLOR)
reset_btn.config(bg=BG_COLOR)
checked_mark.config(bg=BG_COLOR)
reps += 1
# ---------------------------- COUNTDOWN MECHANISM ------------------------------- #
def count_down(count):
global pomo_num
count_min = math.floor(count/60)
count_sec = count%60
if count_sec < 10:
count_sec = f"0{count_sec}"
canvas.itemconfig(timer_text, text=f"{count_min}:{count_sec}")
if count > 0:
global timer
timer = window.after(1000, count_down, count - 1)
elif count == 0:
### Use these 3 lines to ring when time goes to 00:00 and pop-up the pompdoro window.
window.bell()
window.attributes("-topmost", 1)
window.attributes("-topmost", 0)
if reps % 2 == 0:
pomo_num += "⚫"
if reps % 8 == 1:
pomo_num += "-"
checked_mark.config(text=pomo_num)
start_count_down()
# ---------------------------- UI SETUP ------------------------------- #
window = Tk()
window.title("Pomominimal (v1.1)")
window.config(padx=40, pady=20, bg=BG_COLOR)
# --- Theme color and Time at the center ---
canvas = Canvas(width=260, height=200, bg=BG_COLOR, highlightthickness=0)
timer_text = canvas.create_text(130, 120, text="00:00", fill="white", font=(FONT_NAME, 80, "normal"))
canvas.grid(column=0, row=1, columnspan=3)
# Other widgets
timer_label = canvas.create_text(130, 30, text="Timer", fill=YELLOW, font=(FONT_NAME, 32))
start_btn = Button(text="GO", fg="white", bg=BG_COLOR, font=(FONT_NAME, 16), command=start_count_down)
start_btn.grid(column=0, row=2)
reset_btn = Button(text="RESET", fg="white", bg=BG_COLOR, font=(FONT_NAME, 12), pady=6, command=reset_timer)
reset_btn.grid(column=2, row=2)
checked_mark = Label(fg=YELLOW, bg=BG_COLOR, font=(FONT_NAME, 10), height=4)
checked_mark.grid(column=0, row=3, columnspan=3)
window.mainloop()