-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdfx.py
1640 lines (1337 loc) · 79.3 KB
/
pdfx.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
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import copy
import difflib
import math
import os
import random
from re import X
import tkinter as tk
from tkinter import TOP, VERTICAL, Y, Canvas, Image, Text, Tk, filedialog, messagebox, Frame, Label, Entry, Button, LEFT, RIGHT, BOTH, END
from tkinter import ttk
from tkinter.font import Font
from db_connect import *
import pytesseract
import PyPDF2
import ftplib
############################### COLORS VARIABLE ###############################
bg_color = "#f2f2f3"
label_color = "#1B1212"
button_color = "#003151"
btn_hover_color = "#004d80"
btn_hover_white = "#C6E6FB"
btn_color = "#003151"
success = "#3bb54a"
error = "#ff3333"
global user_who
user_who = ""
global code_entered
code_entered = ""
allPDF = {}
assign_details = {}
# plag = {}
avg_plag = {}
plag_values_list = []
calc_avg_plag = []
sum_of_similarity= []
plag_key = []
a = {}
b = 0
sum_of_value = []
create_assign = {}
count_of_assignment = 0
# global st_loggedin, te_loggedin
st_loggedin = False
te_loggedin = False
sh_assign = False
path_list = []
# plagiarism = []
# mark = []
# comp_plag = {}
# is_joined_sec = False
global is_created_sec
is_created_sec = False
joined_team_name = []
teamname = ""
# FTP server settings
server_address = '127.0.0.1'
username = 'pdfx'
password = 'Mohammad#131#'
root = tk.Tk()
root.iconbitmap(r"C:\Users\ANSHARI\Downloads\Python project\pdfx1-02.ico")
root.title("PDFX")
# root.geometry("1980x1080")
root.resizable(False, False)
# Centering the window
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_cordinate = int((screen_width/2) - (1500/2))
y_cordinate = int((screen_height/2) - (810/2))
root.geometry("{}x{}+{}+{}".format(1500, 810, x_cordinate, y_cordinate))
############################### BUTTON FUNCTION TO USE THROUGHOUT THE PROGRAM ###############################
def create_btn(button_frame, align, btn_text, com, bg_col, fg_col, ft_size, y, x, btn_hover_color, btn_color):
button = Button(button_frame, text=btn_text, font=("Roboto", ft_size, "bold"), bg=bg_col, fg=fg_col, bd=0, highlightthickness=0, cursor="hand2", command=com, )
button.pack(side=align, ipadx=x, ipady=y, padx=15, pady=15)
button.bind("<Enter>", lambda event: on_enter(event, btn_hover_color))
button.bind("<Leave>", lambda event: on_leave(event, btn_color))
############################### HOVER EFFECT FUNCITONS ###############################
def on_enter(event, btn_hover_color):
event.widget.config(bg=btn_hover_color)
def on_leave(event, btn_color):
event.widget.config(bg=btn_color)
def open_login_frame():
main_frame.pack_forget()
signup_frame.place_forget()
login_frame.place(relx=.5, rely=.5, anchor="center")
# dialog_frame.place_forget()
def close_login_frame():
login_frame.place_forget()
def open_signup_frame():
main_frame.pack_forget()
login_frame.place_forget()
signup_frame.place(relx=.5, rely=.5, anchor="center")
# dialog_frame.place_forget()
def clear_signup_form():
user_entry.delete(0, tk.END)
pass_entry.delete(0, tk.END)
c_pass_entry.delete(0, tk.END)
def clear_create_team_form():
team_name.delete(0, tk.END)
team_subject_name.delete(0, tk.END)
team_teacher_name.delete(0, tk.END)
def clear_login_form():
login_user_entry.delete(0, tk.END)
login_pass_entry.delete(0, tk.END)
def open_create_team_modal():
modal_frame.place(relx=.5, rely=.5, anchor="center", width=1000, height=600)
def open_home_frame():
home_main_frame.pack(fill=BOTH, expand=True)
def open_options_panel(event, team_card_name_label):
global clicked_team_name, no_assignment_label, user_who
home2_frame.place(relx=0, rely=.5, anchor="w")
create_team_btn.grid_forget()
create_join_btn.grid_forget()
my_team_cards_frame.place_forget()
joined_team_cards_frame.place_forget()
left_frame.grid(row=0, column=0, sticky="n",pady=100, padx=(40,60))
right_frame.grid(row=0, column=1, sticky="w")
create_back_btn.grid_forget()
global is_created_sec
is_created_sec = True
team_detail_frame = event.widget
team_card_name = [w for w in team_detail_frame.winfo_children() if w.winfo_name() == "team_card_name"][0]
clicked_team_name = team_card_name.cget("text")
team_card_name_label.config(text=clicked_team_name)
print(clicked_team_name)
join_welcome_label.place_forget()
welcome_label.config(text=f"Welcome to {clicked_team_name} team", anchor="e")
assignment_label.grid(row=0, column=0, sticky="nsew", pady=(0,40), ipadx=30, ipady=8)
plagiarism_label.grid(row=2, column=0, sticky="nsew", ipadx=30, ipady=8)
back_btn.place(relx=.83, rely=.04)
show_assignment_btn.place_forget()
create_assignment_btn.place_forget()
select_file_btn.place_forget()
upload_file_btn.place_forget()
create_assign_heading.place_forget()
assignment_frame.place_forget()
assign_heading.place_forget()
try:
for frame in uploaded_work_frames:
frame.destroy() # or frame.pack_forget()
no_assignment_label.place_forget()
except:
print("error occured")
update_assignment_cards()
welcome_label.place(relx=.5, rely=.56, anchor="center")
welcome.place(relx=.5, rely=.42, anchor="center")
assignment_card_frame.place_forget()
work_heading.place_forget()
team_code_label.grid(row=0, column=1, padx=(15,50))
try:
query = (f"SELECT code FROM create_teams WHERE teamname = '{clicked_team_name}' and username = '{user_who}'")
mycursor.execute(query)
print("This is query",query)
# Get the result of the query
result = mycursor.fetchone()
teamcode = list(result)
print("This is details corresponding to the code", teamcode[0])
except mysql.connector.Error as e:
print(f"The error '{e}' occurred")
team_code_label.config(text=f'Code: {teamcode[0]}')
max_marks_frame.place_forget()
def close_create_join_btn():
my_teams_btn.place_forget()
joined_teams_btn.place_forget()
def open_joined_team_card():
global user_who
join_user_label.config(text=user_who)
join_user_label.grid(row=0, column=0, padx=(15,50))
joined_team_cards_frame.place(x=0, y=0, width=screen_width, height=screen_height)
def back_joined_team():
joined_team_cards_frame.place(x=0, y=0, width=screen_width, height=screen_height)
create_back_btn.grid(row=0, column=1, padx=(15,50))
user_label.grid(row=0, column=0, padx=(15,50))
def open_my_team_card():
global user_who
my_team_cards_frame.place(x=0, y=0, height=screen_height, width=screen_width)
create_back_btn.grid(row=0, column=1, padx=(15,50))
user_label.config(text=user_who)
user_label.grid(row=0, column=0, padx=(15,50))
team_code_label.grid_forget()
clear_table(table)
table.place_forget()
def close_joined_team_card():
joined_team_cards_frame.place_forget()
def close_my_team_card():
my_team_cards_frame.place_forget()
def show_back_btn():
create_back_btn.grid(row=0, column=1, padx=(15,50))
user_label.grid(row=0, column=0, padx=(15,50))
create_join_btn.grid_forget()
create_team_btn.grid_forget()
def hide_back_btn():
user_label.grid_forget()
create_back_btn.grid_forget()
create_team_btn.grid(row=0, column=0)
create_join_btn.grid(row=0, column=1, padx=(15,50))
my_teams_btn.place(relx=.4, rely=.5, anchor="center")
joined_teams_btn.place(relx=.6, rely=.5, anchor="center")
my_team_cards_frame.place_forget()
joined_team_cards_frame.place_forget()
not_joined_home_label.place_forget()
not_created_home_label.place_forget()
create_logout_btn.grid(row=0, column=2, padx=(20,80))
join_user_label.grid_forget()
def logout():
global team_detail_frame, team_card_frame, my_team_cards_frame
home_main_frame.pack_forget()
main_frame.pack(fill=BOTH, expand=True, padx=50, pady=50)
for frame in my_team_cards_frame.winfo_children():
frame.destroy()
joined_team_cards_frame.pack_forget()
for frame in joined_team_cards_frame.winfo_children():
frame.destroy()
joined_team_cards_frame.pack_forget()
def close_logout_btn():
create_logout_btn.grid_forget()
############################### DIALOG BOX ###############################
def dialog_box(msg, cmd, bgColor, btnColor, labelColor, logo_path):
global dialog_frame, logo_img
dialog_frame = Frame(root, bg=bgColor, padx=25, pady=20)
dialog_frame.place(relx=.5, rely=.5, anchor="center")
logo_img = tk.PhotoImage(file=logo_path)
logo_img = logo_img.subsample(9)
logo_label = Label(dialog_frame, image=logo_img, bg=bgColor)
logo_label.pack(pady=(0,20))
dialog_label = Label(dialog_frame, text=msg, font=("Roboto", 15), bg=bgColor, fg=labelColor, anchor="w")
dialog_label.pack()
create_btn(dialog_frame, "top", "Ok", cmd, btnColor, label_color, 14, 0, 40, btn_hover_white, btnColor)
def close_dialog_box():
dialog_frame.place_forget()
def close_team_modal():
modal_frame.place_forget()
def open_join_team_modal():
join_modal_frame.place(relx=.5, rely=.5, anchor="center", width=500, height=300)
print("Open it")
def close_join_modal():
join_modal_frame.place_forget()
def open_join_options_panel(event, team_card_name_label):
global clicked_team_name
join_home2_frame.place(relx=0, rely=.5, anchor="w")
join_show_assign_label.grid(row=0, column=0, sticky="nsew", pady=(0,40), ipadx=40, ipady=8, padx=40)
# join_marks_label.grid(row=2, column=0, sticky="nsew", ipadx=30, ipady=8, padx=40)
join_back_btn.place(relx=.83, rely=.04)
assignment_label.grid_forget()
plagiarism_label.grid_forget()
welcome_label.place_forget()
welcome.place_forget()
back_btn.place_forget()
create_back_btn.grid_forget()
close_joined_team_card()
team_detail_frame = event.widget
team_card_name = [w for w in team_detail_frame.winfo_children() if w.winfo_name() == "team_card_name"][0]
clicked_team_name = team_card_name.cget("text")
team_card_name_label.config(text=clicked_team_name)
print(clicked_team_name)
join_welcome_label.config(text=f"Welcome to {clicked_team_name} team", anchor="e")
join_show_assignment_btn.place_forget()
join_assign_heading.place_forget()
join_assignment_card_frame.place_forget()
join_welcome_label.place(relx=.5, rely=.5, anchor="center")
no_join_assignment_label.place_forget()
join_uploaded_work.place_forget()
join_work_heading.place_forget()
join_select_file_btn.place_forget()
join_upload_file_btn.place_forget()
############################### CREATING THE TEAM ###############################
def create_team():
global t_name
t_name = team_name.get()
sub_name = team_subject_name.get()
te_name = team_teacher_name.get()
desc = "Description"
# user_name = "username"
team_code = int(round(random.uniform(10000, 50000), 0))
global db_name
db_name = "create_teams"
if t_name == "":
dialog_box("Enter the team name", close_dialog_box, error, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\close.png")
elif sub_name == "":
dialog_box("Enter the subject name", close_dialog_box, error, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\close.png")
elif te_name == "":
dialog_box("Enter the professor name", close_dialog_box, error, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\close.png")
try:
if t_name != None and sub_name != None and te_name != None:
mycursor.execute("INSERT INTO {} (username, teamname, subname, profname, description, code) VALUES (%s, %s, %s, %s, %s, %s)".format(db_name), (user_who, t_name, sub_name, te_name, desc, team_code))
mydb.commit()
dialog_box(f"Your team has been created\nTeam code is {team_code}", lambda:(close_dialog_box()) , success, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\check.png")
clear_create_team_form()
else:
messagebox.showerror("Some other error")
except mysql.connector.Error as e:
print(f"The error '{e}' occurred")
############################### JOINING THE TEAM ###############################
def join_team():
db_name = "create_teams"
code_entered = code_show()
try:
# Execute a SELECT query to check if the username and password exist in the database
query = (f"SELECT username, teamname, subname, profname, description, code FROM {db_name} WHERE code = '{code_entered}'")
mycursor.execute(query)
print("This is query",query)
# Get the result of the query
result = mycursor.fetchone()
print("This is details corresponding to the code", result)
dialog_box("You have joined the team", close_dialog_box, success, "white", "white", r"C:\Users\ANSHARI\Downloads\Python project\check.png")
except mysql.connector.Error as e:
print(f"The error '{e}' occurred")
def create_joining_team_card():
res = []
res.append(result)
print("This is list of tuples",res)
# Inserting data of joined team corresponding to the username (loggedin)
try:
mycursor.execute("INSERT INTO {} (username, teamname, subname, code) VALUES (%s, %s, %s, %s)".format("team_joined"), (user_who, res[0][1], res[0][2], res[0][5]))
# Commit the changes to the database
mydb.commit()
except mysql.connector.Error as e:
print(f"The error '{e}' occurred")
create_joining_team_card()
def fetch_all_teams_joined():
global joined_team_names, team_card_name
try:
display_teams_query = (f"SELECT teamname, subname FROM team_joined WHERE username = '{user_who}'")
print(display_teams_query)
mycursor.execute(display_teams_query)
# Get the result of the query
display_joined_teams_result = mycursor.fetchall()
print("Joined teams", display_joined_teams_result)
print(len(display_joined_teams_result))
joined_team_cards_frame.config(bg=button_color)
if display_joined_teams_result:
not_joined_home_label.place_forget()
row_index = 0
for i in range(0,len(display_joined_teams_result)):
# global join_team_card_frame
if i % 4 == 0 and i != 0:
row_index += 1
join_team_card_frame = Frame(joined_team_cards_frame, bg="white", width=240, height=240)
join_team_card_frame.grid(row=row_index, column=i%4, pady=(160 if row_index == 0 else 90,0), padx=63, sticky="nsew")
team_card = Frame(join_team_card_frame, bg="white", width=250, height=250, highlightthickness=3, highlightcolor="white", relief="groove", highlightbackground="#40bbec", cursor="hand2")
team_card.pack()
team_detail_frame = Frame(team_card, bg="white", width=240, height=240)
team_detail_frame.place(relx=.5, rely=.5, anchor="center")
team_card_name = Label(team_detail_frame, bg="white", text=display_joined_teams_result[i][0], font=("roboto", 20, "bold"), fg=button_color, name="team_card_name")
team_card_name.place(relx=.5, rely=.44, anchor="center")
team_card_subname = Label(team_detail_frame, bg="white", text=display_joined_teams_result[i][1], font=("roboto", 15), fg=button_color)
team_card_subname.place(relx=.5, rely=.63, anchor="center")
joined_team_name.append(display_joined_teams_result[i][0])
team_detail_frame.bind("<Button>", lambda event, name=team_card_name: open_join_options_panel(event, name))
else:
not_joined_home_label.place(relx=.5, rely=.48, anchor="center")
except mysql.connector.Error as e:
print(f"The error '{e}' occurred")
############################### FETCH THE CREATED TEAM DETAIL CORRESPONDING TO USERNAME ###############################
def fetch_teams():
global team_card_name, team_card_subname, team_detail_frame, team_card_frame
db_name = "create_teams"
try:
# Execute a SELECT query to check if the username and password exist in the database
query = (f"SELECT teamname, subname FROM {db_name} WHERE username = '{user_who}'")
mycursor.execute(query)
print("This is query",query)
# Get the result of the query
display_teams_result = mycursor.fetchall()
print("This is details corresponding to username", display_teams_result)
# If the result is not empty, the user is logged in
if display_teams_result:
my_team_cards_frame.place(x=0, y=0, height=screen_height, width=screen_width)
my_team_cards_frame.config(bg=button_color)
row_index = 0
for i in range(len(display_teams_result)):
global team_card_frame
if i % 4 == 0 and i != 0:
row_index += 1
team_card_frame = Frame(my_team_cards_frame, bg=button_color, width=240, height=240)
team_card_frame.grid(row=row_index, column=i%4, pady=(160 if row_index == 0 else 90,0), padx=63, sticky="nsew")
team_card = Frame(team_card_frame, bg="white", width=250, height=250, highlightthickness=3, highlightcolor="white", relief="groove", highlightbackground="#40bbec", cursor="hand2")
team_card.pack()
team_detail_frame = Frame(team_card, bg="white", width=240, height=240)
team_detail_frame.place(relx=.5, rely=.5, anchor="center")
team_card_name = Label(team_detail_frame, bg="white", text=display_teams_result[i][0], font=("roboto", 20, "bold"), fg=button_color, name="team_card_name")
team_card_name.place(relx=.5, rely=.44, anchor="center")
team_card_subname = Label(team_detail_frame, bg="white", text=display_teams_result[i][1], font=("roboto", 15), fg=button_color)
team_card_subname.place(relx=.5, rely=.63, anchor="center")
team_detail_frame.bind("<Button>", lambda event, name=team_card_name: open_options_panel(event, name))
else:
not_created_home_label.place(relx=.5, rely=.48, anchor="center")
except mysql.connector.Error as e:
print(f"The error '{e}' occurred")
############################### sIGNUP LOGIC ###############################
def signup_form(db_name):
global name
name = user_entry.get()
password = pass_entry.get()
confirm_password = c_pass_entry.get()
if name == "":
dialog_box("Enter your name", lambda:(open_signup_frame(), close_dialog_box()), error, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\close.png")
elif password == "":
dialog_box("Enter the password", lambda:(open_signup_frame(), close_dialog_box()), error, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\close.png")
elif len(password) < 8:
dialog_box("Password must be at least 8 characters", lambda:(open_signup_frame(), close_dialog_box()), error, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\close.png")
elif password != confirm_password:
dialog_box("Password do not match", lambda:(open_signup_frame(), close_dialog_box()), error, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\close.png")
try:
if password == confirm_password and name != None and password != None and confirm_password != None:
# Execute an INSERT query to add the new user to the database
# print(db_name)
mycursor.execute("INSERT INTO {} (username, password) VALUES (%s, %s)".format(db_name), (name, password))
# Commit the changes to the database
mydb.commit()
dialog_box("Registered successfully!", lambda:(close_dialog_box(), open_login_frame()) , success, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\check.png")
clear_signup_form()
else:
messagebox.showerror("Confirm Password does not match")
except mysql.connector.Error as e:
print(f"The error '{e}' occurred")
############################### LOGIN LOGIC ###############################
def validate_login(db_name):
# Get the username and password values from the form
global name
name = login_user_entry.get()
password = login_pass_entry.get()
# print("User name is",name)
# print(password)
try:
# Execute a SELECT query to check if the username and password exist in the database
query = ("SELECT * FROM {} WHERE username = %s AND password = %s".format(db_name))
mycursor.execute(query, (name, password))
# Get the result of the query
result = mycursor.fetchone()
# print(result)
# If the result is not empty, the user is logged in
if result:
dialog_box("You are loggedin!", lambda:(close_dialog_box(), clear_login_form(), open_home_frame()), success, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\check.png")
global te_loggedin
te_loggedin = True
global user_who
user_who =name
elif len(name) == 0:
dialog_box("Enter the details", lambda:(open_login_frame(), close_dialog_box()), error, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\close.png")
elif len(password) == 0:
dialog_box("Enter the details", lambda:(open_login_frame(), close_dialog_box()), error, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\close.png")
else:
dialog_box("Incorrect Credentials", lambda:(open_login_frame(), close_dialog_box()), error, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\close.png")
except mysql.connector.Error as e:
print(f"The error '{e}' occurred")
def fetch_team_detail():
try:
team_dict = {}
# Execute a SELECT query to check if the username and password exist in the database
db_name = "create_teams"
query = (f"SELECT * FROM {db_name} where username = '{user_who}' ")
mycursor.execute(query)
# Get the result of the query
result = mycursor.fetchall()
# print(result)
team_dict["team name"] = result[0][1]
# print(team_dict)
joined_team_cards_frame.config(bg="white")
my_team_cards_frame.config(bg="white")
except mysql.connector.Error as e:
print(f"The error '{e}' occurred")
except:
# If the result is not empty, the user is logged in
if result:
print("Result is true")
# middle_home_label.place_forget()
# user_id.place_forget()
else:
joined_team_cards_frame.config(bg="white")
print("No teams joined or created")
# middle_home_label.place(relx=.5, rely=.55, anchor="center")
# user_id.place(relx=.5, rely=.44, anchor="center")
############################### SELECT FILE LOGIC ###############################
def select_files():
if te_loggedin:
file_paths = filedialog.askopenfilenames(filetypes=[("PDF files", "*.pdf")])
path_list.extend(file_paths)
for path in file_paths:
print("Selected file:", path)
pdf_name = os.path.basename(path)
pdf_name = os.path.splitext(pdf_name)[0]
allPDF[pdf_name] = path
print(allPDF)
print(pdf_name)
else:
global file_path
file_path = filedialog.askopenfilename(filetypes=[("PDF files", "*.pdf")])
pdf_name = os.path.basename(file_path)
pdf_name = os.path.splitext(pdf_name)[0]
allPDF[pdf_name] = file_path
print(allPDF)
############################### UPLOADING PDF LOGIC ###############################
def upload_files():
if len(path_list) == 0:
print("No files selected!")
return
print("Uploading files...")
for path in path_list:
print("File path:", path)
path_list.clear()
print("Upload complete!")
calc_plag()
print("This is file path", allPDF.values())
if len(allPDF.values()) == 0:
print("No files selected!")
return
allPDF.clear()
dialog_box("Files are uploaded", close_dialog_box, success, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\check.png")
print("Executed")
############################### EXTRACTING IMAGE LOGIC ###############################
def extractImg(allPDF):
for key in allPDF:
pdf_file = key
pdf_reader = PyPDF2.PdfFileReader(pdf_file)
images = []
for page_num in range(pdf_reader.getNumPages()):
page = pdf_reader.getPage(page_num)
try:
xObject = page['/Resources']['/XObject'].getObject()
except KeyError:
continue
for obj in xObject:
if xObject[obj]['/Subtype'] == '/Image':
size = (xObject[obj]['/Width'], xObject[obj]['/Height'])
data = xObject[obj]._data
if xObject[obj]['/ColorSpace'] == '/DeviceRGB':
mode = "RGB"
else:
mode = "P"
stream = io.BytesIO(data)
image = Image.open(stream)
image = image.convert(mode)
images.append(image)
return stream
############################### EXTRACTING DATA FROM IMAGE LOGIC ###############################
def readFrmImg(allPDF):
# Reading the text from the image
pytesseract.pytesseract.tesseract_cmd = r'C:/Program Files/Tesseract-OCR/tesseract.exe'
try:
for key in allPDF:
imgData = extractImg(allPDF)
images = Image.open(key) #Opening the image
custom_config = r'-l eng --oem 3 --psm 6'
text = pytesseract.image_to_string(images,config=custom_config) #Storing the extracted text in the variable
#Storing the text extracted from the image into the txt file
filename = r"C:\Users\ANSHARI\Desktop\demo3.txt"
os.makedirs(os.path.dirname(filename), exist_ok=True)
with open(filename, "w") as f:
f.write(text)
return text
except:
return "0"
############################### EXTRACT DATA FROM PDF LOGIC ###############################
def getTxt(allPDF, imgTxt):
newPDF = copy.deepcopy(allPDF)
for key in allPDF:
for i in range(PyPDF2.PdfFileReader(allPDF[key]).getNumPages()):
page = PyPDF2.PdfFileReader(allPDF[key]).getPage(i)
pdfText = imgTxt + page.extractText()
rm_line_txt = '\n'.join([line for line in pdfText.split('\n') if line.strip()])
low_pdf_txt = rm_line_txt.lower()
cln_pdf_txt = low_pdf_txt.replace(" ", "")
# print("This is clean text",cln_pdf_txt)
newPDF[key] = cln_pdf_txt
return newPDF
############################### STORING ENTIRE DATA INTO THE VARIABLE ###############################
def entire_text():
entireTxt = ''
imgTxt = readFrmImg(allPDF)
entireTxt = getTxt(allPDF, imgTxt)
# print("This is entire text",entireTxt)
return entireTxt
def get_max_marks():
global marks
marks = max_marks_entry.get()
return marks
############################### CALCULATING THE PLAGIARISM ###############################
def calc_plag():
global user_who, marks
plag = {}
entireTxt = entire_text()
for file1, txt1 in entireTxt.items():
for file2, txt2 in entireTxt.items():
if file1 < file2:
seq = difflib.SequenceMatcher(None, txt1, txt2)
similarity_ratio = seq.ratio()
plag[file1, file2] = round(similarity_ratio*100, 2)
if similarity_ratio > 0.8: # adjust the threshold as needed
print(f"{file1} and {file2} have a high plagiarism: {round(similarity_ratio*100, 2)} %\n")
else:
print(f"{file1} and {file2} has plagiarism: {round(similarity_ratio*100, 2)} %\n")
plag_values = plag.values()
global plag_values_list
plag_values_list = list(plag_values)
print("This is plag",plag)
def dynamic_label():
max_marks = 0
plagiarism = []
mark = []
comp_plag = {}
pdf_list = list(allPDF)
print("this pdf list", pdf_list)
length_of_pdf = len(pdf_list)
for first_key, value in plag.items():
first_char = first_key[0]
sec_char = first_key[1]
if first_char in comp_plag:
print("I am comp plag", comp_plag)
comp_plag[first_char].append(value)
if sec_char in comp_plag:
comp_plag[sec_char].append(value)
else:
comp_plag[sec_char] = [value]
print("Value appended", comp_plag)
else:
comp_plag[first_char] = [value]
if sec_char in comp_plag:
comp_plag[sec_char].append(value)
else:
comp_plag[sec_char] = [value]
print("This is new dictionary", comp_plag)
i = 0
for key, value in comp_plag.items():
greatest_value = max(value)
print(f"The greatest value in the list {key} is {greatest_value}.")
plagiarism.append(greatest_value)
print("Plagiarism Found", plagiarism)
table.place(relx=.475, rely=.5, anchor="center", height=500)
max_marks = int(get_max_marks())
print("I am max marks", type(max_marks))
for i in range(0, length_of_pdf):
if 0.0 <= plagiarism[i] <= 21.0:
marks = int(max_marks)
elif 21.0 <= plagiarism[i] <= 41.0:
marks = int(max_marks * 0.75)
# print(marks)
elif 41.0 <= plagiarism[i] <= 61.0:
marks = int(max_marks * 0.5)
# print(marks)
elif 61.0 <= plagiarism[i] <= 81.0:
marks = int(max_marks * 0.25)
# print(marks)
elif 81.0 <= plagiarism[i] <= 101.0:
marks = int(max_marks * 0.1)
mark.append(marks)
print("Marks are:", mark)
for i, key in enumerate(allPDF.keys()):
print(key)
try:
table.insert(parent='', index='end', iid=i, text=f"{i+1}.", values=(f"{key} {plagiarism[i]} {mark[i]}/{max_marks}"))
mycursor.execute(f"INSERT INTO assignment_marks (teamname, username, pdf_name, plagiarism, marks, total_marks) VALUES (%s, %s, %s, %s, %s, %s)", (clicked_team_name, user_who, key, plagiarism[i], mark[i], max_marks))
print("Data inserted")
mydb.commit()
print("This is i", i)
except:
table.insert(parent='', index='end', iid=i, text=f"{i+1}.", values=(f"{key} {plagiarism[i]} {mark[i]}/{max_marks}"))
mycursor.execute(f"INSERT INTO assignment_marks (teamname, username, pdf_name, plagiarism, marks, total_marks) VALUES (%s, %s, %s, %s, %s, %s)", (clicked_team_name, user_who, key, plagiarism[i], mark[i-1], max_marks))
print("This is except i", i)
print("Except")
comp_plag.clear()
dynamic_label()
def clear_table(table):
# Delete all existing rows in the table
table.delete(*table.get_children())
print("cleared")
############################### SELECT FILE LOGIC ###############################
def join_select_files():
global file_path
file_path = filedialog.askopenfilename(filetypes=[("PDF files", "*.pdf")])
print("Selected file:", file_path)
pdf_name = os.path.basename(file_path)
pdf_name = os.path.splitext(pdf_name)[0]
allPDF[pdf_name] = file_path
print(allPDF)
############################### JOINED UPLOADING PDF LOGIC ###############################
def joined_upload_files():
global file_path, clicked_team_name, clicked_assign_name
if len(file_path) == 0:
print("No files selected!")
return
print("Uploading files...")
# Connect to the FTP server
ftp = ftplib.FTP(server_address)
ftp.login(username, password)
with open(file_path, 'rb') as file:
filename = os.path.basename(file_path)
ftp.storbinary('STOR ' + filename, file)
print("File uploaded:", filename)
file_path_on_server = file_path
try:
# file_abs_path = os.path.abspath(file_path)
# Execute an INSERT query to add the new user to the database
mycursor.execute(f"INSERT INTO submitted_assignments (teamname, assign_name, username, filename, filepath) VALUES (%s, %s, %s, %s, %s)", (clicked_team_name, clicked_assign_name, user_who, filename, file_path_on_server))
# Commit the changes to the database
mydb.commit()
except mysql.connector.Error as e:
print(f"The error '{e}' occurred")
# Close the FTP connection
ftp.quit()
path_list.clear()
print("Upload complete!")
# print("This is file path", allPDF.values())
if len(allPDF.values()) == 0:
print("No files selected!")
return
allPDF.clear()
dialog_box("Files are uploaded", close_dialog_box, success, bg_color, label_color, r"C:\Users\ANSHARI\Downloads\Python project\check.png")
print("Executed")
############################### MAIN FRAME ###############################
main_frame = tk.Frame(root, bg="white")
main_frame.pack(fill=BOTH, expand=True, padx=50, pady=50)
title_frame = Frame(main_frame, bg="white")
title_frame.place(relx=.5, rely=.5, anchor="center")
global logo_main_img
logo_main_img = tk.PhotoImage(file=r"C:\Users\ANSHARI\Downloads\Python project\pdfx1-02.png")
logo_main_img = logo_main_img.subsample(2)
label = Label(title_frame, image= logo_main_img, bg="white")
label.pack(pady=30)
welcome_title = Label(title_frame, text="Welcome to PDFX", font=("Roboto", 30, "bold"), bg="white", fg=label_color)
welcome_title.pack(padx=20)
main_title = Label(title_frame, text="Login or signup to proceed with the app", font=("Roboto", 15), bg="white", fg=label_color)
main_title.pack(pady=10)
button_frame = Frame(title_frame, bg="white")
button_frame.pack()
create_btn(button_frame, LEFT, "Login", lambda: (open_login_frame()), button_color, "white", 12, 7, 30, btn_hover_color, button_color)
create_btn(button_frame, RIGHT, "Signup", lambda: (open_signup_frame()), button_color, "white", 12, 7, 30, btn_hover_color, button_color)
# Create the login frame
login_frame = Frame(root, bg="white", padx=50, pady=40)
# small_title_label = Label(login_frame, text= "Teacher sign in", font=("Roboto", 12, "underline"), bg="white", fg="#003d66", anchor="w")
# small_title_label.pack(pady=(0, 20))
login_title_label = Label(login_frame, text="Log In", font=("Roboto", 25, "bold"), bg="white", fg=button_color, anchor="w")
login_title_label.pack(pady=(0, 10))
login_user_frame = Frame(login_frame, bg="white")
login_user_frame.pack(pady=(25, 25))
login_user_label = Label(login_user_frame, text="Username", font=("Roboto", 14), bg="white", fg=button_color)
login_user_label.grid(row=0, column=0, sticky=tk.W)
login_user_entry = Entry(login_user_frame, font=("Roboto", 14), bg="#fff", fg=button_color, bd=0, highlightthickness=1, highlightbackground="#ccc", highlightcolor="#ccc")
login_user_entry.grid(row=1, column=0,ipady=8, ipadx=50, pady=(0,5))
login_pass_frame = Frame(login_frame, bg="white")
login_pass_frame.pack()
login_pass_label = Label(login_pass_frame, text="Password", font=("Roboto", 14), bg="white", fg=button_color)
login_pass_label.grid(row=2, column=0, sticky=tk.W)
login_pass_entry = Entry(login_pass_frame, font=("Roboto", 14), bg="#fff", fg=button_color, bd=0, highlightthickness=1, highlightbackground="#ccc", highlightcolor="#ccc", show="*")
login_pass_entry.grid(row=3, column=0,ipady=8, ipadx=50, pady=(0,35))
# Create a frame for the buttons
login_button_frame = Frame(login_frame, bg="white")
login_button_frame.pack()
create_btn(login_button_frame, RIGHT, "Login", lambda:(validate_login("te_signup"), close_login_frame(), fetch_team_detail()),button_color, "white", 14, 5, 40, btn_hover_color, button_color)
create_btn(login_button_frame, LEFT, "Signup", open_signup_frame, "white", button_color, 14, 5, 40, "#FAF9F6", "white")
############################### SIGNUP FRAME ###############################
signup_frame = Frame(root, bg="white", padx=50, pady=40)
# small_title_label = Label(signup_frame, text= "Teacher registration", font=("Roboto", 12, "underline"), bg="white", fg="#003d66", anchor="w")
# small_title_label.pack(pady=(0, 20))
title_label = Label(signup_frame, text="Create an account", font=("Roboto", 25, "bold"), bg="white", fg=button_color, anchor="w")
title_label.pack(pady=(0, 10))
user_frame = Frame(signup_frame, bg="white")
user_frame.pack(pady=(25, 25))
user_label = Label(user_frame, text="Username", font=("Roboto", 14), bg="white", fg=button_color)
user_label.grid(row=0, column=0, sticky=tk.W)
user_entry = Entry(user_frame, font=("Roboto", 14), bg="#fff", fg=button_color, bd=0, highlightthickness=1, highlightbackground="#ccc", highlightcolor="#ccc")
user_entry.grid(row=1, column=0,ipady=8, ipadx=50, pady=(0,25))
pass_frame = Frame(signup_frame, bg="white")
pass_frame.pack()
pass_label = Label(user_frame, text="Password", font=("Roboto", 14), bg="white", fg=button_color)
pass_label.grid(row=4, column=0, sticky=tk.W)
pass_entry = Entry(user_frame, font=("Roboto", 14), bg="#fff", fg=button_color, bd=0, highlightthickness=1, highlightbackground="#ccc", highlightcolor="#ccc", show="*")
pass_entry.grid(row=5, column=0,ipady=8, ipadx=50, pady=(0,25))
c_pass_frame = Frame(signup_frame, bg="white")
c_pass_frame.pack()
c_pass_label = Label(user_frame, text="Confirm Password", font=("Roboto", 14), bg="white", fg=button_color)
c_pass_label.grid(row=7, column=0, sticky=tk.W)
c_pass_entry = Entry(user_frame, font=("Roboto", 14), bg="#fff", fg=button_color, bd=0, highlightthickness=1, highlightbackground="#ccc", highlightcolor="#ccc", show="*")
c_pass_entry.grid(row=8, column=0,ipady=8, ipadx=50)
# Create a frame for the buttons
button_frame = Frame(signup_frame, bg="white")
button_frame.pack()
create_btn(button_frame, LEFT, "Signup", lambda:signup_form("te_signup"), button_color, "white", 14, 5, 40, btn_hover_color, button_color)
create_btn(button_frame, LEFT, "Login", open_login_frame, "white", button_color, 14, 5, 40, "#FAF9F6", "white")
############################### HOME MAIN FRAME ###############################
home_main_frame = tk.Frame(root, bg="white")
# home_main_frame.pack(fill=BOTH, expand=True)
home_sub_frame = Frame(home_main_frame, bg="white", width=screen_width, height=screen_height)
home_sub_frame.place(x=0,y=0)
my_team_cards_frame = Frame(home_sub_frame, bg=button_color, width=screen_width, height=screen_height)
my_team_cards_frame.place(x=0, y=0, width=screen_width, height=screen_height)
joined_team_cards_frame = Frame(home_sub_frame, bg=button_color, width=screen_width, height=screen_height)
joined_team_cards_frame.place(x=0, y=0, width=screen_width, height=screen_height)
home_menu_frame = Frame(home_sub_frame, bg=button_color, height=70, width=screen_width)
home_menu_frame.place(x=0, y=0, width=screen_width)
logo_label = Label(home_menu_frame, text="PDFX", font=("Roboto", 30, "bold"), bg=button_color, fg="white")
logo_label.place(relx=.1, rely=.5, anchor="center")
global white_logo
white_logo = tk.PhotoImage(file=r"C:\Users\ANSHARI\Downloads\Python project\white-logo.png")
white_logo = white_logo.subsample(5)
white_logo_label = Label(home_menu_frame, image= white_logo, bg=button_color)
white_logo_label.place(relx=.05, rely=.5, anchor="center")
button_frame = Frame(home_menu_frame, bg=button_color, width=300, height=50)
button_frame.place(relx=.84, rely=.5, anchor="center")
create_team_btn = Button(button_frame, text="Create team", padx=25, pady=5, bg="white", fg=button_color, bd=0, highlightbackground=button_color, highlightthickness=0,font=("roboto", 12, "bold"), cursor="hand2",command=lambda:(open_create_team_modal()))
create_team_btn.grid(row=0, column=0)
create_join_btn = Button(button_frame, text="Join team", padx=25, pady=5, bg="white", fg=button_color, bd=0, highlightbackground=button_color, highlightthickness=0,font=("roboto", 12, "bold"), cursor="hand2",command=open_join_team_modal)
create_join_btn.grid(row=0, column=1, padx=(15,10))
create_back_btn = Button(button_frame, text="Back", padx=25, pady=5, bg="white", fg=button_color, bd=0, highlightbackground=button_color, highlightthickness=0,font=("roboto", 12, "bold"), cursor="hand2",command=hide_back_btn)
create_logout_btn = Button(button_frame, text="Logout", padx=25, pady=5, bg=button_color, fg="white", bd=0, highlightbackground=button_color, highlightthickness=0,font=("roboto", 14, "bold"), cursor="hand2",command=logout)
create_logout_btn.grid(row=0, column=2, padx=(20,80))
# global user_img
user_img = tk.PhotoImage(file=r"C:\Users\ANSHARI\Downloads\Python project\user (3).png")
user_img= user_img.subsample(15)
user_label = Label(button_frame, text="username", fg="white", bg=button_color, font=("roboto", 14, "bold"), compound=LEFT, image=user_img, padx=15)
user_label.image = user_img
team_code_label = Label(button_frame, text="team code", fg=button_color, bg="white", font=("roboto", 14), padx=15, pady=5)
not_created_img = tk.PhotoImage(file=r"C:\Users\ANSHARI\Downloads\Python project\add-friend.png")
not_created_img= not_created_img.subsample(7)
not_created_home_label = Label(home_sub_frame, text="You have not created any team yet", font=("Roboto", 28, "bold"), bg=button_color, fg="white", image=not_created_img, compound=TOP, pady=20)
not_created_home_label.image = not_created_img
not_joined_img = tk.PhotoImage(file=r"C:\Users\ANSHARI\Downloads\Python project\meeting.png")
not_joined_img= not_joined_img.subsample(7)
not_joined_home_label = Label(home_sub_frame, text="You have not joined any team yet", font=("Roboto", 28, "bold"),bg=button_color, fg="white", image=not_joined_img, compound=TOP, pady=20)
not_created_home_label.image = not_joined_img
my_team_img = tk.PhotoImage(file=r"C:\Users\ANSHARI\Downloads\Python project\myteam (1).png")
my_team_img= my_team_img.subsample(8)
joined_team_img = tk.PhotoImage(file=r"C:\Users\ANSHARI\Downloads\Python project\joinedteam.png")
joined_team_img= joined_team_img.subsample(8)
my_teams_btn = Button(home_sub_frame, text="My teams", padx=25, pady=5, bg="white", fg=button_color, bd=0, highlightbackground=button_color, highlightthickness=0,font=("roboto", 20, "bold"), cursor="hand2", compound=LEFT, image=my_team_img, command=lambda:(close_create_join_btn(), fetch_teams(), show_back_btn(), close_joined_team_card(), open_my_team_card(), close_logout_btn()))
my_teams_btn.place(relx=.4, rely=.5, anchor="center")
joined_teams_btn = Button(home_sub_frame, text="Joined teams", padx=25, pady=5, bg="white", fg=button_color, bd=0, highlightbackground=button_color, highlightthickness=0,font=("roboto", 20, "bold"), cursor="hand2", compound=LEFT, image=joined_team_img, command=lambda:(fetch_all_teams_joined(), close_create_join_btn(), show_back_btn(), close_my_team_card(), open_joined_team_card(), close_logout_btn()))
joined_teams_btn.place(relx=.6, rely=.5, anchor="center")
global home2_frame
home2_frame = Frame(home_sub_frame, bg=button_color, width=screen_width, height=screen_height-140)
join_home2_frame = Frame(home_sub_frame, bg=button_color, width=screen_width, height=screen_height-140)
# home2_frame.place(relx=.5, rely=.5, anchor="center")