Skip to content

Commit

Permalink
offload atlas downloading to separate thread (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrofelder authored Aug 23, 2023
1 parent adf5ce6 commit 7121f2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion brainrender_napari/widgets/atlas_table_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_downloaded_atlases,
)
from bg_atlasapi.update_atlases import install_atlas
from napari.qt import thread_worker
from qtpy.QtCore import QAbstractTableModel, QModelIndex, Qt, Signal
from qtpy.QtWidgets import QMenu, QTableView, QWidget

Expand Down Expand Up @@ -157,8 +158,15 @@ def _on_row_double_clicked(self):
def _on_download_atlas_confirmed(self):
"""Downloads an atlas and signals that this has happened."""
atlas_name = self.selected_atlas_name()
worker = self._install_atlas_in_thread(atlas_name)
worker.returned.connect(self.download_atlas_confirmed.emit)
worker.start()

@thread_worker
def _install_atlas_in_thread(self, atlas_name: str):
"""Installs the currently selected atlas in a separate thread."""
install_atlas(atlas_name)
self.download_atlas_confirmed.emit(atlas_name)
return atlas_name

def _on_current_changed(self):
"""Emits a signal with the newly selected atlas name"""
Expand Down
3 changes: 2 additions & 1 deletion tests/test_unit/test_atlas_table_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def test_download_confirmed_callback(atlas_table_view, qtbot):
) # sanity check that local copy is gone

with qtbot.waitSignal(
atlas_table_view.download_atlas_confirmed
atlas_table_view.download_atlas_confirmed,
timeout=150000, # assumes atlas can be installed in 2.5 minutes!
) as download_atlas_confirmed_signal:
model_index = atlas_table_view.model().index(0, 0)
atlas_table_view.setCurrentIndex(model_index)
Expand Down

0 comments on commit 7121f2d

Please sign in to comment.