-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.py
More file actions
126 lines (89 loc) · 4.35 KB
/
App.py
File metadata and controls
126 lines (89 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import tkinter as tk
from Globals import *
from TimerFrame import *
from ButtonFrame import *
from ToDoFrame import *
from TodayActivityFrame import *
from MenuBar import *
class App(tk.Tk):
def __init__(self):
super().__init__()
self.title("Tracker")
self.iconbitmap(ICON_PATH)
self.resizable(0, 0)
self.create_widgets()
self.timer_frame.access_other_frames(self, self.todo_frame, self.today_activity_frame, self.button_frame)
# Centering the window
self.update_idletasks()
app_width = self.winfo_width()
app_height = self.winfo_height()
screen_width = self.winfo_screenwidth()
screen_height = self.winfo_screenheight()
self.geometry(f"+{screen_width//2 - app_width//2}+{screen_height//2 - app_height//2}")
def create_widgets(self):
self.menu = MenuBar(self)
self.timer_frame = TimerFrame(self)
self.timer_frame.pack()
self.button_frame = ButtonFrame(self)
self.button_frame.pack()
self.button_frame.start_button.configure(command=self.start_action)
self.button_frame.pause_button.configure(command=self.pause_action)
self.button_frame.reset_button.configure(command=self.reset_action)
self.button_frame.done_button.configure(command=self.done_action)
self.todo_frame = ToDoFrame(self)
self.todo_frame.pack(expand=True, pady=10)
self.today_activity_frame = TodayActivity(self)
self.today_activity_frame.pack(expand=True, pady=10)
def start_action(self):
""" Start/Resume """
self.timer_frame.paused = False
"""When it is started once the button will be seen as "Resume"
When activy is done or reset it will be seen as "Start" """
self.button_frame.start_button.configure(text="Resume")
if self.timer_frame.alarm_id is None: # First start
self.timer_frame.count_down()
self.button_frame.start_button.configure(state="disabled")
self.button_frame.pause_button.configure(state="enabled")
self.button_frame.done_button.configure(state="enabled")
def pause_action(self):
""" Pause """
if self.timer_frame.alarm_id is not None:
self.timer_frame.paused = True
self.button_frame.start_button.configure(state="enabled")
self.button_frame.pause_button.configure(state="disabled")
def reset_action(self):
""" Reset """
if self.timer_frame.alarm_id is not None:
self.after_cancel(self.timer_frame.alarm_id)
# Reset button
self.button_frame.start_button.configure(text="Start")
# Reset timer_frame variables
self.timer_frame.alarm_id = None
self.timer_frame.paused = False
# Reset
self.timer_frame.progressTime = self.timer_frame.function_start_time
self.timer_frame.update_timer(self.timer_frame.function_start_time)
self.button_frame.start_button.configure(state="enabled")
self.button_frame.pause_button.configure(state="disabled")
def done_action(self):
""" Pause, Save and Reset """
# Timer needs to be paused until done_action is finished
self.timer_frame.paused = True
if self.timer_frame.alarm_id is None: # no ongoing timer
return
if self.timer_frame.is_activity: # Activity is ended by clicking "Done"
# Stop Timer Loop
self.after_cancel(self.timer_frame.alarm_id)
# Saving activity
spent_time = (self.timer_frame.activity_time-self.timer_frame.progressTime)//60
self.timer_frame.save_activity(self, spent_time)
# Reset "Timer" and Start "Break"
self.timer_frame.reset_countdown_and_timer(new_time=self.timer_frame.break_time, next_event="brake")
self.timer_frame.break_countdown_caller(self)
else: # Break is ended by clicking "Done"
# Stop Timer Loop
self.after_cancel(self.timer_frame.alarm_id)
# Reset "Timer" and Start "Break"
self.timer_frame.reset_countdown_and_timer(new_time=self.timer_frame.activity_time, next_event="activity")
# Display message
messagebox.showinfo(title="Break is done", message=BREAK_DONE_MESSAGE_BOX_TEXT)