From fab41962fddb31233b5e6782d93694f283b6096f Mon Sep 17 00:00:00 2001 From: CPD Date: Wed, 12 Mar 2025 17:45:58 +0100 Subject: [PATCH] Add rudimentary drag and drop --- cpdctrl_gui/ui/main_window.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cpdctrl_gui/ui/main_window.py b/cpdctrl_gui/ui/main_window.py index 9dd0144..b84aa79 100644 --- a/cpdctrl_gui/ui/main_window.py +++ b/cpdctrl_gui/ui/main_window.py @@ -86,8 +86,26 @@ class MainWindow(QMainWindow): # Measurement metadata self.w_metadata = MetadataInput(metadata_init_dict) self.w_lefttab.addTab(self.w_metadata, "Measurement metadata") + # TODO: the call_f solution isnt pretty + # TODO: only accept single file? + class RightTab(QTabWidget): + def __init__(self, call_f, parent=None): + super().__init__(parent) + self.setAcceptDrops(True) + self.call_f = call_f + def dragEnterEvent(self, event): + if event.mimeData().hasUrls(): + event.accept() + else: + event.ignore() + 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 = QTabWidget() + self.w_right_tab = RightTab(self.measurement_load) layout.addWidget(self.w_right_tab) max_data_points = AppConfig.MAIN_CFG.get_or("plot_max_data_points", 40000) self.w_plot = Plot(max_data_points=max_data_points)