Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper API call to reset the application to a clean state #3273

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
New Features
------------

* New design for viewer legend. [#3220, #3254, #3263]
- New design for viewer legend. [#3220, #3254, #3263]

- Helper classes (Imviz, Specviz, etc) now have ``reset_app`` method to reset the
application to a fresh state. [#3273]

Cubeviz
^^^^^^^
Expand Down Expand Up @@ -74,7 +77,7 @@ Bug Fixes
- Fixed Aperture Photometry radial profile fit crashing when NaN is present in
aperture data for Cubeviz and Imviz. [#3246]

- Prevent PluginMarks from converting y-range so they maintain their position
- Prevent PluginMarks from converting y-range so they maintain their position
in the spectrum-viewer when spectral y units are converted. [#3242]

Cubeviz
Expand Down
9 changes: 9 additions & 0 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ def _on_layers_changed(self, msg):
children_layers = self._get_assoc_data_children(layer_name)

elif hasattr(msg, 'subset'):
print("Got subset message")
layer_name = msg.subset.label
is_wcs_only = False
is_not_child = True
Expand Down Expand Up @@ -1723,6 +1724,7 @@ def get_viewer_ids(self, prefix=None):
def get_viewer_reference_names(self):
"""Return a list of available viewer reference names."""
# Cannot sort because of None

return [self._viewer_item_by_id(vid).get('reference') for vid in self._viewer_store]

def _update_viewer_reference_name(
Expand Down Expand Up @@ -2769,8 +2771,15 @@ def compose_viewer_area(viewer_area_items):
def _reset_state(self):
""" Resets the application state """
self.state = ApplicationState()
self._viewer_store = {}
self._application_handler._tools = {}

# Need to re-add callbacks to emit messages when icons are updated
self.state.add_callback('viewer_icons',
lambda value: self.hub.broadcast(IconsUpdatedMessage('viewer', value, sender=self))) # noqa
self.state.add_callback('layer_icons',
lambda value: self.hub.broadcast(IconsUpdatedMessage('layer', value, sender=self))) # noqa

def get_configuration(self, path=None, section=None):
"""Returns a copy of the application configuration.

Expand Down
21 changes: 21 additions & 0 deletions jdaviz/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,27 @@ def show_in_new_tab(self, title=None): # pragma: no cover
DeprecationWarning)
return self.show(loc="sidecar:tab-after", title=title)

def reset_app(self):
"""
Re-initialize the entire application. Any current settings and loaded data will
be lost.
"""
# Remove all data from the data collection
data = [d for d in self.app.data_collection]
for d in data:
self.app.data_collection.remove(d)

# Remove all subsets from the data collection
subsets = [s for s in self.app.data_collection.subset_groups]
for s in subsets:
self.app.data_collection.remove_subset_group(s)

# Remove existing subsets from the edit subset menu
self.app.session.edit_subset_mode.edit_subset = []

# Reset everything else
self.app.load_configuration(self.app._loaded_configuration)

def _handle_display_units(self, data, use_display_units=True):
if use_display_units:
if isinstance(data, Spectrum1D):
Expand Down