Skip to content

Commit

Permalink
Don't show layer edit options if layer is not visible
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Jul 2, 2018
1 parent 79ccc8a commit c18d2bf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
--------------------

Expand Down
8 changes: 7 additions & 1 deletion glue/core/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'DataCollectionDeleteMessage', 'ApplicationClosedMessage',
'DataRemoveComponentMessage', 'LayerArtistEnabledMessage',
'LayerArtistDisabledMessage', 'DataRenameComponentMessage',
'DataReorderComponentMessage']
'DataReorderComponentMessage', 'LayerArtistVisibilityMessage']


class Message(object):
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 16 additions & 4 deletions glue/core/qt/layer_artist_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions glue/viewers/common/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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))

0 comments on commit c18d2bf

Please sign in to comment.