diff --git a/cpdctrl_gui/ui/main_window.py b/cpdctrl_gui/ui/main_window.py index 79c5033..30835c4 100644 --- a/cpdctrl_gui/ui/main_window.py +++ b/cpdctrl_gui/ui/main_window.py @@ -19,6 +19,7 @@ from .widgets.about import MarkdownView from .widgets.led_script import LedScriptViewer # from .widgets.treeview import TreeView +import pickle import logging log = logging.getLogger(__name__) @@ -101,9 +102,7 @@ class MainWindow(QMainWindow): def dropEvent(self, event): for url in event.mimeData().urls(): file_path = url.path()[1:] - if file_path.endswith("csv"): - self.call_f(file_path) - return + self.call_f(file_path) # Right: Tabs: Script, Plot self.w_right_tab = RightTab(self.measurement_load) layout.addWidget(self.w_right_tab) @@ -381,7 +380,6 @@ class MainWindow(QMainWindow): elif file_path.endswith(".pkl"): AppConfig.MAIN_CFG.set("tmp_last_measurement_save_ext", "pkl") data = self.data_collector.get_data() - import pickle with open(file_path, "wb") as f: pickle.dump(data, f) else: @@ -391,11 +389,18 @@ class MainWindow(QMainWindow): self.set_status(f"Aborted saving data, no file selected") def measurement_load(self, filepath): + log.info(f"Loading measurement data from '{filepath}'") 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) + if filepath.endswith(".pkl"): + with open(filepath, "rb") as file: + data, mdata = pickle.load(file) + elif filepath.endswith(".csv"): + data, mdata = DataCollector.load_data_from_csv(filepath) + else: + raise NotImplementedError(f"Unknown file extension in path: '{filepath}'.\nOnly .pkl and .csv can be loaded") elif os.path.isdir(filepath): data, mdata = DataCollector.load_data_from_dir(filepath) else: