From d9947e18a9334461447e01f25be35bd6bd518aac Mon Sep 17 00:00:00 2001 From: CPD Date: Mon, 17 Mar 2025 16:06:33 +0100 Subject: [PATCH] Add store led script after measurement --- cpdctrl_gui/ui/main_window.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cpdctrl_gui/ui/main_window.py b/cpdctrl_gui/ui/main_window.py index 407236d..c39d9ea 100644 --- a/cpdctrl_gui/ui/main_window.py +++ b/cpdctrl_gui/ui/main_window.py @@ -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