diff --git a/config/machine_settings/recipes_defaults.csv b/config/machine_settings/recipes_defaults.csv index d0f639e..bc2dc16 100644 --- a/config/machine_settings/recipes_defaults.csv +++ b/config/machine_settings/recipes_defaults.csv @@ -1,2 +1,2 @@ -codice_ricetta,cliente,part_number,verifica_connettore_abilitata,connettore,verifica_codice_a_barre_abilitata,codice_a_barre,avvitatura_abilitata,viti,verifica_resistenza_connettore_abilitata,scala_resistenza,resistenza_attesa,tolleranza_resistenza,prova_tenuta_abilitata,tempo_pre_riempimento,pressione_pre_riempimento,tempo_riempimento,tempo_assestamento,percentuale_minima_pressione_assestamento,percentuale_massima_pressione_assestamento,tempo_di_test,pressione_di_test_delta_minimo,pressione_di_test,pressione_di_test_delta_massimo,tempo_svuotamento,pressione_svuotmento,prova_tenuta_abilitata_2,tempo_pre_riempimento_2,pressione_pre_riempimento_2,tempo_riempimento_2,tempo_assestamento_2,percentuale_minima_pressione_assestamento_2,percentuale_massima_pressione_assestamento_2,tempo_di_test_2,pressione_di_test_delta_minimo_2,pressione_di_test_2,pressione_di_test_delta_massimo_2,tempo_svuotamento_2,pressione_svuotmento_2,test_visione_abilitato,ricetta_visione,stampa_etichetta_abilitata,modello_etichetta -,,,,,,,,0,,500,1000000000,20,x,0,1000,5,5,5,5,5,200,1000,200,1,100,,0,1000,5,5,5,5,5,200,1000,200,1,100,,termorestringente_923578.ini,x,EtichettaR5.prn +codice_ricetta,cliente,part_number,dimensione_lotto_abilitata,dimensione_lotto,verifica_connettore_abilitata,connettore,verifica_codice_a_barre_abilitata,codice_a_barre,avvitatura_abilitata,viti,verifica_resistenza_connettore_abilitata,scala_resistenza,resistenza_attesa,tolleranza_resistenza,prova_tenuta_abilitata,tempo_pre_riempimento,pressione_pre_riempimento,tempo_riempimento,tempo_assestamento,percentuale_minima_pressione_assestamento,percentuale_massima_pressione_assestamento,tempo_di_test,pressione_di_test_delta_minimo,pressione_di_test,pressione_di_test_delta_massimo,tempo_svuotamento,pressione_svuotmento,prova_tenuta_abilitata_2,tempo_pre_riempimento_2,pressione_pre_riempimento_2,tempo_riempimento_2,tempo_assestamento_2,percentuale_minima_pressione_assestamento_2,percentuale_massima_pressione_assestamento_2,tempo_di_test_2,pressione_di_test_delta_minimo_2,pressione_di_test_2,pressione_di_test_delta_massimo_2,tempo_svuotamento_2,pressione_svuotmento_2,test_visione_abilitato,ricetta_visione,stampa_etichetta_abilitata,modello_etichetta +,,,,0,,,,,,0,,500,1000000000,20,x,0,1000,5,5,5,5,5,200,1000,200,1,100,,0,1000,5,5,5,5,5,200,1000,200,1,100,,termorestringente_923578.ini,x,EtichettaR5.prn diff --git a/src/ui/__init__.py b/src/ui/__init__.py index c46343f..d58802c 100644 --- a/src/ui/__init__.py +++ b/src/ui/__init__.py @@ -2,6 +2,8 @@ from .about import About from .archive import Archive from .autotests_archive import Autotests_Archive from .barcodes_step_editor import Barcodes_Step_Editor +from .connector_step_editor import Connector_Step_Editor +from .count_step_editor import Count_Step_Editor from .crud import (Cell, Combo_Box_Cell_Widget, CopyPastableCrudQTableWidget, Crud, External_Dialog_Cell_Widget, Json_External_Dialog_Cell_Widget, @@ -31,6 +33,8 @@ from .test_assembly import Test_Assembly from .test_autotest import Test_Autotest from .test_barcodes import Test_Barcodes from .test_connector import Test_Connector +from .test_count import Test_Count +from .test_count_end import Test_Count_End from .test_fail import Test_Fail from .test_home import Test_Home from .test_leak import Test_Leak diff --git a/src/ui/count_step_editor/__init__.py b/src/ui/count_step_editor/__init__.py new file mode 100644 index 0000000..4c3a06d --- /dev/null +++ b/src/ui/count_step_editor/__init__.py @@ -0,0 +1 @@ +from .count_step_editor import Count_Step_Editor diff --git a/src/ui/count_step_editor/count_step_editor.py b/src/ui/count_step_editor/count_step_editor.py new file mode 100644 index 0000000..d2410c3 --- /dev/null +++ b/src/ui/count_step_editor/count_step_editor.py @@ -0,0 +1,9 @@ +from ui.editor import Editor + + +class Count_Step_Editor(Editor): + def __init__(self, action=None, cell_widget=None): + super().__init__(action=action, cell_widget=cell_widget) + self.spec.update({ + "amount": self.amount_sb, + }) diff --git a/src/ui/count_step_editor/count_step_editor.ui b/src/ui/count_step_editor/count_step_editor.ui new file mode 100644 index 0000000..d78feb4 --- /dev/null +++ b/src/ui/count_step_editor/count_step_editor.ui @@ -0,0 +1,63 @@ + + + Count_Step_Editor + + + + 0 + 0 + 138 + 68 + + + + Count Step Editor + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 10 + 50 + false + + + + Lotto + + + + + + Quantità + + + + + + + 9999 + + + + + + + + + + + diff --git a/src/ui/recipe_selection/recipe_selection.py b/src/ui/recipe_selection/recipe_selection.py index 84a52a2..7ebba98 100755 --- a/src/ui/recipe_selection/recipe_selection.py +++ b/src/ui/recipe_selection/recipe_selection.py @@ -153,6 +153,9 @@ class Recipe_Selection(Widget): barcode_serial_field = self.config.get("recipe", {}).get("barcode_serial_field", "codice_a_barre").strip() print_template_field = self.config.get("recipe", {}).get("label_template_field", "modello_etichetta").strip() return { + "count": { + "amount": row.get("dimensione_lotto", defaults["dimensione_lotto"]), + }, "connector": { "connector": row.get("connettore", defaults["connettore"]), }, @@ -247,6 +250,7 @@ class Recipe_Selection(Widget): recipe.client = row.get("cliente", defaults["cliente"]) recipe.part_number = row.get("part_number", defaults["part_number"]) recipe.spec = { + "count": len(row.get("dimensione_lotto_abilitata", defaults["dimensione_lotto_abilitata"])) and "count" not in self.unsupported_steps, "connector": len(row.get("verifica_connettore_abilitata", defaults["verifica_connettore_abilitata"])) and "connector" not in self.unsupported_steps, "barcodes": len(row.get(barcode_enale_field, defaults["verifica_codice_a_barre_abilitata"])) and "barcodes" not in self.unsupported_steps, "resistance": len(row.get("verifica_resistenza_connettore_abilitata", defaults["verifica_resistenza_connettore_abilitata"])) and "resistance" not in self.unsupported_steps, @@ -257,6 +261,7 @@ class Recipe_Selection(Widget): "print": len(row.get("stampa_etichetta_abilitata", defaults["stampa_etichetta_abilitata"])) and "print" not in self.unsupported_steps, "steps": [], # should be pks of the enabled steps "available_steps": { + "count": steps["count"].get_id(), "connector": steps["connector"].get_id(), "barcodes": steps["barcodes"].get_id(), "resistance": steps["resistance"].get_id(), @@ -304,6 +309,8 @@ class Recipe_Selection(Widget): recipe_name_field, "cliente", "part_number", + "dimensione_lotto_abilitata", + "dimensione_lotto", "verifica_connettore_abilitata", "connettore", barcode_enale_field, @@ -351,6 +358,8 @@ class Recipe_Selection(Widget): recipe_name_field: recipe.name, "cliente": recipe.client, "part_number": recipe.part_number, + "dimensione_lotto_abilitata": "x" if recipe.spec["count"] else "", + "dimensione_lotto": steps["count"].spec["amount"], "verifica_connettore_abilitata": "x" if recipe.spec["connector"] else "", "connettore": steps["connector"].spec["connector"], barcode_enale_field: "x" if recipe.spec["barcodes"] else "", diff --git a/src/ui/recipe_spec_and_step_editor/recipe_spec_and_step_editor.py b/src/ui/recipe_spec_and_step_editor/recipe_spec_and_step_editor.py index 0671bfd..08f783e 100644 --- a/src/ui/recipe_spec_and_step_editor/recipe_spec_and_step_editor.py +++ b/src/ui/recipe_spec_and_step_editor/recipe_spec_and_step_editor.py @@ -2,6 +2,7 @@ from lib.db import Steps from peewee import IntegrityError from ui.barcodes_step_editor import Barcodes_Step_Editor from ui.connector_step_editor import Connector_Step_Editor +from ui.count_step_editor import Count_Step_Editor from ui.editor import Editor from ui.helpers import replace_widget from ui.leak_step_editor import Leak_Step_Editor @@ -15,6 +16,13 @@ class Recipe_Spec_And_Step_Editor(Editor): def __init__(self, action=None, cell_widget=None, unsupported_steps=None): super().__init__(action=action, cell_widget=cell_widget) self.map = { + "count": { + "type": "count", + "enable": self.count_enabled_cb, + "widget": "count_editor_w", + "editor": Count_Step_Editor(), + "tab": self.count_t, + }, "connector": { "type": "connector", "enable": self.connector_enabled_cb, diff --git a/src/ui/recipe_spec_and_step_editor/recipe_spec_and_step_editor.ui b/src/ui/recipe_spec_and_step_editor/recipe_spec_and_step_editor.ui index 367f7b4..72ffd71 100644 --- a/src/ui/recipe_spec_and_step_editor/recipe_spec_and_step_editor.ui +++ b/src/ui/recipe_spec_and_step_editor/recipe_spec_and_step_editor.ui @@ -19,14 +19,6 @@ Recipe Spec And Step Editor - - - - Salva configurazione -Fasi di Test - - - @@ -40,6 +32,49 @@ Fasi di Test 0 + + + Lotto + + + + + + Qt::Horizontal + + + + 457 + 20 + + + + + + + + Fase Abilitata + + + + + + + Qt::Horizontal + + + + 457 + 20 + + + + + + + + + Connettore @@ -386,6 +421,14 @@ Fasi di Test + + + + Salva configurazione +Fasi di Test + + + diff --git a/src/ui/test/test.py b/src/ui/test/test.py index c776717..284eed4 100755 --- a/src/ui/test/test.py +++ b/src/ui/test/test.py @@ -15,6 +15,8 @@ from ui.test_assembly import Test_Assembly from ui.test_autotest import Test_Autotest from ui.test_barcodes import Test_Barcodes from ui.test_connector import Test_Connector +from ui.test_count import Test_Count +from ui.test_count_end import Test_Count_End from ui.test_fail import Test_Fail from ui.test_leak import Test_Leak from ui.test_resistance import Test_Resistance @@ -46,12 +48,13 @@ class Test(Widget): self.step = None self.unsupported_steps = set() self.steps_dependencies = { - "leak": {"tecna_t3", }, - "print": {"label_printer", }, + "count": set(), "connector": {"multicomp", }, - "resistance": {"multicomp", }, - "vision": {("uvc_camera", "galaxy_camera", ), "vision", "vision_saver", }, # "neo_pixels", }, "screws": {"screwdriver", "tecna_t3", }, + "resistance": {"multicomp", }, + "leak": {"tecna_t3", }, + "vision": {("uvc_camera", "galaxy_camera", ), "vision", "vision_saver", }, # "neo_pixels", }, + "print": {"label_printer", }, } self.unsupported_steps = set() for step_name, dependencies in self.steps_dependencies.items(): @@ -62,21 +65,25 @@ class Test(Widget): else: if dependency not in self.components or not self.components[dependency].ready: self.unsupported_steps.add(step_name) + # INIT PIECES COUNTER + self.pieces = {"ok": 0, "ko": 0} # INIT CYCLE STATES self.cycle_available_steps = { # "assembly_1": Test_Assembly(img_path=self.select_step_img("assembly_1"), text=u"INSERIRE SENSORE", widget=None), "autotest": Test_Assembly(img_path=None, text=u"ESEGUIRE PROCEDURA DI AUTOTEST", widget=Test_Autotest()), "barcodes": Test_Assembly(img_path=self.select_step_img("scan"), text=u"LEGGERE IL BARCODE DEL PEZZO DA COLLAUDARE", widget=Test_Barcodes()), "connector": Test_Assembly(img_path=self.select_step_img("scan"), text=u"COLLEGARE IL CONNETTORE INDICATO AL PEZZO E LEGGERE IL SUO BARCODE", widget=Test_Connector(run_once=True)), + "count": Test_Assembly(img_path=None, text=u"INSERIRE IL NUMERO DI PEZZI ATTESI PER IL LOTTO", widget=Test_Count(components=self.components, recipe=self.recipe, step=self.step, pieces=self.pieces, run_once=True)), + "count_end": Test_Assembly(img_path=None, text=u"LOTTO TERMINATO, PREMERE CONTINUA PERCOMINCIARNE UNO NUOVO", widget=Test_Count_End(components=self.components, recipe=self.recipe, step=self.step, pieces=self.pieces)), "done": Test_Assembly(img_path=self.select_step_img("success"), text=u"COLLAUDO COMPLETATO", widget=None), "emergency": Test_Assembly(img_path=self.select_step_img("reset_emergency"), text=u"EMERGENZA INTERVENUTA - RIPRISTINARE PULSANTE E SELEZIONARE \"RESET EMERGENZA\" DAL MEN\u00d9 \"STRUMENTI\"", widget=None), "fail": Test_Assembly(img_path=self.select_step_img("fail"), text=u"CICLO INTERROTTO, PREMERE CONTINUA PER COMINCIARE UN NUOVO CICLO", widget=Test_Fail()), - "leak": Test_Assembly(img_path=None, text=None, widget=Test_Leak(components=self.components, recipe=self.recipe, step=self.step)), + "leak": Test_Assembly(img_path=None, text=None, widget=Test_Leak(components=self.components, recipe=self.recipe, step=self.step, pieces=self.pieces)), "print": Test_Assembly(img_path=self.select_step_img("print"), text=u"STAMPA ETICHETTA IN CORSO", widget=None), - "resistance": Test_Assembly(img_path=None, text=u"COLLEGARE CONNETTORE ELETTRICO PER EFFETTUARE PROVA RESISTENZA", widget=Test_Resistance(components=self.components, recipe=self.recipe, step=self.step)), - "screws": Test_Assembly(img_path=None, text=u"AVVITARE TUTE LE VITI COME INDICATO", widget=Test_Screws(components=self.components, recipe=self.recipe, step=self.step)), + "resistance": Test_Assembly(img_path=None, text=u"COLLEGARE CONNETTORE ELETTRICO PER EFFETTUARE PROVA RESISTENZA", widget=Test_Resistance(components=self.components, recipe=self.recipe, step=self.step, pieces=self.pieces)), + "screws": Test_Assembly(img_path=None, text=u"AVVITARE TUTE LE VITI COME INDICATO", widget=Test_Screws(components=self.components, recipe=self.recipe, step=self.step, pieces=self.pieces)), "select_recipe": Test_Assembly(img_path=None, text=u"SELEZIONARE IL CODICE DA COLLAUDARE", widget=Recipe_Selection(config=self.config, unsupported_steps=self.unsupported_steps)), - "vision": Test_Assembly(img_path=None, text=u"VERIFICARE CONTROLLO CON TELECAMERA", widget=Test_Vision(components=self.components, recipe=self.recipe, step=self.step)), + "vision": Test_Assembly(img_path=None, text=u"VERIFICARE CONTROLLO CON TELECAMERA", widget=Test_Vision(components=self.components, recipe=self.recipe, step=self.step, pieces=self.pieces)), "wait": Test_Assembly(img_path=self.select_step_img("wait"), text=u"ATTENDERE - PAUSA INTER CICLO", widget=None), None: Test_Assembly(img_path=self.select_step_img("warning"), text=u"ATTENZIONE - LA RICETTA SELEZIONATA NON CONTIENE FASI DI TEST", widget=None), } @@ -92,8 +99,6 @@ class Test(Widget): # INIT TEST DATA self.data = {"ok": True, "overridden": False} self.archived = None - # INIT PIECES COUNTER ([pieces_ok, pieces_failed]) - self.pieces = [0, 0] # CONNECT CYCLE CONTROLS self.cancel_b.clicked.connect(self.fail_cycle) self.change_recipe_b.clicked.connect(self.change_recipe) @@ -106,6 +111,8 @@ class Test(Widget): w.ok.connect(lambda data=None, step_name=step_name, self=weakref.ref(self): self().set_step(step_name, data)) if hasattr(w, "ko"): w.ko.connect(self.fail_cycle) + # CUSTOM STEP CONNECTIONS + self.cycle_available_steps["count"].ok.connect(self.cycle_available_steps["count_end"].widget.set_amount) # TESTING if "--test" in sys.argv: self.testing = True @@ -166,7 +173,10 @@ class Test(Widget): self.request_autotest("periodic") def next(self, action=None): - self.log.debug(f"cycle next: cycle step: {self.step!r} action: {action!r}") + if self.step is not None: + self.log.debug(f"cycle next: cycle step: {model_to_dict(self.step)!r} action: {action!r}") + else: + self.log.debug(f"cycle next: cycle step: {self.step!r} action: {action!r}") current_w = self.centralWidget if hasattr(current_w, "stop"): current_w.stop() @@ -179,8 +189,8 @@ class Test(Widget): self.data = {"ok": True, "overridden": False} self.archived = None # COUNT RESET - self.pieces[0] = 0 - self.pieces[1] = 0 + self.pieces["ok"] = 0 + self.pieces["ko"] = 0 elif action == "fail": self.log.info(f"cycle next: action: {action!r}") # FAIL AND RESTART TEST @@ -190,7 +200,7 @@ class Test(Widget): self.data = {"ok": True, "overridden": False} self.archived = None # COUNT FAIL - self.pieces[1] += 1 + self.pieces["ko"] += 1 elif action is not None: raise NotImplementedError(f"cycle next: action {action!r} is not a valid action") # if action did not set the next cycle step @@ -222,7 +232,7 @@ class Test(Widget): "select_recipe", "wait", }) - self.log.info(f"cycle next: next cycle step: {self.step!r}") + self.log.info(f"cycle next: next cycle step: {model_to_dict(self.step)!r}") # INIT TEST DATA IF STARTING CYCLE LOOP if self.recipe is not None and "recipe" not in self.data: self.data["recipe"] = model_to_dict(self.recipe) @@ -230,10 +240,11 @@ class Test(Widget): self.data = {"ok": True, "overridden": False} self.archived = None w = self.cycle_available_steps[self.step.type] - if w is not current_w: - self.setCentralWidget(w) + show = None if hasattr(w, "start"): - w.start(recipe=self.recipe, step=self.cycle_steps[self.cycle_index]) + show = w.start(recipe=self.recipe, step=self.cycle_steps[self.cycle_index], pieces=self.pieces) + if show is not False and w is not current_w: + self.setCentralWidget(w) if self.step.type == "done": self.archived = self.done() self.next_timer.start(2000) @@ -247,7 +258,7 @@ class Test(Widget): elif self.step.type == "wait": self.next_timer.start(6000) # UPDATE PIECES DISPLAY - self.pieces_count_l.setText(f"{self.pieces[0]} OK / {self.pieces[1]} NOK / {sum(self.pieces)} TOT") + self.pieces_count_l.setText(f"{self.pieces['ok']} OK / {self.pieces['ko']} NOK / {sum(self.pieces.values())} TOT") def set_recipe(self, recipe=None): self.recipe = recipe @@ -257,9 +268,12 @@ class Test(Widget): steps = self.recipe.get_steps() skip = set() print_found = False + count_found = False for i, step in enumerate(steps): if i in skip: continue + if step.type == "count": + count_found = True if step.type == "resistance": steps.insert(i + 1, Steps(type="resistance", spec={ "scale": 500, @@ -271,8 +285,12 @@ class Test(Widget): steps.insert(i, Steps(type="done")) print_found = True skip.add(i + 1) + if count_found: + steps.insert(i + 2, Steps(type="count_end")) if not print_found: steps.append(Steps(type="done")) + if count_found: + steps.append(Steps(type="count_end")) steps.append(Steps(type="wait")) self.cycle_steps = steps self.check_steps_dependencies(self.cycle_steps) @@ -281,10 +299,12 @@ class Test(Widget): w.reset() # UPDATE RECIPE DISPLAY if self.recipe is not None: + self.log.info(f"cycle recipe: cycle recipe: {model_to_dict(self.recipe)!r} cycle steps: {[model_to_dict(s) for s in self.cycle_steps]}") self.recipe_l.setText(self.recipe.name) self.recipe_l.setStyleSheet("") self.next() else: + self.log.info(f"cycle recipe: cycle recipe: {self.recipe!r} cycle steps: {self.cycle_steps}") self.recipe_l.setText("NON SELEZIONATA") self.recipe_l.setStyleSheet("QLabel { color: red; }") @@ -353,7 +373,7 @@ class Test(Widget): archived = Archive.archive(self.recipe, self.data, ok and self.data["ok"], overridden=self.data["overridden"]) self.log.info(f"cycle archived locally: {archived!r}") # COUNT OK - self.pieces[0] += 1 + self.pieces["ok"] += 1 return archived @staticmethod diff --git a/src/ui/test/test.ui b/src/ui/test/test.ui index 5d23e5a..9bdf1aa 100755 --- a/src/ui/test/test.ui +++ b/src/ui/test/test.ui @@ -14,7 +14,7 @@ Test - + @@ -28,7 +28,7 @@ - + @@ -52,168 +52,6 @@ 3 - - - - - 0 - 0 - - - - - 12 - 75 - true - - - - N. DISEGNO: - - - - - - - - 12 - 75 - true - - - - - - - - - - - - - 0 - 0 - - - - - 120 - 0 - - - - - 20 - 16777215 - - - - - 12 - 75 - true - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 12 - 75 - true - - - - OPERATORE: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 200 - 40 - - - - - 12 - 75 - true - - - - ANNULLA TEST - - - - - - - - 12 - 75 - true - - - - PEZZI FATTI - - - Qt::AlignCenter - - - @@ -246,23 +84,33 @@ - - + + Qt::Horizontal - - QSizePolicy::Fixed - - 20 + 40 20 - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -279,7 +127,37 @@ - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 12 + 75 + true + + + + PEZZI FATTI + + + Qt::AlignCenter + + + + @@ -297,26 +175,148 @@ + + + + + 0 + 0 + + + + + 200 + 40 + + + + + 12 + 75 + true + + + + ANNULLA TEST + + + + + + + + 0 + 0 + + + + + 12 + 75 + true + + + + N. DISEGNO: + + + + + + + + 12 + 75 + true + + + + OPERATORE: + + + + + + + + 0 + 0 + + + + + 120 + 0 + + + + + 20 + 16777215 + + + + + 12 + 75 + true + + + + - + + + + + + + + 12 + 75 + true + + + + - + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + 16 + 75 + true + + + + - + + + Qt::AlignCenter + + + - - - - - 16 - 75 - true - - - - - - - - Qt::AlignCenter - - - diff --git a/src/ui/test_barcodes/test_barcodes.py b/src/ui/test_barcodes/test_barcodes.py index 03976e2..3244cbc 100644 --- a/src/ui/test_barcodes/test_barcodes.py +++ b/src/ui/test_barcodes/test_barcodes.py @@ -9,8 +9,8 @@ from ui.test_test import Test_Test class Test_Barcodes(Test_Test): - 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) + def __init__(self, components=None, recipe=None, step=None, pieces=None, run_once=False, enable_override=False): + super().__init__(components=components, recipe=recipe, step=step, pieces=pieces, run_once=run_once, enable_override=enable_override) self.barcodes_spec = { "serial": self.check_serial_barcode } @@ -18,10 +18,10 @@ class Test_Barcodes(Test_Test): 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) - if self.run_once is True and self.done is True and self.done_ok is True: - return + def start(self, recipe=None, step=None, pieces=None): + show = super().start(recipe=recipe, step=step, pieces=pieces) + if show is False: + return show self.visualize() self.barcodes_le.setPalette(self.status_palettes[None]) self.barcodes_le.setText("") @@ -34,6 +34,7 @@ class Test_Barcodes(Test_Test): self.test_timer.timeout.connect(self.get) self.test_timer.start(500) # /TESTING + return show # def stop(self): # super().stop() diff --git a/src/ui/test_connector/test_connector.py b/src/ui/test_connector/test_connector.py index 87276f6..12a7a9f 100644 --- a/src/ui/test_connector/test_connector.py +++ b/src/ui/test_connector/test_connector.py @@ -8,16 +8,16 @@ from ui.test_test import Test_Test class Test_Connector(Test_Test): - 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) + def __init__(self, components=None, recipe=None, step=None, pieces=None, run_once=False, enable_override=False): + super().__init__(components=components, recipe=recipe, step=step, pieces=pieces, run_once=run_once, enable_override=enable_override) QShortcut(QKeySequence("Return"), self).activated.connect(self.get) QShortcut(QKeySequence("Enter"), self).activated.connect(self.get) self.connector_le.setFocus() - def start(self, recipe=None, step=None): - super().start(recipe=recipe, step=step) - if self.run_once is True and self.done is True and self.done_ok is True: - return + def start(self, recipe=None, step=None, pieces=None): + show = super().start(recipe=recipe, step=step, pieces=pieces) + if show is False: + return show self.visualize() expected = str(self.step.spec.get("connector", "-")) self.parent_assembly_widget().set_text(f"COLLEGARE IL CONNETTORE {expected} AL MULTIMETRO E LEGGERE IL SUO BARCODE") @@ -33,6 +33,7 @@ class Test_Connector(Test_Test): self.test_timer.timeout.connect(self.get) self.test_timer.start(500) # /TESTING + return show # def stop(self): # super().stop() diff --git a/src/ui/test_count/__init__.py b/src/ui/test_count/__init__.py new file mode 100644 index 0000000..18ab2e2 --- /dev/null +++ b/src/ui/test_count/__init__.py @@ -0,0 +1 @@ +from .test_count import Test_Count diff --git a/src/ui/test_count/test_count.py b/src/ui/test_count/test_count.py new file mode 100644 index 0000000..42cef9a --- /dev/null +++ b/src/ui/test_count/test_count.py @@ -0,0 +1,59 @@ +import sys +import weakref + +from lib.helpers import timing +from PyQt5.QtCore import QTimer +from PyQt5.QtGui import QKeySequence +from PyQt5.QtWidgets import QShortcut +from ui.test_test import Test_Test + + +class Test_Count(Test_Test): + def __init__(self, components=None, recipe=None, step=None, pieces=None, run_once=False, enable_override=False): + super().__init__(components=components, recipe=recipe, step=step, pieces=pieces, run_once=run_once, enable_override=enable_override) + self.amount_sb.setRange(0, 9999) + self.amount = 0 + self.continue_b.clicked.connect(lambda checked, self=weakref.ref(self): self().get(self().amount_sb.value())) + self.ignore_b.clicked.connect(lambda checked, self=weakref.ref(self): self().get(0)) + + def start(self, recipe=None, step=None, pieces=None): + show = super().start(recipe=recipe, step=step, pieces=pieces) + if show is False: + return show + self.visualize() + self.amount = self.step.spec.get("amount", 0) + self.amount_sb.setValue(self.amount) + # TESTING + if "--test-count" in sys.argv or "--test" in sys.argv: + self.amount_sb.setValue(1) + self.test_timer = QTimer() + self.test_timer.setSingleShot(True) + self.test_timer.timeout.connect(self.continue_b.click) + self.test_timer.start(500) + # /TESTING + return show + + # def stop(self): + # super().stop() + + # def reset(self): + # super().reset() + + def get(self, data=None, override=False): + if self.done: # avoid proccessing if completed + return + # if data is None: + # data = self.amount_sb.value() + if data is None: + super().get(None, override=override) + return + result = data + ok = True + super().get([{ + "time": timing(), + "results": { + "ok": ok, + "result": result, + "data": data, + }, + }], override=override, fail=ok is False, skip_delay=True) diff --git a/src/ui/test_count/test_count.ui b/src/ui/test_count/test_count.ui new file mode 100644 index 0000000..a55030e --- /dev/null +++ b/src/ui/test_count/test_count.ui @@ -0,0 +1,123 @@ + + + Test_Count + + + + 0 + 0 + 380 + 229 + + + + Test Count + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 20 + 75 + true + + + + Dimensione lotto + + + + + + + 20 + 75 + true + + + + + + + + Dimensione Lotto + + + + + + + + 20 + 75 + true + + + + background-color:rgb(85, 255, 127); + + + CONTINUA + + + + + + + + 20 + 75 + true + + + + background-color:rgb(254, 254, 114); + + + COONTINUA SENZA LOTTO + + + + + + + + + + + 0 + 0 + + + + FORZA ACCETTAZIONE + + + + + + + override_b + + + + diff --git a/src/ui/test_count_end/__init__.py b/src/ui/test_count_end/__init__.py new file mode 100644 index 0000000..a138add --- /dev/null +++ b/src/ui/test_count_end/__init__.py @@ -0,0 +1 @@ +from .test_count_end import Test_Count_End diff --git a/src/ui/test_count_end/test_count_end.py b/src/ui/test_count_end/test_count_end.py new file mode 100644 index 0000000..ea24b3d --- /dev/null +++ b/src/ui/test_count_end/test_count_end.py @@ -0,0 +1,47 @@ +import sys +import weakref + +from lib.helpers import timing +from PyQt5.QtCore import QTimer +from PyQt5.QtGui import QKeySequence +from PyQt5.QtWidgets import QShortcut +from ui.test_test import Test_Test + + +class Test_Count_End(Test_Test): + def __init__(self, components=None, recipe=None, step=None, pieces=None, run_once=False, enable_override=False): + super().__init__(components=components, recipe=recipe, step=step, pieces=pieces, run_once=run_once, enable_override=enable_override) + self.continue_b.clicked.connect(lambda checked, self=weakref.ref(self): self().ok.emit(None)) + self.amount = 0 + self.lots = 0 + self.previous_pieces = 0 + + def set_amount(self, data=None): + self.amount = data.get("results", {}).get("data", 0) + + def start(self, recipe=None, step=None, pieces=None): + show = super().start(recipe=recipe, step=step, pieces=pieces) + if show is False or self.amount == 0 or self.pieces["ok"] - self.previous_pieces < self.amount: # current piece counted since this step is after the "done" step + if show is not False: + self.ok.emit(None) + return False + self.visualize() + self.lots += 1 + self.previous_pieces = self.pieces["ok"] + # TESTING + if "--test-count" in sys.argv or "--test" in sys.argv: + self.test_timer = QTimer() + self.test_timer.setSingleShot(True) + self.test_timer.timeout.connect(self.continue_b.click) + self.test_timer.start(500) + # /TESTING + return show + + # def stop(self): + # super().stop() + + def reset(self): + super().reset() + self.amount = 0 + self.lots = 0 + self.previous_pieces = 0 diff --git a/src/ui/test_count_end/test_count_end.ui b/src/ui/test_count_end/test_count_end.ui new file mode 100644 index 0000000..3d2a785 --- /dev/null +++ b/src/ui/test_count_end/test_count_end.ui @@ -0,0 +1,98 @@ + + + Test_Count_End + + + + 0 + 0 + 468 + 173 + + + + Test Count End + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 20 + 75 + true + + + + Dimensione lotto + + + + + + + 20 + 75 + true + + + + background-color:rgb(85, 255, 127); + + + CONTINUA CON UN ALTRO LOTTO + + + + + + + Lotto terminato + + + Qt::AlignCenter + + + + + + + + + + + 0 + 0 + + + + FORZA ACCETTAZIONE + + + + + + + override_b + + + + diff --git a/src/ui/test_fail/test_fail.py b/src/ui/test_fail/test_fail.py index f9b44f5..1ed050e 100644 --- a/src/ui/test_fail/test_fail.py +++ b/src/ui/test_fail/test_fail.py @@ -10,14 +10,14 @@ from ui.test_test import Test_Test class Test_Fail(Test_Test): - 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) + def __init__(self, components=None, recipe=None, step=None, pieces=None, run_once=False, enable_override=False): + super().__init__(components=components, recipe=recipe, step=step, pieces=pieces, run_once=run_once, enable_override=enable_override) self.continue_b.clicked.connect(lambda checked, self=weakref.ref(self): self().ok.emit(None)) - def start(self, recipe=None, step=None): - super().start(recipe=recipe, step=step) - if self.run_once is True and self.done is True and self.done_ok is True: - return + def start(self, recipe=None, step=None, pieces=None): + show = super().start(recipe=recipe, step=step, pieces=pieces) + if show is False: + return show self.visualize() # TESTING if "--test" in sys.argv: @@ -26,6 +26,7 @@ class Test_Fail(Test_Test): self.test_timer.timeout.connect(self.continue_b.click) self.test_timer.start(500) # /TESTING + return show # def stop(self): # super().stop() diff --git a/src/ui/test_leak/test_leak.py b/src/ui/test_leak/test_leak.py index 25cffc2..799361e 100644 --- a/src/ui/test_leak/test_leak.py +++ b/src/ui/test_leak/test_leak.py @@ -5,21 +5,21 @@ from ui.test_test import Test_Test class Test_Leak(Test_Test): - 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) + def __init__(self, components=None, recipe=None, step=None, pieces=None, run_once=False, enable_override=False): + super().__init__(components=components, recipe=recipe, step=step, pieces=pieces, run_once=run_once, enable_override=enable_override) self.start_b.clicked.connect(lambda checked, self=weakref.ref(self): self().components["tecna_t3"].start_test()) self.stop_b.clicked.connect(lambda checked, self=weakref.ref(self): self().components["tecna_t3"].stop_test()) - def start(self, recipe=None, step=None): + def start(self, recipe=None, step=None, pieces=None): # TESTING if "--test-leak" in sys.argv or "--test" in sys.argv: self.simulate = True else: self.simulate = False # /TESTING - super().start(recipe=recipe, step=step) - if self.run_once is True and self.done is True and self.done_ok is True: - return + show = super().start(recipe=recipe, step=step, pieces=pieces) + if show is False: + return show # setup test loop self.components["tecna_t3"].write_recipe(self.recipe, self.step) self.get_connection = self.components["tecna_t3"].out.connect(self.get) @@ -28,6 +28,7 @@ class Test_Leak(Test_Test): self.parent_assembly_widget().set_text(text=None) self.start_b.setEnabled(False) self.stop_b.setEnabled(False) + return show def stop(self): # disable test loop diff --git a/src/ui/test_resistance/test_resistance.py b/src/ui/test_resistance/test_resistance.py index 4693cd7..c3c57c1 100644 --- a/src/ui/test_resistance/test_resistance.py +++ b/src/ui/test_resistance/test_resistance.py @@ -5,11 +5,11 @@ from ui.test_test import Test_Test class Test_Resistance(Test_Test): - 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) + def __init__(self, components=None, recipe=None, step=None, pieces=None, run_once=False, enable_override=False): + super().__init__(components=components, recipe=recipe, step=step, pieces=pieces, run_once=run_once, enable_override=enable_override) self.ok_counter_limit = 3 - def start(self, recipe=None, step=None): + def start(self, recipe=None, step=None, pieces=None): # TESTING if "--test-resistance" in sys.argv or "--test" in sys.argv: self.simulate = True @@ -19,9 +19,9 @@ class Test_Resistance(Test_Test): expected = step.spec.get("expected", "-") if expected == float("+inf"): step.spec["expected"] = 1e9 - super().start(recipe=recipe, step=step) - if self.run_once is True and self.done is True and self.done_ok is True: - return + show = super().start(recipe=recipe, step=step, pieces=pieces) + if show is False: + return show # setup test loop self.components["multicomp"].set_resistance_scale(self.step.spec.get("scale", 500)) self.get_connection = self.components["multicomp"].out.connect(self.get) @@ -50,6 +50,7 @@ class Test_Resistance(Test_Test): bg = self.status_palettes[None].color(QPalette.Background) color = f"rgb({bg.red()}, {bg.green()}, {bg.blue()})" self.resistance_l.setStyleSheet(f"background-color: {color};\nborder: 1px solid black;\n") + return show def stop(self): # disable test loop diff --git a/src/ui/test_screws/test_screws.py b/src/ui/test_screws/test_screws.py index 2d84405..53ecde8 100644 --- a/src/ui/test_screws/test_screws.py +++ b/src/ui/test_screws/test_screws.py @@ -5,19 +5,19 @@ from ui.test_test import Test_Test class Test_Screws(Test_Test): - def __init__(self, components=None, recipe=None, step=None, run_once=False, enable_override=True): - super().__init__(components=components, recipe=recipe, step=step, run_once=run_once, enable_override=enable_override) + def __init__(self, components=None, recipe=None, step=None, pieces=None, run_once=False, enable_override=True): + super().__init__(components=components, recipe=recipe, step=step, pieces=pieces, run_once=run_once, enable_override=enable_override) - def start(self, recipe=None, step=None): + def start(self, recipe=None, step=None, pieces=None): # TESTING if "--test-screws" in sys.argv or "--test" in sys.argv: self.simulate = True else: self.simulate = False # /TESTING - super().start(recipe=recipe, step=step) - if self.run_once is True and self.done is True and self.done_ok is True: - return + show = super().start(recipe=recipe, step=step, pieces=pieces) + if show is False: + return show # setup test loop self.get_connection = self.components["screwdriver"].out.connect(self.get) self.components["tecna_t3"].resume() @@ -26,6 +26,7 @@ class Test_Screws(Test_Test): self.screws_counter_l.setText(str(0)) self.screws_expected_l.setText(str(self.ok_counter_limit)) self.components["screwdriver"].enable(self.ok_counter_limit > 0) + return show def stop(self): # disable test loop diff --git a/src/ui/test_test/test_test.py b/src/ui/test_test/test_test.py index 5ca4df3..1d419e6 100644 --- a/src/ui/test_test/test_test.py +++ b/src/ui/test_test/test_test.py @@ -13,11 +13,12 @@ class Test_Test(Widget): ok = pyqtSignal(object) ko = pyqtSignal(object) - def __init__(self, components=None, recipe=None, step=None, run_once=False, enable_override=True): + def __init__(self, components=None, recipe=None, step=None, pieces=None, run_once=False, enable_override=True): super().__init__() self.components = components self.recipe = recipe self.step = step + self.pieces = pieces self.run_once = run_once self.enable_override = enable_override # setup variables @@ -80,13 +81,14 @@ class Test_Test(Widget): else: self.parent_assembly_widget = weakref.ref(parent_assembly_widget) - def start(self, recipe=None, step=None): + def start(self, recipe=None, step=None, pieces=None): self.admin_challenged = False self.recipe = recipe self.step = step + self.pieces = pieces if self.run_once is True and self.done is True and self.done_ok is True: self.emit_ok() - return + return False self.reset() if self.enable_override: self.override_b.setVisible(True) @@ -102,6 +104,7 @@ class Test_Test(Widget): if self.enable_override and hasattr(self, "_test_overridden_test_"): del self._test_overridden_test_ # /TESTING + return True def stop(self): pass @@ -112,7 +115,7 @@ class Test_Test(Widget): self.done_ok = None self.last = None - def get(self, data=None, override=False, fail=False, preserve_counter=False): + def get(self, data=None, override=False, fail=False, preserve_counter=False, skip_delay=False): if self.done: # avoid proccessing if completed return if data is None: @@ -152,14 +155,20 @@ class Test_Test(Widget): if hasattr(self, "override_b"): self.override_b.setEnabled(False) self.stop() - self.ko_timer.start() + if skip_delay: + self.emit_ko() + else: + self.ko_timer.start() elif self.ok_counter >= self.ok_counter_limit: self.done = True self.done_ok = True if hasattr(self, "override_b"): self.override_b.setEnabled(False) self.stop() - self.ok_timer.start() + if skip_delay: + self.emit_ok() + else: + self.ok_timer.start() self.visualize(self.last) # TESTING if "--test" in sys.argv: diff --git a/src/ui/test_vision/test_vision.py b/src/ui/test_vision/test_vision.py index dbaf5d7..acf5fc7 100644 --- a/src/ui/test_vision/test_vision.py +++ b/src/ui/test_vision/test_vision.py @@ -10,8 +10,8 @@ from ui.test_test import Test_Test class Test_Vision(Test_Test): request_frame = pyqtSignal() - def __init__(self, components=None, recipe=None, step=None, run_once=False, enable_override=True): - super().__init__(components=components, recipe=recipe, step=step, run_once=run_once, enable_override=enable_override) + def __init__(self, components=None, recipe=None, step=None, pieces=None, run_once=False, enable_override=True): + super().__init__(components=components, recipe=recipe, step=step, pieces=pieces, run_once=run_once, enable_override=enable_override) if "--sim-camera" not in sys.argv: self.ok_counter_limit = 2 else: @@ -27,10 +27,10 @@ class Test_Vision(Test_Test): self.results_tw.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.results_tw.verticalHeader().setSectionResizeMode(QHeaderView.Stretch) - def start(self, recipe=None, step=None): - super().start(recipe=recipe, step=step) - if self.run_once is True and self.done is True and self.done_ok is True: - return + def start(self, recipe=None, step=None, pieces=None): + show = super().start(recipe=recipe, step=step, pieces=pieces) + if show is False: + return show # setup camera-vision loop if "uvc_camera" in self.components: self.components["uvc_camera"].set_period(period=None) # only get frame on request @@ -52,6 +52,7 @@ class Test_Vision(Test_Test): # DETECTIONS TABLE # hide previous results self.results_tw.setRowCount(0) + return show def stop(self): # disable camera-vision loop