From 7e98430bd8d26dbbf9fc64eb7aa9f228f6f27cba Mon Sep 17 00:00:00 2001 From: niksirbi Date: Wed, 28 Feb 2024 18:20:00 +0000 Subject: [PATCH] pose file is loaded upon "Load" button click --- movement/napari/loader_widget.py | 23 +++++++++++-------- .../test_napari_widgets.py | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) rename tests/{test_integration => test_unit}/test_napari_widgets.py (82%) diff --git a/movement/napari/loader_widget.py b/movement/napari/loader_widget.py index aa27218d5..17be05458 100644 --- a/movement/napari/loader_widget.py +++ b/movement/napari/loader_widget.py @@ -41,6 +41,7 @@ def __init__(self, napari_viewer: Viewer, parent=None): self.create_source_software_widget() self.create_fps_widget() self.create_file_path_widget() + self.create_load_button() def create_source_software_widget(self): """Create a combo box for selecting the source software.""" @@ -66,12 +67,17 @@ def create_file_path_widget(self): self.file_path_edit = QLineEdit() self.browse_button = QPushButton("browse") self.browse_button.clicked.connect(self.open_file_dialog) - self.file_path_edit.returnPressed.connect(self.load_file_from_edit) # Layout for line edit and button self.file_path_layout = QHBoxLayout() self.file_path_layout.addWidget(self.file_path_edit) self.file_path_layout.addWidget(self.browse_button) - self.layout().addRow("Pose file:", self.file_path_layout) + self.layout().addRow("pose file:", self.file_path_layout) + + def create_load_button(self): + """Create a button to load the file and add layers to the viewer.""" + self.load_button = QPushButton("Load") + self.load_button.clicked.connect(lambda: self.load_file()) + self.layout().addRow(self.load_button) def open_file_dialog(self): dlg = QFileDialog() @@ -84,17 +90,14 @@ def open_file_dialog(self): file_paths = dlg.selectedFiles() # Set the file path in the line edit self.file_path_edit.setText(file_paths[0]) - # Load the file immediately after selection - self.load_file(file_paths[0]) - - def load_file_from_edit(self): - # Load the file based on the path in the QLineEdit - file_path = self.file_path_edit.text() - self.load_file(file_path) - def load_file(self, file_path): + def load_file(self): fps = self.fps_spinbox.value() source_software = self.source_software_combo.currentText() + file_path = self.file_path_edit.text() + if file_path == "": + logger.warning("No file path specified.") + return ds = load_poses.from_file(file_path, source_software, fps) self.data, self.props = ds_to_napari_tracks(ds) diff --git a/tests/test_integration/test_napari_widgets.py b/tests/test_unit/test_napari_widgets.py similarity index 82% rename from tests/test_integration/test_napari_widgets.py rename to tests/test_unit/test_napari_widgets.py index 5df0ae2e5..ad4f7be3f 100644 --- a/tests/test_integration/test_napari_widgets.py +++ b/tests/test_unit/test_napari_widgets.py @@ -4,7 +4,7 @@ @pytest.fixture -def movement_meta_widget(make_napari_viewer) -> MovementMetaWidget: +def meta_widget(make_napari_viewer) -> MovementMetaWidget: """Fixture to expose the MovementMetaWidget for testing. Simultaneously acts as a smoke test that the widget