dev rfid new featured wip

This commit is contained in:
edo-neo 2025-02-10 15:41:36 +01:00
parent 89565ef276
commit ceebe6ad6c
3 changed files with 220 additions and 51 deletions

View File

@ -3,7 +3,7 @@ import ctypes
import sys import sys
import platform import platform
from PyQt5.QtCore import QMutex, Qt, QTimer, pyqtSlot, pyqtSignal from PyQt5.QtCore import QMutex, Qt, QTimer, pyqtSlot, pyqtSignal
from .component import Component from src.components import Component
import ndef import ndef
import src.lib.nfc import src.lib.nfc
from src.lib.nfc.clf import RemoteTarget from src.lib.nfc.clf import RemoteTarget

View File

@ -6,14 +6,52 @@ from PyQt5 import Qt
from lib.helpers import timing from lib.helpers import timing
from PyQt5.QtCore import Qt, QTimer, QThread from PyQt5.QtCore import Qt, QTimer, QThread
from PyQt5.QtGui import QKeySequence, QPixmap, QPalette, QColor from PyQt5.QtGui import QKeySequence, QPixmap, QPalette, QColor
from PyQt5.QtWidgets import QShortcut, QApplication from PyQt5.QtWidgets import QShortcut, QApplication, QDialog, QVBoxLayout, QLabel, QPushButton, QPlainTextEdit, \
QHBoxLayout, QMessageBox
from ui.test_test import Test_Test from ui.test_test import Test_Test
from ui.widget import Widget from ui.widget import Widget
from lib import db from lib import db
from lib.db.models import Recipes from lib.db.models import Recipes , Users
test_scan="xxx\nyyy\nzzz" test_scan="xxx\nyyy\nzzz"
class TagWindow(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Scrittura NFC")
self.setFixedSize(400, 300)
layout = QVBoxLayout(self)
self.text_edit = QPlainTextEdit(self)
self.text_edit.setPlaceholderText("Scanerizza il QRcode della Dima")
self.text_edit.setFixedHeight(100)
layout.addWidget(self.text_edit)
button_layout = QHBoxLayout()
self.ok_button = QPushButton("Conferma Tag", self)
self.ok_button.clicked.connect(self.on_ok_clicked)
# Create the Close button
self.close_button = QPushButton("Chiudi", self)
self.close_button.clicked.connect(self.close)
button_layout.addWidget(self.ok_button)
button_layout.addWidget(self.close_button)
layout.addLayout(button_layout)
def on_ok_clicked(self):
entered_text = self.text_edit.toPlainText()
print(f"Text Entered: {entered_text}")
self.accept()
class Barcode_Recipe_Selection(Test_Test): class Barcode_Recipe_Selection(Test_Test):
def __init__(self, parent): def __init__(self, parent):
super().__init__() super().__init__()
@ -34,6 +72,8 @@ class Barcode_Recipe_Selection(Test_Test):
self.status_palettes["warning"].setColor(QPalette.Base, QColor(255, 165, 0)) self.status_palettes["warning"].setColor(QPalette.Base, QColor(255, 165, 0))
self.status_palettes[""].setColor(QPalette.Base, QColor(255, 255, 0)) self.status_palettes[""].setColor(QPalette.Base, QColor(255, 255, 0))
self.tag_b.clicked.connect(self.open_tag_window)
self.recipe_selection_b.clicked.connect(self.parent.set_recipe_mode_table) self.recipe_selection_b.clicked.connect(self.parent.set_recipe_mode_table)
self.barcode_input_l.setFocus() self.barcode_input_l.setFocus()
@ -49,6 +89,12 @@ class Barcode_Recipe_Selection(Test_Test):
self.ok_timer.setSingleShot(True) self.ok_timer.setSingleShot(True)
self.ok_timer.timeout.connect(self.set_recipe) self.ok_timer.timeout.connect(self.set_recipe)
session= Users.get_session()
if session.is_admin:
self.tag_b.setVisible(True)
else:
self.tag_b.setVisible(False)
def start(self, recipe=None, step=None, pieces=None): def start(self, recipe=None, step=None, pieces=None):
@ -113,4 +159,35 @@ class Barcode_Recipe_Selection(Test_Test):
self.parent_assembly_widget().set_text("SCANSIONARE BARCODE SELEZIONE RICETTA") self.parent_assembly_widget().set_text("SCANSIONARE BARCODE SELEZIONE RICETTA")
def open_tag_window(self):
# Open the tag writing window
self.tag_window = TagWindow(self)
result = self.tag_window.exec_() # Get the result of the dialog (OK or Cancel)
if result != QDialog.Accepted:
return # If canceled, return
entered_text = self.tag_window.text_edit.toPlainText().strip()
if not entered_text:
QMessageBox.warning(
self,
"Warning",
"The text is empty. Please enter text to write to the tag.",
)
return
# Check if the tag is empty
if self.parent.components["fixture_id"].current_data:
# Tag already contains data, ask for confirmation to overwrite
confirmation_result = QMessageBox.question(
self,
"Tag Already Written",
"The tag already contains data. Do you want to overwrite it?",
QMessageBox.Yes | QMessageBox.No,
)
if confirmation_result == QMessageBox.No:
return # User does not want to overwrite, so return without writing
# Write the entered text to the tag
self.parent.components["fixture_id"].write_tag(entered_text)
QMessageBox.information(self, "Success", "The tag has been successfully written.")

View File

@ -13,20 +13,37 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Test Connector</string> <string>Test Connector</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="leftMargin"> <item row="1" column="3">
<number>0</number> <spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property> </property>
<property name="topMargin"> <property name="sizeHint" stdset="0">
<number>0</number> <size>
<width>308</width>
<height>20</height>
</size>
</property> </property>
<property name="rightMargin"> </spacer>
<number>0</number> </item>
<item row="4" column="1" colspan="2">
<widget class="QPushButton" name="recipe_selection_b">
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property> </property>
<property name="bottomMargin"> <property name="text">
<number>0</number> <string>TORNA ALLA TABELLA RICETTE</string>
</property> </property>
<item row="2" column="0" alignment="Qt::AlignHCenter"> </widget>
</item>
<item row="1" column="1" rowspan="2" colspan="2">
<widget class="QPlainTextEdit" name="barcode_input_l"> <widget class="QPlainTextEdit" name="barcode_input_l">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@ -50,18 +67,93 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" alignment="Qt::AlignHCenter"> <item row="3" column="1">
<widget class="QPushButton" name="recipe_selection_b"> <spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>78</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>378</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="2">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>78</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>168</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="tag_b">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font"> <property name="font">
<font> <font>
<pointsize>20</pointsize> <pointsize>11</pointsize>
</font> </font>
</property> </property>
<property name="text"> <property name="text">
<string>TORNA ALLA TABELLA RICETTE</string> <string>SCRIVI TAG NFC</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>28</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>