Repository: napari/napari

Issue:
Show all key bindings dialog is not displaying text for some keybindings
This is probably broken since the action manager merge since we are not using it to populate these bindings.

![Screen Shot 2021-06-02 at 5.14.32 PM.png](https://images.zenhubusercontent.com/560c1b40638e718c995d70b3/b3c44d0a-dae8-4aa2-bf31-3cf334578658)


Discussion:

Resolving patch:
diff --git a/napari/_qt/dialogs/qt_about_key_bindings.py b/napari/_qt/dialogs/qt_about_key_bindings.py
--- a/napari/_qt/dialogs/qt_about_key_bindings.py
+++ b/napari/_qt/dialogs/qt_about_key_bindings.py
@@ -11,6 +11,7 @@
 
 import napari
 
+from ...utils.action_manager import action_manager
 from ...utils.interactions import get_key_bindings_summary
 from ...utils.theme import get_theme
 from ...utils.translations import trans
@@ -65,11 +66,13 @@ def __init__(self, viewer, key_map_handler, parent=None):
         self.textEditBox = QTextEdit()
         self.textEditBox.setTextInteractionFlags(Qt.TextSelectableByMouse)
         self.textEditBox.setMinimumWidth(360)
+
         # Can switch to a normal dict when our minimum Python is 3.7
         self.key_bindings_strs = OrderedDict()
         self.key_bindings_strs[self.ALL_ACTIVE_KEYBINDINGS] = ''
         self.key_map_handler = key_map_handler
         theme = get_theme(self.viewer.theme)
+
         col = theme['secondary']
         layers = [
             napari.layers.Image,
@@ -79,19 +82,24 @@ def __init__(self, viewer, key_map_handler, parent=None):
             napari.layers.Surface,
             napari.layers.Vectors,
         ]
+        layer_shortcuts = action_manager._get_layer_shortcuts(layers)
         for layer in layers:
             if len(layer.class_keymap) == 0:
                 text = trans._('No key bindings')
             else:
-                text = get_key_bindings_summary(layer.class_keymap, col=col)
+                text = get_key_bindings_summary(
+                    layer_shortcuts[layer], col=col
+                )
+
+            # TODO: Add localization. Add localized layer name to layer types.
             self.key_bindings_strs[f"{layer.__name__} layer"] = text
 
         # layer type selection
         self.layerTypeComboBox = QComboBox()
         self.layerTypeComboBox.addItems(list(self.key_bindings_strs))
+
         self.layerTypeComboBox.activated[str].connect(self.change_layer_type)
         self.layerTypeComboBox.setCurrentText(self.ALL_ACTIVE_KEYBINDINGS)
-        # self.change_layer_type(current_layer)
         layer_type_layout = QHBoxLayout()
         layer_type_layout.setContentsMargins(10, 5, 0, 0)
         layer_type_layout.addWidget(self.layerTypeComboBox)
@@ -131,10 +139,13 @@ def update_active_layer(self, event=None):
         """
         theme = get_theme(self.viewer.theme)
         col = theme['secondary']
+
         # Add class and instance viewer key bindings
-        text = get_key_bindings_summary(
-            self.key_map_handler.active_keymap, col=col
+        active_shortcuts = action_manager._get_active_shortcuts(
+            self.key_map_handler.active_keymap
         )
+        text = get_key_bindings_summary(active_shortcuts, col=col)
+
         # Update layer speficic key bindings if all active are displayed
         self.key_bindings_strs[self.ALL_ACTIVE_KEYBINDINGS] = text
         if self.layerTypeComboBox.currentText() == self.ALL_ACTIVE_KEYBINDINGS:
diff --git a/napari/utils/action_manager.py b/napari/utils/action_manager.py
--- a/napari/utils/action_manager.py
+++ b/napari/utils/action_manager.py
@@ -355,5 +355,53 @@ def unbind_shortcut(self, name: str):
         self._update_gui_elements(name)
         return shortcut
 
+    def _get_layer_shortcuts(self, layers):
+        """
+        Get shortcuts filterd by the given layers.
+
+        Parameters
+        ----------
+        layers : list of layers
+            Layers to use for shortcuts filtering.
+
+        Returns
+        -------
+        dict
+            Dictionary of layers with dictionaries of shortcuts to
+            descriptions.
+        """
+        layer_shortcuts = {}
+        for layer in layers:
+            layer_shortcuts[layer] = {}
+            for name, shortcut in self._shortcuts.items():
+                action = self._actions.get(name, None)
+                if action and layer == action.keymapprovider:
+                    layer_shortcuts[layer][str(shortcut)] = action.description
+
+        return layer_shortcuts
+
+    def _get_active_shortcuts(self, active_keymap):
+        """
+        Get active shortcuts for the given active keymap.
+
+        Parameters
+        ----------
+        active_keymap : KeymapProvider
+            The active keymap provider.
+
+        Returns
+        -------
+        dict
+            Dictionary of shortcuts to descriptions.
+        """
+        active_func_names = [i[1].__name__ for i in active_keymap.items()]
+        active_shortcuts = {}
+        for name, shortcut in self._shortcuts.items():
+            action = self._actions.get(name, None)
+            if action and action.command.__name__ in active_func_names:
+                active_shortcuts[str(shortcut)] = action.description
+
+        return active_shortcuts
+
 
 action_manager = ActionManager()
diff --git a/napari/utils/interactions.py b/napari/utils/interactions.py
--- a/napari/utils/interactions.py
+++ b/napari/utils/interactions.py
@@ -308,23 +308,23 @@ def get_key_bindings_summary(keymap, col='rgb(134, 142, 147)'):
 
     Returns
     -------
-    key_bindings_str : str
+    str
         String with summary of all key_bindings and their functions.
     """
-    key_bindings_str = '<table border="0" width="100%">'
+    key_bindings_strs = ['<table border="0" width="100%">']
     for key in keymap:
         keycodes = [KEY_SYMBOLS.get(k, k) for k in key.split('-')]
         keycodes = "+".join(
             [f"<span style='color: {col}'><b>{k}</b></span>" for k in keycodes]
         )
-        key_bindings_str += (
+        key_bindings_strs.append(
             "<tr><td width='80' style='text-align: right; padding: 4px;'>"
             f"<span style='color: rgb(66, 72, 80)'>{keycodes}</span></td>"
             "<td style='text-align: left; padding: 4px; color: #CCC;'>"
-            f"{get_function_summary(keymap[key])}</td></tr>"
+            f"{keymap[key]}</td></tr>"
         )
-    key_bindings_str += '</table>'
-    return key_bindings_str
+    key_bindings_strs.append('</table>')
+    return ''.join(key_bindings_strs)
 
 
 def get_function_summary(func):


Test patch: