Add store led script after measurement

This commit is contained in:
CPD 2025-03-17 16:06:33 +01:00
parent dc93134651
commit d9947e18a9

View File

@ -33,7 +33,7 @@ from ..utility.config import AppConfig
import cpdctrl.voltage_measurement_device as vmd
import cpdctrl.led_control_device as ledd
from cpdctrl.led_script import LedScript
from cpdctrl.led_script import LedScript, InvalidScript
from cpdctrl.utility.data import DataCollector
from cpdctrl.measurement import measure
@ -343,6 +343,21 @@ class MainWindow(QMainWindow):
self.proc_measure = None
# don't update w_led_script, keep displaying the last values
self.led_script.reset()
# store a copy of the led script
if AppConfig.MAIN_CFG.get_or("led_script_save_copy", True):
filename = self.led_script.filepath
extra_header = []
if filename is None:
filename = "led_script.led"
else:
filename = os.path.basename(filename)
extra_header.append(f"# Original file path: {self.led_script.filepath}")
filename = "led_script.led" # always use led_script.led
datadir = self.data_collector.dirpath
filepath = os.path.join(datadir, filename)
led_script = self.led_script.to_file(add_default_header=True, add_extra_header=extra_header)
with open(filepath, "w") as f:
f.write(led_script)
self.topbar.enable_button("meas_start")
self.topbar.enable_button("connect_vmdev")
self.topbar.enable_button("connect_leddev")
@ -460,9 +475,9 @@ class MainWindow(QMainWindow):
log.info(f"Loading led script of type '{script_type}' with auto-update {auto_update}")
try:
self.led_script = LedScript(script=script, auto_update=False, verbose=True)
except ValueError as e:
except InvalidScript as e:
# show qt error
QMessageBox.critical(self, "LED script error", str(e))
QMessageBox.critical(self, "Invalid script", str(e))
return
if auto_update and script_type == "file":
# can not use "integrated" auto update function because we cant receive qt signals