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

Fix infinite toggle loop #202

Merged
merged 7 commits into from
Aug 3, 2020
Merged
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
24 changes: 22 additions & 2 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from glue.core import BaseData, HubListener, Data, DataCollection
from glue.core.autolinking import find_possible_links
from glue.core.link_helpers import LinkSame
from glue.core.message import DataCollectionAddMessage
from glue.core.message import (DataCollectionAddMessage,
DataCollectionDeleteMessage)
from glue.core.state_objects import State
from glue.core.subset import Subset
from glue_jupyter.app import JupyterApplication
Expand Down Expand Up @@ -157,6 +158,11 @@ def __init__(self, configuration=None, *args, **kwargs):
self.hub.subscribe(self, DataCollectionAddMessage,
handler=self._on_data_added)

# Subscribe to the event fired when data is deleted from the
# application-level data collection object
self.hub.subscribe(self, DataCollectionDeleteMessage,
handler=self._on_data_deleted)

# Subscribe to snackbar messages and tie them to the display of the
# message box
self.hub.subscribe(self, SnackbarMessage,
Expand Down Expand Up @@ -833,7 +839,6 @@ def _update_selected_data_items(self, viewer_id, selected_items):
for data in viewer_data:
if data.label not in active_data_labels:
viewer.remove_data(data)

remove_data_message = RemoveDataMessage(data, viewer,
viewer_id=viewer_id,
sender=self)
Expand Down Expand Up @@ -864,6 +869,21 @@ def _on_data_added(self, msg):
data_item = self._create_data_item(msg.data.label)
self.state.data_items.append(data_item)

def _on_data_deleted(self, msg):
"""
Callback for when data is removed from the internal ``DataCollection``.
Removes the data item dictionary in the ``data_items`` state list.

Parameters
----------
msg : `~glue.core.DataCollectionAddMessage`
The Glue data collection add message containing information about
the new data.
"""
for data_item in self.state.data_items:
if data_item['name'] == msg.data.label:
self.state.data_items.remove(data_item)

@staticmethod
def _create_data_item(label):
return {
Expand Down
8 changes: 7 additions & 1 deletion jdaviz/configs/default/plugins/line_lists/line_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ def _on_viewer_data_changed(self, msg=None):
if msg is not None and msg.viewer_id != self._viewer_id:
return

self._viewer_spectrum = self.app.get_viewer('spectrum-viewer').data()[0]
viewer_data = self.app.get_viewer('spectrum-viewer').data()

# If no data is currently plotted, don't attempt to update
if len(viewer_data) == 0:
return

self._viewer_spectrum = viewer_data[0]

self._units["x"] = str(self._viewer_spectrum.spectral_axis.unit)
self._units["y"] = str(self._viewer_spectrum.flux.unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ def collect_result(result):
for r in results:
r.wait()

pool.close()

# Collect units from all parameters
param_units = []
for name in initial_model.param_names:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,7 @@ def vue_unit_conversion(self, *args, **kwargs):
# a new version with the most recent conversion.
if selected_data_label in self.data_collection:
self.app.remove_data_from_viewer('spectrum-viewer', selected_data_label)
# Some hacky code to remove the label from the data dropdown
temp_items = []
for data_item in self.app.state.data_items:
if data_item['name'] != selected_data_label:
temp_items.append(data_item)
self.app.state.data_items = temp_items

# Remove the actual Glue data object from the data_collection
self.data_collection.remove(self.data_collection[selected_data_label])
self.data_collection[selected_data_label] = converted_spec
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def load_template(file_name, path=None, traitlet=True):
----------
file_name : str
The name of the template file.
root_path : str
path : str
The path to where the template file is stored. If none is given,
assumes the directory where the python file calling this function
resides.
Expand Down