Revert: remove features introduced by last two commits 58f5ee2 and 48e6acf

This commit is contained in:
edo-neo 2025-10-24 14:26:07 +02:00
parent 48e6acf2fb
commit 49e92c7aea
2 changed files with 10 additions and 125 deletions

View File

@ -107,21 +107,6 @@ class RFID_PN532(Component):
self.close_device()
self.rfid_error_signal.emit(False)
self.mutex.unlock()
else:
# Simulation mode: emit a signal with multiple RFID entries
if self.current_data is None:
# Simulate a tag with multiple entries
simulated_data = "123456789\n987654321\n555555555"
self.log.info(f"Simulating RFID tag with multiple entries: {simulated_data}")
self.current_data = simulated_data
self.new_id_signal.emit(self.current_data)
self.rfid_error_signal.emit(True)
elif "--sim-rfid-remove" in sys.argv:
# Simulate tag removal if requested
self.log.info(f"Simulating RFID tag removal")
self.current_data = None
self.new_id_signal.emit(None)
self.rfid_error_signal.emit(False)
def write_tag(self, data):
self.data_to_write = copy.deepcopy(data)
@ -158,3 +143,4 @@ class RFID_PN532(Component):
# Close AFTER writing and mutex release
if self.connected:
self.close_device() # close_device can raise exception

View File

@ -4,10 +4,10 @@ import peewee
from PyQt5 import Qt
from lib.helpers import timing
from PyQt5.QtCore import Qt, QTimer, QThread, pyqtSignal
from PyQt5.QtCore import Qt, QTimer, QThread
from PyQt5.QtGui import QKeySequence, QPixmap, QPalette, QColor
from PyQt5.QtWidgets import QShortcut, QApplication, QDialog, QVBoxLayout, QLabel, QPushButton, QPlainTextEdit, \
QHBoxLayout, QMessageBox, QWidget
QHBoxLayout, QMessageBox
from ui.test_test import Test_Test
from ui.widget import Widget
@ -16,64 +16,6 @@ from lib.db.models import Recipes , Users
test_scan="xxx\nyyy\nzzz"
class QRCodeScannerDialog(QDialog):
qr_code_scanned = pyqtSignal(str)
def __init__(self, parent=None, candidates=None):
super().__init__(parent)
self.setWindowTitle("Scansione QR Code")
self.setMinimumSize(500, 400)
layout = QVBoxLayout()
# Instructions
instructions = QLabel("SCANSIONARE IL QR CODE CON IL NOME DELLA RICETTA")
instructions.setStyleSheet("font-size: 16pt; font-weight: bold; color: blue;")
instructions.setAlignment(Qt.AlignCenter)
layout.addWidget(instructions)
# QR code input field
self.qr_input = QPlainTextEdit()
self.qr_input.setPlaceholderText("Il QR code apparirà qui...")
self.qr_input.textChanged.connect(self.on_text_changed)
self.qr_input.setStyleSheet("font-size: 14pt;")
layout.addWidget(self.qr_input)
# Candidates list
if candidates:
candidates_label = QLabel("Candidati possibili:")
candidates_label.setStyleSheet("font-size: 14pt; font-weight: bold;")
layout.addWidget(candidates_label)
candidates_layout = QVBoxLayout()
for candidate in candidates:
candidate_label = QLabel(f"- {candidate}")
candidate_label.setStyleSheet("font-size: 12pt;")
candidates_layout.addWidget(candidate_label)
candidates_widget = QWidget()
candidates_widget.setLayout(candidates_layout)
layout.addWidget(candidates_widget)
# Cancel button
cancel_button = QPushButton("Annulla")
cancel_button.setStyleSheet("font-size: 14pt; padding: 10px;")
cancel_button.clicked.connect(self.reject)
layout.addWidget(cancel_button)
self.setLayout(layout)
# Set focus to the input field
self.qr_input.setFocus()
def on_text_changed(self):
# When text is entered, emit the signal with the text
text = self.qr_input.toPlainText().strip()
if text:
self.qr_code_scanned.emit(text)
self.accept() # Close the dialog
class Barcode_Recipe_Selection(Test_Test):
def __init__(self, parent):
@ -139,20 +81,15 @@ class Barcode_Recipe_Selection(Test_Test):
lines = data.splitlines()
#lines = data.split("-")
candidates = [i for i in lines if len(i) in(9,10,11,12,13,17,18)]
if len(candidates) > 0:
if len(candidates)>0:
# RECIPE CODE FOUND
if len(candidates) > 1:
# Multiple candidates found, open QR code scanner
self.open_qr_scanner(candidates)
else:
# Only one candidate, use it directly
self.recipe = candidates[0]
self.barcode_input_l.setPalette(self.status_palettes[True])
self.recipe=candidates[-1]
self.barcode_input_l.setPalette(self.status_palettes[True])
if "--write-tags" not in sys.argv:
self.ok_timer.start(2000)
else:
self.parent.components["rfid"].write_tag(data)
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
@ -180,44 +117,6 @@ class Barcode_Recipe_Selection(Test_Test):
else:
self.parent_assembly_widget().set_text("SCANSIONARE BARCODE SELEZIONE RICETTA")
def open_qr_scanner(self, candidates):
"""
Opens a dialog for scanning a QR code when multiple candidates are found.
Args:
candidates (list): List of candidate recipe codes found in the RFID tag.
"""
dialog = QRCodeScannerDialog(self, candidates)
dialog.qr_code_scanned.connect(self.on_qr_code_scanned)
dialog.exec_()
def on_qr_code_scanned(self, qr_code_text):
"""
Handles the QR code scan result.
Args:
qr_code_text (str): The text scanned from the QR code.
"""
if not qr_code_text:
QMessageBox.warning(self, "Attenzione", "Nessun codice QR rilevato. Riprovare.")
return
# Try to find a recipe with the name from the QR code
try:
recipe = self.recipe_db_model.get(self.recipe_db_model.name == qr_code_text)
# Recipe found, set it
self.recipe = str(recipe.id)
self.barcode_input_l.setPalette(self.status_palettes[True])
self.parent_assembly_widget().set_text(f"RICETTA '{recipe.name}' SELEZIONATA", bg_color="green")
self.ok_timer.start(2000)
except peewee.DoesNotExist:
# Recipe not found, show error
error_msg = f"Ricetta '{qr_code_text}' non trovata nel database. Verificare il codice QR e riprovare."
QMessageBox.warning(self, "Attenzione", error_msg)
self.barcode_input_l.setPalette(self.status_palettes[False])
self.parent_assembly_widget().set_text("RICETTA NON TROVATA", bg_color="red")
self.focus_timer.start(3000)
def tag_write(self, data_to_write=None):
self.parent_assembly_widget().set_text("SCRITTURA TAG NFC ", bg_color=" yellow")
tag_data = data_to_write if data_to_write else self.barcode_input_l.toPlainText().strip()