2022-07-25 13:36:42 +00:00
|
|
|
from lib.helpers import timing
|
|
|
|
|
from PyQt5.QtGui import QKeySequence
|
|
|
|
|
from PyQt5.QtWidgets import QShortcut
|
|
|
|
|
from ui.test_test import Test_Test
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Test_Barcodes(Test_Test):
|
2022-09-06 13:15:01 +00:00
|
|
|
def __init__(self, components=None, recipe=None, step=None, run_once=False, enable_override=False):
|
|
|
|
|
super().__init__(components=components, recipe=recipe, step=step, run_once=run_once, enable_override=enable_override)
|
2022-07-25 13:36:42 +00:00
|
|
|
self.barcodes_spec = {
|
|
|
|
|
"serial": self.check_serial_barcode
|
|
|
|
|
}
|
|
|
|
|
QShortcut(QKeySequence("Return"), self).activated.connect(self.get)
|
|
|
|
|
QShortcut(QKeySequence("Enter"), self).activated.connect(self.get)
|
|
|
|
|
self.barcodes_le.setFocus()
|
|
|
|
|
|
|
|
|
|
def start(self, recipe=None, step=None):
|
|
|
|
|
super().start(recipe=recipe, step=step)
|
2022-08-24 10:59:16 +00:00
|
|
|
if self.run_once is True and self.done is True and self.done_ok is True:
|
|
|
|
|
return
|
2022-07-26 14:05:04 +00:00
|
|
|
self.visualize()
|
2022-07-25 13:36:42 +00:00
|
|
|
self.barcodes_le.setPalette(self.status_palettes[None])
|
|
|
|
|
self.barcodes_le.setText("")
|
|
|
|
|
self.barcodes_le.setFocus()
|
2022-09-13 10:39:09 +00:00
|
|
|
# TESTING
|
2022-09-13 10:40:33 +00:00
|
|
|
if "--test-barcodes" in sys.argv or "--test" in sys.argv:
|
2022-09-13 10:39:09 +00:00
|
|
|
self.barcodes_le.setText("-----TEST_BARCODE-----")
|
|
|
|
|
self.test_timer = QTimer()
|
|
|
|
|
self.test_timer.setSingleShot(True)
|
|
|
|
|
self.test_timer.timeout.connect(self.get)
|
|
|
|
|
self.test_timer.start(500)
|
|
|
|
|
# /TESTING
|
2022-07-25 13:36:42 +00:00
|
|
|
|
|
|
|
|
# def stop(self):
|
|
|
|
|
# super().stop()
|
|
|
|
|
|
2022-08-24 10:59:16 +00:00
|
|
|
def reset(self):
|
|
|
|
|
super().reset()
|
|
|
|
|
self.barcodes = {}
|
|
|
|
|
|
2022-07-25 13:36:42 +00:00
|
|
|
def get(self, data=None, override=False):
|
2022-07-27 12:54:19 +00:00
|
|
|
if self.done: # avoid proccessing if completed
|
2022-07-25 13:36:42 +00:00
|
|
|
return
|
|
|
|
|
if data is None:
|
|
|
|
|
data = self.barcodes_le.text()
|
|
|
|
|
if not len(data):
|
|
|
|
|
data = None
|
|
|
|
|
if data is None:
|
|
|
|
|
super().get(None, override=override)
|
|
|
|
|
return
|
|
|
|
|
barcode_ok = False
|
|
|
|
|
for barcode_name, barcode_check in self.barcodes_spec.items():
|
|
|
|
|
if barcode_check(data):
|
|
|
|
|
self.barcodes[barcode_name] = data
|
|
|
|
|
barcode_ok = True
|
|
|
|
|
break
|
|
|
|
|
if barcode_ok:
|
|
|
|
|
self.barcodes_le.setPalette(self.status_palettes[True])
|
|
|
|
|
else:
|
|
|
|
|
self.barcodes_le.setPalette(self.status_palettes[False])
|
|
|
|
|
self.barcodes_le.setText("")
|
|
|
|
|
self.barcodes_le.setFocus()
|
|
|
|
|
if len(self.barcodes_spec.keys() - self.barcodes.keys()) == 0:
|
|
|
|
|
result = self.barcodes
|
|
|
|
|
ok = True
|
|
|
|
|
else:
|
|
|
|
|
result = None
|
|
|
|
|
ok = None
|
|
|
|
|
super().get([{
|
|
|
|
|
"time": timing(),
|
|
|
|
|
"results": {
|
|
|
|
|
"ok": ok,
|
|
|
|
|
"result": result,
|
|
|
|
|
"data": self.barcodes,
|
|
|
|
|
},
|
|
|
|
|
}], override=override, fail=ok is False)
|
|
|
|
|
|
|
|
|
|
def visualize(self, data=None):
|
|
|
|
|
if data is None:
|
|
|
|
|
data = {}
|
|
|
|
|
d = data.get("results", {}).get("data", {})
|
|
|
|
|
for k, l in {
|
|
|
|
|
"serial": self.serial_l,
|
|
|
|
|
}.items():
|
|
|
|
|
l.setText(str(d.get(k, "-")))
|
|
|
|
|
super().visualize(data)
|
|
|
|
|
|
|
|
|
|
def check_serial_barcode(self, barcode=None):
|
|
|
|
|
return barcode is not None and len(barcode)
|