-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
415 lines (282 loc) · 11.5 KB
/
gui.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
from tkinter import *
from email_function import *
#from authentication import *
#from bluetooth import *
#import registration
import os.path, json
#import picamera
import encryption
import time
#picamera.PiCamera().close()
#camera = picamera.PiCamera()
def switch_windows(current, new):
current.destroy()
new()
def main_gui():
global root_main
root_main = Tk()
# set the backgroud color of GUI window
root_main.configure(background='light green')
# set the title of the GUI window
root_main.title('authentication form')
# set the configuration of the GUI window
root_main.geometry("500x300")
# create a text
auth = Label(root_main, text="WELCOME", fg="red", background="light green")
auth.place(relx=.5, rely=.5, anchor="center")
auth.config(font=("Courier", 150))
#create button to send email
send_email_button=Button(root_main, text="send email code", fg="Black", bg="light gray", command= lambda: switch_windows(root_main, email_send_gui))
send_email_button.place(relx=.35, rely=.8, anchor="center")
send_email_button.config(font=("Courier", 20))
auth_email_button = Button(root_main, text="enter email code", fg="Black", bg="light gray", command=lambda: switch_windows(root_main, email_auth_gui))
auth_email_button.place(relx=.65, rely=.8, anchor="center")
auth_email_button.config(font=("Courier", 20))
reg_button = Button(root_main, text="register", fg="Black", bg="light gray", command=lambda: ( switch_windows(root_main, reg_gui) )
reg_button.place(relx=.5, rely=.8, anchor="center")
reg_button.config(font=("Courier", 20))
# start the GUI
root_main.mainloop()
def reg_gui():
#create json file if it doens't already exist
if os.path.isfile("data.json") == False :
data={}
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
else:
with open('./data.json') as json_file:
data = json.load(json_file)
#calculate the id of the next input
if len(data)==0:
id = 1
else:
id = int(max(data)) + 1
#send the id to the arduino and put him in the registration mode
#bluetooth_send(id, '/dev/rfcomm0')
# Write the GUI data to the json file
def insert(id):
# if user hasn't filled anything, print "empty input"
if (first_name_field.get() == "" or
family_name_field.get() == "" or
email_field.get() == ""):
name = ""
print("empty input")
else:
name = first_name_field.get()
customer_info = {"first_name": encryption.encrypt(name,'key.key'), "family_name": encryption.encrypt(family_name_field.get(),'key.key'),
"email": encryption.encrypt(email_field.get(),'key.key')}
data[id]=customer_info
with open('./data.json', 'w') as outfile:
json.dump(data, outfile)
#registration.face_registration(name, 5, camera)
#registration.learn_faces()
print("learned")
switch_windows(root_reg, main_gui)
# Function to set focus (cursor)
def focus1(event):
# set focus on the course_field box
family_name_field.focus_set()
# Function to set focus
def focus2(event):
# set focus on the sem_field box
email_field.focus_set()
# Function to set focus
def focus3(event):
# set focus on the form_no_field box
insert()
# Function for clearing the
# contents of text entry boxes
def clear():
# clear the content of text entry box
first_name_field.delete(0, END)
family_name_field.delete(0, END)
email_field.delete(0, END)
global root_reg
# create a GUI window
root_reg = Tk()
# set the background colour of GUI window
root_reg.configure(background='light green')
# set the title of GUI window
root_reg.title("registration form")
# set the configuration of GUI window
root_reg.geometry("500x300")
# create a Form label
heading = Label(root_reg, text="Registration form", bg="light green")
# create a first name label
first_name = Label(root_reg, text="First name", bg="light green")
# create a family name label
family_name = Label(root_reg, text="Family name", bg="light green")
# create an email label
email = Label(root_reg, text="Email", bg="light green")
# grid method is used for placing
# the widgets at respective positions
# in table like structure .
heading.grid(row=0, column=1)
first_name.grid(row=1, column=0)
family_name.grid(row=2, column=0)
email.grid(row=3, column=0)
# create a text entry box
# for typing the information
first_name_field = Entry(root_reg)
family_name_field = Entry(root_reg)
email_field = Entry(root_reg)
# bind method of widget is used for
# the binding the function with the events
# whenever the enter key is pressed
# then call the focus1 function
first_name_field.bind("<Return>", focus1)
# whenever the enter key is pressed
# then call the focus2 function
family_name_field.bind("<Return>", focus2)
# whenever the enter key is pressed
# then call the focus3 function
email_field.bind("<Return>", focus3)
# grid method is used for placing
# the widgets at respective positions
# in table like structure .
first_name_field.grid(row=1, column=1, ipadx="100")
family_name_field.grid(row=2, column=1, ipadx="100")
email_field.grid(row=3, column=1, ipadx="100")
# create a Submit Button and place into the root window
submit = Button(root_reg, text="Submit", fg="Black", bg="Red", command= lambda : insert(id) )
submit.grid(row=8, column=1)
back = Button(root_reg, text="<--", fg="Black", bg="Red", command= lambda: switch_windows(root_reg, main_gui) )
back.grid(row=9, column=1)
# start the GUI
root_reg.mainloop()
"""
def bluetooth_gui():
root_bluetooth = Tk()
root_bluetooth.configure(background='light green')
root_bluetooth.title("Register bluetooth")
root_bluetooth.geometry("500x300")
msg = Label(root_bluetooth, text="Please scan your finger on the fingerprint scanner. After couple of seconds lift the finger and then scan again. Repeat the proccess until you see a registration form on thisi screen", fg="red", background="light green")
msg.place(relx=.5, rely=.5, anchor="center")
msg.config(font=("Courier", 50))
time.sleep(5))
print("a")
root_bluetooth.mainloop()
bluetooth_gui()
"""
def email_send_gui():
global root_email_send
if os.path.isfile("data.json") == False :
data={}
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
# create a GUI window
root_email_send = Tk()
# set the background colour of GUI window
root_email_send.configure(background='light green')
# set the title of GUI window
root_email_send.title("Bypass code")
# set the configuration of GUI window
root_email_send.geometry("500x300")
# create a Form label
heading = Label(root_email_send, text="Bypass form", bg="light green")
# create an email label
email = Label(root_email_send, text="Email", bg="light green")
# grid method is used for placing
# the widgets at respective positions
# in table like structure .
heading.grid(row=0, column=1)
email.grid(row=1, column=0)
# create a text entry box
# for typing the information
email_field = Entry(root_email_send)
# bind method of widget is used for
# the binding the function with the events
# grid method is used for placing
# the widgets at respective positions
# in table like structure .
email_field.grid(row=1, column=1, ipadx="100")
# create a Submit Button and place into the root window
submit = Button(root_email_send, text="Submit", fg="Black", bg="Red", command= lambda: (send_email(email_field.get()), switch_windows(root_email_send, root_main) ) )
submit.grid(row=8, column=1)
back = Button(root_email_send, text="<--", fg="Black", bg="Red", command=lambda: switch_windows(root_email_send, main_gui))
back.grid(row=9, column=1)
# start the GUI
root_email_send.mainloop()
def email_auth_gui():
global root_email_auth
if os.path.isfile("data.json") == False :
data={}
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
# Function to set focus (cursor)
def focus1(event):
# set focus on the course_field box
code_field.focus_set()
# Function for clearing the
# contents of text entry boxes
def clear():
# clear the content of text entry box
email_field.delete(0, END)
code_field.delete(0, END)
# Function to take data from GUI
# window and write to an excel file
def validate_email_code():
# if user not fill any entry
# then print "empty input"
email_input=email_field.get()
code_input=code_field.get()
with open('./data.json') as json_file:
data = json.load(json_file)
email_in_database=False
for id in data:
if email_input == data[id]["email"]:
if "code" in data[id]:
if data[id]["code"] == str(code_input):
print("Welcome %s %s" % (data[id]["first_name"], data[id]["family_name"]))
del data[id]["code"]
del data[id]["code_timestamp"]
email_in_database = True
if email_in_database == False:
print("This email is not recognised in our database")
with open('./data.json', 'w') as outfile:
json.dump(data, outfile)
# call the clear() function
clear()
root_email_auth.destroy()
# create a GUI window
root_email_auth = Tk()
# set the background colour of GUI window
root_email_auth.configure(background='light green')
# set the title of GUI window
root_email_auth.title("Bypass code")
# set the configuration of GUI window
root_email_auth.geometry("500x300")
# create a Form label
heading = Label(root_email_auth, text="Bypass form", bg="light green")
# create an email label
email = Label(root_email_auth, text="Email", bg="light green")
# create a code label
code = Label(root_email_auth, text="Code", bg="light green")
# grid method is used for placing
# the widgets at respective positions
# in table like structure .
heading.grid(row=0, column=1)
email.grid(row=1, column=0)
code.grid(row=2, column=0)
# create a text entry box
# for typing the information
email_field = Entry(root_email_auth)
code_field = Entry(root_email_auth)
# bind method of widget is used for
# the binding the function with the events
# whenever the enter key is pressed
# then call the focus1 function
email_field.bind("<Return>", focus1)
# grid method is used for placing
# the widgets at respective positions
# in table like structure .
email_field.grid(row=1, column=1, ipadx="100")
code_field.grid(row=2, column=1, ipadx="100")
# create a Submit Button and place into the root window
submit = Button(root_email_auth, text="Submit", fg="Black", bg="Red", command=validate_email_code)
submit.grid(row=8, column=1)
back = Button(root_email_auth, text="<--", fg="Black", bg="Red", command=lambda: switch_windows(root_email_auth, main_gui))
back.grid(row=9, column=1)
# start the GUI
root_email_auth.mainloop()
main_gui()