-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScannerGUI.py
executable file
·216 lines (187 loc) · 5.49 KB
/
ScannerGUI.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
#!/usr/bin/python
from appJar import gui
from threading import Lock
from threading import Thread
import sambaThread
import time
from datetime import datetime
import dbfSqliter
import sqlite3
dbfLock = Lock()
BARCODE_URL = 'barcodes.db'
PRODUCT_FILES = ['BARCODES.dbf', 'LIQCODE.dbf']
class product:
def __init__(self):
self.brand = ''
self.descrip = ''
self.qty = None
self.singlePrice = None
self.casePrice = None
self.price = None
self.dep = False
self.depAmt = None
self.barcode = ''
self.code_num = ''
self.found = False
def setSinglePrice(self, price):
if not self.singlePrice:
self.singlePrice = price
def setPrice(self, price):
if not self.price:
if price:
self.price = price
def setCasePrice(self, price):
if not self.casePrice:
self.casePrice = price
def setQty(self, qty):
if not self.qty:
if not qty <= 0:
self.qty = qty
else:
self.qty = 1
def setDep(self, d, amt):
if d == 'Y':
self.dep = True
if amt != 0:
self.depAmt = amt
def makeProduct(self, bar):
barcodeSel = 'SELECT * FROM BARCODES WHERE BARCODE = "'
liqcodeSel = 'SELECT * FROM LIQCODE WHERE CODE_NUM = "'
conn = sqlite3.connect(BARCODE_URL)
conn.execute('PRAGMA read_uncommitted = true;')
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute(barcodeSel+bar+'";')
barc = c.fetchall()[-1]
self.barcode = bar
if barc and (not barc['DeletionFlag'] or barc['DeletionFlag']==0):
self.found = True
self.code_num = barc['CODE_NUM']
self.setPrice(barc['PRICE'])
c.execute(barcodeSel+'S'+bar+'";')
barc = c.fetchone()
if barc:
self.setSinglePrice(barc['PRICE'])
c.execute(barcodeSel+'C'+bar+'";')
barc = c.fetchone()
if barc:
self.setCasePrice(barc['PRICE'])
c.execute(liqcodeSel+self.code_num+'";')
liqc = c.fetchone()
if liqc and (not liqc['DeletionFlag'] or liqc['DeletionFlag']==0):
self.brand = liqc['BRAND']
self.descrip = liqc['DESCRIP']
self.setQty(liqc['STD_QTY'])
self.setPrice(liqc['PRICE'])
self.setDep(liqc['DEPOSIT'], liqc['DEP_AMT'])
else:
self.found = False
else:
self.found = False
conn.close()
return
def makePrice(self, price):
if not price:
return 'N/A'
else:
return '${:.2f}'.format(price)
def makeQty(self):
if not self.qty:
return str(1)
else:
return str(self.qty)
def makeDeposit(self):
if self.dep:
if not self.depAmt:
return '${:.2f}'.format(int(self.makeQty())*0.05)
else:
return '${:.2f}'.format(int(self.makeQty())*self.depAmt)
else:
return 'N/A'
def __str__(self):
if not self.found:
return('Product Not Found :(\nPlease ask associate for help\nBarcode: '+self.barcode)
s = 'Brand: ' + self.brand + '\n'
s += 'Description: ' + self.descrip + '\n'
s += 'Qty: ' + self.makeQty() + '\n'
s += 'Price: ' + self.makePrice(self.price) + '\n'
s += 'Single Price: ' + self.makePrice(self.singlePrice) + '\n'
s += 'Case Price: ' + self.makePrice(self.casePrice) + '\n'
s += 'Deposit: ' + self.makeDeposit() + '\n'
s += 'Barcode: ' + self.barcode + '\n'
return s
def meter(meterPercent):
app.queueFunction(app.showMeter, "progress")
app.queueFunction(app.setMeter, "progress", meterPercent)
if meterPercent == 100:
app.queueFunction(app.hideMeter, "progress")
def findProduct():
bar = app.getEntry("Barcode")
prod = product()
prod.makeProduct(bar)
return(str(prod))
def updateMessage(mess):
app.queueFunction(app.setMessage, "prod", mess)
app.queueFunction(app.setEntry, "Barcode", "")
def entryFunc():
app.threadCallback(findProduct, updateMessage)
def fileWorker():
time.sleep(150)
app.queueFunction(app.setStatusbar, "File Sync: Updating", field=0)
with dbfLock:
s = sambaThread.samb()
status = s.getFile()
if status:
app.queueFunction(app.setStatusbar, "File Sync: Updated", field=0)
else:
app.queueFunction(app.setStatusbar, "File Sync: Failed!", field=0)
time.sleep(150)
fileWorker()
def updateDB():
app.queueFunction(app.setStatusbar, "DB Sync: Importing Products", field=1)
for f in PRODUCT_FILES:
with dbfLock:
q = dbfSqliter.sqler()
d = dbfSqliter.reader(f)
if d.recordsAdded():
print "Records added in "+f+", adding new entries to db..."
q.insertRows(d)
del d
del q
app.queueFunction(app.setStatusbar, "DB Sync: Imported "+f, field=1)
app.queueFunction(app.setStatusbar, "DB Sync: Products Imported", field=1)
time.sleep(300)
def updateDBDelete():
hour = datetime.now().hour
if not (hour >= 2 and hour <= 4):
time.sleep((2 - hour) % 24)
else:
app.queueFunction(app.setStatusbar, "Checking Deleted Entries...", field=2)
for f in PRODUCT_FILES:
with dbfLock:
q = dbfSqliter.sqler()
d = dbfSqliter.reader(f)
q.updateDelete(d)
app.queueFunction(app.setStatusbar, "DB Delete: Updated "+f, field=2)
app.queueFunction(app.setStatusbar, "DB Delete: Updated", field=2)
if __name__ == "__main__":
app = gui("Downtown Wine & Spirits Price Scanner", "667x400")
app.setSize("fullscreen")
app.addLabel("testLabel", "Scan barcode")
app.addMeter("progress")
app.setMeterFill("progress", "green")
app.addLabelEntry("Barcode")
app.setEntryWidth('Barcode', 200)
app.setEntryUpperCase("Barcode")
app.setFocus("Barcode")
app.setEntrySubmitFunction("Barcode", entryFunc)
app.hideMeter("progress")
app.addMessage("prod", "")
app.setMessageAnchor('prod', 'center')
app.setMessageSticky('prod', 'both')
app.setMessageWidth('prod', 400)
app.addStatusbar(fields=3, side="left")
app.thread(fileWorker)
app.thread(updateDB)
app.thread(updateDBDelete)
app.go()