Tool System: Updates for keymap stored as string
authorCampbell Barton <ideasman42@gmail.com>
Thu, 22 Nov 2018 00:13:22 +0000 (11:13 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 22 Nov 2018 00:13:53 +0000 (11:13 +1100)
release/scripts/modules/bl_keymap_utils/keymap_from_toolbar.py
release/scripts/startup/bl_ui/space_toolsystem_common.py

index b5dcb12312002fac2d61821c86283dd99dcfc8c1..183f13b92fb71569eef289b3138a542845536184 100644 (file)
@@ -197,17 +197,23 @@ def generate(context, space_type):
                     context='INVOKE_REGION_WIN',
                 )[1]
             elif item.keymap is not None:
-                kmi_first = item.keymap[0].keymap_items
-                kmi_first = kmi_first[0] if kmi_first else None
-                if kmi_first is not None:
-                    kmi_found = wm.keyconfigs.find_item_from_operator(
-                        idname=kmi_first.idname,
-                        # properties=kmi_first.properties,  # prevents matches, don't use.
-                        context='INVOKE_REGION_WIN',
-                    )[1]
-                else:
+                km = keyconf.keymaps.get(item.keymap[0])
+                if km is None:
+                    print("Keymap", repr(item.keymap[0]), "not found for tool", item.text)
                     kmi_found = None
-                del kmi_first
+                else:
+                    kmi_first = km.keymap_items
+                    kmi_first = kmi_first[0] if kmi_first else None
+                    if kmi_first is not None:
+                        kmi_found = wm.keyconfigs.find_item_from_operator(
+                            idname=kmi_first.idname,
+                            # properties=kmi_first.properties,  # prevents matches, don't use.
+                            context='INVOKE_REGION_WIN',
+                        )[1]
+                    else:
+                        kmi_found = None
+                    del kmi_first
+                del km
             else:
                 kmi_found = None
             item_container[1] = kmi_found
index 09a1d961e2492f3bc9dc5cfe4b28f946a1bb5bb0..2ff5c9692ec941555a84d3067d94c0d9c714f276 100644 (file)
@@ -687,8 +687,14 @@ def description_from_name(context, space_type, text, *, use_operator=True):
 
         if operator is None:
             if item.keymap is not None:
-                if item.keymap[0].keymap_items:
-                    operator = item.keymap[0].keymap_items[0].idname
+                wm = context.window_manager
+                keyconf = wm.keyconfigs.active
+                km = keyconf.keymaps.get(item.keymap[0])
+                if km is not None:
+                    for kmi in km.keymap_items:
+                        if kmi.active:
+                            operator = kmi.idname
+                            break
 
         if operator is not None:
             import _bpy