Repository: napari/napari

Issue:
only show status from layers if they are selected
# Description
The status bar of the main window only shows the status of the selected layer.
![image](https://user-images.githubusercontent.com/12660498/99157098-89ab0a00-26c6-11eb-9190-a9ab10b16988.png)

This fixes #1872 and is an alternative and/or potential addendum to #1873 . 

## Type of change
<!-- Please delete options that are not relevant. -->
- [x] Bug-fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

# References
<!-- What resources, documentation, and guides were used in the creation of this PR? -->
<!-- If this is a bug-fix or otherwise resolves an issue, reference it here with "closes #(issue)" -->
closes #1872 

# How has this been tested?
<!-- Please describe the tests that you ran to verify your changes. -->
- [ ] example: the test suite for my feature covers cases x, y, and z
- [ ] example: all tests pass with my change

I tested manually and I'm not sure if there are side effects because of this change. Looking forward to developer feedback :)

## Final checklist:
- [x] My PR is the minimum possible work for the desired functionality
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my feature works



Discussion:
I need to look into this now, but i believe this is a regression in `0.4.0` and that the behavior in `0.3.8` was what you want - see #1836 and the linked image.sc discussion.

We have a concept called the `active_layer` which is the top most selected layer that should be updating the status bar, but seems to have broken in that last release. It could provide an alternative fix to #1874 or #1873, or at least if we don't fix it that concept should probably be removed

Resolving patch:
diff --git a/napari/components/add_layers_mixin.py b/napari/components/add_layers_mixin.py
--- a/napari/components/add_layers_mixin.py
+++ b/napari/components/add_layers_mixin.py
@@ -52,8 +52,6 @@ def add_layer(self, layer: layers.Layer) -> layers.Layer:
         """
         layer.events.select.connect(self._update_active_layer)
         layer.events.deselect.connect(self._update_active_layer)
-        layer.events.status.connect(self._update_status)
-        layer.events.help.connect(self._update_help)
         layer.events.interactive.connect(self._update_interactive)
         layer.events.cursor.connect(self._update_cursor)
         layer.events.cursor_size.connect(self._update_cursor_size)
diff --git a/napari/components/viewer_model.py b/napari/components/viewer_model.py
--- a/napari/components/viewer_model.py
+++ b/napari/components/viewer_model.py
@@ -415,14 +415,6 @@ def _on_layers_change(self, event):
         self.events.layers_change()
         self._update_active_layer(event)
 
-    def _update_status(self, event):
-        """Set the viewer status with the `event.status` string."""
-        self.status = event.status
-
-    def _update_help(self, event):
-        """Set the viewer help with the `event.help` string."""
-        self.help = event.help
-
     def _update_interactive(self, event):
         """Set the viewer interactivity with the `event.interactive` bool."""
         self.interactive = event.interactive
@@ -440,6 +432,11 @@ def _on_cursor_position_change(self, event):
         for layer in self.layers:
             layer.position = self.cursor.position
 
+        # Update status and help bar based on active layer
+        if self.active_layer is not None:
+            self.status = self.active_layer.status
+            self.help = self.active_layer.help
+
     def _on_grid_change(self, event):
         """Arrange the current layers is a 2D grid."""
         for i, layer in enumerate(self.layers[::-1]):


Test patch:
diff --git a/napari/components/_tests/test_viewer_model.py b/napari/components/_tests/test_viewer_model.py
--- a/napari/components/_tests/test_viewer_model.py
+++ b/napari/components/_tests/test_viewer_model.py
@@ -521,6 +521,19 @@ def test_active_layer():
     assert viewer.active_layer is None
 
 
+def test_active_layer_status_update():
+    """Test status updates from active layer on cursor move."""
+    viewer = ViewerModel()
+    np.random.seed(0)
+    viewer.add_image(np.random.random((5, 5, 10, 15)))
+    viewer.add_image(np.random.random((5, 6, 5, 10, 15)))
+    assert len(viewer.layers) == 2
+    assert viewer.active_layer == viewer.layers[1]
+
+    viewer.cursor.position = [1, 1, 1, 1, 1]
+    assert viewer.status == viewer.active_layer.status
+
+
 def test_sliced_world_extent():
     """Test world extent after adding layers and slicing."""
     np.random.seed(0)