-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_gui.py
565 lines (436 loc) · 16 KB
/
main_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
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
"""
Coder : ENG.Mahmoud | Eng.Hager
Version : v2.0B
version Date : 19 / 5 / 2023
Code Type : python
Title : Smart Parking System
Interpreter : cPython v3.11.0 [Compiler : MSC v.1933 AMD64]
"""
import os , sys
import tkinter as tk
from tkinter import messagebox
import random
import ocr_cv
import parking_db as db
import communication as arduino
def message(window,text,type):
'''
type:
0 => error
1 => message
'''
color = '#72fb6f'
if(type == 0):
color = '#ffb0b0'
l_m = tk.Label(window, text=text, font=('Arial',10, 'bold'), bg=color, fg='#2a0000', borderwidth=10)
l_m.place(x=50, y=50)
window.update()
window.after(3000,l_m.destroy)
def park_wait_page():
global l_8
global done_b
# define page
global p_page_2
p_page_2 = tk.Tk()
p_page_2.configure(bg='#000F35')
p_page_2.geometry(f"{screen_w}x{screen_h}+0+0")
p_page_2.title("parking Page.2")
p_page_2.iconbitmap('icon_1.ico')
p_page_2.attributes('-fullscreen', True)
global error_type
global text_error
if (error_type == 1):
message(p_page_2,text_error,0)
error_type = 0
text_error = ''
elif (error_type==2):
message(p_page_2,text_error,1)
error_type = 0
text_error = ''
#################################
# wait word
l_3 = tk.Label(p_page_2, text='WAIT', font=('Arial', 150, 'bold'), bg='#000F35', fg='#FAFF00', borderwidth=0)
l_3.place(x=(screen_w / 2)-240, y=(screen_h / 2)-150)
def done():
l_8.destroy()
done_b.destroy()
l_9 = tk.Label(p_page_2, text='WAIT', font=('Arial', 150, 'bold'), bg='#000F35', fg='#FAFF00', borderwidth=0)
l_9.place(x=(screen_w / 2) - 240, y=(screen_h / 2) - 150)
def park():
'''arduino code'''
try:
arduino.park(user_info['park_cell']+1)
except:
p_page_2.destroy()
global error_type
global text_error
error_type = 1
text_error = 'Error in arduino'
root_page()
return 0
#########################
l_9.destroy()
l_4 = tk.Label(p_page_2, text='DONE', font=('Arial', 150, 'bold'), bg='#000F35', fg='#04B400', borderwidth=0)
l_4.place(x=(screen_w / 2) - 240, y=(screen_h / 2) - 150)
def destroy_l():
p_page_2.destroy();root_page()
p_page_2.after(5000, destroy_l)
p_page_2.after(100, park)
def park_now():
'''arduino code'''
try:
arduino.prepare_for_parknig(user_info['park_cell']+1)
except:
p_page_2.destroy()
global error_type
global text_error
error_type = 1
text_error = 'Error in arduino'
root_page()
return 0
#########################
l_3.destroy()
global l_8
global done_b
l_8 = tk.Label(p_page_2, text='Park car now', font=('Arial', 50, 'bold'), bg='#000F35', fg='#FAFF00',borderwidth=0)
l_8.place(x=(screen_w / 2) - 200, y=(screen_h / 4))
done_b = tk.Button(p_page_2, text='Done', font=('Arial', 16, 'bold'), bg='#04B400', fg='white',borderwidth=0)
done_b.configure(command=done)
done_b.place(x=(screen_w / 2) - 70, y=(screen_h / 2) + 50,width=screen_w/9,height=screen_h/15)
# will change to 10 after add arduino
p_page_2.after(1000,park_now)
p_page_2.mainloop()
def park_page_1():
#define page
global p_page_1
p_page_1 = tk.Tk()
p_page_1.configure(bg='#000F35')
p_page_1.geometry(f"{screen_w}x{screen_h}+0+0")
p_page_1.title("parking Page.1")
p_page_1.iconbitmap('icon_1.ico')
p_page_1.attributes('-fullscreen', True)
global error_type
global text_error
if (error_type == 1):
message(p_page_1,text_error,0)
error_type = 0
text_error = ''
elif (error_type==2):
message(p_page_1,text_error,1)
error_type = 0
text_error = ''
#################################
# show password
l_1 = tk.Label(p_page_1,text='Please save this password',font=('Arial',12),bg='#000F35',fg='#FF4141', borderwidth=0)
l_1.place(x=(screen_w/2)-90,y=(screen_h/4)-100)
password = str(random.randint(1000,9999))
user_info['password']= password
l_2 = tk.Label(p_page_1,text=f'{password}',font=('Arial',90,'bold'),bg='#000F35',fg='#FAFF00', borderwidth=0)
l_2.place(x=(screen_w / 2)-125, y=(screen_h / 4)-20)
#####################
l_4 = tk.Label(p_page_1, text='Password will be sent to your E-mail.', font=('Arial', 12), bg='#000F35', fg='#04B400',borderwidth=0)
l_4.place(x=(screen_w / 2) - 110, y=(screen_h /2)-30)
def b_park_2():
p_page_1.destroy()
'''add user_info to DB'''
user_info['park_cell']= db.db_cmd(0,user_info['id'],password)[0]
global error_type
global text_error
if(user_info['park_cell']==-1):
error_type = 1
text_error = f'User ID \'{user_info["id"]}\' Not found or Already in Parking .'
root_page()
return 0
#########################
park_wait_page()
# define continue parking button
park_2 = tk.Button(p_page_1, text='Park Now',font=('Arial',16,'bold'),bg='#04B400',fg='white', borderwidth=0)
park_2.configure(command=b_park_2)
park_2.place(x=(screen_w/2)-70,y=(screen_h/2)+50,width=screen_w/9,height=screen_h/15)
###################################
def b_cancel():
p_page_1.destroy()
global error_type
global text_error
error_type = 1
text_error = f'Order is canceled'
root_page()
# define cancel button
cancel = tk.Button(p_page_1, text='Cancel',font=('Arial',16,'bold'),bg='#D40101',fg='white', borderwidth=0)
cancel.configure(command=b_cancel)
cancel.place(x=(screen_w/2)-70,y=(screen_h/4)*3-50,width=screen_w/9,height=screen_h/15)
###################################
p_page_1.mainloop()
def park_button():
if(db.db_cmd(2)) :
message(root,'Parking is full',0)
return 0
root.destroy()
ocr_cv.testing_mode = False
ocr_cv.sec_passed = 0
id = ocr_cv.ocr_main()
#id=('11111111111111',True)
user_info['id']=id[0]
global error_type
global text_error
if(id[1]):
error_type = 2
text_error = f'Your ID is {id[0]}'
park_page_1()
else:
error_type = 1
text_error = 'Not found id , Try again'
root_page()
def get_wait_page():
global l_g_8
# define page
global g_page_2
g_page_2 = tk.Tk()
g_page_2.configure(bg='#000F35')
g_page_2.geometry(f"{screen_w}x{screen_h}+0+0")
g_page_2.title("GET Page.2")
g_page_2.iconbitmap('icon_1.ico')
g_page_2.attributes('-fullscreen', True)
global error_type
global text_error
if (error_type == 1):
message(g_page_2,text_error,0)
error_type = 0
text_error = ''
elif (error_type==2):
message(g_page_2,text_error,1)
error_type = 0
text_error = ''
#################################
# wait word
l_3 = tk.Label(g_page_2, text='WAIT', font=('Arial', 150, 'bold'), bg='#000F35', fg='#FAFF00', borderwidth=0)
l_3.place(x=(screen_w / 2)-240, y=(screen_h / 2)-150)
def done():
'''arduino code'''
arduino.getcar(int(get_info[0])+1)
#########################
l_3.destroy()
l_4 = tk.Label(g_page_2, text='DONE', font=('Arial', 150, 'bold'), bg='#000F35', fg='#04B400', borderwidth=0)
l_4.place(x=(screen_w / 2) - 240, y=(screen_h / 2) - 150)
def destroy_l():
g_page_2.destroy();root_page()
g_page_2.after(5000, destroy_l)
# will change to 10 after add arduino
g_page_2.after(100,done)
g_page_2.mainloop()
def pay_page():
global pay_p
pay_p = tk.Tk()
pay_p.title("pay")
pay_p.configure(bg='#000F35')
pay_p.geometry(f"{screen_w}x{screen_h}")
pay_p.iconbitmap('icon_1.ico')
pay_p.attributes('-fullscreen', True)
global error_type
global text_error
if (error_type == 1):
message(pay_p,text_error,0)
error_type = 0
text_error = ''
elif (error_type==2):
message(pay_p,text_error,1)
error_type = 0
text_error = ''
def pay_b_func():
pay_p.destroy()
get_wait_page()
tk.Label(pay_p,text=f"Parking Time: {get_info[3]} hour/s ",font=('Arial',20,'bold'),bg='#000F35',fg='white').place(x=(screen_w / 2)-95, y=(screen_h / 4)+100)
tk.Label(pay_p,text=f"Parking Cost: {get_info[2]} $",font=('Arial',20,'bold'),bg='#000F35',fg='white').place(x=(screen_w / 2)-95, y=(screen_h /4)+200 )
pay_b=tk.Button(pay_p,
text="Pay ",
font=('Arial', 16, 'bold'),
bg='#04B400',
fg='white',
borderwidth=0,
command=pay_b_func)
pay_b.place(x=(screen_w / 2) - 70, y=(screen_h / 4) * 3 - 50,width=screen_w/9,height=screen_h/15)
pay_p.mainloop()
def password_page():
password_p = tk.Tk()
password_p.title("get car")
password_p.configure(bg='#000F35')
password_p.geometry(f"{screen_w}x{screen_h}")
password_p.iconbitmap('icon_1.ico')
password_p.attributes('-fullscreen', True)
global error_type
global text_error
if (error_type == 1):
message(password_p,text_error,0)
error_type = 0
text_error = ''
elif (error_type==2):
message(password_p,text_error,1)
error_type = 0
text_error = ''
def validate_numeric_input(value):
if value.isdigit():
return True
elif value == "":
return True
else:
return False
validate_command = password_p.register(validate_numeric_input)
tk.Label(password_p, text='ID', font=('Arial', 18, 'bold'), bg='#000F35', fg='#BBC2FE').place(
x=(screen_w / 2)-10, y=200)
entry_id = tk.Entry(password_p,font=('Arial', 14, 'bold'), validate="key", validatecommand=(validate_command, "%P"))
entry_id.place(x=(screen_w / 2)-150, y=240,width=300,height=30)
tk.Label(password_p, text='PASSWORD', font=('Arial', 18, 'bold'), bg='#000F35', fg='#BBC2FE').place(
x=(screen_w / 2) -70, y=300)
entry_password = tk.Entry(password_p, font=('Arial', 14, 'bold'), validate="key",validatecommand=(validate_command, "%P"))
entry_password.place(x=(screen_w / 2) - 150, y=340, width=300, height=30)
def enter_b_func():
id_user = entry_id.get()
password = entry_password.get()
if(id_user == "" or password == ""):
messagebox.showwarning("Warning", "EMPTY INPUT")
return 0
global get_info
get_info = db.db_cmd(1,id_user,password)
#get_info = (2, True, 50, 5)
if (get_info[0] == -1):
messagebox.showwarning("Warning", " User Doesn't Exist or Didn't Park here")
return 0
password_p.destroy()
pay_page()
enter_b = tk.Button(password_p,
text="Enter",
font=('Arial', 16, 'bold'),
bg='#04B400',
fg='white',
borderwidth=0,
command=enter_b_func)
enter_b.place(x=(screen_w / 2) - 70, y=(screen_h / 4) * 3 - 150,width=screen_w/9,height=screen_h/15)
def cancel():
password_p.destroy()
get_car_page()
btn3=tk.Button(password_p,
text="Cancel",
font = ('Arial', 16, 'bold'),
bg = '#D40101',
fg = 'white',
borderwidth = 0,
command=cancel)
btn3.place(x=(screen_w/2)-70,y=(screen_h/4)*3-50,width=screen_w/9,height=screen_h/15)
password_p.mainloop()
def get_car_page():
global get_car
get_car=tk.Tk()
get_car.title("get car")
get_car.configure(bg='#000F35')
get_car.geometry(f"{screen_w}x{screen_h}")
get_car.iconbitmap('icon_1.ico')
get_car.attributes('-fullscreen', True)
global error_type
global text_error
if (error_type == 1):
message(get_car, text_error, 0)
error_type = 0
text_error = ''
elif (error_type == 2):
message(get_car, text_error, 1)
error_type = 0
text_error = ''
def ocr_b():
get_car.destroy()
'''OCR'''
ocr_cv.testing_mode = False
global ocr_info
global get_info
ocr_cv.sec_passed = 0
ocr_info = ocr_cv.ocr_main()
#ocr_info=('11111111111111',True)
if (ocr_info[1]):
get_info = db.db_cmd(1,ocr_info[0])
#get_info = (2, True, 50, 5)
global error_type
global text_error
if (get_info[0] == -1):
error_type = 1
text_error = f'ID \'{ocr_info[0]}\' not found . Try Using password instead'
get_car_page()
return 0
error_type = 2
text_error = f'id : {ocr_info[0]}'
pay_page()
else:
error_type = 1
text_error = f'ID \'{ocr_info[0]}\' not found . Try Using password instead'
get_car_page()
##############
def password_b():
get_car.destroy()
password_page()
tk.Label(get_car,
text="Get it by",font=('Arial',30,'bold'),bg='#000F35',fg='#FF0000').place(x=(screen_w/8),y=(screen_h/2)-100)
btn1=tk.Button(get_car,
text="ID Card",
font=('Arial', 16, 'bold'),
bg='#04B400',
fg='white', borderwidth=0,
command=ocr_b)
btn1.place(x=(screen_w/3),y=(screen_h/2)-90,width=screen_w/9,height=screen_h/15)
btn2=tk.Button(get_car,
text="password",
font=('Arial', 16, 'bold'),
bg='#04B400',
fg='white', borderwidth=0,
command=password_b)
btn2.place(x=(screen_w/3)*2-120,y=(screen_h/2)-90,width=screen_w/9,height=screen_h/15)
def cancel():
get_car.destroy()
root_page()
btn3=tk.Button(get_car,
text="Cancel",
font = ('Arial', 16, 'bold'),
bg = '#D40101',
fg = 'white',
borderwidth = 0,
command=cancel)
btn3.place(x=(screen_w/2)-70,y=(screen_h/4)*3-50,width=screen_w/9,height=screen_h/15)
get_car.mainloop()
def root_page():
global root
root = tk.Tk()
# Get the screen geometry
global screen_w
global screen_h
screen_w = root.winfo_screenwidth()
screen_h = root.winfo_screenheight()
# Set the dimensions of the root
root.configure(bg='#000F35')
root.geometry(f"{screen_w}x{screen_h}+0+0")
root.attributes('-fullscreen', True)
root.title("Home Page")
root.iconbitmap('icon_1.ico')
global error_type
global text_error
if (error_type==1):
message(root,text_error,0)
error_type = 0
text_error=''
elif (error_type==2):
message(root,text_error,1)
error_type = 0
text_error=''
#define parking button
b_park = tk.Button(root, text='Park',font=('Arial',16,'bold'),bg='#04B400',fg='white', borderwidth=0)
b_park.configure(command=park_button)
b_park.place(x=(screen_w/2)-70,y=(screen_h/2)-50,width=screen_w/9,height=screen_h/15)
###################################
def get_car_button(): root.destroy();get_car_page()
#define getcar button
b_get = tk.Button(root, text='Get Car',font=('Arial',16,'bold'),bg='#D40101',fg='white', borderwidth=0)
b_get.configure(command=get_car_button)
b_get.place(x=(screen_w/2)-70,y=(screen_h/4)*3-50,width=screen_w/9,height=screen_h/15)
###################################
root.mainloop()
if __name__ == "__main__":
error_type = 0 # 0=> no error , 1=> error , 2=> message
text_error = ''
user_info ={'id':None,'password':None,'park_cell':None}
root_page()