Signal on led script change

This commit is contained in:
CPD 2025-03-05 17:06:08 +01:00
parent 27f3dba066
commit 3ac994a7d6
2 changed files with 29 additions and 6 deletions

View File

@ -2,18 +2,19 @@
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QLabel, QStatusBar, QFileDialog, \
QVBoxLayout
from PyQt6.QtWidgets import QToolBox
from PyQt6.QtWidgets import QToolBox, QTabWidget
from PyQt6.QtGui import QIcon, QPixmap
from PyQt6.QtWidgets import QDialog, QDialogButtonBox
from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QMessageBox
from ..resources import get_resource_path
from .widgets.menubar import MenuBar
from .widgets.toolbar import ToolBar
from .widgets.metadata_input import MetadataInput
from .widgets.measurement_settings import MeasurementSettings
from .widgets.measurement_settings import MeasurementSettings, ScriptSelection
from .widgets.plot import Plot
from .widgets.device_select import ListChoice
from .widgets.about import MarkdownView
from .widgets.led_script import LedScriptViewer
# from .widgets.treeview import TreeView
import multiprocessing as mp
@ -69,9 +70,16 @@ class MainWindow(QMainWindow):
self.w_leftbox.addItem(self.w_measurement_settings, "Measurement settings")
self.w_measurement_settings.set_value("interval", AppConfig.MAIN_CFG.get_or("interval", 0.5))
# Right: Plot
# Right: Tabs: Script, Plot
self.w_right_tab = QTabWidget()
layout.addWidget(self.w_right_tab)
self.w_plot = Plot()
layout.addWidget(self.w_plot)
self.w_right_tab.addTab(self.w_plot, "Plot")
# LED SCRIPT
self.w_led_script = LedScriptViewer(LedScript(0))
self.w_right_tab.addTab(self.w_led_script, "LED Script")
self.w_measurement_settings.w_led_script.script_changed.connect(self.led_script_load)
self.verbose = True
@ -298,6 +306,16 @@ class MainWindow(QMainWindow):
else:
self.set_status(f"Aborted saving data, no file selected")
def led_script_load(self):
script = self.w_measurement_settings.get_value("led_script")
try:
self.led_script = LedScript(script=script, auto_update=True, verbose=True)
except ValueError as e:
# show qt error
QMessageBox.critical(self, "LED script error", str(e))
return
self.w_led_script.set_script(self.led_script)
def app_exit(self) -> None:
"""
Closes the application.

View File

@ -1,3 +1,4 @@
from PyQt6.QtCore import pyqtSignal
from PyQt6.QtWidgets import QWidget, QRadioButton, QVBoxLayout, QHBoxLayout, QPushButton, QSpinBox, QFileDialog, QLabel
from PyQt6.QtWidgets import QFormLayout, QDoubleSpinBox, QCheckBox, QLineEdit, QGroupBox
@ -6,6 +7,7 @@ from os import path
from ...utility.config import AppConfig
class ScriptSelection(QGroupBox):
script_changed = pyqtSignal()
def __init__(self, parent=None):
super().__init__(parent=parent, title="LED Script")
self.layout = QVBoxLayout()
@ -25,6 +27,8 @@ class ScriptSelection(QGroupBox):
# QSpinBox for constant value
self.w_constant_value = QSpinBox()
self.w_constant_value.setRange(0, 100)
# signal when changed
self.w_constant_value.valueChanged.connect(lambda: self.script_changed.emit())
# Layouts
l_constant_value = QVBoxLayout()
@ -66,6 +70,8 @@ class ScriptSelection(QGroupBox):
AppConfig.MAIN_CFG.set("tmp_last_script_dir", dir_name)
self.file_path = file_path
self.w_script_file.setText(self.file_path)
# signal the change
self.script_changed.emit()
def get_script(self):
@ -117,7 +123,6 @@ class MeasurementSettings(QWidget):
self.l_form.addRow(QLabel(label), widget)
self.ws_form[key] = widget
def value_updated(self, key, value):
AppConfig.MEAS_CFG.set(key, value)