UI: use keymap introspection for tooltip creation
authorCampbell Barton <ideasman42@gmail.com>
Wed, 9 Jan 2019 01:27:58 +0000 (12:27 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 9 Jan 2019 01:27:58 +0000 (12:27 +1100)
Also support non existing keymap items which gave an error, see: T60335

release/scripts/startup/bl_ui/space_toolsystem_toolbar.py

index 125ac67a816dddf8a802881377995a54690ab5a8..99d6104d42c7da0265ef6d00e924a03ed5d13a46 100644 (file)
@@ -33,6 +33,10 @@ from .space_toolsystem_common import (
 )
 
 
+def kmi_to_string_or_none(kmi):
+    return kmi.to_string() if kmi else "<none>"
+
+
 def generate_from_enum_ex(
         context, *,
         icon_prefix,
@@ -101,6 +105,10 @@ class _defs_view3d_generic:
     @ToolDef.from_fn
     def ruler():
         def description(context, item, km):
+            if km is not None:
+                kmi = km.keymap_items.find_from_operator("view3d.ruler_add")
+            else:
+                kmi = None
             return (
                 "Measure distance and angles.\n"
                 "\u2022 {} anywhere for new measurement.\n"
@@ -109,7 +117,7 @@ class _defs_view3d_generic:
                 "\u2022 Ctrl to snap.\n"
                 "\u2022 Shift to measure surface thickness"
             ).format(
-                km.keymap_items[0].to_string()
+                kmi_to_string_or_none(kmi)
             )
         return dict(
             text="Measure",