full rethinking of the program
This commit is contained in:
96
main.py
96
main.py
@@ -1,41 +1,97 @@
|
||||
import tkinter as tk
|
||||
import time
|
||||
|
||||
STATE_IDLE = "IDLE"
|
||||
STATE_FOCUS = "FOCUS"
|
||||
STATE_WORK = "WORK"
|
||||
STATE_OVERTIME = "OVERTIME"
|
||||
STATE_BREAK = "BREAK"
|
||||
|
||||
current_state = STATE_IDLE
|
||||
seconds_left = 0
|
||||
distractions = 0
|
||||
|
||||
width = 120
|
||||
height = 140
|
||||
|
||||
app = tk.Tk(className="focustimer")
|
||||
|
||||
app = tk.Tk()
|
||||
app.title("Focus-Timer")
|
||||
app.configure(background="#17153B")
|
||||
app.geometry(f"{width}x{height}")
|
||||
app.minsize(width, height)
|
||||
app.maxsize(width, height)
|
||||
app.resizable(False, False)
|
||||
app.update_idletasks()
|
||||
|
||||
text_label = tk.Label(app, text="Wanna start?", fg="#C8ACD6", background="#17153B",font=("Helvetica", 14), anchor="center")
|
||||
text_label.pack(side="top",pady="15")
|
||||
timer_label = tk.Label(app, text="hh:mm:ss",fg="#C8ACD6",background="#17153B",font=("Helvetica", 25) , anchor="center")
|
||||
timer_label.pack(expand=True,fill="y")
|
||||
|
||||
time_label = tk.Label(app, text="hh:mm:ss",fg="#C8ACD6",background="#17153B",font=("Helvetica", 25) , anchor="center")
|
||||
time_label.pack(expand=True,fill="y")
|
||||
def tick():
|
||||
global seconds_left, current_state
|
||||
|
||||
seconds = 1200
|
||||
match current_state:
|
||||
case STATE_IDLE:
|
||||
return
|
||||
case STATE_OVERTIME:
|
||||
seconds_left += 1
|
||||
case _:
|
||||
seconds_left -= 1
|
||||
|
||||
def start():
|
||||
global seconds
|
||||
text_label.config(text="Time to focus!")
|
||||
time_label.config(fg="#AE445A")
|
||||
if seconds > 0:
|
||||
mins, secs = divmod(seconds, 60)
|
||||
time_label.config(text=f"{mins}:{secs}")
|
||||
app.after(1000, start)
|
||||
seconds -= 1
|
||||
update_timer_label()
|
||||
|
||||
if current_state in ("FOCUS","WORK","BREAK") and seconds_left <= 0:
|
||||
handle_transition()
|
||||
|
||||
app.after(1000, tick)
|
||||
|
||||
def update_timer_label():
|
||||
global seconds_left
|
||||
mins, secs = divmod(seconds_left, 60)
|
||||
time_label.config(text=f"{mins}:{secs}")
|
||||
|
||||
def handle_transition():
|
||||
global current_state, seconds_left, focus_attempts
|
||||
|
||||
match current_state:
|
||||
case "FOCUS":
|
||||
current_state = STATE_WORK
|
||||
seconds_left = 4200 # 70 min
|
||||
distractions = 0
|
||||
|
||||
case "WORK":
|
||||
current_state = STATE_OVERTIME
|
||||
seconds_left = 0
|
||||
|
||||
case "BREAK":
|
||||
current_state = STATE_IDLE
|
||||
seconds_left = 0
|
||||
|
||||
def start_button():
|
||||
global current_state, seconds_left, distractions
|
||||
distractions = 0
|
||||
current_state = STATE_FOCUS
|
||||
seconds_left = 0
|
||||
|
||||
tick()
|
||||
|
||||
start_button = tk.Button(app, text="start", command=start, fg="#C8ACD6", background="#17153B")
|
||||
start_button.pack(side="bottom", pady="15")
|
||||
def distracted_button():
|
||||
global current_state, seconds_left, distractions
|
||||
|
||||
if current_state != STATE_FOCUS:
|
||||
return
|
||||
|
||||
distractions += 1
|
||||
|
||||
if distractions > 2:
|
||||
seconds_left = 600
|
||||
else:
|
||||
seconds_left = 1200 - (300 * distractions)
|
||||
|
||||
update_timer_label()
|
||||
|
||||
def break_button():
|
||||
global current_state, seconds_left
|
||||
|
||||
current_state = STATE_BREAK
|
||||
seconds_left = 1500
|
||||
update_timer_label()
|
||||
|
||||
app.mainloop()
|
||||
|
||||
Reference in New Issue
Block a user