-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui_interface.py
483 lines (365 loc) · 22.1 KB
/
gui_interface.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
import tkinter as tk
from tkinter import Button, Label, Entry, Tk, Text, Scrollbar, IntVar, Radiobutton, StringVar, OptionMenu
from tktimepicker import SpinTimePickerOld, constants
from db_queries import add_employee, remove_employee, list_employees, add_working_hours, list_working_hours, \
remove_working_hours, add_week_schedule, remove_week_schedule, list_week_schedule, get_employees, get_work_hours, \
list_week_schedule_name, check_week_schedule, update_week_schedule, add_month, list_employee_names, list_week_names
from xls_table_create_and_modify import create_table, wb
def refresh_data(text, func):
text.delete('1.0', 'end')
text.insert('1.0', str(func))
class App:
def __init__(self, master):
self.master = master
self.master.geometry("1200x900")
self.master.resizable(True, True)
self.master.title("My GUI")
self.main_page()
drop_down_vars_weeks = {}
option_menu_weeks = {}
week_labels = {}
def delete_labels_and_option_menus_weeks(self):
self.drop_down_vars_weeks = {}
for key in self.option_menu_weeks:
self.option_menu_weeks[key].destroy()
for key in self.week_labels:
self.week_labels[key].destroy()
def winfo_children_destroy(self):
for i in self.master.winfo_children():
i.destroy()
def create_labels(self, row, col):
grid_row = row
grid_col = col
all_employees = get_employees()
employees_labels = {}
for i in range(len(all_employees)):
employees_labels[i] = Label(self.master, text=all_employees[i].name, font=('Arial', 18))
employees_labels[i].grid(row=grid_row, column=grid_col, sticky="E", padx=15, pady=15)
grid_row += 1
return employees_labels.values()
def create_option_menu(self, row, col):
grid_row = row
grid_col = col
all_employees = get_employees()
drop_down_vars = {}
option_menu = {}
options = get_work_hours()
for i in range(len(all_employees)):
drop_down_vars[i] = StringVar(self.master)
drop_down_vars[i].set('Избери')
option_menu[i] = OptionMenu(self.master, drop_down_vars[i], *options)
option_menu[i].config(font=('Arial', 18))
option_menu[i].grid(row=grid_row, column=grid_col, sticky="WE")
grid_row += 1
return drop_down_vars.values()
def create_labels_and_option_menu_weeks(self, row, col, month):
if month == None:
return
self.delete_labels_and_option_menus_weeks()
grid_row = row
grid_col = col
options = list_week_schedule_name()
week_number = 1
for i in range(len(month)):
if month[i][1] == "Понеделник" or month[i][0] == 1:
self.drop_down_vars_weeks[week_number] = StringVar(self.master)
self.drop_down_vars_weeks[week_number].set('Избери')
self.option_menu_weeks[week_number] = OptionMenu(self.master, self.drop_down_vars_weeks[week_number], *options)
self.option_menu_weeks[week_number].config(font=('Arial', 18))
self.option_menu_weeks[week_number].grid(row=grid_row, column=grid_col + 1, sticky="WE")
self.week_labels[week_number] = Label(self.master, text=f'week {week_number}', font=('Arial', 18))
self.week_labels[week_number].grid(row=grid_row, column=grid_col, sticky="E", padx=15, pady=30)
week_number += 1
grid_row += 1
return self.drop_down_vars_weeks.values()
@staticmethod
def refresh_options(var, option, choices):
var.set('')
option['menu'].delete(0, 'end')
for choice in choices:
option['menu'].add_command(label=choice, command=tk._setit(var, choice))
def main_page(self):
self.winfo_children_destroy()
self.master.columnconfigure(0, weight=1)
self.master.columnconfigure(1, weight=3)
self.master.columnconfigure(2, weight=3)
self.master.columnconfigure(3, weight=3)
add_employee_btn = Button(self.master, text="Добави/Премахни Работник", font=('Arial', 18), command=self.add_remove_employee)
add_employee_btn.grid(row=0, column=3, sticky="EW", padx=15, pady=30, columnspan=2)
add_btn = Button(self.master, text="Добави/Премахни работни часове", font=('Arial', 18), command=self.add_remove_workhours)
add_btn.grid(row=1, column=3, sticky="EW", padx=15, columnspan=2)
add_week_schedule_btn = Button(self.master, text="Добави/Премахни седмичен график", font=('Arial', 18), command=self.add_remove_week_schedule)
add_week_schedule_btn.grid(row=2, column=3, sticky="EW", padx=15, pady=30, columnspan=2)
check_week_schedule_btn = Button(self.master, text="Прегледай/Промени седмичен график", font=('Arial', 18), command=self.check_edit_week_schedule)
check_week_schedule_btn.grid(row=3, column=3, sticky="EW", padx=15, columnspan=2)
check_week_schedule_btn = Button(self.master, text="Създай месечен график", font=('Arial', 18),
command=self.create_month_schedule)
check_week_schedule_btn.grid(row=4, column=3, sticky="EW", padx=15, pady= 30, columnspan=2)
def add_remove_employee(self):
self.winfo_children_destroy()
all_employees = ['Избери']
all_employees += list_employee_names()
add_employee_label = Label(self.master, text='Добави нов работник', font=('Arial', 18))
add_employee_label.grid(row=0, column=0, sticky="E", padx=15, pady=30)
add_employee_entry = Entry(self.master, font=('Arial', 18))
add_employee_entry.grid(row=0, column=1, sticky="WE", padx=15, pady=30)
add_btn = Button(self.master, text='Добави',font=('Arial', 18), command= lambda :(
add_employee(add_employee_entry.get()),
all_employees.append(add_employee_entry.get()),
add_employee_entry.delete(0, 'end'),
refresh_data(employee_list_text, list_employees()),
self.refresh_options(drop_down_employee_name, employee_name_option, all_employees),
drop_down_employee_name.set(all_employees[0]),
))
add_btn.grid(row=0, column=3, sticky="WE", padx=15, pady=30)
remove_employee_label = Label(self.master, text='Премахни работник', font=('Arial', 18))
remove_employee_label.grid(row=1, column=0, sticky="E", padx=15, pady=10)
drop_down_employee_name = StringVar(self.master)
drop_down_employee_name.set(all_employees[0])
employee_name_option = OptionMenu(self.master, drop_down_employee_name, *all_employees)
employee_name_option.config(font=('Arial', 18))
employee_name_option.grid(row=1, column=1, sticky="WE")
remove_btn = Button(self.master, text='Премахни', font=('Arial', 18), command=lambda: (
remove_employee(drop_down_employee_name.get()),
(all_employees.remove(drop_down_employee_name.get()) if drop_down_employee_name.get() != 'Избери' else None),
self.refresh_options(drop_down_employee_name, employee_name_option, all_employees),
drop_down_employee_name.set(all_employees[0]),
refresh_data(employee_list_text, list_employees()),
))
remove_btn.grid(row=1, column=3, sticky="WE", padx=15, pady=10)
employees_label = Label(self.master, text='Регистрирани работници', font=('Arial', 18), borderwidth=1, relief="solid")
employees_label.grid(row=2, column=0, padx=15, pady=30, sticky="EW", columnspan=2)
sc = Scrollbar(self.master, orient='vertical')
sc.grid(row=3, column=0, sticky='nse', columnspan=2, rowspan=2)
employee_list_text = Text(self.master, font=('Arial', 18), width=1, height=10, yscrollcommand=sc.set)
employee_list_text.insert('1.0', str(list_employees()))
sc.config(command=employee_list_text.yview)
employee_list_text.grid(row=3, column=0, padx=15, columnspan=2, rowspan=2, sticky="EWNS")
main_page_btn = Button(self.master, text="Назад", command=self.main_page, font=('Arial', 18))
main_page_btn.grid(row=4, column=3, sticky="EWS", padx=15)
def add_remove_workhours(self):
self.winfo_children_destroy()
start_hour_label = Label(self.master, text='Начален час', font=('Arial', 18))
start_hour_label.grid(row=0, column=0, sticky="E", padx=15, pady=30)
start_hour_entry = SpinTimePickerOld(self.master)
start_hour_entry.addAll(constants.HOURS24)
start_hour_entry.grid(row=0, column=1, sticky="W", pady=30, columnspan=2)
end_hour_label = Label(self.master, text='Краен час', font=('Arial', 18))
end_hour_label.grid(row=1, column=0, sticky="E", padx=15)
end_hour_entry = SpinTimePickerOld(self.master)
end_hour_entry.addAll(constants.HOURS24)
end_hour_entry.grid(row=1, column=1, sticky="W", columnspan=2)
radiobutton_var = IntVar(master=self.master, value=0)
is_working_radiobutton = Radiobutton(self.master, text='Работи', variable=radiobutton_var, value=0, font=('Arial', 18), )
is_working_radiobutton.grid(row=2, column=0, sticky="W", padx=15)
is_on_vacation_radiobtn = Radiobutton(self.master, text='Отпуск', variable=radiobutton_var, value=1, font=('Arial', 18), )
is_on_vacation_radiobtn.grid(row=2, column=1, sticky="W", pady=30,)
is_sick_radiobtn = Radiobutton(self.master, text='Болничен', variable=radiobutton_var, value=2, font=('Arial', 18))
is_sick_radiobtn.grid(row=2, column=2, sticky="W",)
# is_resting_radiobtn = Radiobutton(self.master, text='Почивка', variable=radiobutton_var, value=3, font=('Arial', 18))
# is_resting_radiobtn.grid(row=2, column=3, sticky="W", )
add_btn = Button(self.master, text='Добави', font=('Arial', 18), command=lambda: (
add_working_hours(start_hour_entry.time(), end_hour_entry.time(), radiobutton_var.get()),
refresh_data(work_hours_list_text, list_working_hours()),
))
add_btn.grid(row=0, column=3, sticky="WE", padx=15, pady=30)
remove_btn = Button(self.master, text='Премахни', font=('Arial', 18), command=lambda: (
remove_working_hours(start_hour_entry.time(), end_hour_entry.time(), radiobutton_var.get()),
refresh_data(work_hours_list_text, list_working_hours()),
))
remove_btn.grid(row=1, column=3, sticky="WE", padx=15)
sc = Scrollbar(self.master, orient='vertical')
sc.grid(row=3, column=0, sticky='nse', columnspan=3, rowspan=2)
work_hours_list_text = Text(self.master, font=('Arial', 18), width=1, height=10, yscrollcommand=sc.set)
work_hours_list_text.insert('1.0', str(list_working_hours()))
sc.config(command=work_hours_list_text.yview)
work_hours_list_text.grid(row=3, column=0, padx=15, columnspan=3, rowspan=2, sticky="EWNS")
main_page_btn = Button(self.master, text="Назад", command=self.main_page, font=('Arial', 18))
main_page_btn.grid(row=4, column=3, sticky="EWS", padx=15)
def add_remove_week_schedule(self):
WEEK_DAYS = [
'Понеделник',
'Вторник',
'Сряда',
'Четвъртък',
'Петък',
'Събота',
'Неделя',
]
week_names = ['Избери']
week_names += list_week_names()
self.winfo_children_destroy()
add_remove_week_schedule_label = Label(self.master, text='Добави\nседмичен график', font=('Arial', 18))
add_remove_week_schedule_label.grid(row=0, column=0, sticky="E", padx=15, pady=30)
add_week_schedule_entry = Entry(self.master, font=('Arial', 18))
add_week_schedule_entry.grid(row=0, column=1, sticky="WE", pady=30)
add_btn = Button(self.master, text='Добави', font=('Arial', 18), command=lambda: (
add_week_schedule(add_week_schedule_entry),
(week_names.append(add_week_schedule_entry.get()) if add_week_schedule_entry.get() != '' else None),
self.refresh_options(drop_down_schedule_name, schedule_name_option, week_names),
drop_down_schedule_name.set(week_names[0]),
add_week_schedule_entry.delete(0, 'end'),
refresh_data(week_schedule_list_text, str('\n'.join(list_week_names())))
))
add_btn.grid(row=0, column=3, sticky="WE", padx=15, pady=30)
drop_down_schedule_name = StringVar(self.master)
drop_down_schedule_name.set(week_names[0])
schedule_name_label = Label(self.master, text='Премахни\nседмичен график', font=('Arial', 18))
schedule_name_label.grid(row=1, column=0, sticky="E", padx=15)
schedule_name_option = OptionMenu(self.master, drop_down_schedule_name, *week_names)
schedule_name_option.config(font=('Arial', 18))
schedule_name_option.grid(row=1, column=1, sticky="WE")
remove_btn = Button(self.master, text='Премахни', font=('Arial', 18), command=lambda: (
(remove_week_schedule(drop_down_schedule_name.get()) if drop_down_schedule_name.get() != 'Избери' else None),
(week_names.remove(drop_down_schedule_name.get()) if drop_down_schedule_name.get() != 'Избери' else None),
self.refresh_options(drop_down_schedule_name, schedule_name_option, week_names),
drop_down_schedule_name.set(week_names[0]),
refresh_data(week_schedule_list_text, str('\n'.join(list_week_names())))
))
remove_btn.grid(row=1, column=3, sticky="WE", padx=15, pady=10)
# choose_week_day_label = Label(self.master, text='Избери работен ден',
# font=('Arial', 18))
# choose_week_day_label.grid(row=2, column=0, sticky="E", padx=15, pady=15)
#
# drop_down_var = StringVar(self.master)
# drop_down_var.set('Избери') # default value
#
# week_days_option = OptionMenu(self.master, drop_down_var, *WEEK_DAYS)
# week_days_option.config(font=('Arial', 18))
# week_days_option.grid(row=2, column=1, sticky="WE")
#
# employees = self.create_labels(4, 0)
#
# option_menus = self.create_option_menu(4, 1)
#
sc = Scrollbar(self.master, orient='vertical')
sc.grid(row=3, column=1, sticky='nse', pady=15, columnspan=2, rowspan=2)
week_schedule_list_text = Text(self.master, font=('Arial', 18), width=1, height=21, yscrollcommand=sc.set)
week_schedule_list_text.insert('1.0', str('\n'.join(list_week_names())))
sc.config(command=week_schedule_list_text.yview)
week_schedule_list_text.grid(row=3, column=1, pady=15, columnspan=2, rowspan=2, sticky="EWNS")
#
# refresh_btn = Button(self.master, text='Опресни',
# command=lambda: refresh_data(week_schedule_list_text, list_week_schedule(add_remove_week_schedule_entry.get())),
# font=('Arial', 18))
# refresh_btn.grid(row=1, column=3, padx=15, sticky="WE", columnspan=2)
main_page_btn = Button(self.master, text="Назад", command=self.main_page, font=('Arial', 18))
main_page_btn.grid(row=12, column=3, sticky="EWS", padx=15)
def check_edit_week_schedule(self):
WEEK_DAYS = [
'Понеделник',
'Вторник',
'Сряда',
'Четвъртък',
'Петък',
'Събота',
'Неделя',
]
self.winfo_children_destroy()
week_names = list_week_schedule_name()
if week_names:
employees = [employee.name for employee in get_employees()]
# working_hours = get_work_hours()
drop_down_schedule_name = StringVar(self.master)
drop_down_schedule_name.set('Избери')
schedule_name_label = Label(self.master, text='Избери седмичен график', font=('Arial', 18))
schedule_name_label.grid(row=0, column=0, sticky="E", padx=15, pady=15)
schedule_name_option = OptionMenu(self.master, drop_down_schedule_name, *week_names)
schedule_name_option.config(font=('Arial', 18))
schedule_name_option.grid(row=0, column=1, sticky="WE")
drop_down_days = StringVar(self.master)
drop_down_days.set('Избери')
days_label = Label(self.master, text='Избери ден', font=('Arial', 18))
days_label.grid(row=1, column=0, sticky="E", padx=15)
days_option = OptionMenu(self.master, drop_down_days, *WEEK_DAYS)
days_option.config(font=('Arial', 18))
days_option.grid(row=1, column=1, sticky="WE", pady=15)
employees = self.create_labels(3, 0)
option_menus = self.create_option_menu(3, 1)
check_label = Button(self.master, text='Провери', font=('Arial', 18), command=lambda: (
refresh_data(week_schedule_list_text, str(check_week_schedule(drop_down_schedule_name.get(), drop_down_days.get())))
))
check_label.grid(row=0, column=3, sticky="EW", padx=15, columnspan=2)
update_label = Button(self.master, text='Промени', font=('Arial', 18), command=lambda: (update_week_schedule(drop_down_schedule_name.get(), drop_down_days.get(), employees, option_menus)))
update_label.grid(row=3, column=3, sticky="EW", padx=15, columnspan=2)
sc = Scrollbar(self.master, orient='vertical')
sc.grid(row=4, column=3, sticky='nse', pady=30, columnspan=2, rowspan=10)
week_schedule_list_text = Text(self.master, font=('Arial', 18), width=1, height=16, yscrollcommand=sc.set)
week_schedule_list_text.insert('1.0', str(check_week_schedule(drop_down_schedule_name.get(), drop_down_days.get()) or ''))
sc.config(command=week_schedule_list_text.yview)
week_schedule_list_text.grid(row=4, column=3, padx=15, pady=30, columnspan=2, rowspan=10, sticky="EWNS")
else:
schedule_name_label = Label(self.master, text='Нямате създадени седмични графици', font=('Arial', 18))
schedule_name_label.grid(row=0, column=0, sticky="E", padx=15, pady=15)
main_page_btn = Button(self.master, text="Назад", command=self.main_page, font=('Arial', 18))
main_page_btn.grid(row=16, column=3, sticky="EWS", padx=15, columnspan=2)
def create_month_schedule(self):
self.winfo_children_destroy()
months = [
'Януари',
'Февруари',
'Март',
"Април",
'Май',
'Юни',
'Юли',
'Август',
'Септември',
'Октомври',
'Ноември',
'Декември',
]
years = [
2024,
2025,
2026,
2027,
2028,
2029,
2030,
2031,
2032,
2033,
2034,
2035,
2036,
2037,
]
week_names = list_week_schedule_name()
if week_names:
drop_down_months = StringVar(self.master)
drop_down_months.set('Избери')
months_label = Label(self.master, text='Избери месец', font=('Arial', 18))
months_label.grid(row=0, column=0, sticky="E", padx=15, pady=30)
months_option = OptionMenu(self.master, drop_down_months, *months)
months_option.config(font=('Arial', 18))
months_option.grid(row=0, column=1, sticky="WE")
drop_down_years = StringVar(self.master)
drop_down_years.set('Избери')
year_label = Label(self.master, text='Избери година', font=('Arial', 18))
year_label.grid(row=1, column=0, sticky="E", padx=15, pady=30)
years_option = OptionMenu(self.master, drop_down_years, *years)
years_option.config(font=('Arial', 18))
years_option.grid(row=1, column=1, sticky="WE")
work_days_label = Label(self.master, text='Брой работни дни', font=('Arial', 18))
work_days_label.grid(row=2, column=0, sticky="E", padx=15, pady=30)
work_days_entry = Entry(self.master, font=('Arial', 18))
work_days_entry.grid(row=2, column=1, sticky="WE")
add_label = Button(self.master, text='Добави месец', font=('Arial', 18), command=lambda: (
self.create_labels_and_option_menu_weeks(3, 0, add_month(drop_down_months.get(), drop_down_years.get()))
))
add_label.grid(row=0, column=4, sticky="EW", padx=15, columnspan=2)
generate_xls = Button(self.master, text='Генерирай график', font=('Arial', 18), command=lambda: (
create_table(drop_down_years.get(), drop_down_months.get(), work_days_entry.get(), self.option_menu_weeks),
wb.save(f"{drop_down_months.get()}_{drop_down_years.get()}.xlsx")
))
generate_xls.grid(row=1, column=4, sticky="EW", padx=15, columnspan=2)
else:
months_label = Label(self.master, text='Създайте седмичен график и добавете работници за да използвате тази функционалност!', font=('Arial', 18))
months_label.grid(row=0, column=0, sticky="E", padx=15, pady=30)
main_page_btn = Button(self.master, text="Назад", command=self.main_page, font=('Arial', 18))
main_page_btn.grid(row=12, column=4, sticky="EW", padx=15, columnspan=2)
# if __name__ == "__main__":
# root = Tk()
# App(root)
# root.mainloop()