-
Notifications
You must be signed in to change notification settings - Fork 29
/
Attendance_app.py
835 lines (744 loc) · 27.6 KB
/
Attendance_app.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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
import os
import sys
import subprocess
from datetime import datetime
import tkinter as tk
from tkinter import messagebox, END
from tkinter import font as tkfont
from tkinter import StringVar
from calendar import monthrange
import cv2
import pyautogui
from openpyxl import Workbook, load_workbook
import excel
from capture import capture
from capture import detect_faces
from face_train import FaceTrain
from students_list import StudentsList
from main_file import MainFile
class_codes = ["Marauders"]
manager_id = "ADMIN"
manager_pass = "ubuntu"
current_class = "Marauders"
if current_class != "Marauders":
current_class_obj = MainFile(current_class)
FaceTrainObj = FaceTrain(current_class)
else:
current_class_obj = None
FaceTrainObj = None
# Dynamic variables
normal_width = 1920
normal_height = 1080
x, y = pyautogui.size()
percentage_width = x / (normal_width / 100)
percentage_height = y / (normal_height / 100)
scale_factor = ((percentage_width + percentage_height) / 2) / 100
title_fontsize = int(30 * scale_factor)
minimum_size = 24
title_fontsize = max(title_fontsize, minimum_size)
text_fontsize = int(18 * scale_factor)
minimum_textsize = 13
text_fontsize = max(minimum_textsize, text_fontsize)
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.title_font = tkfont.Font(
family="Helvetica", size=18, weight="bold", slant="italic"
)
geo = str(int(0.43 * x)) + "x" + str(int(0.52 * y))
self.geometry(geo)
self.resizable(False, False)
self.title("Attendance Management App")
self.protocol("WM_DELETE_WINDOW", self.on_closing)
# The container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.createInitialDirectories()
self.frames = {}
for F in (
StartPage,
StudentPanelPage,
ManagerPanelPage,
CreateNewBatchPage,
AddStudentPage,
):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
# Put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def createInitialDirectories(self):
temp_dir = os.path.join(os.getcwd(), "images", ".temp")
temp_dir_exists = os.path.isdir(temp_dir)
extras_dir = os.path.join(os.getcwd(), "extras")
extras_dir_exists = os.path.isdir(extras_dir)
studs_list_dir = os.path.join(os.getcwd(), "student's list")
studs_list_dir_exists = os.path.isdir(studs_list_dir)
if not extras_dir_exists:
os.makedirs(extras_dir)
if not temp_dir_exists:
os.makedirs(temp_dir)
if not studs_list_dir_exists:
os.makedirs(studs_list_dir)
classes_file = os.path.join(os.getcwd(), "extras", "classes.xlsx")
try:
global class_codes, current_class
class_codes = set(["Marauders"])
wb = load_workbook(classes_file)
ws = wb.active
number_of_classes = ws["A1"].value
if number_of_classes != 0:
current_class = ws["A2"].value
for i in range(2, number_of_classes + 2):
class_codes.add(ws["A" + str(i)].value)
except:
wb = Workbook()
wb.guess_types = True
ws = wb.active
ws["A1"] = 0
wb.save(classes_file)
def show_frame(self, page_name):
# Show a frame for the given page name
frame = self.frames[page_name]
frame.tkraise()
def on_closing(self):
self.destroy()
self.quit()
def validate(self, page_name, c_code, id, pwd):
global class_codes
if id == manager_id and pwd == manager_pass and c_code in class_codes:
frame = self.frames[page_name]
global current_class
current_class = c_code
print("current class", current_class)
if current_class != "Marauders":
# frame.lb_class_code.config(text="Batch Code : {}".format(current_class))
# frame.lb_class_code['text']="Batch Code : {}".format(current_class)
StudentsList(current_class).make_pkl_file()
if page_name == "ManagerPanelPage":
global FaceTrainObj
FaceTrainObj = FaceTrain(current_class)
elif page_name == "StudentPanelPage":
global current_class_obj
current_class_obj = MainFile(current_class)
elif current_class == "Marauders" and page_name == "StudentPanelPage":
messagebox.showerror(
"Error", "Only Manager Panel is valid for this class-code"
)
return
else:
frame = self.frames["CreateNewBatchPage"]
frame.tkraise()
else:
messagebox.showerror("Error", "Incorrect Credentials !!")
class StartPage(tk.Frame):
global class_codes
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.bkg = "#222629"
self.text_color = "#65CCB8"
StartPage.config(self, bg=self.bkg)
entry_width = int(30 * scale_factor)
min_entrywidth = 25
entry_width = max(entry_width, min_entrywidth)
self.label = tk.Label(
self,
width=25,
text="Attendance Management",
bg=self.bkg,
fg="#F8E9A1",
font=("Times", title_fontsize),
)
self.label.place(x=130 * scale_factor, y=40 * scale_factor)
self.lb_class = tk.Label(
self,
text="CLASS-CODE: ",
bg=self.bkg,
fg=self.text_color,
font=("Courier", text_fontsize),
)
self.lb_class.place(x=170 * scale_factor, y=155 * scale_factor)
# Class Codes Autocompletion Stuff
self.filled = False
self.class_codes = class_codes
self.class_variable = StringVar(self)
self.class_variable.set("") # default value
self.tv_class = tk.Entry(
self, textvariable=self.class_variable, width=entry_width
)
self.tv_class.focus_set()
self.tv_class.bind("<KeyRelease>", self.get_typed)
self.tv_class.bind("<Key>", self.filled)
self.tv_class.icursor("end")
self.tv_class.place(x=340 * scale_factor, y=160 * scale_factor)
self.lb_username = tk.Label(
self,
text="USERNAME : ",
bg=self.bkg,
fg=self.text_color,
font=("Courier", text_fontsize),
)
self.lb_username.place(x=183 * scale_factor, y=210 * scale_factor)
self.tv_username = tk.Entry(self, width=entry_width)
self.tv_username.place(x=340 * scale_factor, y=215 * scale_factor)
self.lb_pass = tk.Label(
self,
text="PASSWORD : ",
bg=self.bkg,
fg=self.text_color,
font=("Courier", text_fontsize),
)
self.lb_pass.place(x=183 * scale_factor, y=265 * scale_factor)
self.tv_pass = tk.Entry(self, show="*", width=entry_width)
self.tv_pass.place(x=340 * scale_factor, y=270 * scale_factor)
self.showbtn = tk.Button(
self, text="SHOW", bg="#ed3833", command=self.show, width=2, font=("", 8)
) # 32ff6a
self.show = False
self.showbtn.place(
x=(340 * scale_factor) + (entry_width * 9), y=270 * scale_factor
)
bt_width = int(16 * scale_factor)
min_width = 12
bt_width = max(min_width, bt_width)
self.button1 = tk.Button(
self,
bg="#45056e",
fg=self.text_color,
text="Go to\nStudent Portal",
width=bt_width,
height=3,
font=("", 15),
command=lambda: self.doWork(
"StudentPanelPage",
self.tv_class.get(),
self.tv_username.get(),
self.tv_pass.get(),
),
)
self.button2 = tk.Button(
self,
bg="#5f1854",
fg=self.text_color,
text="Go to\nManager Portal",
width=bt_width,
height=3,
font=("", 15),
command=lambda: self.doWork(
"ManagerPanelPage",
self.tv_class.get(),
self.tv_username.get(),
self.tv_pass.get(),
),
)
self.button1.place(x=140 * scale_factor, y=340 * scale_factor)
self.button2.place(x=410 * scale_factor, y=340 * scale_factor)
self.bt_exit = tk.Button(
self, bg="red", fg="yellow", text="Exit", width=10, command=self.exit
)
self.bt_exit.place(x=340 * scale_factor, y=490 * scale_factor)
def show(self):
if self.show is False:
self.tv_pass.config(show="")
self.show = True
self.showbtn.config(bg="#32ff6a")
elif self.show is True:
self.tv_pass.config(show="*")
self.show = False
self.showbtn.config(bg="#ed3833")
def doWork(self, page_name, c_code, id, pwd):
self.tv_class.delete(0, END)
self.tv_username.delete(0, END)
self.tv_pass.delete(0, END)
self.controller.validate(page_name, c_code, id, pwd)
def exit(self):
self.controller.destroy()
self.controller.quit()
# Autocompletion Helper Functions
def match_string(self):
hits = []
class_var = self.class_variable.get()
for item in self.class_codes:
if item.startswith(class_var):
hits.append(item)
return hits
def get_typed(self, event):
if len(event.keysym) == 1:
hits = self.match_string()
self.show_hit(hits)
def show_hit(self, lst):
if len(lst) == 1:
self.class_variable.set(lst[0])
self.filled = True
def detect_pressed(self, event):
self.key = event.keysym
if len(self.key) == 1 and self.filled is True:
pos = self.tv_class.index(tk.INSERT)
self.tv_class.delete(pos, tk.END)
class StudentPanelPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.bkg = "#222629"
self.text_color = "#65CCB8"
StudentPanelPage.config(self, bg=self.bkg)
label = tk.Label(
self,
width=25,
text="Student Portal",
bg=self.bkg,
fg="#F8E9A1",
font=("Times", title_fontsize),
)
label.place(x=130 * scale_factor, y=40 * scale_factor)
bt_mark = tk.Button(
self,
bg="#45056e",
fg=self.text_color,
text="Mark my\n ATTENDANCE",
font=("", 18),
width=16,
height=7,
command=self.doWork,
)
bt_mark.place(x=215 * scale_factor, y=150 * scale_factor)
bt_back = tk.Button(
self,
bg="#af0404",
fg="yellow",
text="Back",
width=10,
command=lambda: controller.show_frame("StartPage"),
)
bt_back.place(x=115 * scale_factor, y=485 * scale_factor)
bt_exit = tk.Button(
self, bg="#af0404", fg="yellow", text="Exit", width=10, command=self.exit
)
bt_exit.place(x=520 * scale_factor, y=485 * scale_factor)
def doWork(self):
global current_class_obj
current_class_obj.capture_and_mark()
def exit(self):
self.controller.destroy()
self.controller.quit()
class ManagerPanelPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.bkg = "#222629"
self.text_color = "#65CCB8"
ManagerPanelPage.config(self, bg=self.bkg)
global current_class
label = tk.Label(
self,
width=25,
text="Manager Portal",
bg=self.bkg,
fg="#F8E9A1",
font=("Times", title_fontsize),
)
label.place(x=130 * scale_factor, y=40 * scale_factor)
bt_ht = int(5 * scale_factor)
min_ht = 3
bt_ht = max(min_ht, bt_ht)
bt_width = int(15 * scale_factor)
min_width = 12
bt_width = max(min_width, bt_width)
bt_train = tk.Button(
self,
text="Train the\n Recogniser",
bg="#45056e",
fg=self.text_color,
width=bt_width,
height=bt_ht,
font=("", 15),
command=self.doWork,
)
bt_train.place(x=130 * scale_factor, y=160 * scale_factor)
bt_addstud = tk.Button(
self,
text="Add a student\n to this class",
bg="#3b0944",
width=bt_width,
fg=self.text_color,
height=bt_ht,
font=("", 15),
command=self.addStudent,
)
bt_addstud.place(x=430 * scale_factor, y=160 * scale_factor)
bt_view_register = tk.Button(
self,
text="View\nAttendance\nRegister",
width=bt_width,
bg="#581845",
fg=self.text_color,
height=bt_ht,
font=("", 15),
command=self.viewRegister,
)
bt_view_register.place(x=265 * scale_factor, y=320 * scale_factor)
bt_back = tk.Button(
self,
bg="#af0404",
fg="yellow",
text="Back",
width=10,
command=lambda: controller.show_frame("StartPage"),
)
bt_back.place(x=115 * scale_factor, y=485 * scale_factor)
bt_exit = tk.Button(
self, bg="#af0404", fg="yellow", text="Exit", width=10, command=self.exit
)
bt_exit.place(x=520 * scale_factor, y=485 * scale_factor)
def viewRegister(self):
global current_class
atten_register = os.path.join(
os.getcwd(), "extras", current_class, f"{current_class}.xlsx"
)
try:
opener = "open" if sys.platform == "darwin" else "xdg-open"
subprocess.call([opener, atten_register])
except (subprocess.CalledProcessError, OSError):
os.startfile(atten_register)
def addStudent(self):
global current_class
students_list_file = os.path.join(
os.getcwd(), "student's list", f"{current_class}.xlsx"
)
self.controller.show_frame("AddStudentPage")
def doWork(self):
global FaceTrainObj, current_class
if current_class == "Marauders":
wb = load_workbook(os.path.join(os.getcwd(), "extras", "classes.xlsx"))
ws = wb.active
number_of_classes = ws["A1"].value
if number_of_classes == 0:
messagebox.showerror("Error", "No class in the database yet")
return
else:
messagebox.showerror(
"Error", "Please login again with a valid class-code"
)
current_class = ws["A2"].value
return
FaceTrainObj.main()
def exit(self):
self.controller.destroy()
self.controller.quit()
class CreateNewBatchPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.bkg = "#222629"
self.text_color = "#65CCB8"
CreateNewBatchPage.config(self, bg=self.bkg)
self.label = tk.Label(
self,
width=25,
text="Create a new Batch",
bg=self.bkg,
fg="#F8E9A1",
font=("Times", title_fontsize),
)
self.label.place(x=130 * scale_factor, y=40 * scale_factor)
entry_width = int(30 * scale_factor)
min_entrywidth = 23
entry_width = max(min_entrywidth, entry_width)
self.lb_class = tk.Label(
self,
text="CLASS-CODE: ",
bg=self.bkg,
fg=self.text_color,
font=("Courier", text_fontsize),
)
self.lb_class.place(x=320 * scale_factor, y=140 * scale_factor)
self.tv_class = tk.Entry(
self, width=entry_width, font=("", 16), justify="center"
)
self.tv_class.focus()
self.tv_class.place(x=190 * scale_factor, y=175 * scale_factor)
self.lb_number = tk.Label(
self,
text="NUMBER OF STUDENTS: ",
bg=self.bkg,
fg=self.text_color,
font=("Courier", text_fontsize),
)
self.lb_number.place(x=265 * scale_factor, y=240 * scale_factor)
vcmd = (
self.controller.register(self.validate_number_field),
"%d",
"%i",
"%P",
"%s",
"%S",
"%v",
"%V",
"%W",
)
self.tv_number = tk.Entry(
self,
width=entry_width,
font=("", 16),
justify="center",
validate="key",
validatecommand=vcmd,
)
self.tv_number.place(x=190 * scale_factor, y=275 * scale_factor)
bt_new_batch = tk.Button(
self,
bg="#45056e",
fg=self.text_color,
text="ADD BATCH",
width=16,
height=2,
font=("", 15),
command=self.create_new_batch,
)
bt_new_batch.place(x=237 * scale_factor, y=350 * scale_factor)
bt_back = tk.Button(
self,
bg="#ed3833",
fg="yellow",
text="Back",
width=10,
command=lambda: controller.show_frame("StartPage"),
)
bt_back.place(x=340 * scale_factor, y=490 * scale_factor)
def validate_number_field(
self,
action,
index,
value_if_allowed,
prior_value,
text,
validation_type,
trigger_type,
widget_name,
):
if text in "0123456789":
try:
int(value_if_allowed)
return True
except (TypeError, ValueError):
return False
else:
return False
def create_new_batch(self):
global class_codes
class_name = self.tv_class.get()
number_of_studs = int(self.tv_number.get())
batchexists = os.path.exists(os.path.join(os.getcwd(), "extras", class_name))
if batchexists:
messagebox.showerror("Error", "This batch name already exists")
return
if number_of_studs < 1 or number_of_studs > 99:
messagebox.showerror("Error", "Number of students not in allowed range!")
return
images_dir = os.path.join(os.getcwd(), "images", class_name)
unrecog_studs_dir = os.path.join(
os.getcwd(), "images", class_name, "unrecognized students"
)
os.makedirs(unrecog_studs_dir)
for i in range(number_of_studs):
os.makedirs(os.path.join(images_dir, "s" + str(i).zfill(2)))
studs_list_file = os.path.join(
os.getcwd(), "student's list", f"{class_name}.xlsx"
)
wb = Workbook()
wb.guess_types = True
ws = wb.active
ws["A1"] = 0
ws["B1"] = number_of_studs
wb.save(studs_list_file)
classes_file = os.path.join(os.getcwd(), "extras", "classes.xlsx")
wb = load_workbook(classes_file)
ws = wb.active
row = ws["A1"].value
ws["A1"] = row + 1
ws["A" + str(row + 2)] = class_name
wb.save(classes_file)
sl = StudentsList(class_name)
sl.make_pkl_file()
atten_reg_dir = os.path.join(os.getcwd(), "extras", class_name)
os.makedirs(atten_reg_dir)
wb = excel.attendance_workbook(class_name)
messagebox.showinfo(
"Batch Successfully Created",
"All the necessary Directories and Files created"
f"for Batch-Code {class_name}",
)
class_codes.add(class_name)
self.tv_class.delete(0, END)
self.tv_number.delete(0, END)
self.tv_number.insert(0, "")
self.controller.show_frame("StartPage")
class AddStudentPage(tk.Frame):
"""docstring for AddStudentPage"""
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.bkg = "#222629"
self.text_color = "#65CCB8"
AddStudentPage.config(self, bg=self.bkg)
self.label = tk.Label(
self,
width=25,
text="Add a new Student",
bg=self.bkg,
fg="#F8E9A1",
font=("Times", title_fontsize),
)
self.label.place(x=130 * scale_factor, y=40 * scale_factor)
self.lb_name = tk.Label(
self,
text="Name of Student: ",
bg=self.bkg,
fg=self.text_color,
font=("Courier", text_fontsize),
)
self.lb_name.place(x=285 * scale_factor, y=175 * scale_factor)
entry_width = int(30 * scale_factor)
min_entrywidth = 23
entry_width = max(min_entrywidth, entry_width)
self.tv_name = tk.Entry(
self, width=entry_width, justify="center", font=("", 16)
)
self.tv_name.focus()
self.tv_name.place(x=180 * scale_factor, y=210 * scale_factor)
self.bt_addstud = tk.Button(
self,
bg="#45056e",
fg=self.text_color,
text="ADD STUDENT",
width=16,
height=2,
font=("", 15),
command=self.doWork,
)
self.bt_addstud.place(x=245 * scale_factor, y=300 * scale_factor)
self.bt_back = tk.Button(
self,
bg="#af0404",
fg="yellow",
text="Back",
width=10,
command=lambda: controller.show_frame("ManagerPanelPage"),
)
self.bt_back.place(x=115 * scale_factor, y=485 * scale_factor)
self.bt_exit = tk.Button(
self, bg="#af0404", fg="yellow", text="Exit", width=10, command=self.exit
)
self.bt_exit.place(x=520 * scale_factor, y=485 * scale_factor)
def doWork(self):
global current_class
students_list_file = os.path.join(
os.getcwd(), "student's list", f"{current_class}.xlsx"
)
wb = load_workbook(students_list_file)
ws = wb.active
total_studs = ws["B1"].value
currently_studs = ws["A1"].value
if currently_studs == total_studs:
messagebox.showinfo(
"Batch Full", "No more accomodation for any new student"
)
return
ws["A1"] = currently_studs + 1
row_here = currently_studs + 2
student_name = self.tv_name.get()
ws["A" + str(row_here)] = student_name
roll_no = currently_studs
roll_no = str(roll_no).zfill(2)
ws["B" + str(row_here)] = current_class + roll_no
wb.save(students_list_file)
sl = StudentsList(current_class)
sl.make_pkl_file()
atten_reg = os.path.join(
os.getcwd(), "extras", current_class, f"{current_class}.xlsx"
)
wb = load_workbook(atten_reg)
today = datetime.now().date()
month = today.strftime("%B")
try:
# If current month exists
ws = wb[month]
row_here = excel.gap + int(roll_no)
ws.merge_cells(
start_row=row_here, start_column=3, end_row=row_here, end_column=4
)
ws.cell(row=row_here, column=1, value=str(int(roll_no) + 1))
fill_roll = excel.PatternFill(fgColor="A5EFAF", fill_type="solid")
fill_name = excel.PatternFill(fgColor="E9EFA5", fill_type="solid")
ws.cell(
row=row_here, column=2, value=current_class + roll_no
).fill = fill_roll
ws.cell(row=row_here, column=3, value=student_name).fill = fill_name
cellrange = "A" + str(row_here) + ":AN" + str(row_here)
excel.set_border(ws, cellrange)
first_date_column = excel.get_column_letter(excel.date_column)
days_in_month = monthrange(today.year, today.month)[1]
last_date_column = excel.get_column_letter(
excel.date_column + days_in_month - 1
)
sum_cell_column = excel.date_column + days_in_month + 1
fill_total = excel.PatternFill(fgColor="25F741", fill_type="solid")
ws.cell(
row=row_here,
column=sum_cell_column,
value="=SUM("
+ first_date_column
+ str(row_here)
+ ":"
+ last_date_column
+ str(row_here)
+ ")",
).fill = fill_total
wb.save(atten_reg)
except: # If current month does not exist
wb = excel.attendance_workbook(current_class)
image_dir = os.path.join(os.getcwd(), "images", current_class, "s" + roll_no)
messagebox.showinfo(
"Student Added",
f"{student_name} admitted!\n"
"Click OK to proceed for capturing training images. "
"Make sure that your surroundings are well lit",
)
i = 5
face_detected_right = False
xml_file = os.path.join(os.getcwd(), "haarcascade_frontalface_default.xml")
while i > 0:
while face_detected_right is False:
img_path, frame = capture()
face_detected_right = detect_faces(xml_file, frame)
img_path = os.path.join(
os.getcwd(),
"images",
current_class,
"s" + str(roll_no).zfill(2),
os.path.basename(img_path),
)
cv2.imwrite(img_path, frame)
cv2.destroyAllWindows()
face_detected_right = False
i = i - 1
if i == 0:
messagebox.showinfo("Message", "Training images added successfully!")
messagebox.showinfo(
"Enrollment Number", f"Roll Number of student: {current_class + roll_no}"
)
self.tv_name.delete(0, END)
def exit(self):
self.controller.destroy()
self.controller.quit()
if __name__ == "__main__":
app = SampleApp()
app.mainloop()