Skip to content

Commit fa8fc22

Browse files
committed
Registration: Propagate the result of the atlas loading dialog
This allows calling code to handle cases where the user cancelled the (down)load.
1 parent 85481f3 commit fa8fc22

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/histalign/frontend/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def prepare_gui_for_new_project(self) -> None:
335335
tab.alignment_widget.reset_volume()
336336
tab.alignment_widget.reset_histology()
337337

338-
def switch_workspace(self) -> None:
338+
def switch_workspace(self) -> bool:
339339
"""Handles a change in the current workspace.
340340
341341
Note that when this function is called, the workspace should already have been
@@ -353,7 +353,7 @@ def switch_workspace(self) -> None:
353353
# Update the registration tab
354354
tab = self.registration_tab
355355

356-
tab.load_atlas()
356+
return tab.load_atlas()
357357

358358
def propagate_workspace(self) -> None:
359359
"""Ensures workspace models are properly shared with all that rely on it."""
@@ -412,7 +412,9 @@ def _create_project(self, settings: ProjectSettings) -> None:
412412

413413
# Initialise a new workspace
414414
self.workspace = Workspace(settings)
415-
self.switch_workspace()
415+
if not self.switch_workspace():
416+
# The user cancelled the download/load of the atlas
417+
return
416418

417419
# Update workspace state
418420
self.workspace_is_dirty = True
@@ -455,7 +457,9 @@ def _open_project(self, path: str | Path) -> None:
455457
except ValueError as e:
456458
_module_logger.error(f"Failed to load project from '{path}': {e}")
457459
return InvalidProjectFileDialog(self).open()
458-
self.switch_workspace()
460+
if not self.switch_workspace():
461+
# The user cancelled the download/load of the atlas
462+
return
459463

460464
# Restore registration saved state
461465
tab = self.registration_tab

src/histalign/frontend/registration/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def clear_volume_state(self) -> None:
341341
"""Clears any atlas on the GUI."""
342342
self.alignment_widget.reset_volume()
343343

344-
def load_atlas(self) -> int:
344+
def load_atlas(self) -> bool:
345345
"""Loads the atlas and annotations volumes."""
346346
_module_logger.debug("Loading atlas and annotations.")
347347

@@ -355,14 +355,19 @@ def load_atlas(self) -> int:
355355
annotation_volume.loaded.connect(
356356
lambda: _module_logger.debug("Annotations loaded.")
357357
)
358-
self.annotation_volume = annotation_volume
359358
atlas_volume = unwrap(self.alignment_widget.volume_slicer).volume
360359

361360
# Set up the dialog and loader threads
362361
dialog = AtlasProgressDialog(self)
363362
annotation_loader_thread = VolumeLoaderThread(annotation_volume)
364363
atlas_loader_thread = VolumeLoaderThread(atlas_volume)
365364

365+
dialog.canceled.connect(annotation_loader_thread.requestInterruption)
366+
dialog.canceled.connect(atlas_loader_thread.requestInterruption)
367+
dialog.canceled.connect(
368+
lambda: _module_logger.debug("Volume (down)loading cancelled by user.")
369+
)
370+
366371
atlas_volume.downloaded.connect(
367372
lambda: dialog.setLabelText("Loading atlas"),
368373
type=QtCore.Qt.ConnectionType.QueuedConnection,
@@ -379,13 +384,17 @@ def load_atlas(self) -> int:
379384
annotation_loader_thread.start()
380385
atlas_loader_thread.start()
381386

382-
result = dialog.exec() # Blocking
387+
result = QtWidgets.QDialog.DialogCode(dialog.exec()) # Blocking
383388

384389
# Ensure we wait for the threads to be destroyed
385390
annotation_loader_thread.wait()
386391
atlas_loader_thread.wait()
387392

388-
return result
393+
successful = result == QtWidgets.QDialog.DialogCode.Accepted
394+
if successful:
395+
self.annotation_volume = annotation_volume
396+
397+
return successful
389398

390399
def locate_mouse(self) -> None:
391400
if self.annotation_volume is None:

0 commit comments

Comments
 (0)