dev
This commit is contained in:
parent
e73cf12878
commit
f3386630c3
|
|
@ -1,15 +1,65 @@
|
|||
import sys
|
||||
import logging
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal
|
||||
from PyQt5.QtCore import pyqtSignal, QTimer
|
||||
from PyQt5.QtGui import QColor, QImage, QPalette, QPixmap
|
||||
from PyQt5.QtWidgets import QHeaderView, QProgressBar, QTableWidgetItem
|
||||
from PyQt5.QtWidgets import QHeaderView, QProgressBar, QTableWidgetItem, QDialog, QVBoxLayout, QLabel
|
||||
|
||||
from src.lib.helpers.blocking_dialog import BlockingDialog
|
||||
from src.ui.helpers import calc_foreground_color
|
||||
from src.ui.test_test import Test_Test
|
||||
|
||||
|
||||
class SchemeProgressDialog(QDialog):
|
||||
"""
|
||||
Dialog to show scheme switching progress and block the UI until complete.
|
||||
"""
|
||||
def __init__(self, parent=None, target_scheme=""):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle("Switching Camera Scheme")
|
||||
self.setModal(True)
|
||||
self.setMinimumWidth(400)
|
||||
|
||||
layout = QVBoxLayout()
|
||||
self.setLayout(layout)
|
||||
|
||||
self.label = QLabel(f"Switching camera to scheme: {target_scheme}\nPlease wait...")
|
||||
layout.addWidget(self.label)
|
||||
|
||||
self.progress_bar = QProgressBar()
|
||||
self.progress_bar.setMinimum(0)
|
||||
self.progress_bar.setMaximum(100)
|
||||
layout.addWidget(self.progress_bar)
|
||||
|
||||
self.status_label = QLabel("Status: Initializing...")
|
||||
layout.addWidget(self.status_label)
|
||||
|
||||
# Set a timeout in case the progress signal doesn't complete
|
||||
self.timer = QTimer(self)
|
||||
self.timer.setSingleShot(True)
|
||||
self.timer.timeout.connect(self.handle_timeout)
|
||||
self.timer.start(30000) # 30 second timeout
|
||||
|
||||
def update_progress(self, progress, status):
|
||||
"""
|
||||
Update the progress bar and status label based on the progress signal.
|
||||
"""
|
||||
self.progress_bar.setValue(progress)
|
||||
self.status_label.setText(f"Status: {status}")
|
||||
|
||||
if progress >= 100 and status == "Success":
|
||||
self.accept()
|
||||
elif status == "Failed":
|
||||
self.reject()
|
||||
|
||||
def handle_timeout(self):
|
||||
"""
|
||||
Handle the case where the progress signal doesn't complete within the timeout.
|
||||
"""
|
||||
self.status_label.setText("Status: Timeout - Continuing anyway")
|
||||
self.accept() # Continue with the cycle even if timeout occurs
|
||||
|
||||
|
||||
class Test_Vision(Test_Test):
|
||||
request_frame = pyqtSignal()
|
||||
|
||||
|
|
@ -56,14 +106,40 @@ class Test_Vision(Test_Test):
|
|||
# Get the target scheme from the recipe name
|
||||
target_scheme = self.step.spec.get("recipe", "").replace(".ini", "")
|
||||
|
||||
# Use the synchronous scheme switching method
|
||||
self.log.info(f"Switching camera scheme to: {target_scheme}")
|
||||
success = self.components[cam_type].switch_scheme_sync(target_scheme, timeout=30)
|
||||
# Get the current scheme name from the camera
|
||||
current_scheme = self.components[cam_type].get_current_scheme()
|
||||
self.log.info(f"Current camera scheme: {current_scheme}, Target scheme: {target_scheme}")
|
||||
|
||||
if success:
|
||||
self.log.info(f"Successfully switched to scheme: {target_scheme}")
|
||||
# If schemes don't match or a scheme switch is already in progress, show the progress dialog
|
||||
if current_scheme != target_scheme or self.components[cam_type].current_operation == "switch_scheme":
|
||||
self.log.info(f"Waiting for camera to switch to scheme: {target_scheme}")
|
||||
|
||||
# Create and show the progress dialog
|
||||
progress_dialog = SchemeProgressDialog(self.ui, target_scheme=target_scheme)
|
||||
|
||||
# Connect to the progress signal
|
||||
progress_connection = self.components[cam_type].progress_signal.connect(
|
||||
progress_dialog.update_progress
|
||||
)
|
||||
|
||||
# If a scheme switch is not already in progress, start one
|
||||
if self.components[cam_type].current_operation != "switch_scheme":
|
||||
self.log.info(f"Initiating scheme switch to: {target_scheme}")
|
||||
self.components[cam_type].switch_scheme(target_scheme)
|
||||
|
||||
# Show the dialog and wait for it to complete
|
||||
result = progress_dialog.exec_()
|
||||
|
||||
# Disconnect from the progress signal
|
||||
self.components[cam_type].progress_signal.disconnect(progress_connection)
|
||||
|
||||
if result == QDialog.Rejected:
|
||||
# Scheme switching failed, but we'll continue anyway
|
||||
self.log.warning(f"Failed to switch to scheme: {target_scheme}, continuing anyway")
|
||||
else:
|
||||
self.log.info(f"Successfully switched to scheme: {target_scheme}")
|
||||
else:
|
||||
self.log.warning(f"Failed to switch to scheme: {target_scheme}, continuing anyway")
|
||||
self.log.info(f"Camera already using correct scheme: {current_scheme}")
|
||||
|
||||
self.components[cam_type].resume()
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user