the logical part is almost complete
This commit is contained in:
102
main.py
102
main.py
@@ -1,4 +1,8 @@
|
||||
import tkinter as tk
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
STORAGE_PATH = os.path.expanduser("~/.config/focus-timer/data.txt")
|
||||
|
||||
STATE_IDLE = "IDLE"
|
||||
STATE_FOCUS = "FOCUS"
|
||||
@@ -21,8 +25,6 @@ app.minsize(width, height)
|
||||
app.maxsize(width, height)
|
||||
app.resizable(False, False)
|
||||
|
||||
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")
|
||||
|
||||
def tick():
|
||||
global seconds_left, current_state
|
||||
@@ -45,10 +47,10 @@ def tick():
|
||||
def update_timer_label():
|
||||
global seconds_left
|
||||
mins, secs = divmod(seconds_left, 60)
|
||||
time_label.config(text=f"{mins}:{secs}")
|
||||
timer_label.config(text=f"{mins}:{secs}")
|
||||
|
||||
def handle_transition():
|
||||
global current_state, seconds_left, focus_attempts
|
||||
global current_state, seconds_left, distraction
|
||||
|
||||
match current_state:
|
||||
case "FOCUS":
|
||||
@@ -64,15 +66,18 @@ def handle_transition():
|
||||
current_state = STATE_IDLE
|
||||
seconds_left = 0
|
||||
|
||||
def start_button():
|
||||
update_ui()
|
||||
|
||||
def start_button_f():
|
||||
global current_state, seconds_left, distractions
|
||||
distractions = 0
|
||||
current_state = STATE_FOCUS
|
||||
seconds_left = 0
|
||||
seconds_left = 1200
|
||||
|
||||
tick()
|
||||
update_ui()
|
||||
|
||||
def distracted_button():
|
||||
def distracted_button_f():
|
||||
global current_state, seconds_left, distractions
|
||||
|
||||
if current_state != STATE_FOCUS:
|
||||
@@ -87,11 +92,92 @@ def distracted_button():
|
||||
|
||||
update_timer_label()
|
||||
|
||||
def break_button():
|
||||
def break_button_f():
|
||||
global current_state, seconds_left
|
||||
|
||||
current_state = STATE_BREAK
|
||||
seconds_left = 1500
|
||||
update_timer_label()
|
||||
|
||||
update_ui()
|
||||
|
||||
def complete_task_button_f():
|
||||
create_post()
|
||||
break_button_f()
|
||||
|
||||
def create_post():
|
||||
os.makedirs(os.path.dirname(STORAGE_PATH), exist_ok=True)
|
||||
history = {}
|
||||
|
||||
if os.path.exists(STORAGE_PATH):
|
||||
with open(STORAGE_PATH, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if " : " in line and line.endswith(" cycles."):
|
||||
date_part, cycles_part = line.split(" : ", maxsplit=1)
|
||||
count = int(cycles_part.replace(" cycles.", ""))
|
||||
history[date_part] = count
|
||||
|
||||
date = datetime.now().strftime("%Y-%m-%d")
|
||||
if date in history:
|
||||
history[date] += 1
|
||||
else:
|
||||
history[date] = 1
|
||||
|
||||
with open(STORAGE_PATH, "w", encoding="utf-8") as f:
|
||||
for dates, counts in history.items():
|
||||
f.write(f"{dates} : {counts} cycles.\n")
|
||||
|
||||
def update_ui():
|
||||
global current_state
|
||||
|
||||
start_button.pack_forget()
|
||||
distracted_button.pack_forget()
|
||||
complete_task_button.pack_forget()
|
||||
break_button.pack_forget()
|
||||
|
||||
match current_state:
|
||||
case "IDLE":
|
||||
text_label.config(text="Wanna start?")
|
||||
timer_label.config(text="00:20:00")
|
||||
|
||||
start_button.pack(side="bottom",pady="15")
|
||||
|
||||
case "FOCUS":
|
||||
text_label.config(text="Time to focus!")
|
||||
timer_label.config()
|
||||
distracted_button.pack(side="bottom", pady="15")
|
||||
|
||||
case "WORK":
|
||||
text_label.config(text="Work.")
|
||||
timer_label.config()
|
||||
complete_task_button.pack(side="bottom", pady="15")
|
||||
|
||||
case "OVERTIME":
|
||||
text_label.config(text="Maybe a break?")
|
||||
timer_label.config()
|
||||
break_button.pack(side="bottom", pady="15")
|
||||
|
||||
case "BREAK":
|
||||
text_label.config(text="Relax..")
|
||||
timer_label.config()
|
||||
start_button.pack(side="bottom", pady="15")
|
||||
|
||||
text_label = tk.Label(app, text="", font=("Helvetica", 14))
|
||||
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")
|
||||
|
||||
start_button = tk.Button(app, text="Start.", command=start_button_f)
|
||||
|
||||
distracted_button = tk.Button(app, text="I got distracted.", command=distracted_button_f)
|
||||
|
||||
complete_task_button = tk.Button(app, text="Complete the task.", command=complete_task_button_f)
|
||||
|
||||
break_button = tk.Button(app, text="Go break :3", command=break_button_f)
|
||||
|
||||
|
||||
|
||||
update_ui()
|
||||
app.mainloop()
|
||||
|
||||
Reference in New Issue
Block a user