-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
262 lines (192 loc) · 8.45 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
#!/usr/bin/env/ python3
#interface
import tkinter as tk
from tkinter import font as tkfont
from PIL import ImageTk,Image
#qrcode
import cv2
import numpy as np
from pyzbar.pyzbar import decode
import csv
import RPi.GPIO as GPIO
class custQLADZ:
def __init__(self,first='NaN',last='NaN',email='NaN',userID='NaN'):
self.first = first
self.last = last
self.email = email
self.userID = userID
self.exists = False
class webcam:
def __init__(self,src=0):
self.cam = cv2.VideoCapture(src)
if not self.cam.isOpened():
print("Unable to open the camera")
self.cam.set(3,640)
self.cam.set(4,480)
def start(self):
global currCust
while self.stop:
#reading using cam if not QR it is empty list
success,img = self.cam.read()
#decode scanned img and it has QR (this will start when it gets a QR or it wont)
for barcode in decode(img):
#get the userID from barcode var
userID = barcode.data.decode('utf-8')
#check if this userID exists in data base
for cust in data:
#assign user data to the currect customer
currCust.first = cust[0]
currCust.last = cust[1]
currCust.email = cust[2]
currCust.userID = cust[3]
#if QR matched data then exit this data loop
if userID == currCust.userID:
self.stop = False
currCust.exists = True
break
#if the detected barcode matched break this cam loop
if currCust.exists:
break
cv2.imshow('Result',img)
cv2.waitKey(1)
def stopF(self):
self.cam.release()
cv2.destroyAllWindows()
class interQLADZ(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
#rasp resolution
self.geometry('800x480')
#program text
self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
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.frames = {}
for F in (HomePage,ScanPage,InfoPage,confirmPage,loadingPage):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("HomePage")
def getUserData(self,currCust):
strr ='Name: ' + str(currCust.first) + ' ' + str(currCust.last) + '\nEmail: ' + str(currCust.email) + '\nUserID: ' + str(currCust.userID)
return strr
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
global cam
global currCust
flag = 1
if page_name == 'loadingPage':
self.after(10000, self.show_frame, 'HomePage')
#hardware turn on LED
GPIO.output(40,GPIO.HIGH)
if page_name == 'HomePage':
#initialize(reset)
currCust.exists = False
#hardware turn off LED
GPIO.output(40,GPIO.LOW)
if page_name == 'ScanPage':
cam.stop = True
cam.start()
#turn off camera when getting user data and send it to infopage
if currCust.exists:
cam.stopF()
self.after(0, self.show_frame, 'InfoPage')
class HomePage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Welcome to Screen-Bozz",font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
qrButton = tk.Button(self,text="Scan your QR code",
command=lambda: controller.show_frame("ScanPage"))
payButton = tk.Button(self,text="Pay with cash")
qrButton.pack()
payButton.pack()
class ScanPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Please Scan your QR code",font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
backButton = tk.Button(self,text="Go back",
command=lambda: controller.show_frame("HomePage"))
backButton.pack()
print('scan')
class InfoPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Confirm your information",font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
global currCust
#show user data
strr = controller.getUserData(currCust)
userLabel = tk.Label(self, text=strr,font=controller.title_font)
userLabel.pack()
confirmButton = tk.Button(self,text="Confirm",
command=lambda: controller.show_frame("confirmPage"))
confirmButton.pack()
backButton = tk.Button(self,text="Start Over",
command=lambda: controller.show_frame("HomePage"))
backButton.pack()
class confirmPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Select your phone then start",font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
#implement hardware when confirmButtom is clicked (required self because of garbage collection)
self.phone1 = ImageTk.PhotoImage(Image.open('./images/phone1.png'))
self.phoneClick1 = ImageTk.PhotoImage(Image.open('./images/phone1-2.png'))
self.phone2 = ImageTk.PhotoImage(Image.open('./images/phone2.png'))
self.phoneClick2 = ImageTk.PhotoImage(Image.open('./images/phone2-2.png'))
self.phoneButt1 = tk.Button(self,image=self.phone1,command=lambda *args: self.setSize(1))
self.phoneButt2 = tk.Button(self,image=self.phone2,command=lambda *args: self.setSize(2))
self.phoneButt1.pack()
self.phoneButt2.pack()
confirmButton = tk.Button(self,text="Start Screen Chaning",
command=lambda: [controller.show_frame("loadingPage"),self.resetButtons()])
confirmButton.pack()
backButton = tk.Button(self,text="Go back",
command=lambda: [controller.show_frame("InfoPage"),self.resetButtons()])
backButton.pack()
print('confirm')
def setSize(self,size):
global phoneSize
#make sure the other one is not display as selected
self.resetButtons()
if size == 1:
phoneSize = 10
self.phoneButt1["image"] = self.phoneClick1
elif size == 2:
phoneSize = 12
self.phoneButt2["image"] = self.phoneClick2
def resetButtons(self):
self.phoneButt1["image"] = self.phone1
self.phoneButt2["image"] = self.phone2
class loadingPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Processing",font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
#global values
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, GPIO.LOW)
phoneSize = 0
cam = webcam()
currCust = custQLADZ()
data = []
with open('fdata.csv', newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in spamreader:
data.append(row)
if __name__ == "__main__":
app = interQLADZ()
app.mainloop()