From 30b8120afa9bad9d304cd66063b5f7c41591b2f8 Mon Sep 17 00:00:00 2001 From: germano Date: Sun, 9 Jul 2023 22:57:18 +0200 Subject: [PATCH 1/3] copypaste fix --- src/ui/crud/CopyPastableCrudQTableWidget.py | 99 +++++++++++---------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/src/ui/crud/CopyPastableCrudQTableWidget.py b/src/ui/crud/CopyPastableCrudQTableWidget.py index 7709c73..b4b4de9 100644 --- a/src/ui/crud/CopyPastableCrudQTableWidget.py +++ b/src/ui/crud/CopyPastableCrudQTableWidget.py @@ -10,55 +10,56 @@ class CopyPastableCrudQTableWidget(QTableWidget): def eventFilter(self, target, event): if event.type() == QEvent.KeyPress: - if event.key() == Qt.Key_C and (event.modifiers() & Qt.ControlModifier): - if event.key() == Qt.Key_C and (event.modifiers() & Qt.ControlModifier): - copied_cells = sorted(self.selectedIndexes()) - min_row, max_row, min_col, max_col = sys.maxsize, 0, sys.maxsize, 0 - for cell in copied_cells: - row = cell.row() - min_row, max_row = min(row, min_row), max(row, max_row) - col = cell.column() - min_col, max_col = min(col, min_col), max(col, max_col) - if min_row == 0: # if filters row - return False - copy_sparse = {} - for cell in copied_cells: - row = cell.row() - col = cell.column() - if row not in copy_sparse: - copy_sparse[row] = {} - cell = self.cellWidget(row, col) - if cell is not None: - copy_sparse[row][col] = cell.parse(row_number=row, crud=weakref.ref(self.crud)) - copy_dense = [["" for col in range(max_col - min_col + 1)] for row in range(max_row - min_row + 1)] - for row, row_cells in copy_sparse.items(): - for col, cell_text in row_cells.items(): - if cell_text is not None: - copy_dense[row - min_row][col - min_col] = str(cell_text) - copy_text = "\n".join(["\t".join(row) for row in copy_dense]) - QApplication.clipboard().setText(copy_text) - super().keyPressEvent(event) - QApplication.sendEvent(self, event) - return True - elif event.key() == Qt.Key_V and (event.modifiers() & Qt.ControlModifier): - min_row = self.currentRow() - min_col = self.currentColumn() - if min_row == 0: # if filters row - return False - copy_text = QApplication.clipboard().text() - copy_dense = [row.split("\t") for row in copy_text.split("\n")] - if len(copy_dense) > 1 and len(copy_dense[-1]) == 1 and not len(copy_dense[-1][-1]): - copy_dense.pop(-1) - for row, row_cells in enumerate(copy_dense): - for col, cell_text in enumerate(row_cells): - r = min_row + row - c = min_col + col - cell = self.cellWidget(r, c) - if cell is not None: - cell.render(cell_text, field_name=self.crud.select[c] if self.crud is not None else None, row_number=r, crud=weakref.ref(self.crud)) - super().keyPressEvent(event) - QApplication.sendEvent(self, event) - return True + pass + # if event.key() == Qt.Key_C and (event.modifiers() & Qt.ControlModifier): + # if event.key() == Qt.Key_C and (event.modifiers() & Qt.ControlModifier): + # copied_cells = sorted(self.selectedIndexes()) + # min_row, max_row, min_col, max_col = sys.maxsize, 0, sys.maxsize, 0 + # for cell in copied_cells: + # row = cell.row() + # min_row, max_row = min(row, min_row), max(row, max_row) + # col = cell.column() + # min_col, max_col = min(col, min_col), max(col, max_col) + # if min_row == 0: # if filters row + # return False + # copy_sparse = {} + # for cell in copied_cells: + # row = cell.row() + # col = cell.column() + # if row not in copy_sparse: + # copy_sparse[row] = {} + # cell = self.cellWidget(row, col) + # if cell is not None: + # copy_sparse[row][col] = cell.parse(row_number=row, crud=weakref.ref(self.crud)) + # copy_dense = [["" for col in range(max_col - min_col + 1)] for row in range(max_row - min_row + 1)] + # for row, row_cells in copy_sparse.items(): + # for col, cell_text in row_cells.items(): + # if cell_text is not None: + # copy_dense[row - min_row][col - min_col] = str(cell_text) + # copy_text = "\n".join(["\t".join(row) for row in copy_dense]) + # QApplication.clipboard().setText(copy_text) + # super().keyPressEvent(event) + # QApplication.sendEvent(self, event) + # return True + # elif event.key() == Qt.Key_V and (event.modifiers() & Qt.ControlModifier): + # min_row = self.currentRow() + # min_col = self.currentColumn() + # if min_row == 0: # if filters row + # return False + # copy_text = QApplication.clipboard().text() + # copy_dense = [row.split("\t") for row in copy_text.split("\n")] + # if len(copy_dense) > 1 and len(copy_dense[-1]) == 1 and not len(copy_dense[-1][-1]): + # copy_dense.pop(-1) + # for row, row_cells in enumerate(copy_dense): + # for col, cell_text in enumerate(row_cells): + # r = min_row + row + # c = min_col + col + # cell = self.cellWidget(r, c) + # if cell is not None: + # cell.render(cell_text, field_name=self.crud.select[c] if self.crud is not None else None, row_number=r, crud=weakref.ref(self.crud)) + # super().keyPressEvent(event) + # QApplication.sendEvent(self, event) + # return True return super().eventFilter(target, event) def setCellWidget(self, row, column, widget): From bed886f2a5f99669bb4e9c69b74027777f58b667 Mon Sep 17 00:00:00 2001 From: stres1 Date: Wed, 12 Jul 2023 10:03:07 +0200 Subject: [PATCH 2/3] csv --- src/test/csv_import/test_import_himatic my24.csv | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/test/csv_import/test_import_himatic my24.csv diff --git a/src/test/csv_import/test_import_himatic my24.csv b/src/test/csv_import/test_import_himatic my24.csv new file mode 100644 index 0000000..acf0c77 --- /dev/null +++ b/src/test/csv_import/test_import_himatic my24.csv @@ -0,0 +1,13 @@ +codice_ricetta,cliente,codice_prodotto,descrizione,avvitatura_abilitata,viti,prova_tenuta_abilitata,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_svuotamento,stampa_etichetta_abilitata,modello_etichetta +5803148257,IVECO,5803148257,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn +5803148256,IVECO,5803148256,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn +5803148263,IVECO,5803148263,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn +5803148261,IVECO,5803148261,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn +5803148264,IVECO,5803148264,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn +5803148265,IVECO,5803148265,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn +5803148267,IVECO,5803148267,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn +5803148266,IVECO,5803148266,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn +5803166717,IVECO,5803166717,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn +5803148269,IVECO,5803148269,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn +5803148268,IVECO,5803148268,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn +5803167128,IVECO,5803167128,Daily Himatic MY24,,,x,5,5,10,10,5,30,5000,30,1,100,x,ETA30x16.prn From a819a2f7c20ad6baa2cf70e6f7b98a62103327cb Mon Sep 17 00:00:00 2001 From: neo-dl Date: Wed, 12 Jul 2023 19:37:57 +0200 Subject: [PATCH 3/3] write tags wip --- src/components/os_label_printer.py | 4 +- src/components/rfid_pn532.py | 60 +++++++++++-------- src/components/usb_586x.py | 2 +- src/scripts/fix_db_qpos_qneg.sqlite | 2 +- src/test/rfid.py | 8 ++- src/test_usb586x.py | 2 +- .../barcode_recipe_selection.py | 9 ++- 7 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/components/os_label_printer.py b/src/components/os_label_printer.py index 39d94f0..ccab0a4 100644 --- a/src/components/os_label_printer.py +++ b/src/components/os_label_printer.py @@ -8,7 +8,7 @@ from PyQt5.QtWidgets import QMessageBox from .component import Component -if platform.system() == "Windows": +if platform.system().lower() == "windows": import win32print @@ -43,7 +43,7 @@ class Os_Label_Printer(Component): for key, val in context.items(): key = "{" + key + "}" label_file_contents = label_file_contents.replace(key, val) - if platform.system() == "Windows": + if platform.system().lower() == "windows": try: printer = win32print.OpenPrinter(self.printer) job = win32print.StartDocPrinter(printer, 1, ("label", None, "RAW")) diff --git a/src/components/rfid_pn532.py b/src/components/rfid_pn532.py index c919ae6..86b03d0 100644 --- a/src/components/rfid_pn532.py +++ b/src/components/rfid_pn532.py @@ -1,3 +1,4 @@ +import copy import ctypes import sys import platform @@ -14,13 +15,14 @@ class RFID_PN532(Component): new_id_signal = pyqtSignal(str) def __init__(self, config=None, name=None, period=1, lazy=True, paused=False, threaded=True): super().__init__(config=config, name=name, period=period, lazy=lazy, paused=paused, threaded=threaded) + self.data_to_write = None self.mutex = QMutex() self.simulate="--sim-rfid" in sys.argv self.clf = None self.connected=False self.tag_present=False self.current_data=None - self.is_win = platform.system() == "Windows" + self.is_win = platform.system().lower() == "windows" self.dev_list = [f"{self.config['fixture_rfid']['port']}:pn532"] if self.is_win else ['tty:USB0:pn532','tty:USB1:pn532'] self._period = 1 @@ -43,30 +45,36 @@ class RFID_PN532(Component): @pyqtSlot() def _get(self): - try: - if not self.connected: - self.open_device() - else: - target = self.clf.sense(RemoteTarget('106A'), RemoteTarget('106B'), RemoteTarget('212F')) - if target is not None: - tag = nfc.tag.activate(self.clf, target) - if tag is not None: - self.log.debug("tag present") - if tag.ndef is not None: - tag_content=tag.ndef.records[0].text - if tag_content!=self.current_data: - self.log.info(f"new tag detected:{tag_content}") - self.current_data=tag_content - self.new_id_signal.emit(self.current_data) - else: - self.log.error("tag is not NDEF") + if self.mutex.tryLock(): + try: + if not self.connected: + self.open_device() else: - if self.current_data: - self.log.info(f"tag removed:{self.current_data}") - self.current_data = None - self.new_id_signal.emit(None) - self.log.debug("no target present") + target = self.clf.sense(RemoteTarget('106A'), RemoteTarget('106B'), RemoteTarget('212F')) + if target is not None: + tag = nfc.tag.activate(self.clf, target) + if tag is not None: + self.log.debug("tag present") + if tag.ndef is not None: + tag_content=tag.ndef.records[0].text + if tag_content!=self.current_data: + self.log.info(f"new tag detected:{tag_content}") + self.current_data=tag_content + self.new_id_signal.emit(self.current_data) + else: + self.log.error("tag is not NDEF") + else: + if self.current_data: + self.log.info(f"tag removed:{self.current_data}") + self.current_data = None + self.new_id_signal.emit(None) + self.log.debug("no target present") - except Exception as e: - self.log.info(f"{e}") - self.connected = False + except Exception as e: + self.log.info(f"{e}") + self.connected = False + finally: + self.mutex.unlock() + + def write_tag(self,data): + self.data_to_write=copy.deepcopy(data) diff --git a/src/components/usb_586x.py b/src/components/usb_586x.py index e4d12c1..a5cadee 100644 --- a/src/components/usb_586x.py +++ b/src/components/usb_586x.py @@ -8,7 +8,7 @@ from PyQt5.QtCore import QMutex, Qt, QTimer, pyqtSlot, pyqtSignal from .component import Component -is_win = platform.system() == "Windows" +is_win = platform.system().lower() == "windows" if "--sim-io" not in sys.argv: if is_win: diff --git a/src/scripts/fix_db_qpos_qneg.sqlite b/src/scripts/fix_db_qpos_qneg.sqlite index b73d7aa..d8afd95 100644 --- a/src/scripts/fix_db_qpos_qneg.sqlite +++ b/src/scripts/fix_db_qpos_qneg.sqlite @@ -1,5 +1,5 @@ -- REMEMBER TO BACKUP DB FIRST -- update steps set spec = json_insert(spec,"$.test_pressure_qpos",(json_extract(steps.spec, '$.test_pressure_max_delta'))) where type == "leak_1" or type=="leak_2"; update steps set spec = json_insert(spec,"$.test_pressure_qneg",(json_extract(steps.spec, '$.test_pressure_min_delta'))) where type == "leak_1" or type=="leak_2"; -update steps set spec = json_(spec,"$.test_pressure_qpos",(json_extract(steps.spec, '$.test_pressure_max_delta'))) where type == "leak_1" or type=="leak_2"; +update steps set spec = json_insert(spec,"$.test_pressure_qpos",(json_extract(steps.spec, '$.test_pressure_max_delta'))) where type == "leak_1" or type=="leak_2"; update steps set spec = json_insert(spec,"$.test_pressure_qneg",(json_extract(steps.spec, '$.test_pressure_min_delta'))) where type == "leak_1" or type=="leak_2"; diff --git a/src/test/rfid.py b/src/test/rfid.py index a84577d..ad48bbd 100644 --- a/src/test/rfid.py +++ b/src/test/rfid.py @@ -1,4 +1,5 @@ import logging +import platform import sys import time from datetime import datetime @@ -31,7 +32,12 @@ logging.basicConfig( ) connected=False -dev_list=['tty:USB0:pn532','tty:USB1:pn532','tty:USB2:pn532'] +is_win = platform.system().lower() == "windows" + +if is_win: + dev_list=['COM5:pn532'] +else: + dev_list = ['tty:USB0:pn532', 'tty:USB1:pn532', 'tty:USB2:pn532'] while True: try: if not connected: diff --git a/src/test_usb586x.py b/src/test_usb586x.py index a6ff41c..0d55c44 100644 --- a/src/test_usb586x.py +++ b/src/test_usb586x.py @@ -3,7 +3,7 @@ import platform import sys import time -if platform.system() == "Windows": +if platform.system().lower() == "windows": sys.path.append(f"{os.getcwd()}\src\components") from src.components.usb_586x import USB_586x from lib.helpers import ConfigReader diff --git a/src/ui/barcode_recipe_selection/barcode_recipe_selection.py b/src/ui/barcode_recipe_selection/barcode_recipe_selection.py index a66889c..7b7249a 100644 --- a/src/ui/barcode_recipe_selection/barcode_recipe_selection.py +++ b/src/ui/barcode_recipe_selection/barcode_recipe_selection.py @@ -71,24 +71,27 @@ class Barcode_Recipe_Selection(Test_Test): if data is None: return else: - lines = data.splitlines() candidates = [i for i in lines if len(i)==10] if len(candidates)>0: # RECIPE CODE FOUND self.recipe=candidates[-1] self.barcode_input_l.setPalette(self.status_palettes[True]) - self.ok_timer.start(2000) + + if "--write-tags" not in sys.argv: + self.ok_timer.start(2000) + else: + self.parent.components["rfid"].write_tag(data) else: # RECIPE CODE NOT FOUND self.barcode_input_l.setPalette(self.status_palettes[False]) self.focus_timer.start(3000) - # LOOKUP RECIPE def set_recipe(self): try: + # LOOKUP RECIPE recipe = self.recipe_db_model.get_by_id(self.recipe) self.parent.set_recipe(recipe) except peewee.DoesNotExist: