-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREST.py
More file actions
111 lines (93 loc) · 3.86 KB
/
REST.py
File metadata and controls
111 lines (93 loc) · 3.86 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
import sched
import time
import tkinter as tk
# Define the time intervals
WORK_TIME = 30 * 60 # 30 minutes in seconds
REST_TIME = 10 * 60 # 10 minutes in seconds
START_HOUR = 8 # Start time hour (24-hour format)
END_HOUR = 22 # End time hour (24-hour format)
EXTENSION_TIME = 60 * 60 # 1 hour in seconds
# Create the scheduler
scheduler = sched.scheduler(time.monotonic, time.sleep)
def remind_to_rest(is_resting):
global WORK_TIME, REST_TIME
if is_resting:
title = "Rest Reminder"
message = f"It's time to take a break! Rest for {REST_TIME // 60} minutes."
duration = REST_TIME
else:
title = "Work Reminder"
message = "Break time is over! Time to get back to work."
duration = WORK_TIME
# Create the GUI window
window = tk.Tk()
window.title(title)
window.geometry("900x320")
window.configure(bg="black") # Set window background color to black
window.resizable(width=False, height=False) #set the window resizable property to False
# Define the GUI elements
label = tk.Label(window, text=message, font=("Arial", 32), bg="black", fg="gray")
label.pack(pady=20)
# Add a label to show remaining time
time_label = tk.Label(window, text=f"Remaining time: {duration // 60:02d}:{duration % 60:02d}", font=("Arial", 23),
bg="black", fg="gray")
time_label.pack()
# Add a button to extend the timer by 1 hour
def extend_timer():
nonlocal duration
duration += EXTENSION_TIME # Extend the timer
extend_button = tk.Button(window, text=f"Extend for {EXTENSION_TIME // 60} minutes", command=extend_timer,
font=("Arial", 23), bg="black", fg="gray")
extend_button.pack(side=tk.LEFT, padx=30)
# Add a button to Reset reminders
def reset_reminders():
for event in scheduler.queue:
scheduler.cancel(event)
window.destroy()
schedule_reminders()
scheduler.run()
reset_button = tk.Button(window, text="Reset Reminders", command=reset_reminders,
font=("Arial", 23), bg="black", fg="gray")
reset_button.pack(side=tk.LEFT, padx=20)
# Add a button to Reset reminders
def force_rest():
for event in scheduler.queue:
scheduler.cancel(event)
window.destroy()
scheduler.enter(3, 1, remind_to_rest, (True,))
scheduler.enter(REST_TIME + 1, 1, schedule_reminders)
rest_button = tk.Button(window, text="Force rest", command=force_rest,
font=("Arial", 23), bg="black", fg="gray")
rest_button.pack(side=tk.LEFT, padx=9)
# Display the window
window.attributes("-topmost", True)
window.grab_set()
window.focus_force()
# Define the function to update the timer label
def update_time_label():
nonlocal duration, time_label, window
remaining_time = max(0, duration - int(time.monotonic() - start_time))
time_label.config(
text=f"Remaining time: {remaining_time // 60:02d}:{remaining_time % 60:02d}", font=("Arial", 23),
bg="black", fg="gray")
if remaining_time > 0:
window.after(1000, update_time_label)
# Check if the window is still valid
#TODO if window.winfo_exists():
else:
window.destroy()
# Start the countdown timer
start_time = time.monotonic()
update_time_label()
# Start the mainloop to update the GUI
window.mainloop()
def schedule_reminders():
current_hour = time.localtime().tm_hour
if START_HOUR <= current_hour < END_HOUR:
scheduler.enter(3, 1, remind_to_rest, (False,))
scheduler.enter(3, 1, remind_to_rest, (True,))
scheduler.enter(WORK_TIME + REST_TIME + 1, 1, schedule_reminders)
# Schedule the first reminder
schedule_reminders()
# Start the scheduler
scheduler.run()