Add drag-n-drop load data from directory

This commit is contained in:
CPD 2025-03-17 10:33:14 +01:00
parent 5e3d4a4328
commit 2f28d6f122

View File

@ -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
# 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):
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: