forked from probablyArth/meet-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
312 lines (259 loc) · 9.66 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
from CONSTANTS import *
from tkinter import Frame, Listbox
from tkinter.ttk import Button, Entry, Label
from tkinter import messagebox
from ttkthemes import ThemedTk
from models.Schedule import Schedule
from models.User import User
user_orm = User()
schedule_orm = Schedule()
signed_in_user = None
root = ThemedTk(theme="Breeze")
root.geometry(f"{SCREEN_WIDTH}x{SCREEN_HEIGHT}")
root.title("Meet Scheduler")
home_screen = Frame(root)
signup_screen = Frame(root)
login_screen = Frame(root)
dashboard_screen = Frame(root)
home_screen.grid(sticky="NESW")
screens_array = [home_screen, signup_screen, login_screen, dashboard_screen]
def setScreen(screen: Frame):
for sc in screens_array:
sc.grid_forget()
screen.grid(column=1)
goto_home_button = Button(root, text="Home", command=lambda: setScreen(home_screen))
goto_home_button.grid(column=1, row=1)
goto_signup_button = Button(
root, text="Sign Up", command=lambda: setScreen(signup_screen)
)
goto_signup_button.grid(column=1, row=2)
goto_login_button = Button(root, text="Login", command=lambda: setScreen(login_screen))
goto_login_button.grid(column=1, row=3)
# HOME SCREEN
Label(home_screen, text="Welcome to Meet Scheduler", font=("bold", 22)).grid(row=0)
def removeButtons():
goto_home_button.grid_forget()
goto_signup_button.grid_forget()
goto_login_button.grid_forget()
def signUp(username: str, password: str):
global signed_in_user
try:
res = user_orm.getByCondition(f'name = "{username}"')
if len(res) != 0:
messagebox.showerror(
title="Already Exists",
message=f"User with name {username} already exists!",
)
return
user_id = user_orm.insert(username, password)
schedule_orm.insert(
user_id,
"09:00-14:00",
"09:00-14:00",
"09:00-14:00",
"09:00-14:00",
"09:00-14:00",
"09:00-14:00",
"09:00-14:00",
)
messagebox.showinfo(title="Success", message="User created successfully!")
setScreen(dashboard_screen)
removeButtons()
signed_in_user = user_id
updateSchedule()
populate_listbox()
except Exception as e:
print(e)
messagebox.showerror(
title="Error", message="An error occured while signing up :("
)
def logIn(username: str, password: str):
global signed_in_user
try:
res = user_orm.getByCondition(f'name = "{username}"')
if len(res) == 0:
messagebox.showerror(
title="404!", message=f"User with name {username} doesn't exist!"
)
return
if password != res[0][2]:
messagebox.showerror(title="Forbidden", message=f"Incorrect Password!")
return
messagebox.showinfo(title="Success", message="User logged in successfully!")
setScreen(dashboard_screen)
signed_in_user = res[0][0]
updateSchedule()
removeButtons()
populate_listbox()
except Exception as e:
print(e)
messagebox.showerror(
title="Error", message="An error occured while logging in :("
)
# SIGNUP SCREEN
Label(signup_screen, text="Name").grid(row=0, column=0)
Label(signup_screen, text="Password").grid(row=1, column=0)
signup_username = Entry(signup_screen)
signup_username.grid(row=0, column=1)
signup_password = Entry(signup_screen)
signup_password.grid(row=1, column=1)
signup_button = Button(
signup_screen,
text="Sign Up",
command=lambda: signUp(signup_username.get(), signup_password.get()),
).grid(row=2, column=0)
# LOGIN SCREEN
Label(login_screen, text="Name").grid(row=0, column=0)
Label(login_screen, text="Password").grid(row=1, column=0)
login_username = Entry(login_screen)
login_username.grid(row=0, column=1)
login_password = Entry(login_screen)
login_password.grid(row=1, column=1)
Button(
login_screen,
text="Login",
command=lambda: logIn(login_username.get(), login_password.get()),
).grid(row=2, column=0)
# DASHBOARD SCREEN
Label(dashboard_screen, text="DASHBOARD").grid(row=0, column=0)
dashboard_home_frame = Frame(dashboard_screen)
update_schedule_frame = Frame(dashboard_screen)
book_schedule_frame = Frame(dashboard_screen)
dashboard_frames_array = [
dashboard_home_frame,
update_schedule_frame,
book_schedule_frame,
]
dashboard_home_frame.grid(column=1)
def setDashboardFrame(screen: Frame):
for sc in dashboard_frames_array:
sc.grid_forget()
screen.grid(column=1)
def updateSchedule():
data = schedule_orm.getByCondition(f"userId = {signed_in_user}")[0]
monday_label.config(text=data[1])
tuesday_label.config(text=data[2])
wednesday_label.config(text=data[3])
thursday_label.config(text=data[4])
friday_label.config(text=data[5])
saturday_label.config(text=data[6])
sunday_label.config(text=data[7])
monday_label = Label(update_schedule_frame, text="")
monday_label.grid(row=1, column=3)
tuesday_label = Label(update_schedule_frame, text="")
tuesday_label.grid(row=2, column=3)
wednesday_label = Label(update_schedule_frame, text="")
wednesday_label.grid(row=3, column=3)
thursday_label = Label(update_schedule_frame, text="")
thursday_label.grid(row=4, column=3)
friday_label = Label(update_schedule_frame, text="")
friday_label.grid(row=5, column=3)
saturday_label = Label(update_schedule_frame, text="")
saturday_label.grid(row=6, column=3)
sunday_label = Label(update_schedule_frame, text="")
sunday_label.grid(row=7, column=3)
# Dashboard Home Screen
Button(
dashboard_home_frame,
text="Update Schedule",
command=lambda: setDashboardFrame(update_schedule_frame),
).grid()
Button(
dashboard_home_frame,
text="Book a Schedule",
command=lambda: setDashboardFrame(book_schedule_frame),
).grid()
# Update schedule FRAME
Label(update_schedule_frame, text="Update your schedule").grid(row=0, column=1)
Label(update_schedule_frame, text="Monday").grid(row=1, column=0)
Label(update_schedule_frame, text="Tuesday").grid(row=2, column=0)
Label(update_schedule_frame, text="Wednesday").grid(row=3, column=0)
Label(update_schedule_frame, text="Thursday").grid(row=4, column=0)
Label(update_schedule_frame, text="Friday").grid(row=5, column=0)
Label(update_schedule_frame, text="Saturday").grid(row=6, column=0)
Label(update_schedule_frame, text="Sunday").grid(row=7, column=0)
in_monday = Entry(update_schedule_frame)
in_monday.grid(row=1, column=1)
in_tuesday = Entry(update_schedule_frame)
in_tuesday.grid(row=2, column=1)
in_wednesday = Entry(update_schedule_frame)
in_wednesday.grid(row=3, column=1)
in_thursday = Entry(update_schedule_frame)
in_thursday.grid(row=4, column=1)
in_friday = Entry(update_schedule_frame)
in_friday.grid(row=5, column=1)
in_saturday = Entry(update_schedule_frame)
in_saturday.grid(row=6, column=1)
in_sunday = Entry(update_schedule_frame)
in_sunday.grid(row=7, column=1)
def update_schedule():
schedule_orm.update(
in_monday.get(),
in_tuesday.get(),
in_wednesday.get(),
in_thursday.get(),
in_friday.get(),
in_saturday.get(),
in_sunday.get(),
)
messagebox.showinfo(title="Success", message="Schedule updated successfully!")
updateSchedule()
Button(update_schedule_frame, text="Update", command=update_schedule).grid()
Button(
update_schedule_frame,
text="Go Back",
command=lambda: setDashboardFrame(dashboard_home_frame),
).grid()
Button(
book_schedule_frame,
text="Go Back",
command=lambda: setDashboardFrame(dashboard_home_frame),
).grid()
list_box_idx = 1
def populate_listbox():
global list_box_idx
users = user_orm.getAll()
for record in users:
if record[0] != signed_in_user:
user_list_box.insert(list_box_idx, record[:2])
list_box_idx += 1
# BOOK SCHEDULE FRAME
def print_selected(event):
selected_index = user_list_box.curselection()
data = schedule_orm.getByCondition(
f"userId = {user_list_box.get(selected_index)[0]}"
)[0]
print(data)
monday_label_booking.config(text=data[1])
tuesday_label_booking.config(text=data[2])
wednesday_label_booking.config(text=data[3])
thursday_label_booking.config(text=data[4])
friday_label_booking.config(text=data[5])
saturday_label_booking.config(text=data[6])
sunday_label_booking.config(text=data[7])
Label(book_schedule_frame, text="Book a schedule").grid()
user_list_box = Listbox(book_schedule_frame)
user_list_box.bind("<<ListboxSelect>>", print_selected)
user_list_box.grid(column=0, rowspan=7)
Label(book_schedule_frame, text="Monday").grid(row=1, column=1)
Label(book_schedule_frame, text="Tuesday").grid(row=2, column=1)
Label(book_schedule_frame, text="Wednesday").grid(row=3, column=1)
Label(book_schedule_frame, text="Thursday").grid(row=4, column=1)
Label(book_schedule_frame, text="Friday").grid(row=5, column=1)
Label(book_schedule_frame, text="Saturday").grid(row=6, column=1)
Label(book_schedule_frame, text="Sunday").grid(row=7, column=1)
monday_label_booking = Label(book_schedule_frame, text="")
monday_label_booking.grid(row=1, column=3)
tuesday_label_booking = Label(book_schedule_frame, text="")
tuesday_label_booking.grid(row=2, column=3)
wednesday_label_booking = Label(book_schedule_frame, text="")
wednesday_label_booking.grid(row=3, column=3)
thursday_label_booking = Label(book_schedule_frame, text="")
thursday_label_booking.grid(row=4, column=3)
friday_label_booking = Label(book_schedule_frame, text="")
friday_label_booking.grid(row=5, column=3)
saturday_label_booking = Label(book_schedule_frame, text="")
saturday_label_booking.grid(row=6, column=3)
sunday_label_booking = Label(book_schedule_frame, text="")
sunday_label_booking.grid(row=7, column=3)
root.mainloop()