diff --git a/CHANGES.rst b/CHANGES.rst index 2b1a782015..c92f63ffc5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ^^^^^^^ @@ -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 diff --git a/jdaviz/app.py b/jdaviz/app.py index bcc0c405b2..7bd1c6a8b7 100644 --- a/jdaviz/app.py +++ b/jdaviz/app.py @@ -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 @@ -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( @@ -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. diff --git a/jdaviz/core/helpers.py b/jdaviz/core/helpers.py index ebee7d0e86..14621840d6 100644 --- a/jdaviz/core/helpers.py +++ b/jdaviz/core/helpers.py @@ -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):