diff --git a/cpdctrl_gui/ui/main_window.py b/cpdctrl_gui/ui/main_window.py index b84aa79..2116a71 100644 --- a/cpdctrl_gui/ui/main_window.py +++ b/cpdctrl_gui/ui/main_window.py @@ -278,12 +278,12 @@ class MainWindow(QMainWindow): log.info(f"Starting measurement with:\n\tinterval = {interval}\n\tflush_after = {flush_after}\n\tuse_buffer = {use_buffer}\n\tmax_measurements = {max_measurements}\n\tstop_on_script_end = {stop_on_script_end}") - # the time left estimation might be a little to short, since the actual measurement is started a few lines of - # code later - t_now = time.time() - self.w_led_script.w_time_left.set_start_end_time(t_now, t_now + led_script.script["dtsum"][-1]) + # have the led script member be the only auto-updating script, + # and pass a non-updating copy to the measurement thread + if self.led_script is None: + self.led_script_load() + led_script_no_update = self.led_script.copy() - self.led_script = LedScript(script=script, auto_update=True, verbose=True) self.data_collector = DataCollector(metadata=metadata, data_path=AppConfig.MAIN_CFG.get("dir_cache"), data_name=name) # data_collector.clear() self.data_queue = mp.Queue() @@ -292,7 +292,7 @@ class MainWindow(QMainWindow): self.proc_measure = mt.Thread(target=measure, args=( self.vmdev, self.leddev, - self.led_script, + led_script_no_update, self.data_collector, interval, flush_after, @@ -309,25 +309,31 @@ class MainWindow(QMainWindow): self.measurement_timer.timeout.connect(self.measure_update) self.measurement_timer.start(300) # TODO: set interval + # the time left estimation might be a little to short, since the actual measurement is started a few lines of + # code later + self.led_script.start() + self.w_led_script.update_time_predictions() + def measure_stop(self): log.info("Stopping measurement") if not self.measurement_is_running(): raise RuntimeError("measure_stop: Measurement is not running") + self.set_status("Stopping measurement") self.command_queue.put("stop") self.measurement_timer.stop() self.proc_measure.join() - self.set_status("Ready") - self.led_script.stop_updating() # stop watching for file updates (if enabled) + self.set_status("Saving data...") self.data_collector.save_csv(verbose=True) - data, metadata = self.data_collector.get_data() self.proc_measure = None - self.led_script = None + # dont update w_led_script, keep displaying the last values + self.led_script.reset() self.topbar.enable_button("meas_start") self.topbar.enable_button("connect_vmdev") self.topbar.enable_button("connect_leddev") self.topbar.enable_button("meas_save") self.topbar.enable_button("meas_load") self.topbar.disable_button("meas_stop") + self.set_status("Ready") def measure_update(self): import time @@ -368,12 +374,12 @@ class MainWindow(QMainWindow): if self.measurement_is_running(): QMessageBox.critical(self, "Measurement running", "Can not load data while measurement is running") return - - if os.path.isfile(filepath): data, mdata = DataCollector.load_data_from_csv(filepath) + elif os.path.isdir(filepath): + data, mdata = DataCollector.load_data_from_dir(filepath) else: - raise FileNotFoundError(f"No such file or directory {filepath} not found") + raise FileNotFoundError(f"No such file or directory: '{filepath}'") self.w_plot.set_data(data[:,1], data[:,2], data[:,3]) def measurement_load_dialog(self): @@ -394,12 +400,20 @@ class MainWindow(QMainWindow): 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) + self.led_script = LedScript(script=script, auto_update=AppConfig.MAIN_CFG.get_or("led_script_watch_file", False), verbose=True) except ValueError as e: # show qt error QMessageBox.critical(self, "LED script error", str(e)) return + self.led_script_updated() + + def led_script_updated(self): + # update the measurement led script + if self.measurement_is_running(): + self.command_queue.put(("led_script", self.led_script.copy())) self.w_led_script.set_script(self.led_script) + # update gui + self.w_led_script.update_time_predictions() def app_exit(self) -> None: """ diff --git a/cpdctrl_gui/ui/widgets/settings/app_settings.py b/cpdctrl_gui/ui/widgets/settings/app_settings.py index b503d96..d1a3743 100644 --- a/cpdctrl_gui/ui/widgets/settings/app_settings.py +++ b/cpdctrl_gui/ui/widgets/settings/app_settings.py @@ -19,4 +19,5 @@ class AppSettings(QWidget): w_plot_n.setMaximum(200000) 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("led_script_watch_file", "Watch Led Script File", False, QCheckBox(), "Watch the LED script file for changes and reload it automatically")