Skip to content

Commit df1c5ba

Browse files
committed
Update timer.py
1 parent 72a682c commit df1c5ba

1 file changed

Lines changed: 75 additions & 15 deletions

File tree

timer.py

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import customtkinter as ctk
1010
from styles import *
1111
from matplotlib.ticker import MaxNLocator
12-
from PIL import Image
12+
from notifypy import Notify
13+
import random
1314

1415
APPNAME = "Timer App"
1516
FILENAME = "Timer Data.xlsx"
@@ -38,6 +39,7 @@
3839
default_choice = ctk.StringVar(value="1 hour")
3940
color = "Orange"
4041
default_color = ctk.StringVar(value=color)
42+
notification_limit = False
4143

4244

4345
main_frame = ctk.CTkFrame(WINDOW, fg_color=main_frame_color, height=HEIGHT+((widget_padding_x+frame_padding)*2), width=WIDTH, corner_radius=0)
@@ -64,6 +66,7 @@
6466
history_frame.grid_forget()
6567
history_frame.grid_propagate(False)
6668

69+
6770
def customize_excel(worksheet):
6871
worksheet["A1"].value = "Start:"
6972
worksheet["B1"].value = "End:"
@@ -168,8 +171,6 @@ def save_weekday():
168171
global monday_duration, tuesday_duration, wednesday_duration, thursday_duration, friday_duration, saturday_duration, sunday_duration
169172

170173
duration = calculate_duration()
171-
print("AAAAA")
172-
print(duration)
173174

174175
match datetime.datetime.now().weekday():
175176
case 0:
@@ -371,10 +372,12 @@ def update_break_time():
371372

372373
#------------------------------------------------------------------------------DATA-----------------------------------------------------------------------------#
373374
def save_data():
374-
global data_amount, duration_list, date_list, goal_amount, time_studied_label, total_duration, times_studied_label, progressbar
375+
global data_amount, duration_list, date_list, goal_amount, time_studied_label, total_duration, times_studied_label, progressbar, notification_limit
375376
global timer_running, timer_time, start_time, timer_btn, timer_label
376377
global break_running, break_time, break_btn, break_label
377378

379+
notification_limit = False
380+
378381
progressbar.set(0)
379382

380383
if timer_time < 60:
@@ -414,11 +417,13 @@ def save_data():
414417

415418

416419
def reset_data():
417-
global data_amount, duration_list, date_list, goal_amount, total_duration, times_studied_label, time_studied_label
420+
global data_amount, duration_list, date_list, goal_amount, total_duration, times_studied_label, time_studied_label, notification_limit
418421
global timer_time, timer_running, time_display_label
419422
global break_time, break_running, break_display_label
420423
global monday_duration, tuesday_duration, wednesday_duration, thursday_duration, friday_duration, saturday_duration, sunday_duration
421424

425+
notification_limit = False
426+
422427
data_amount = 0
423428
del workbook[workbook.active.title]
424429
workbook.create_sheet()
@@ -446,6 +451,15 @@ def reset_data():
446451
customize_excel(worksheet)
447452

448453

454+
def send_notification(title, message):
455+
global notification_limit
456+
notification = Notify()
457+
notification.title(title)
458+
notification.message(message)
459+
notification_limit = True
460+
print("Notification " + title + " sent.")
461+
462+
449463
def save_on_quit():
450464
global color
451465
global timer_time
@@ -502,13 +516,29 @@ def switch_tab(tab = str):
502516

503517

504518
def load_history():
505-
global start_text
506519
start_history = ""
507-
for data in range(data_amount+1, 1, -1):
508-
print("A" + str(data))
509-
start_history += worksheet["A" + str(data)].value
510-
start_history += "\n"
511-
start_text.configure(text=start_history)
520+
end_history = ""
521+
duration_history = ""
522+
break_history = ""
523+
if data_amount > 0:
524+
for data in range(data_amount+1, 1, -1):
525+
start_history += str(worksheet["A" + str(data)].value)
526+
start_history += "\n"
527+
end_history += str(worksheet["B" + str(data)].value)
528+
end_history += "\n"
529+
duration_history += str(round(worksheet["C" + str(data)].value)) + "m"
530+
duration_history += "\n"
531+
break_history += str(round(worksheet["D" + str(data)].value)) + "m"
532+
break_history += "\n"
533+
start_text.configure(text=start_history)
534+
end_text.configure(text=end_history)
535+
duration_text.configure(text=duration_history)
536+
break_text.configure(text=break_history)
537+
else:
538+
start_text.configure(text="-")
539+
end_text.configure(text="-")
540+
duration_text.configure(text="-")
541+
break_text.configure(text="-")
512542

513543

514544
def get_goal():
@@ -525,11 +555,19 @@ def get_goal():
525555

526556

527557
def update_slider(timer_time):
528-
global progressbar, goal
558+
global progressbar, goal, notification_limit
529559
if goal == 0:
530560
goal = 60
531561
if (timer_time/60) < goal:
532562
progressbar.set((timer_time/60)/goal)
563+
if not notification_limit and timer_time/60 >= goal:
564+
message = random.randint(1 ,10)
565+
messages = {1: "Congratulations! You've reached your study goal. Take a well-deserved break and recharge!", 2: "Study session complete! Great job on reaching your goal. Time for a quick break!",
566+
3: "You did it! Study session accomplished. Treat yourself to a moment of relaxation!", 4: "Well done! You've met your study goal. Now, take some time to unwind and reflect on your progress.",
567+
5: "Study session over! You've achieved your goal. Reward yourself with a brief pause before your next task.", 6: "Goal achieved! Take a breather and pat yourself on the back for your hard work.",
568+
7: "Mission accomplished! You've hit your study target. Enjoy a short break before diving back in.", 8: "Study session complete. Nicely done! Use this time to relax and rejuvenate before your next endeavor.",
569+
9: "You've reached your study goal! Treat yourself to a well-deserved break. You've earned it!", 10: "Goal achieved! Take a moment to celebrate your success. Your dedication is paying off!"}
570+
#send_notification("Study Goal Reached", messages[message])
533571

534572

535573
def load_color(color, widget_list, progressbar):
@@ -594,7 +632,7 @@ def change_focus(event):
594632
goal_label = ctk.CTkLabel(goal_frame, text="Goal", font=(font_family, font_size), text_color=font_color)
595633
goal_label.place(anchor="nw", relx=0.05, rely=0.05)
596634

597-
goal_dropdown = ctk.CTkComboBox(goal_frame, values=["30 minutes", "1 hour", "1 hour, 30 minutes", "2 hours", "2 hours, 30 minutes", "3 hours", "3 hours, 30 minutes",
635+
goal_dropdown = ctk.CTkComboBox(goal_frame, values=["1 minutes", "30 minutes", "1 hour", "1 hour, 30 minutes", "2 hours", "2 hours, 30 minutes", "3 hours", "3 hours, 30 minutes",
598636
"4 hours", "4 hours, 30 minutes", "5 hours", "5 hours, 30 minutes", "6 hours"], variable=default_choice,
599637
state="readonly", width=200, height=30, dropdown_font=(font_family, int(font_size*0.75)),
600638
font=(font_family, int(font_size)), fg_color=border_frame_color, button_color=border_frame_color)
@@ -694,14 +732,36 @@ def change_focus(event):
694732

695733
last_sessions_frame = ctk.CTkFrame(history_frame, fg_color=frame_color, corner_radius=10, height=(HEIGHT+((widget_padding_x)*2))/2, width=WIDTH-(frame_padding*2),)
696734
last_sessions_frame.grid(padx=frame_padding, pady=frame_padding)
697-
last_sessions_frame.pack_propagate(False)
735+
last_sessions_frame.grid_propagate(False)
736+
698737
start_frame = ctk.CTkFrame(last_sessions_frame, fg_color="transparent")
699-
start_frame.pack(padx=frame_padding, pady=frame_padding)
738+
start_frame.grid(row=0, column=0, padx=frame_padding, pady=frame_padding)
700739
start_label = ctk.CTkLabel(start_frame, text="Start", font=(font_family, font_size), text_color=font_color)
701740
start_label.pack(padx=widget_padding_x, pady=widget_padding_y)
702741
start_text = ctk.CTkLabel(start_frame, font=(font_family, font_size), text_color=font_color)
703742
start_text.pack(padx=widget_padding_x, pady=widget_padding_y)
704743

744+
end_frame = ctk.CTkFrame(last_sessions_frame, fg_color="transparent")
745+
end_frame.grid(row=0, column=1, padx=frame_padding, pady=frame_padding)
746+
end_label = ctk.CTkLabel(end_frame, text="End", font=(font_family, font_size), text_color=font_color)
747+
end_label.pack(padx=widget_padding_x, pady=widget_padding_y)
748+
end_text = ctk.CTkLabel(end_frame, text="", font=(font_family, font_size), text_color=font_color)
749+
end_text.pack(padx=widget_padding_x, pady=widget_padding_y)
750+
751+
duration_frame = ctk.CTkFrame(last_sessions_frame, fg_color="transparent")
752+
duration_frame.grid(row=0, column=2, padx=frame_padding, pady=frame_padding)
753+
duration_label = ctk.CTkLabel(duration_frame, text="Duration", font=(font_family, font_size), text_color=font_color)
754+
duration_label.pack(padx=widget_padding_x, pady=widget_padding_y)
755+
duration_text = ctk.CTkLabel(duration_frame, text="", font=(font_family, font_size), text_color=font_color)
756+
duration_text.pack(padx=widget_padding_x, pady=widget_padding_y)
757+
758+
break_frame = ctk.CTkFrame(last_sessions_frame, fg_color="transparent")
759+
break_frame.grid(row=0, column=3, padx=frame_padding, pady=frame_padding)
760+
break_label = ctk.CTkLabel(break_frame, text="Break", font=(font_family, font_size), text_color=font_color)
761+
break_label.pack(padx=widget_padding_x, pady=widget_padding_y)
762+
break_text = ctk.CTkLabel(break_frame, text="", font=(font_family, font_size), text_color=font_color)
763+
break_text.pack(padx=widget_padding_x, pady=widget_padding_y)
764+
705765
settings_tab = ctk.CTkFrame(tab_frame, width=tab_frame_width, height=tab_height*0.8, fg_color=tab_color)
706766
settings_tab.place(relx=0.5, rely=1, anchor="s")
707767
settings_btn = ctk.CTkButton(settings_tab, text="Settings", font=(tab_font_family, 22*tab_height/50, tab_font_weight), text_color=font_color,

0 commit comments

Comments
 (0)