Add live metadata updates

This commit is contained in:
CPD 2025-03-17 15:30:25 +01:00
parent 9c566412ae
commit dc93134651
4 changed files with 22 additions and 6 deletions

View File

@ -87,6 +87,7 @@ class MainWindow(QMainWindow):
self.w_lefttab.addTab(self.w_measurement_settings, "Measurement settings") self.w_lefttab.addTab(self.w_measurement_settings, "Measurement settings")
# Measurement metadata # Measurement metadata
self.w_metadata = MetadataInput(metadata_init_dict) self.w_metadata = MetadataInput(metadata_init_dict)
self.w_metadata.metadataChanged.connect(self._metadata_updated)
self.w_lefttab.addTab(self.w_metadata, "Measurement metadata") self.w_lefttab.addTab(self.w_metadata, "Measurement metadata")
# TODO: the call_f solution isnt pretty # TODO: the call_f solution isnt pretty
# TODO: only accept single file? # TODO: only accept single file?
@ -274,7 +275,7 @@ class MainWindow(QMainWindow):
max_measurements = self.w_measurement_settings.get_value("max_measurements") max_measurements = self.w_measurement_settings.get_value("max_measurements")
stop_on_script_end = self.w_measurement_settings.get_value("stop_on_script_end") stop_on_script_end = self.w_measurement_settings.get_value("stop_on_script_end")
interval = self.w_measurement_settings.get_value("interval") interval = self.w_measurement_settings.get_value("interval")
auto_add_metadata = self.w_measurement_settings.get_value("auto_add_metadata") auto_add_metadata = AppConfig.MAIN_CFG.get_or("metadata_auto_add", True)
metadata = self.w_metadata.get_dict() metadata = self.w_metadata.get_dict()
metadata["name"] = name metadata["name"] = name
@ -289,6 +290,7 @@ class MainWindow(QMainWindow):
self.topbar.disable_button("meas_load") self.topbar.disable_button("meas_load")
self.topbar.enable_button("meas_stop") self.topbar.enable_button("meas_stop")
self.w_measurement_settings.setEnabled(False) self.w_measurement_settings.setEnabled(False)
if not AppConfig.MAIN_CFG.get_or("metadata_auto_update", True):
self.w_metadata.setEnabled(False) self.w_metadata.setEnabled(False)
self.w_plot.clear_data() self.w_plot.clear_data()
@ -490,6 +492,14 @@ class MainWindow(QMainWindow):
if self.measurement_is_running(): if self.measurement_is_running():
self.command_queue.put(("led_script", self.led_script.copy())) self.command_queue.put(("led_script", self.led_script.copy()))
def _metadata_updated(self):
"""
Send the new metadata to the measurement thread.
"""
if self.measurement_is_running() and AppConfig.MAIN_CFG.get_or("metadata_update_live", True):
metadata = self.w_metadata.get_dict()
self.command_queue.put(("metadata", metadata))
def app_exit(self) -> None: def app_exit(self) -> None:
""" """
Closes the application. Closes the application.

View File

@ -1,5 +1,6 @@
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QLabel, QLineEdit, QSpacerItem, QSpinBox, QDoubleSpinBox from PyQt6.QtWidgets import QWidget, QVBoxLayout, QLabel, QLineEdit, QSpacerItem, QSpinBox, QDoubleSpinBox
from PyQt6.QtWidgets import QGridLayout, QMenu, QListWidget, QPushButton, QFormLayout, QDialog, QDialogButtonBox from PyQt6.QtWidgets import QGridLayout, QMenu, QListWidget, QPushButton, QFormLayout, QDialog, QDialogButtonBox
from PyQt6.QtCore import pyqtSignal
""" """
QWidget class that contains a variable amount of key - input pairs. QWidget class that contains a variable amount of key - input pairs.
@ -8,6 +9,7 @@ pairs. The value may be text - line edit, float - qdoublespinbox and int - qspin
""" """
class MetadataInput(QWidget): class MetadataInput(QWidget):
metadataChanged = pyqtSignal()
def __init__(self, elements: list[tuple[str, str]]|dict[str,str]=None): def __init__(self, elements: list[tuple[str, str]]|dict[str,str]=None):
super().__init__() super().__init__()
# set layout # set layout
@ -68,6 +70,7 @@ class MetadataInput(QWidget):
ret = dialog.exec() ret = dialog.exec()
if ret == QDialog.DialogCode.Accepted: if ret == QDialog.DialogCode.Accepted:
self.add_element(dialog.key_input.text(), dialog.value_input.text()) self.add_element(dialog.key_input.text(), dialog.value_input.text())
self.metadataChanged.emit()
def add_element(self, key, init_val=""): def add_element(self, key, init_val=""):
if key in self.ws_elements: if key in self.ws_elements:
@ -79,6 +82,7 @@ class MetadataInput(QWidget):
self.l_grid.addWidget(w_label, row, 0) self.l_grid.addWidget(w_label, row, 0)
w_input= QLineEdit(str(init_val)) w_input= QLineEdit(str(init_val))
w_input.editingFinished.connect(self.metadataChanged)
self.l_grid.addWidget(w_input, row, 1) self.l_grid.addWidget(w_input, row, 1)
@ -98,6 +102,7 @@ class MetadataInput(QWidget):
self.l_grid.removeWidget(w) self.l_grid.removeWidget(w)
del self.ws_elements[name] del self.ws_elements[name]
self.layout_changed() self.layout_changed()
self.metadataChanged.emit()
def set_from_dict(self, d: dict[str, str]): def set_from_dict(self, d: dict[str, str]):

View File

@ -18,11 +18,14 @@ class AppSettings(QWidget):
w_plot_n.setMinimum(1000) w_plot_n.setMinimum(1000)
w_plot_n.setMaximum(200000) w_plot_n.setMaximum(200000)
w_plot_n.setSingleStep(1000) w_plot_n.setSingleStep(1000)
self.w_form.add_form_row("plot_max_data_points", "Max datapoints in the plot", 20000, w_plot_n, "Maximum number of datapoints in the live plot.\nThis value is limited to ensure performance is not degraded in long measurements") self.w_form.add_form_row("plot_max_data_points", "Max. Datapoints in the Plot", 20000, w_plot_n, "Maximum number of datapoints in the live plot.\nThis value is limited to ensure performance is not degraded in long measurements")
w_plot_dt = QSpinBox() w_plot_dt = QSpinBox()
w_plot_dt.setMinimum(10) w_plot_dt.setMinimum(10)
w_plot_dt.setMaximum(200000) w_plot_dt.setMaximum(200000)
w_plot_dt.setSingleStep(100) w_plot_dt.setSingleStep(100)
self.w_form.add_form_row("plot_update_interval_ms", "Plot update interval (ms)", 200, w_plot_dt, "Number of milliseconds to wait before updating the live plot") self.w_form.add_form_row("plot_update_interval_ms", "Plot Update Interval (ms)", 200, w_plot_dt, "Number of milliseconds to wait before updating the live plot")
self.w_form.add_form_row("led_script_watch_file", "Watch Led Script File", False, QCheckBox(), "Watch the LED script file for changes and reload it automatically") self.w_form.add_form_row("led_script_watch_file", "Watch Led Script File", False, QCheckBox(), "Watch the LED script file for changes and reload it automatically")
self.w_form.add_form_row("led_script_save_copy", "Copy Led Script to Cache Dir", True, QCheckBox(), "Save the final version of the led script in the cache directory")
self.w_form.add_form_row("metadata_auto_update", "Auto-Update Metadata", True, QCheckBox(), "Allow metadata updates while the program is running")
self.w_form.add_form_row("metadata_auto_add", "Auto-Add Metadata", True, QCheckBox(), "Automatically add measurement metadata to the data file.\nThis includes: device names, measurement mode, measurement interval, start and stop times, led script")

View File

@ -151,8 +151,6 @@ class MeasurementSettings(QWidget):
w_box_flush_after.setMaximum(2147483647) # max int32 w_box_flush_after.setMaximum(2147483647) # max int32
w_box_flush_after.setSingleStep(500) w_box_flush_after.setSingleStep(500)
self.w_form.add_form_row("flush_after", "Flush-Data Interval", 0, w_box_flush_after, "Number of measurements to take before writing the data to an intermediate file") self.w_form.add_form_row("flush_after", "Flush-Data Interval", 0, w_box_flush_after, "Number of measurements to take before writing the data to an intermediate file")
self.w_form.add_form_row("auto_add_metadata", "Auto-add Metadata", True, QCheckBox(self), "Automatically add measurement metadata to the data file.\nThis includes: device names, measurement mode, measurement interval, start and stop times, led script")
self.l_vbox.addStretch(1) self.l_vbox.addStretch(1)
def set_value(self, key, value): def set_value(self, key, value):