-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanner.py
220 lines (176 loc) · 8.84 KB
/
planner.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
import customtkinter as tk
import subprocess
import customtkinter
import math
import os
from PIL import Image
import json
import sys
from plyer import notification
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
user_color = sys.argv[2]
user_theme = sys.argv[3]
new_theme_mode = sys.argv[4]
if user_theme != new_theme_mode:
user_theme = new_theme_mode
def change_appearance_mode_event(self, new_appearance_mode: str):
customtkinter.set_appearance_mode(new_appearance_mode)
def change_scaling_event(self, new_scaling: str):
new_scaling_float = int(new_scaling.replace("%", "")) / 100
customtkinter.set_widget_scaling(new_scaling_float)
def center_window(w):
w.update_idletasks()
width = w.winfo_width()
height = w.winfo_height()
x_offset = math.floor((w.winfo_screenwidth() - width) / 2)
y_offset = math.floor((w.winfo_screenheight() - height) / 2)
w.geometry(f"+{x_offset}+{y_offset}")
def open_Calc():
subprocess.run(["python", "Calculator.py", signed_in_user, user_color, user_theme, new_theme_mode])
def open_Marks():
subprocess.run(["python", "Marks.py", signed_in_user, user_color, user_theme, new_theme_mode])
def open_Chart():
subprocess.run(["python", "Chart.py", signed_in_user, user_color, user_theme, new_theme_mode])
def open_Help():
subprocess.run(['python', 'helpDesk.py', signed_in_user, user_color, user_theme, new_theme_mode])
def open_Time():
subprocess.run(['python', 'planner.py', signed_in_user, user_color, user_theme, new_theme_mode])
def open_Timer():
subprocess.run(['python', 'timer.py', signed_in_user, user_color, user_theme, new_theme_mode])
def open_Notes():
subprocess.run(["python", "notes.py", signed_in_user, user_color, user_theme, new_theme_mode])
def open_bard():
subprocess.run(["python", "quill.py", signed_in_user, user_color, user_theme, new_theme_mode])
def open_web():
subprocess.run(["python", "browser.py", signed_in_user, user_color, user_theme, new_theme_mode])
signed_in_user = sys.argv[1]
user_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "users")
directory_path = f"{user_path}/{signed_in_user}"
if os.path.isdir(directory_path):
print("Exists")
else:
os.makedirs(directory_path, exist_ok=True)
def save_timetable():
timetable_data = []
for i in range(1, num_rows):
row_data = [entry.get() for entry in timetable_entries[i]]
timetable_data.append(row_data)
dialog = customtkinter.CTkInputDialog(text="Enter file name:", title="Save as")
dialog_result = dialog.get_input() # Capture the input immediately
if dialog_result is None or dialog_result.strip() == "":
notification.notify(
app_icon="icon.ico",
title="Invalid File Name",
message="Please check the file name",
timeout=5
)
return # Exit the function if input is invalid
# Save the timetable data as JSON
with open(f"{directory_path}/{dialog_result}.json", "w") as file:
json.dump(timetable_data, file)
def open_timetable():
dialog = customtkinter.CTkInputDialog(text="Enter file name:", title="Open File")
dialog_result = dialog.get_input() # Capture the input immediately
if dialog_result is None or dialog_result.strip() == "":
notification.notify(
app_icon="icon.ico",
title="Invalid File Name",
message="Please check the file name",
timeout=5
)
return # Exit the function if input is invalid
# Read the timetable data from the JSON file
try:
with open(f"{directory_path}/{dialog_result}.json", "r") as file:
timetable_data = json.load(file)
except FileNotFoundError:
notification.notify(
app_icon="icon.ico",
title="File Not Found",
message="The specified file does not exist",
timeout=5
)
return # Exit the function if file is not found
# Update the timetable entries with the loaded data
for i in range(1, num_rows):
for j in range(num_columns):
entry = timetable_entries[i][j]
entry.delete(0, "end")
entry.insert(0, timetable_data[i-1][j])
customtkinter.set_appearance_mode(user_theme)
customtkinter.set_default_color_theme(user_color)
self = customtkinter.CTk()
self.geometry(f"{750}x{580}")
self.title(f'Study Buddy • {signed_in_user}')
self.iconbitmap('icon.ico')
self.resizable(False, False)
self.grid_columnconfigure(1, weight=1)
self.grid_columnconfigure((2,3), weight=0)
self.grid_rowconfigure((0, 1, 2, 4), weight=1)
image_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "_images")
self.logo_image = customtkinter.CTkImage(Image.open(os.path.join(image_path, "logo.png")), size=(35, 35))
self.bard = customtkinter.CTkImage(Image.open(os.path.join(image_path, "bard.png")), size=(20,20))
self.web = customtkinter.CTkImage(Image.open(os.path.join(image_path, "webview.png")), size=(20,20))
self.notes = customtkinter.CTkImage(Image.open(os.path.join(image_path, "notes.png")), size=(20,20))
self.timer = customtkinter.CTkImage(Image.open(os.path.join(image_path, "timer.png")), size=(20,20))
self.planner = customtkinter.CTkImage(Image.open(os.path.join(image_path, "planner.png")), size=(20,20))
self.marks = customtkinter.CTkImage(Image.open(os.path.join(image_path, "marks.png")), size=(20,20))
self.plotter = customtkinter.CTkImage(Image.open(os.path.join(image_path, "plotter.png")), size=(20,20))
self.calc = customtkinter.CTkImage(Image.open(os.path.join(image_path, "calc.png")), size=(20,20))
self.sidebar_frame = customtkinter.CTkFrame(self, width=140, corner_radius=0, height=700)
self.sidebar_frame.grid(row=0, column=0, rowspan=8, sticky="nsew")
self.sidebar_frame.grid_rowconfigure(6, weight=1)
self.navigation_frame_label = customtkinter.CTkLabel(self.sidebar_frame, text=" Study Buddy", image=self.logo_image,
compound="left", font=customtkinter.CTkFont(size=20, weight="bold"))
self.navigation_frame_label.grid(row=0, column=0, padx=20, pady=20)
# Set uniform padding between buttons
self.sidebar_frame.grid_rowconfigure((6), weight=0)
self.sidebar_frame.grid_rowconfigure((1,2,3,4,5,7,10), weight=0)
self.appearance_mode_label = customtkinter.CTkLabel(self.sidebar_frame, text="Appearance Mode:", anchor="w")
self.appearance_mode_label.grid(row=8, column=0, padx=20, pady=(10, 0))
self.appearance_mode_optionmenu = customtkinter.CTkOptionMenu(self.sidebar_frame, values=["System", "Light", "Dark"],
command=lambda mode: change_appearance_mode_event(self, mode))
self.appearance_mode_optionmenu.grid(row=9, column=0, padx=20, pady=(10, 10))
self.scaling_optionmenu = customtkinter.CTkOptionMenu(self.sidebar_frame, values=["80%", "90%", "100%", "110%", "120%"],
command=lambda mode: change_scaling_event(self, mode))
self.scaling_optionmenu.grid(row=10, column=0, padx=20, pady=(10, 20))
self.table_frame = tk.CTkFrame(self)
self.table_frame.grid(row=0, column=1, rowspan=8, columnspan=3, padx=20, pady=20, sticky="nsew")
# Create a grid of entry widgets for the table
table_data = [
["Topic", "Day", "Time"],
["", "", ""],
["", "", ""],
["", "", ""],
["", "", ""],
["", "", ""],
["", "", ""],
["", "", ""],
["", "", ""],
["", "", ""],
["", "", ""],
]
num_rows = len(table_data)
num_columns = len(table_data[0])
timetable_entries = []
for i in range(num_rows):
row_entries = []
for j in range(num_columns):
entry = tk.CTkEntry(self.table_frame)
entry.insert(0, table_data[i][j])
entry.grid(row=i, column=j, padx=5, pady=5, sticky="nsew")
entry.grid_configure(ipadx=10, ipady=3)
# Disable the "Name", "Age", and "Gender" entries
if i == 0:
entry.configure(state="disabled")
# Set placeholder text for the entries
if i == 0:
entry.configure(placeholder_text=table_data[i][j], fg_color='#4d4d4e', text_color='white')
row_entries.append(entry)
timetable_entries.append(row_entries)
self.save_button = customtkinter.CTkButton(master=self, text='Save Timetable', border_width=1, command=save_timetable)
self.save_button.grid(row=9, column=1, padx=(20, 20), pady=(10, 10), sticky="nsew", columnspan='1')
self.open_button = customtkinter.CTkButton(master=self, text='Open Timetable', border_width=1, command=open_timetable)
self.open_button.grid(row=9, column=2, padx=(20, 20), pady=(10, 10), sticky="nsew")
self.mainloop()