diff --git a/CHANGES.md b/CHANGES.md index 85c2f7446..9c608cedc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -55,6 +55,8 @@ v0.14.0 (unreleased) after they were closed if they were accessed through the IPython console. [#1770] +* Don't show layer edit options if layer is not visible. [#1805] + v0.13.4 (unreleased) -------------------- diff --git a/glue/core/message.py b/glue/core/message.py index 4fe6ba75c..4085fe06a 100644 --- a/glue/core/message.py +++ b/glue/core/message.py @@ -13,7 +13,7 @@ 'DataCollectionDeleteMessage', 'ApplicationClosedMessage', 'DataRemoveComponentMessage', 'LayerArtistEnabledMessage', 'LayerArtistDisabledMessage', 'DataRenameComponentMessage', - 'DataReorderComponentMessage'] + 'DataReorderComponentMessage', 'LayerArtistVisibilityMessage'] class Message(object): @@ -251,6 +251,12 @@ def __init__(self, sender, tag=None): self.layer_artist = self.sender +class LayerArtistVisibilityMessage(Message): + def __init__(self, sender, tag=None): + super(LayerArtistVisibilityMessage, self).__init__(sender, tag=tag) + self.layer_artist = self.sender + + class LayerArtistDisabledMessage(Message): def __init__(self, sender, tag=None): super(LayerArtistDisabledMessage, self).__init__(sender, tag=tag) diff --git a/glue/core/qt/layer_artist_model.py b/glue/core/qt/layer_artist_model.py index 563825d33..0f75144dc 100644 --- a/glue/core/qt/layer_artist_model.py +++ b/glue/core/qt/layer_artist_model.py @@ -23,7 +23,10 @@ from glue.utils import nonpartial from glue.utils.qt import PythonListModel, PyMimeData from glue.core.hub import HubListener -from glue.core.message import LayerArtistEnabledMessage, LayerArtistUpdatedMessage, LayerArtistDisabledMessage +from glue.core.message import (LayerArtistEnabledMessage, + LayerArtistUpdatedMessage, + LayerArtistDisabledMessage, + LayerArtistVisibilityMessage) class LayerArtistModel(PythonListModel): @@ -211,6 +214,7 @@ def __init__(self, parent=None, hub=None): self.hub.subscribe(self, LayerArtistUpdatedMessage, self._update_viewport) self.hub.subscribe(self, LayerArtistEnabledMessage, self._layer_enabled_or_disabled) self.hub.subscribe(self, LayerArtistDisabledMessage, self._layer_enabled_or_disabled) + self.hub.subscribe(self, LayerArtistVisibilityMessage, self._layer_enabled_or_disabled) def _update_viewport(self, *args): # This forces the widget containing the list view to update/redraw, @@ -339,7 +343,6 @@ def __init__(self, parent=None, layer_style_widget_cls=None, hub=None): self.disabled_warning = QtWidgets.QLabel() self.disabled_warning.setWordWrap(True) - self.disabled_warning.setAlignment(Qt.AlignJustify) self.padded_warning = QtWidgets.QWidget() warning_layout = QtWidgets.QVBoxLayout() warning_layout.setContentsMargins(20, 20, 20, 20) @@ -370,10 +373,19 @@ def on_selection_change(self, layer_artist): if layer_artist in self.layout_style_widgets: if layer_artist.enabled: - self.layer_options_layout.setCurrentWidget(self.layout_style_widgets[layer_artist]) - self.disabled_warning.setText('') + if layer_artist.visible: + self.disabled_warning.setText('') + self.layer_options_layout.setCurrentWidget(self.layout_style_widgets[layer_artist]) + else: + self.disabled_warning.setText('Layer is not currently visible. ' + 'Click on the checkbox for this ' + 'layer to make it visible') + self.disabled_warning.setAlignment(Qt.AlignLeft) + self.layer_options_layout.setCurrentWidget(self.padded_warning) + else: self.disabled_warning.setText(layer_artist.disabled_message) + self.disabled_warning.setAlignment(Qt.AlignJustify) self.layer_options_layout.setCurrentWidget(self.padded_warning) else: self.layer_options_layout.setCurrentWidget(self.empty) diff --git a/glue/viewers/common/layer_artist.py b/glue/viewers/common/layer_artist.py index d17e66c3c..6e74cea37 100644 --- a/glue/viewers/common/layer_artist.py +++ b/glue/viewers/common/layer_artist.py @@ -3,6 +3,7 @@ from glue.external.echo import keep_in_sync, CallbackProperty from glue.core.layer_artist import LayerArtistBase from glue.viewers.common.state import LayerState +from glue.core.message import LayerArtistVisibilityMessage __all__ = ['LayerArtist'] @@ -33,5 +34,11 @@ def __init__(self, viewer_state, layer_state=None, layer=None): self._sync_zorder = keep_in_sync(self, 'zorder', self.state, 'zorder') self._sync_visible = keep_in_sync(self, 'visible', self.state, 'visible') + self.state.add_callback('visible', self._on_visibility_change) + + def _on_visibility_change(self, *args): + if self.state.layer is not None and self.state.layer.hub is not None: + self.state.layer.hub.broadcast(LayerArtistVisibilityMessage(self)) + def __gluestate__(self, context): return dict(state=context.id(self.state))