2023-03-03 17:51:35 +00:00
|
|
|
import sys
|
|
|
|
|
|
2023-03-29 16:12:27 +00:00
|
|
|
import peewee
|
2023-03-03 17:51:35 +00:00
|
|
|
from PyQt5 import Qt
|
|
|
|
|
|
|
|
|
|
from lib.helpers import timing
|
|
|
|
|
from PyQt5.QtCore import Qt, QTimer, QThread
|
|
|
|
|
from PyQt5.QtGui import QKeySequence, QPixmap, QPalette, QColor
|
2025-02-10 14:41:36 +00:00
|
|
|
from PyQt5.QtWidgets import QShortcut, QApplication, QDialog, QVBoxLayout, QLabel, QPushButton, QPlainTextEdit, \
|
|
|
|
|
QHBoxLayout, QMessageBox
|
2023-06-26 17:21:12 +00:00
|
|
|
|
|
|
|
|
from ui.test_test import Test_Test
|
2023-03-03 17:51:35 +00:00
|
|
|
from ui.widget import Widget
|
2023-03-29 16:12:27 +00:00
|
|
|
from lib import db
|
2025-02-10 14:41:36 +00:00
|
|
|
from lib.db.models import Recipes , Users
|
2023-03-03 17:51:35 +00:00
|
|
|
test_scan="xxx\nyyy\nzzz"
|
|
|
|
|
|
2025-02-10 14:41:36 +00:00
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
2023-06-26 17:21:12 +00:00
|
|
|
class Barcode_Recipe_Selection(Test_Test):
|
2023-03-25 14:42:32 +00:00
|
|
|
def __init__(self, parent):
|
2023-03-03 17:51:35 +00:00
|
|
|
super().__init__()
|
2023-03-25 14:42:32 +00:00
|
|
|
self.parent=parent
|
2023-06-26 17:21:12 +00:00
|
|
|
self.components=parent.components
|
2023-03-29 16:12:27 +00:00
|
|
|
self.recipe_db_model=Recipes
|
|
|
|
|
self.debounce_time = 200
|
|
|
|
|
self.barcode_input_l.textChanged.connect(self.debounce)
|
2023-03-03 17:51:35 +00:00
|
|
|
self.status_palettes = {
|
|
|
|
|
True: QPalette(),
|
|
|
|
|
"": QPalette(),
|
|
|
|
|
"warning": QPalette(),
|
|
|
|
|
False: QPalette(),
|
|
|
|
|
None: QPalette(),
|
|
|
|
|
}
|
|
|
|
|
self.status_palettes[True].setColor(QPalette.Base, Qt.green)
|
|
|
|
|
self.status_palettes[False].setColor(QPalette.Base, Qt.red)
|
|
|
|
|
self.status_palettes["warning"].setColor(QPalette.Base, QColor(255, 165, 0))
|
|
|
|
|
self.status_palettes[""].setColor(QPalette.Base, QColor(255, 255, 0))
|
|
|
|
|
|
2025-02-10 14:41:36 +00:00
|
|
|
self.tag_b.clicked.connect(self.open_tag_window)
|
|
|
|
|
|
2023-03-25 15:09:23 +00:00
|
|
|
self.recipe_selection_b.clicked.connect(self.parent.set_recipe_mode_table)
|
2023-03-03 17:51:35 +00:00
|
|
|
self.barcode_input_l.setFocus()
|
2023-03-25 14:42:32 +00:00
|
|
|
|
2023-03-03 17:51:35 +00:00
|
|
|
self.focus_timer = QTimer()
|
|
|
|
|
self.focus_timer.setSingleShot(True)
|
|
|
|
|
self.focus_timer.timeout.connect(self.set_focus)
|
|
|
|
|
|
2023-03-29 16:12:27 +00:00
|
|
|
self.wait_timer = QTimer()
|
|
|
|
|
self.wait_timer.setSingleShot(True)
|
|
|
|
|
self.wait_timer.timeout.connect(self.get)
|
|
|
|
|
|
|
|
|
|
self.ok_timer = QTimer()
|
|
|
|
|
self.ok_timer.setSingleShot(True)
|
|
|
|
|
self.ok_timer.timeout.connect(self.set_recipe)
|
|
|
|
|
|
2025-02-10 14:41:36 +00:00
|
|
|
session= Users.get_session()
|
|
|
|
|
|
|
|
|
|
if session.is_admin:
|
|
|
|
|
self.tag_b.setVisible(True)
|
|
|
|
|
else:
|
|
|
|
|
self.tag_b.setVisible(False)
|
2023-06-26 17:21:12 +00:00
|
|
|
|
2023-03-03 17:51:35 +00:00
|
|
|
def start(self, recipe=None, step=None, pieces=None):
|
|
|
|
|
|
|
|
|
|
self.barcode_input_l.setPalette(self.status_palettes[None])
|
|
|
|
|
self.barcode_input_l.setPlainText("")
|
|
|
|
|
self.barcode_input_l.setFocus()
|
2024-02-23 17:34:17 +00:00
|
|
|
if self.parent.tag_loaded_recipe is not None:
|
|
|
|
|
self.get(self.parent.tag_loaded_recipe)
|
2023-03-03 17:51:35 +00:00
|
|
|
self.focus_timer.start(500)
|
|
|
|
|
|
2023-03-29 16:12:27 +00:00
|
|
|
def debounce(self):
|
|
|
|
|
if self.wait_timer.remainingTime()>0:
|
|
|
|
|
self.wait_timer.setInterval(self.debounce_time)
|
|
|
|
|
else:
|
|
|
|
|
self.wait_timer.start(self.debounce_time)
|
|
|
|
|
|
2023-03-03 17:51:35 +00:00
|
|
|
def get(self, data=None, override=False):
|
|
|
|
|
if data is None:
|
|
|
|
|
data = self.barcode_input_l.toPlainText()
|
|
|
|
|
if not len(data):
|
|
|
|
|
data = None
|
|
|
|
|
if data is None:
|
|
|
|
|
return
|
|
|
|
|
else:
|
2024-05-13 07:02:44 +00:00
|
|
|
lines = data.splitlines()
|
|
|
|
|
#lines = data.split("-")
|
2025-01-14 14:24:15 +00:00
|
|
|
candidates = [i for i in lines if len(i) in(9,10,12,13)]
|
2023-03-29 16:12:27 +00:00
|
|
|
if len(candidates)>0:
|
|
|
|
|
# RECIPE CODE FOUND
|
|
|
|
|
self.recipe=candidates[-1]
|
|
|
|
|
self.barcode_input_l.setPalette(self.status_palettes[True])
|
2023-07-12 17:37:57 +00:00
|
|
|
|
|
|
|
|
if "--write-tags" not in sys.argv:
|
|
|
|
|
self.ok_timer.start(2000)
|
|
|
|
|
else:
|
|
|
|
|
self.parent.components["rfid"].write_tag(data)
|
2023-03-29 16:12:27 +00:00
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
# RECIPE CODE NOT FOUND
|
|
|
|
|
self.barcode_input_l.setPalette(self.status_palettes[False])
|
|
|
|
|
self.focus_timer.start(3000)
|
2023-03-03 17:51:35 +00:00
|
|
|
|
2023-03-29 16:12:27 +00:00
|
|
|
def set_recipe(self):
|
|
|
|
|
try:
|
2023-07-12 17:37:57 +00:00
|
|
|
# LOOKUP RECIPE
|
2023-03-29 16:12:27 +00:00
|
|
|
recipe = self.recipe_db_model.get_by_id(self.recipe)
|
|
|
|
|
self.parent.set_recipe(recipe)
|
|
|
|
|
except peewee.DoesNotExist:
|
|
|
|
|
self.barcode_input_l.setPalette(self.status_palettes[False])
|
|
|
|
|
self.focus_timer.start(3000)
|
2023-07-27 16:19:05 +00:00
|
|
|
self.parent_assembly_widget().set_text("RICETTA NON TROVATA",bg_color="red")
|
2023-03-29 16:12:27 +00:00
|
|
|
|
2023-03-03 17:51:35 +00:00
|
|
|
def set_focus(self):
|
|
|
|
|
self.barcode_input_l.setFocus()
|
|
|
|
|
self.barcode_input_l.setPlainText("")
|
|
|
|
|
self.barcode_input_l.setPalette(self.status_palettes[""])
|
2023-03-29 16:12:27 +00:00
|
|
|
if getattr(self.parent.centralWidget,"set_text"):
|
2023-06-26 17:21:12 +00:00
|
|
|
if "fixture_id" in self.components.keys():
|
|
|
|
|
self.parent_assembly_widget().set_text(
|
|
|
|
|
"INSERIRE LA DIMA PER SELEZIONARE AUTOMATICAMENTE LA RICETTA DI COLLAUDO")
|
|
|
|
|
else:
|
|
|
|
|
self.parent_assembly_widget().set_text("SCANSIONARE BARCODE SELEZIONE RICETTA")
|
2023-03-29 16:12:27 +00:00
|
|
|
|
2023-03-03 17:51:35 +00:00
|
|
|
|
2025-02-10 14:41:36 +00:00
|
|
|
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
|
2023-03-03 17:51:35 +00:00
|
|
|
|
2025-02-10 14:41:36 +00:00
|
|
|
# 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.")
|