Skip to content

Commit

Permalink
Atlas test temporary fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomaubier committed Jan 27, 2025
1 parent dd1eef1 commit 6bde405
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
59 changes: 36 additions & 23 deletions coperniFUS/modules/atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class BrainAtlas(Module):
def __init__(self, parent_viewer, skip_online_atlas_retreival=False, **kwargs) -> None:
super().__init__(parent_viewer, 'atlas', **kwargs)

self.test_atlas = False
if 'running_test' in self.module_kwargs and self.module_kwargs['running_test']:
print('running test')
self.test_atlas = True
self._DEFAULT_PARAMS['default_atlas_name'] = 'example_mouse_100um'

self.skip_online_atlas_retreival = skip_online_atlas_retreival
self.init_attributes()

Expand Down Expand Up @@ -172,30 +178,37 @@ def _add_atlas(self):

selected_atlas_description = self.atlas_selector.currentText()

def download_atlas_wrapper(online_atlas_name):
bg_atlas = BrainGlobeAtlas(online_atlas_name, check_latest=True)
self._add_atlas()

if selected_atlas_description is None:
pass # TODO msg in status bar
elif selected_atlas_description.endswith('(DOWNLOADED)'):
offline_atlas_name = selected_atlas_description.split(' | ')[0]
self.parent_viewer.statusBar().showMessage(f'Loading offline {offline_atlas_name}', self.parent_viewer._STATUS_BAR_MSG_TIMEOUT)
self.bg_atlas = BrainGlobeAtlas(offline_atlas_name, check_latest=False)
elif selected_atlas_description.endswith('(online)'):
online_atlas_name = selected_atlas_description.split(' | ')[0]
dialog = AcceptRejectDialog(parent=self.parent_viewer, title='Proceed with Brain Atlas download?', msg=f'Do you want to download {online_atlas_name} ?\nThis might take a few minutes')
dialog_result = dialog.exec()
if dialog_result == 1:
self.parent_viewer.statusBar().showMessage(f'Downloading {online_atlas_name}')
# def download_atlas_wrapper(online_atlas_name):
# bg_atlas = BrainGlobeAtlas(online_atlas_name, check_latest=True)
# self._add_atlas()

if self.test_atlas: # Only when testing application
pass # TEMPORARY TODO implement proper test
else:
if selected_atlas_description is None:
pass # TODO msg in status bar
elif selected_atlas_description.endswith('(DOWNLOADED)'):
offline_atlas_name = selected_atlas_description.split(' | ')[0]
self.parent_viewer.statusBar().showMessage(f'Loading offline {offline_atlas_name}', self.parent_viewer._STATUS_BAR_MSG_TIMEOUT)
self.bg_atlas = BrainGlobeAtlas(offline_atlas_name, check_latest=False)
elif selected_atlas_description.endswith('(online)'):
online_atlas_name = selected_atlas_description.split(' | ')[0]

self.threaded_atlas_download = threading.Thread(
target=download_atlas_wrapper,
args=(online_atlas_name,))
self.threaded_atlas_download.start()
# TODO allow thread interruption
else:
self.parent_viewer.statusBar().showMessage('Atlas Download Canceled!', self.parent_viewer._STATUS_BAR_MSG_TIMEOUT)
dialog = AcceptRejectDialog(parent=self.parent_viewer, title='Proceed with Brain Atlas download?', msg=f'Do you want to download {online_atlas_name} ?\nThis might take a few minutes')
dialog_result = dialog.exec()
if dialog_result == 1:
self.parent_viewer.statusBar().showMessage(f'Downloading {online_atlas_name}')

# TODO reimplement threaded download
# self.threaded_atlas_download = threading.Thread(
# target=download_atlas_wrapper,
# args=(online_atlas_name,))
# self.threaded_atlas_download.start()
# TODO allow thread interruption
self.bg_atlas = BrainGlobeAtlas(online_atlas_name, check_latest=True)

else:
self.parent_viewer.statusBar().showMessage('Atlas Download Canceled!', self.parent_viewer._STATUS_BAR_MSG_TIMEOUT)

if self.bg_atlas is not None:

Expand Down
1 change: 1 addition & 0 deletions coperniFUS/modules/module_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Module:
_DEFAULT_PARAMS = {}

def __init__(self, parent_viewer, module_id, **kwargs) -> None:
self.module_kwargs = kwargs
self.parent_viewer = parent_viewer
self._module_id = None
self.module_id = module_id
Expand Down
2 changes: 1 addition & 1 deletion tests/test_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@pytest.fixture
def viewer_window(qtbot):
"""Fixture to create CoperniFUS viewer window."""
window = Window(app=None)
window = Window(app=None, running_test=True)
return window

def test_window_title(viewer_window):
Expand Down

0 comments on commit 6bde405

Please sign in to comment.