33import random
44
55import openpyxl as op
6- from openpyxl .styles import Font
76import pandas as pd
87import matplotlib .pyplot as plt
98import matplotlib .dates as mdates
@@ -25,6 +24,7 @@ def __init__(self):
2524 self .initialize_variables ()
2625 self .create_gui ()
2726 self .file_setup ()
27+ self .settings_gui_setup ()
2828
2929
3030 def create_gui (self ):
@@ -56,6 +56,7 @@ def file_setup(self):
5656 self .data_manager = DataManager (self , self .timer_manager , self .workbook , self .worksheet )
5757
5858 self .collect_data ()
59+ self .update_streak_values ()
5960 print ("File loaded" )
6061
6162 else :
@@ -67,13 +68,15 @@ def file_setup(self):
6768 self .data_manager = DataManager (self , self .timer_manager , self .workbook , self .worksheet )
6869
6970 print ("New file created" )
70- #customize_excel(worksheet)
71+ self .data_manager .initialize_new_file_variables ()
72+
73+ self .data_manager .customize_excel ()
7174
7275
7376 def initialize_variables (self ):
7477 self .default_choice = ctk .StringVar (value = "1 hour" )
7578 self .notification_limit = False
76- self .goal = 1
79+ self .goal = 60
7780
7881
7982 def window_setup (self ):
@@ -139,6 +142,11 @@ def tab_frames_gui_setup(self):
139142 fg_color = tab_color , width = int (tab_frame_width * 0.95 ), height = int (tab_height * 0.7 ), hover_color = tab_highlight_color ,
140143 anchor = "w" , command = lambda : self .switch_tab ("history" ))
141144 self .history_tab_button .place (relx = 0.5 , rely = 0.5 , anchor = "center" )
145+ self .settings_tab = ctk .CTkFrame (self .tab_frame , width = tab_frame_width , height = tab_height * 0.8 , fg_color = tab_color )
146+ self .settings_tab .place (relx = 0.5 , rely = 1 , anchor = "s" )
147+ settings_tab_button = ctk .CTkButton (self .settings_tab , text = "Settings" , font = (tab_font_family , 22 * tab_height / 50 , tab_font_weight ), text_color = font_color ,
148+ fg_color = tab_color , width = int (tab_frame_width * 0.95 ), height = int (tab_height * 0.7 ), hover_color = tab_highlight_color , anchor = "w" , command = lambda : self .switch_tab ("settings" ))
149+ settings_tab_button .place (relx = 0.5 , rely = 0.5 , anchor = "center" )
142150
143151
144152 def secondary_frames_gui_setup (self ):
@@ -186,18 +194,20 @@ def progress_gui_setup(self):
186194 def streak_gui_setup (self ):
187195 streak_frame = ctk .CTkFrame (self .goal_progress_frame , fg_color = frame_color , width = frame_width , corner_radius = 10 , height = 220 )
188196 streak_frame .pack (padx = frame_padding , pady = frame_padding )
197+
189198 streak_label = ctk .CTkLabel (streak_frame , text = "Streak" , font = (font_family , int (font_size )), text_color = font_color )
190199 streak_label .place (anchor = "nw" , relx = 0.05 , rely = 0.05 )
200+
191201 times_studied_text = ctk .CTkLabel (streak_frame , text = "Goal\n reached" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
192202 times_studied_text .place (anchor = "center" , relx = 0.3 , rely = 0.4 )
193- self .times_goal_reached = ctk .CTkLabel (streak_frame , text = "goal_amount" , font = (font_family , int (font_size * 2.7 )), text_color = font_color )
203+ self .times_goal_reached = ctk .CTkLabel (streak_frame , text = 0 , font = (font_family , int (font_size * 2.7 )), text_color = font_color )
194204 self .times_goal_reached .place (anchor = "center" , relx = 0.3 , rely = 0.6 )
195205 times_reached_label = ctk .CTkLabel (streak_frame , text = "times" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
196206 times_reached_label .place (anchor = "center" , relx = 0.3 , rely = 0.8 )
197207
198208 duration_studied_text = ctk .CTkLabel (streak_frame , text = "Time\n studied" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
199209 duration_studied_text .place (anchor = "center" , relx = 0.7 , rely = 0.4 )
200- self .streak_duration = ctk .CTkLabel (streak_frame , text = "total_duration" , font = (font_family , int (font_size * 2.7 )), text_color = font_color )
210+ self .streak_duration = ctk .CTkLabel (streak_frame , text = 0 , font = (font_family , int (font_size * 2.7 )), text_color = font_color )
201211 self .streak_duration .place (anchor = "center" , relx = 0.7 , rely = 0.6 )
202212 duration_minute_label = ctk .CTkLabel (streak_frame , text = "minutes" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
203213 duration_minute_label .place (anchor = "center" , relx = 0.7 , rely = 0.8 )
@@ -239,6 +249,17 @@ def save_data_gui(self):
239249 save_data_btn .place (relx = 0.5 , anchor = "center" , rely = 0.5 )
240250
241251
252+ def settings_gui_setup (self ):
253+ reset_frame = ctk .CTkFrame (self .settings_frame , fg_color = tab_color )
254+ reset_frame .place (anchor = "s" , relx = 0.5 , rely = 0.985 )
255+ reset_data_btn = ctk .CTkButton (reset_frame , text = "Reset Data" , font = (font_family , font_size ), fg_color = button_color , text_color = button_font_color ,
256+ border_color = frame_border_color , hover_color = button_highlight_color , height = button_height , command = self .reset_data , width = 450 )
257+ reset_data_btn .pack ()
258+
259+
260+
261+
262+
242263 def switch_tab (self , tab = str ):
243264 tabs = {
244265 "main" : self .main_frame ,
@@ -262,6 +283,15 @@ def forget_tabs():
262283
263284 def timer_mechanism (self ):
264285 self .timer_manager .timer_mechanism (self .timer_button , self .break_button , self .time_display_label )
286+ if self .timer_manager .timer_time <= 1 :
287+ self .data_manager .get_start_time ()
288+
289+
290+ def reset_gui_values (self ):
291+ self .times_goal_reached .configure (text = 0 )
292+ self .streak_duration .configure (text = 0 )
293+ self .progressbar .set (0 )
294+ self .reset_timers ()
265295
266296
267297 def reset_timers (self ):
@@ -284,21 +314,18 @@ def set_goal(self):
284314
285315
286316 def reach_goal (self , timer_time ):
287- if self .goal == 0 :
288- self .goal = 60
289317 if (timer_time / 60 ) < self .goal :
290318 self .progressbar .set ((timer_time / 60 )/ self .goal )
291- elif not self . notification_limit and timer_time / 60 >= self .goal :
319+ elif timer_time / 60 >= self .goal and not self . notification_limit :
292320 self .progressbar .set (1 )
293321
294- self .data_manager .increase_goal_streak ()
295-
296322 message = random .choice (["Congratulations! You've reached your study goal. Take a well-deserved break and recharge!" , "Study session complete! Great job on reaching your goal. Time for a quick break!" ,
297- "You did it! Study session accomplished. Treat yourself to a moment of relaxation!" , "Well done! You've met your study goal. Now, take some time to unwind and reflect on your progress." ,
298- "Study session over! You've achieved your goal. Reward yourself with a brief pause before your next task." , "Goal achieved! Take a breather and pat yourself on the back for your hard work." ,
299- "Mission accomplished! You've hit your study target. Enjoy a short break before diving back in." , "Study session complete. Nicely done! Use this time to relax and rejuvenate before your next endeavor." ,
300- "You've reached your study goal! Treat yourself to a well-deserved break. You've earned it!" , "Goal achieved! Take a moment to celebrate your success. Your dedication is paying off!" ])
323+ "You did it! Study session accomplished. Treat yourself to a moment of relaxation!" , "Well done! You've met your study goal. Now, take some time to unwind and reflect on your progress." ,
324+ "Study session over! You've achieved your goal. Reward yourself with a brief pause before your next task." , "Goal achieved! Take a breather and pat yourself on the back for your hard work." ,
325+ "Mission accomplished! You've hit your study target. Enjoy a short break before diving back in." , "Study session complete. Nicely done! Use this time to relax and rejuvenate before your next endeavor." ,
326+ "You've reached your study goal! Treat yourself to a well-deserved break. You've earned it!" , "Goal achieved! Take a moment to celebrate your success. Your dedication is paying off!" ])
301327 self .send_notification ("Study Goal Reached" , message )
328+ print (self .notification_limit )
302329
303330 def update_streak_values (self ):
304331 self .times_goal_reached .configure (text = self .data_manager .goal_amount )
@@ -311,11 +338,22 @@ def break_mechanism(self):
311338
312339 def collect_data (self ):
313340 self .data_manager .collect_data ()
341+ self .data_manager .data_to_variable ()
314342
315343
316344 def save_data (self ):
317- self .data_manager .save_data (self .timer_button , self .break_button , self .time_display_label , self .break_display_label )
318- self .progressbar .set (0 )
345+ if self .timer_manager .timer_time > 60 :
346+ if self .timer_manager .timer_time / 60 >= self .goal :
347+ self .data_manager .increase_goal_streak ()
348+
349+ self .data_manager .save_data ()
350+ self .collect_data ()
351+ self .reset_gui_values ()
352+ self .update_streak_values ()
353+
354+ self .notification_limit = False
355+ else :
356+ print ("No data to save. (time less than 1m)" )
319357
320358
321359 def send_notification (self , title , message ):
@@ -325,6 +363,16 @@ def send_notification(self, title, message):
325363 print ("Notification " + title + " sent." )
326364
327365
366+ def reset_data (self ):
367+ del self .workbook [self .workbook .active .title ]
368+ self .workbook .create_sheet ()
369+ self .worksheet = self .workbook .active
370+
371+ self .data_manager .reset_data (self .workbook , self .worksheet )
372+
373+ self .reset_gui_values ()
374+
375+
328376 def run (self ):
329377 self .WINDOW .mainloop ()
330378
0 commit comments