1818
1919class App :
2020 def __init__ (self ):
21- self .file_setup ()
22- self .window_setup ()
23-
24- self .timer_manager = TimerManager (self , self .WINDOW )
25- self .data_manager = DataManager (self .timer_manager , self .workbook , self .worksheet )
21+ self .APPNAME = "Timer App"
22+ self .FILENAME = "Timer Data.xlsx"
2623
24+ self .window_setup ()
2725 self .initialize_variables ()
2826 self .create_gui ()
27+ self .file_setup ()
2928
3029
3130 def create_gui (self ):
@@ -43,26 +42,30 @@ def create_gui(self):
4342
4443
4544 def file_setup (self ):
46- self .APPNAME = "Timer App"
47- FILENAME = "Timer Data.xlsx"
48-
4945 self .local_folder = os .path .expandvars (rf"%APPDATA%\{ self .APPNAME } " )
50- self .data_file = os .path .expandvars (rf"%APPDATA%\{ self .APPNAME } \{ FILENAME } " )
46+ self .data_file = os .path .expandvars (rf"%APPDATA%\{ self .APPNAME } \{ self . FILENAME } " )
5147
5248 os .makedirs (self .local_folder , exist_ok = True )
5349
50+ self .timer_manager = TimerManager (self , self .WINDOW )
51+
5452 if os .path .isfile (self .data_file ):
5553 self .workbook = op .load_workbook (self .data_file )
5654 self .worksheet = self .workbook .active
5755
58- #collect_data()
56+ self .data_manager = DataManager (self , self .timer_manager , self .workbook , self .worksheet )
57+
58+ self .collect_data ()
5959 print ("File loaded" )
6060
6161 else :
6262 self .workbook = op .Workbook ()
6363 self .worksheet = self .workbook .active
6464
6565 self .workbook .save (self .data_file )
66+
67+ self .data_manager = DataManager (self , self .timer_manager , self .workbook , self .worksheet )
68+
6669 print ("New file created" )
6770 #customize_excel(worksheet)
6871
@@ -156,14 +159,14 @@ def goal_gui_setup(self):
156159 goal_label = ctk .CTkLabel (goal_frame , text = "Goal" , font = (font_family , font_size ), text_color = font_color )
157160 goal_label .place (anchor = "nw" , relx = 0.05 , rely = 0.05 )
158161
159- 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" ,
162+ self . 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" ,
160163 "4 hours" , "4 hours, 30 minutes" , "5 hours" , "5 hours, 30 minutes" , "6 hours" ], variable = self .default_choice ,
161164 state = "readonly" , width = 200 , height = 30 , dropdown_font = (font_family , int (font_size * 0.75 )),
162165 font = (font_family , int (font_size )), fg_color = border_frame_color , button_color = border_frame_color )
163- goal_dropdown .place (anchor = "center" , relx = 0.5 , rely = 0.45 )
166+ self . goal_dropdown .place (anchor = "center" , relx = 0.5 , rely = 0.45 )
164167
165168 goal_button = ctk .CTkButton (goal_frame , text = "Save" , font = (font_family , font_size ), text_color = button_font_color , fg_color = button_color , hover_color = button_highlight_color ,
166- height = button_height )
169+ height = button_height , command = self . set_goal )
167170 goal_button .place (anchor = "s" , relx = 0.5 , rely = 0.9 )
168171
169172
@@ -187,17 +190,17 @@ def streak_gui_setup(self):
187190 streak_label .place (anchor = "nw" , relx = 0.05 , rely = 0.05 )
188191 times_studied_text = ctk .CTkLabel (streak_frame , text = "Goal\n reached" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
189192 times_studied_text .place (anchor = "center" , relx = 0.3 , rely = 0.4 )
190- times_studied_label = ctk .CTkLabel (streak_frame , text = "goal_amount" , font = (font_family , int (font_size * 2.7 )), text_color = font_color )
191- times_studied_label .place (anchor = "center" , relx = 0.3 , rely = 0.6 )
193+ self . times_goal_reached = ctk .CTkLabel (streak_frame , text = "goal_amount" , font = (font_family , int (font_size * 2.7 )), text_color = font_color )
194+ self . times_goal_reached .place (anchor = "center" , relx = 0.3 , rely = 0.6 )
192195 times_reached_label = ctk .CTkLabel (streak_frame , text = "times" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
193196 times_reached_label .place (anchor = "center" , relx = 0.3 , rely = 0.8 )
194197
195198 duration_studied_text = ctk .CTkLabel (streak_frame , text = "Time\n studied" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
196199 duration_studied_text .place (anchor = "center" , relx = 0.7 , rely = 0.4 )
197- time_studied_label = ctk .CTkLabel (streak_frame , text = "total_duration" , font = (font_family , int (font_size * 2.7 )), text_color = font_color )
198- time_studied_label .place (anchor = "center" , relx = 0.7 , rely = 0.6 )
199- time_reached_label = ctk .CTkLabel (streak_frame , text = "minutes" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
200- time_reached_label .place (anchor = "center" , relx = 0.7 , rely = 0.8 )
200+ self . streak_duration = ctk .CTkLabel (streak_frame , text = "total_duration" , font = (font_family , int (font_size * 2.7 )), text_color = font_color )
201+ self . streak_duration .place (anchor = "center" , relx = 0.7 , rely = 0.6 )
202+ duration_minute_label = ctk .CTkLabel (streak_frame , text = "minutes" , font = (font_family , int (font_size / 1.25 )), text_color = font_color )
203+ duration_minute_label .place (anchor = "center" , relx = 0.7 , rely = 0.8 )
201204
202205
203206 def timer_gui (self ):
@@ -261,24 +264,55 @@ def timer_mechanism(self):
261264 self .timer_manager .timer_mechanism (self .timer_button , self .break_button , self .time_display_label )
262265
263266
264- def update_slider (self , timer_time ):
267+ def reset_timers (self ):
268+ self .timer_button .configure (text = "Start" )
269+ self .break_button .configure (text = "Start" )
270+ self .time_display_label .configure (text = "0:00:00" )
271+ self .break_display_label .configure (text = "0:00:00" )
272+
273+
274+ def set_goal (self ):
275+ x = 0
276+ choice = self .goal_dropdown .get ()
277+ if "hour" in choice :
278+ x += int (choice .split (" " )[0 ]) * 60
279+ if "minutes" in choice and "hour" in choice :
280+ x += int (choice .split (", " )[1 ].removesuffix (" minutes" ))
281+ if "hour" not in choice :
282+ x += int (choice .split (" " )[0 ])
283+ self .goal = x
284+
285+
286+ def reach_goal (self , timer_time ):
265287 if self .goal == 0 :
266288 self .goal = 60
267289 if (timer_time / 60 ) < self .goal :
268290 self .progressbar .set ((timer_time / 60 )/ self .goal )
269291 elif not self .notification_limit and timer_time / 60 >= self .goal :
270292 self .progressbar .set (1 )
293+
294+ self .data_manager .increase_goal_streak ()
295+
271296 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!" ,
272297 "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." ,
273298 "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." ,
274299 "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." ,
275300 "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!" ])
276301 self .send_notification ("Study Goal Reached" , message )
302+
303+ def update_streak_values (self ):
304+ self .times_goal_reached .configure (text = self .data_manager .goal_amount )
305+ self .streak_duration .configure (text = self .data_manager .total_duration )
306+
277307
278308 def break_mechanism (self ):
279309 self .timer_manager .break_mechanism (self .break_button , self .timer_button , self .break_display_label )
280310
281311
312+ def collect_data (self ):
313+ self .data_manager .collect_data ()
314+
315+
282316 def save_data (self ):
283317 self .data_manager .save_data (self .timer_button , self .break_button , self .time_display_label , self .break_display_label )
284318 self .progressbar .set (0 )
0 commit comments