[Bf-blender-cvs] [c906cdc197c] blender2.8: Cleanup: remove unused code & add comments

Campbell Barton noreply at git.blender.org
Mon Nov 26 06:10:53 CET 2018


Commit: c906cdc197ccfb97c18c3c38ce0cf122c3975a80
Author: Campbell Barton
Date:   Mon Nov 26 16:07:03 2018 +1100
Branches: blender2.8
https://developer.blender.org/rBc906cdc197ccfb97c18c3c38ce0cf122c3975a80

Cleanup: remove unused code & add comments

===================================================================

M	release/scripts/modules/bl_keymap_utils/keymap_from_toolbar.py

===================================================================

diff --git a/release/scripts/modules/bl_keymap_utils/keymap_from_toolbar.py b/release/scripts/modules/bl_keymap_utils/keymap_from_toolbar.py
index 4952dfa992b..501b15c3dc3 100644
--- a/release/scripts/modules/bl_keymap_utils/keymap_from_toolbar.py
+++ b/release/scripts/modules/bl_keymap_utils/keymap_from_toolbar.py
@@ -61,8 +61,6 @@ def generate(context, space_type):
     ]
     items_all_text = {item_container[0].text for item_container in items_all}
 
-    use_simple_keymap = False
-
     # Press the toolbar popup key again to set the default tool,
     # this is useful because the select box tool is useful as a way
     # to 'drop' currently active tools (it's basically a 'none' tool).
@@ -165,212 +163,231 @@ def generate(context, space_type):
             if item_container[0].text != tap_reset_tool
         ]
 
-    if use_simple_keymap:
-        # Simply assign a key from A-Z.
-        for i, (item, _, _) in enumerate(items_all):
-            key = chr(ord('A') + i)
-            kmi = keymap.keymap_items.new("wm.tool_set_by_name", key, 'PRESS')
-            kmi.properties.name = item.text
-    else:
-        for item_container in items_all:
-            item = item_container[0]
-            # Only check the first item in the tools key-map (a little arbitrary).
-            if use_hack_properties:
-                # First check for direct assignment.
-                kmi_hack_properties.name = item.text
-                kmi_found = wm.keyconfigs.find_item_from_operator(
-                    idname="wm.tool_set_by_name",
-                    context='INVOKE_REGION_WIN',
-                    # properties={"name": item.text},
-                    properties=kmi_hack_properties,
-                )[1]
-
-                if kmi_found is None:
-                    if item.data_block:
-                        # PAINT_OT_brush_select
-                        mode = context.active_object.mode
-                        # See: BKE_paint_get_tool_prop_id_from_paintmode
-                        attr = {
-                            'SCULPT': "sculpt_tool",
-                            'VERTEX_PAINT': "vertex_tool",
-                            'WEIGHT_PAINT': "weight_tool",
-                            'TEXTURE_PAINT': "image_tool",
-                            'GPENCIL_PAINT': "gpencil_tool",
-                        }.get(mode, None)
-                        if attr is not None:
-                            setattr(kmi_hack_brush_select_properties, attr, item.data_block)
-                            kmi_found = wm.keyconfigs.find_item_from_operator(
-                                idname="paint.brush_select",
-                                context='INVOKE_REGION_WIN',
-                                properties=kmi_hack_brush_select_properties,
-                            )[1]
-                        else:
-                            print("Unsupported mode:", mode)
-                        del mode, attr
+    # -----------------------
+    # Begin Keymap Generation
 
-            else:
-                kmi_found = None
+    # -------------------------------------------------------------------------
+    # Direct Tool Assignment & Brushes
 
-            if kmi_found is not None:
-                pass
-            elif item.operator is not None:
-                kmi_found = wm.keyconfigs.find_item_from_operator(
-                    idname=item.operator,
-                    context='INVOKE_REGION_WIN',
-                )[1]
-            elif item.keymap is not None:
-                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
-                else:
-                    kmi_first = km.keymap_items
-                    kmi_first = kmi_first[0] if kmi_first else None
-                    if kmi_first is not None:
+    for item_container in items_all:
+        item = item_container[0]
+        # Only check the first item in the tools key-map (a little arbitrary).
+        if use_hack_properties:
+            # First check for direct assignment.
+            kmi_hack_properties.name = item.text
+            kmi_found = wm.keyconfigs.find_item_from_operator(
+                idname="wm.tool_set_by_name",
+                context='INVOKE_REGION_WIN',
+                # properties={"name": item.text},
+                properties=kmi_hack_properties,
+            )[1]
+
+            if kmi_found is None:
+                if item.data_block:
+                    # PAINT_OT_brush_select
+                    mode = context.active_object.mode
+                    # See: BKE_paint_get_tool_prop_id_from_paintmode
+                    attr = {
+                        'SCULPT': "sculpt_tool",
+                        'VERTEX_PAINT': "vertex_tool",
+                        'WEIGHT_PAINT': "weight_tool",
+                        'TEXTURE_PAINT': "image_tool",
+                        'GPENCIL_PAINT': "gpencil_tool",
+                    }.get(mode, None)
+                    if attr is not None:
+                        setattr(kmi_hack_brush_select_properties, attr, item.data_block)
                         kmi_found = wm.keyconfigs.find_item_from_operator(
-                            idname=kmi_first.idname,
-                            # properties=kmi_first.properties,  # prevents matches, don't use.
+                            idname="paint.brush_select",
                             context='INVOKE_REGION_WIN',
+                            properties=kmi_hack_brush_select_properties,
                         )[1]
                     else:
-                        kmi_found = None
-                    del kmi_first
-                del km
-            else:
-                kmi_found = None
-            item_container[1] = kmi_found
+                        print("Unsupported mode:", mode)
+                    del mode, attr
 
-        # More complex multi-pass test.
-        for item_container in items_all:
-            item, kmi_found = item_container[:2]
-            if kmi_found is None:
-                continue
-            kmi_found_type = kmi_found.type
+        else:
+            kmi_found = None
 
-            # Only for single keys.
-            if (
-                    (len(kmi_found_type) == 1) or
-                    # When a tool is being activated instead of running an operator, just copy the shortcut.
-                    (kmi_found.idname in {"wm.tool_set_by_name", "WM_OT_tool_set_by_name"})
-            ):
+        if kmi_found is not None:
+            pass
+        elif item.operator is not None:
+            kmi_found = wm.keyconfigs.find_item_from_operator(
+                idname=item.operator,
+                context='INVOKE_REGION_WIN',
+            )[1]
+        elif item.keymap is not None:
+            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
+            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
+
+    # -------------------------------------------------------------------------
+    # Single Key Access
+
+    # More complex multi-pass test.
+    for item_container in items_all:
+        item, kmi_found = item_container[:2]
+        if kmi_found is None:
+            continue
+        kmi_found_type = kmi_found.type
+
+        # Only for single keys.
+        if (
+                (len(kmi_found_type) == 1) or
+                # When a tool is being activated instead of running an operator, just copy the shortcut.
+                (kmi_found.idname in {"wm.tool_set_by_name", "WM_OT_tool_set_by_name"})
+        ):
+            kmi_args = {"type": kmi_found_type, **modifier_keywords_from_item(kmi_found)}
+            if kmi_unique_or_pass(kmi_args):
+                kmi = keymap.keymap_items.new(idname="wm.tool_set_by_name", value='PRESS', **kmi_args)
+                kmi.properties.name = item.text
+                item_container[2] = kmi
+
+    # -------------------------------------------------------------------------
+    # Single Key Modifier
+    #
+    #
+    # Test for key_modifier, where alpha key is used as a 'key_modifier'
+    # (grease pencil holding 'D' for example).
+
+    for item_container in items_all:
+        item, kmi_found, kmi_exist = item_container
+        if kmi_found is None or kmi_exist:
+            continue
+
+        kmi_found_type = kmi_found.type
+        if kmi_found_type in {
+                'LEFTMOUSE',
+                'RIGHTMOUSE',
+                'MIDDLEMOUSE',
+                'BUTTON4MOUSE',
+                'BUTTON5MOUSE',
+                'BUTTON6MOUSE',
+                'BUTTON7MOUSE',
+        }:
+            kmi_found_type = kmi_found.key_modifier
+            # excludes 'NONE'
+            if len(kmi_found_type) == 1:
                 kmi_args = {"type": kmi_found_type, **modifier_keywords_from_item(kmi_found)}
+                del kmi_args["key_modifier"]
                 if kmi_unique_or_pass(kmi_args):
                     kmi = keymap.keymap_items.new(idname="wm.tool_set_by_name", value='PRESS', **kmi_args)
                     kmi.properties.name = item.text
                     item_container[2] = kmi
 
-        # Test for key_modifier, where alpha key is used as a 'key_modifier'
-        # (grease pencil holding 'D' for example).
+    # -------------------------------------------------------------------------
+    # Assign A-Z to Keys
+    #
+    # When th keys are free.
+
+  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list