From 1edfb24415fb57c0004201a5d7d1fa2e96a39f2e Mon Sep 17 00:00:00 2001 From: matteo porta Date: Wed, 27 Jul 2022 14:54:19 +0200 Subject: [PATCH] wip --- src/components/vision.py | 2 +- src/lib/db/__init__.py | 20 ---------- src/main.py | 2 +- src/ui/recipe_selection/recipe_selection.py | 7 ++-- src/ui/test/test.py | 3 +- src/ui/test_barcodes/test_barcodes.py | 3 +- src/ui/test_barcodes/test_barcodes.ui | 6 +++ src/ui/test_leak/test_leak.py | 4 +- src/ui/test_leak/test_leak.ui | 41 +++++++-------------- src/ui/test_test/test_test.py | 10 ++++- src/ui/test_vision/test_vision.py | 24 ++++++++++-- 11 files changed, 57 insertions(+), 65 deletions(-) diff --git a/src/components/vision.py b/src/components/vision.py index 5290881..9d01c1b 100644 --- a/src/components/vision.py +++ b/src/components/vision.py @@ -556,7 +556,7 @@ class Vision(Component): zone = self.zones[item_name] items[str(item_name)] = { "center": zone["center"], - "size": [s + 100 for s in zone["size"]], + "size": zone["size"], "shape": zone["shape"], **style, "border_color": Qt.green if item["ok"] else Qt.red, diff --git a/src/lib/db/__init__.py b/src/lib/db/__init__.py index 14841e6..12c45f0 100644 --- a/src/lib/db/__init__.py +++ b/src/lib/db/__init__.py @@ -61,26 +61,6 @@ if admin is None or not admin.is_admin: Users.register(username="USER", password="user") -# Recipes.replace( -# id=0, -# name="Ferrari 923578", -# client="Ferrari", -# part_number="923578", -# spec={"steps": []}, -# description="Tubo plastica doppia biforcazione con termorestringente centrale", -# archived=False, -# ).execute() -# Recipes.replace( -# id=1, -# name="BLOW-BY 5802814210", -# client="", -# part_number="5802814210", -# spec={"steps": []}, -# description="Tubo blow-by", -# archived=False, -# ).execute() - - if True: # crud_db must be imported after db and models_reference are available from .crud_db import Crud_DB diff --git a/src/main.py b/src/main.py index 972f6f5..dda030e 100644 --- a/src/main.py +++ b/src/main.py @@ -77,7 +77,7 @@ try: self.config = ConfigReader() # INIT COMPONENT self.components_specs = { - # "archive_synchronizer": {"c": ArchiveSynchronizer}, + "archive_synchronizer": {"c": ArchiveSynchronizer}, "galaxy_camera": {"c": GalaxyCamera, "k": {"paused": True}}, "label_printer": {"c": Os_Label_Printer, "t": False}, "neo_pixels": {"c": NeoPixels, "t": False}, diff --git a/src/ui/recipe_selection/recipe_selection.py b/src/ui/recipe_selection/recipe_selection.py index 028341e..83b4902 100755 --- a/src/ui/recipe_selection/recipe_selection.py +++ b/src/ui/recipe_selection/recipe_selection.py @@ -1,5 +1,6 @@ +import os import sys -from glob import iglob +from glob import glob from lib.db import Recipes, Users from PyQt5.QtCore import QTimer, pyqtSignal @@ -51,8 +52,8 @@ class Recipe_Selection(Widget): "spec": { "step_editors": { "vision": { - # "recipe": iglob("*.ini", root_dir="./config/vision/recipes/"), # only in python3.10 - "recipe": list(iglob("./config/vision/recipes/*.ini")), + # "recipe": sorted(glob("*.ini", root_dir="./config/vision/recipes/") + glob("*.INI", root_dir="./config/vision/recipes/")), # only in python3.10 + "recipe": sorted(map(os.path.basename, glob("./config/vision/recipes/*.ini") + glob("./config/vision/recipes/*.INI"))), }, }, }, diff --git a/src/ui/test/test.py b/src/ui/test/test.py index 4ad7dc4..1dc7b5d 100755 --- a/src/ui/test/test.py +++ b/src/ui/test/test.py @@ -48,7 +48,6 @@ class Test(Widget): "print": Test_Assembly(self.select_step_img("print"), u"STAMPA ETICHETTA IN CORSO"), "select_recipe": Test_Assembly(None, u"SELEZIONARE IL CODICE DA COLLAUDARE", Recipe_Selection()), "vision": Test_Assembly(None, u"VERIFICARE CONTROLLO CON TELECAMERA", Test_Vision(components=self.components, recipe=self.recipe, step=self.step)), - "wait_start": Test_Assembly(self.select_step_img("wait_start"), u"PREMERE START PER INIZIARE PROVA TENUTA"), "wait": Test_Assembly(self.select_step_img("wait"), u"ATTENDERE - PAUSA INTER CICLO"), None: Test_Assembly(self.select_step_img("warning"), u"ATTENZIONE - LA RICETTA SELEZIONATA NON CONTIENE FASI DI TEST"), } @@ -296,7 +295,7 @@ class Test(Widget): "TTEST": str(self.data.get("leak", [{}, {}])[0].get("step", {}).get("spec", {}).get("test_time", "-")), "MAXLEAK": str(self.data.get("leak", [{}, {}])[0].get("step", {}).get("spec", {}).get("test_pressure_max_delta", "-")), "PTESTMIN": str(self.data.get("leak", [{}, {}])[0].get("step", {}).get("spec", {}).get("test_pressure_min_delta", "-")), - "RESULT_L1": "ESITO", + "RESULT_L1": "ESITO" + str(" FORZATO" if self.data.get("overridden", False) else ""), "RESULT_L2": str("CONFORME" if self.data.get("leak", [{}, {}])[0].get("results", {}).get("ok", False) else "SCARTO"), } self.components["label_printer"].print_label("EtichettaR5", context=context) diff --git a/src/ui/test_barcodes/test_barcodes.py b/src/ui/test_barcodes/test_barcodes.py index bfde4ec..50d6c5a 100644 --- a/src/ui/test_barcodes/test_barcodes.py +++ b/src/ui/test_barcodes/test_barcodes.py @@ -26,8 +26,7 @@ class Test_Barcodes(Test_Test): # super().stop() def get(self, data=None, override=False): - if self.ok_timer.isActive(): - # avoid proccessing if completed + if self.done: # avoid proccessing if completed return if data is None: data = self.barcodes_le.text() diff --git a/src/ui/test_barcodes/test_barcodes.ui b/src/ui/test_barcodes/test_barcodes.ui index 3cd0254..994686b 100644 --- a/src/ui/test_barcodes/test_barcodes.ui +++ b/src/ui/test_barcodes/test_barcodes.ui @@ -32,6 +32,12 @@ + + + 0 + 0 + + Stato diff --git a/src/ui/test_leak/test_leak.py b/src/ui/test_leak/test_leak.py index cbd34f5..97dd767 100644 --- a/src/ui/test_leak/test_leak.py +++ b/src/ui/test_leak/test_leak.py @@ -15,7 +15,6 @@ class Test_Leak(Test_Test): self.components["tecna_t3"].write_recipe(self.recipe, self.step) self.get_connection = self.components["tecna_t3"].out.connect(self.get) self.components["tecna_t3"].resume() - self.components["tecna_t3"].start_test() def stop(self): # disable tes loop @@ -25,8 +24,7 @@ class Test_Leak(Test_Test): super().stop() def get(self, data=None, override=False): - if self.ok_timer.isActive(): - # avoid proccessing if completed + if self.done: # avoid proccessing if completed return if data is None or data[-1] is None: super().get(None, override=override) diff --git a/src/ui/test_leak/test_leak.ui b/src/ui/test_leak/test_leak.ui index 2cad037..022405d 100644 --- a/src/ui/test_leak/test_leak.ui +++ b/src/ui/test_leak/test_leak.ui @@ -6,7 +6,7 @@ 0 0 - 322 + 244 456 @@ -475,32 +475,6 @@ - - - - - 0 - 0 - - - - SALVA IMMAGINE - - - - - - - - 0 - 0 - - - - FORZA ACCETTAZIONE - - - @@ -1150,6 +1124,19 @@ + + + + + 0 + 0 + + + + FORZA ACCETTAZIONE + + + diff --git a/src/ui/test_test/test_test.py b/src/ui/test_test/test_test.py index d590dda..2acd5a2 100644 --- a/src/ui/test_test/test_test.py +++ b/src/ui/test_test/test_test.py @@ -21,6 +21,7 @@ class Test_Test(Widget): self.ok_counter = 0 self.ok_counter_limit = 1 # setup controls + self.done = False self.ok_timer = QTimer() self.ok_timer.setSingleShot(True) self.ok_timer.setInterval(2000) @@ -65,6 +66,8 @@ class Test_Test(Widget): self.recipe = recipe self.step = step self.ok_counter = 0 + self.done = False + self.override_b.setEnabled(True) self.visualize() # start test self.start_time = timing() @@ -78,8 +81,7 @@ class Test_Test(Widget): pass def get(self, data=None, override=False, fail=False): - if self.ok_timer.isActive() or self.ko_timer.isActive(): - # avoid proccessing if completed + if self.done: # avoid proccessing if completed return if data is None: data = self.last if self.last is not None else {} @@ -113,9 +115,13 @@ class Test_Test(Widget): self.ok_counter = 0 # check if completed if fail: + self.done = True + self.override_b.setEnabled(False) self.stop() self.ko_timer.start() elif self.ok_counter >= self.ok_counter_limit: + self.done = True + self.override_b.setEnabled(False) self.stop() self.ok_timer.start() self.visualize(self.last) diff --git a/src/ui/test_vision/test_vision.py b/src/ui/test_vision/test_vision.py index 9d7b9e7..3d1ebdf 100644 --- a/src/ui/test_vision/test_vision.py +++ b/src/ui/test_vision/test_vision.py @@ -22,7 +22,8 @@ class Test_Vision(Test_Test): self.components["galaxy_camera"].add_sources({"test_vision": self.request_frame}) self.request_frame_connection = self.components["vision"].out.connect(self.request_frame) # request new frame as soon as vision finishes self.get_connection = self.components["vision"].out.connect(self.get) - self.components["vision"].set_recipe(self.step.spec.get("recipe", "1.ini")) + self.components["neo_pixels"].set_all_pixel_color("#ffffff") + self.components["vision"].set_recipe(self.step.spec.get("recipe", None)) self.components["vision"].resume() self.components["galaxy_camera"].resume() self.request_frame.emit() # request first frame @@ -37,8 +38,7 @@ class Test_Vision(Test_Test): super().stop() def get(self, data=None, override=False): - if self.ok_timer.isActive(): - # avoid proccessing if completed + if self.done: # avoid proccessing if completed return if data is None or data[-1] is None: super().get(None, override=override) @@ -72,6 +72,15 @@ class Test_Vision(Test_Test): )) else: img = self.status_imgs_full[None] + if self.done: + if data.get("overridden", False): + self.components["neo_pixels"].set_all_pixel_color("#ffff00") + elif self.ok_counter >= self.ok_counter_limit: + self.components["neo_pixels"].set_all_pixel_color("#00ff00") + else: + self.components["neo_pixels"].set_all_pixel_color("#ff0000") + else: + self.components["neo_pixels"].set_all_pixel_color("#ffffff") super().visualize(data, img=img) def save_last(self): @@ -81,4 +90,11 @@ class Test_Vision(Test_Test): def emit_ok(self): self.last.pop("frame", None) self.last.pop("render", None) - self.ok.emit(self.last) + super().emit_ok() + self.components["neo_pixels"].set_all_pixel_color("#000000") + + def emit_ko(self): + self.last.pop("frame", None) + self.last.pop("render", None) + super().emit_ko() + self.components["neo_pixels"].set_all_pixel_color("#000000")