-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
314 lines (279 loc) · 14 KB
/
main.py
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
from customtkinter import *
import tkinter
import CTkMessagebox
prev_val = []
set_default_color_theme("blue")
def CheckDestroyed(box):
return CTkMessagebox.CTkMessagebox.Isdestroyed(box)
class PostureCheckPage(CTkFrame):
def __init__(self, master):
super().__init__(master)
self.label = CTkLabel(self, text="Posture Reminder", font=("Helvetica", 24))
self.label.grid(row=0, column=1, pady=10)
self.button = CTkButton(self, text="Back", command=self.hide_page)
self.button.grid(row=1, column=1, pady=10)
self.timeLabel = CTkLabel(self, text="Remind me to check my posture every: ", font=("Helivetica", 16))
self.timeLabel.grid(row=1, column=1, pady=20, padx=10)
self.time = CTkEntry(self, placeholder_text="Never")
self.time.grid(row=1, column=2, pady=20)
self.time.bind("<Return>", self.remind)
self.timeEnd = CTkLabel(self, text="minutes", font=("Helivetica", 16))
self.timeEnd.grid(row=1, column=3, pady=20, padx=10)
self.button = CTkButton(self, text="Back Home", command=self.hide_page)
self.button.grid(row=2, column=1, pady=10)
self.PreminderID = None
def hide_page(self):
self.grid_forget()
self.master.show_dashboard()
def remind(self, event=None):
flag = True
prev_val.append(self.time.get())
try:
int(self.time.get())
except ValueError:
flag=False
if flag==True:
print("got: " + str(self.time.get()))
if (len(prev_val)>1 and prev_val[len(prev_val)-1] == prev_val[len(prev_val)-2]):
print("Repeated input detected.")
self.after_cancel(self.PreminderID)
if self.PreminderID and prev_val[len(prev_val)-1] != prev_val[len(prev_val)-2]:
print("Canceled prev")
self.after_cancel(self.PreminderID)
self.wait()
def wait(self):
print("wait called")
self.PreminderID = self.after(int(self.time.get())*60000, self.actualRemind)
def actualRemind(self):
print("look away")
box = CTkMessagebox.CTkMessagebox(title="Break Reminder", message=str("Its been " + self.time.get() + " minute(s)! Check your posture!"), option_1="OK")
self.check_box_status(box)
def check_box_status(self, box):
if CheckDestroyed(box):
print("Box destroyed, waiting for next reminder...")
self.wait()
else:
print("Box still exists, checking again in 1000 milliseconds.")
self.after(1000, lambda: self.check_box_status(box))
class EyeCheckPage(CTkFrame):
def __init__(self, master):
super().__init__(master)
self.label = CTkLabel(self, text="Eye Reminder", font=("Helvetica", 24))
self.label.grid(row=0, column=1, pady=10)
self.timeLabel = CTkLabel(self, text="Remind me to look away from my screen every: ", font=("Helivetica", 16))
self.timeLabel.grid(row=1, column=1, pady=20, padx=10)
self.time = CTkEntry(self, placeholder_text="Never")
self.time.grid(row=1, column=2, pady=20)
self.time.bind("<Return>", self.remind)
self.timeEnd = CTkLabel(self, text="minutes", font=("Helivetica", 16))
self.timeEnd.grid(row=1, column=3, pady=20, padx=10)
self.button = CTkButton(self, text="Back Home", command=self.hide_page)
self.button.grid(row=2, column=1, pady=10)
self.reminder_id = None
def remind(self, event=None):
flag = True
prev_val.append(self.time.get())
try:
int(self.time.get())
except ValueError:
flag=False
if flag==True:
print("got: " + str(self.time.get()))
if (len(prev_val)>1 and prev_val[len(prev_val)-1] == prev_val[len(prev_val)-2]):
print("Repeated input detected.")
self.after_cancel(self.reminder_id)
if self.reminder_id and prev_val[len(prev_val)-1] != prev_val[len(prev_val)-2]:
print("Canceled prev")
self.after_cancel(self.reminder_id)
self.wait()
def wait(self):
print("wait called")
self.reminder_id = self.after(int(self.time.get())*60000, self.actualRemind)
def actualRemind(self):
print("look away")
box = CTkMessagebox.CTkMessagebox(title="Eye Reminder", message=str("Its been " + self.time.get() + " minute(s)! Time to let your eyes take a break!"), option_1="OK")
self.check_box_status(box)
def check_box_status(self, box):
if CheckDestroyed(box):
print("Box destroyed, waiting for next reminder...")
self.wait()
else:
print("Box still exists, checking again in 1000 milliseconds.")
self.after(1000, lambda: self.check_box_status(box))
def hide_page(self):
self.grid_forget()
self.master.show_dashboard()
class BreakPage(CTkFrame):
def __init__(self, master):
super().__init__(master)
self.label = CTkLabel(self, text="Break Reminder", font=("Helvetica", 24))
self.label.grid(row=0, column=1, pady=10)
self.timeLabel = CTkLabel(self, text="Remind me to take a break every: ", font=("Helivetica", 16))
self.timeLabel.grid(row=1, column=1, pady=20, padx=10)
self.time = CTkEntry(self, placeholder_text="Never")
self.time.grid(row=1, column=2, pady=20)
self.time.bind("<Return>", self.remind)
self.timeEnd = CTkLabel(self, text="minutes", font=("Helivetica", 16))
self.timeEnd.grid(row=1, column=3, pady=20, padx=10)
self.button = CTkButton(self, text="Back Home", command=self.hide_page)
self.button.grid(row=2, column=1, pady=10)
self.Breminder_id = None
def remind(self, event=None):
flag = True
prev_val.append(self.time.get())
try:
int(self.time.get())
except ValueError:
flag=False
if flag==True:
print("got: " + str(self.time.get()))
if (len(prev_val)>1 and prev_val[len(prev_val)-1] == prev_val[len(prev_val)-2]):
print("Repeated input detected.")
self.after_cancel(self.Breminder_id)
if self.Breminder_id and prev_val[len(prev_val)-1] != prev_val[len(prev_val)-2]:
print("Canceled prev")
self.after_cancel(self.Breminder_id)
self.wait()
def wait(self):
print("wait called")
self.Breminder_id = self.after(int(self.time.get())*60000, self.actualRemind)
def actualRemind(self):
print("look away")
box = CTkMessagebox.CTkMessagebox(title="Break Reminder", message=str("Its been " + self.time.get() + " minute(s)! Time to take a break!"), option_1="OK")
self.check_box_status(box)
def check_box_status(self, box):
if CheckDestroyed(box):
print("Box destroyed, waiting for next reminder...")
self.wait()
else:
print("Box still exists, checking again in 1000 milliseconds.")
self.after(1000, lambda: self.check_box_status(box))
def hide_page(self):
self.grid_forget()
self.master.show_dashboard()
class HydraPage(CTkFrame):
def __init__(self, master):
super().__init__(master)
self.label = CTkLabel(self, text="Hydration Reminder", font=("Helvetica", 24))
self.label.grid(row=0, column=1, pady=10)
self.timeLabel = CTkLabel(self, text="Remind me to drink water every: ", font=("Helivetica", 16))
self.timeLabel.grid(row=1, column=1, pady=20, padx=10)
self.time = CTkEntry(self, placeholder_text="Never")
self.time.grid(row=1, column=2, pady=20)
self.time.bind("<Return>", self.remind)
self.timeEnd = CTkLabel(self, text="minutes", font=("Helivetica", 16))
self.timeEnd.grid(row=1, column=3, pady=20, padx=10)
self.button = CTkButton(self, text="Back Home", command=self.hide_page)
self.button.grid(row=2, column=1, pady=10)
self.Greminder_id = None
def remind(self, event=None):
flag = True
prev_val.append(self.time.get())
try:
int(self.time.get())
except ValueError:
flag=False
if flag==True:
print("got: " + str(self.time.get()))
if (len(prev_val)>1 and prev_val[len(prev_val)-1] == prev_val[len(prev_val)-2]):
print("Repeated input detected.")
self.after_cancel(self.Greminder_id)
if self.Greminder_id and prev_val[len(prev_val)-1] != prev_val[len(prev_val)-2]:
print("Canceled prev")
self.after_cancel(self.Greminder_id)
self.wait()
def wait(self):
print("wait called")
self.Greminder_id = self.after(int(self.time.get())*60000, self.actualRemind)
def actualRemind(self):
print("look away")
box = CTkMessagebox.CTkMessagebox(title="Break Reminder", message=str("Its been " + self.time.get() + " minute(s)! Time to take a break!"), option_1="OK")
self.check_box_status(box)
def check_box_status(self, box):
if CheckDestroyed(box):
print("Box destroyed, waiting for next reminder...")
self.wait()
else:
print("Box still exists, checking again in 1000 milliseconds.")
self.after(1000, lambda: self.check_box_status(box))
def hide_page(self):
self.grid_forget()
self.master.show_dashboard()
class DashboardPage(CTkFrame):
def __init__(self, master, eye_check, posture_check, break_remind, app_track):
super().__init__(master)
# self.dashboard_frame = CTkFrame(self, width=880, corner_radius=15)
# self.dashboard_frame.grid(row=0, column=0, rowspan=4, sticky="nsew")
# self.dashboard_frame.grid_rowconfigure(2, weight=1)
# self.dashboard_frame.grid_columnconfigure(2, weight=1)
class App(CTk):
def __init__(self):
# Inheriting constructor of super class
super().__init__()
# Giving apt title and window size
self.title("BHAC")
self.geometry(f"{1100}x{580}")
# configure grid layout (2x2)
self.grid_columnconfigure(1, weight=1)
self.grid_columnconfigure(2, weight=1)
self.grid_rowconfigure((0, 1, 2), weight=1)
self.eye_check_page = EyeCheckPage(self)
self.posture_reminder_page = PostureCheckPage(self)
self.hydra_check_page = HydraPage(self)
self.break_reminder_page = BreakPage(self)
self.dashboard_page = DashboardPage(self, self.show_eye_check, self.show_posture_check, self.show_break_remind, self.show_hydra_check)
self.current_page = None
self.sidebar_frame = CTkFrame(self, width=140, corner_radius=15)
self.sidebar_frame.grid(row=0, column=0, rowspan=4, sticky="nsew")
self.sidebar_frame.grid_rowconfigure(4, weight=1)
self.logo_label = CTkLabel(self.sidebar_frame, text="BHAC", font=CTkFont(size=20, weight="bold"))
self.logo_label.grid(row=0, column=0, padx=20, pady=(20, 10))
self.sidebar_button_1 = CTkButton(self.sidebar_frame, command=self.show_eye_check, text="Eye Reminder")
self.sidebar_button_1.grid(row=1, column=0, padx=20, pady=10)
self.sidebar_button_2 = CTkButton(self.sidebar_frame, command=self.show_posture_check, text="Posture Reminder")
self.sidebar_button_2.grid(row=2, column=0, padx=20, pady=10)
self.sidebar_button_3 = CTkButton(self.sidebar_frame, command=self.show_hydra_check, text="Hydration Reminder")
self.sidebar_button_3.grid(row=4, column=0, padx=20, pady=10, sticky="nw")
self.sidebar_button_4 = CTkButton(self.sidebar_frame, command=self.show_break_remind, text="Break Reminder")
self.sidebar_button_4.grid(row=3, column=0, padx=20, pady=10)
self.show_dashboard()
def hide_dashboard(self):
self.eyecheck.grid_forget()
self.posturecheck.grid_forget()
self.breakremind.grid_forget()
self.apptrack.grid_forget()
def show_eye_check(self):
self.hide_dashboard()
self.show_page(self.eye_check_page)
def hide_eye(self):
self.eye_label.grid_forget()
self.eye_back.grid_forget()
self.show_dashboard()
def show_posture_check(self):
self.hide_dashboard()
self.show_page(self.posture_reminder_page)
def show_hydra_check(self):
self.hide_dashboard()
self.show_page(self.hydra_check_page)
def show_break_remind(self):
self.hide_dashboard()
self.show_page(self.break_reminder_page)
def show_dashboard(self):
self.eyecheck = CTkButton(self, command=self.show_eye_check, text="Eye Reminder", fg_color="gray85", text_color="black", hover_color="gray80", font=CTkFont(size=20, weight="bold"))
self.eyecheck.grid(row=0, column=1, padx=(20, 20), pady=(20, 0), sticky="nsew")
self.posturecheck = CTkButton(self, command=self.show_posture_check, text="Posture Reminder", fg_color="gray85", text_color="black", hover_color="gray80", font=CTkFont(size=20, weight="bold"))
self.posturecheck.grid(row=0, column=2, padx=(20, 20), pady=(20, 0), sticky="nsew")
self.breakremind = CTkButton(self, command=self.show_break_remind,text="Break Reminder", fg_color="gray85", text_color="black", hover_color="gray80", font=CTkFont(size=20, weight="bold"))
self.breakremind.grid(row=1, column=2, padx=(20, 20), pady=(30, 0), sticky="nsew")
self.apptrack = CTkButton(self, command=self.show_hydra_check,text="Hydration Reminder", fg_color="gray85", text_color="black", hover_color="gray80", font=CTkFont(size=20, weight="bold"))
self.apptrack.grid(row=1, column=1, padx=(20, 20), pady=(30, 0), sticky="nsew")
def show_page(self, page):
# Hide the current page
if self.current_page:
self.current_page.grid_forget()
# Show the selected page
page.grid(row=0, column=1, rowspan=3, sticky="nsew")
self.current_page = page
if __name__ == "__main__":
app = App()
app.mainloop()