[Bf-blender-cvs] [3064da1200a] blender2.8: Keymap: move builtin keymaps from C to Python

Brecht Van Lommel noreply at git.blender.org
Fri Nov 9 01:33:53 CET 2018


Commit: 3064da1200a97e4fba08be33dd271b09d65a2fde
Author: Brecht Van Lommel
Date:   Thu Nov 8 15:59:51 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB3064da1200a97e4fba08be33dd271b09d65a2fde

Keymap: move builtin keymaps from C to Python

This should be purely an implementation change,
for end users there should be no functional difference.

The entire key configuration is in one file with ~5000 lines of code.
Mostly avoiding code duplication and preserve comments and utility
functions from the C code.
It's a bit long but for searching and editing it's also convenient to
have it all in one file.

Notes:

- Actual keymap is shared by blender / blender_legacy
  and stored in `keymap_data/blender_default.py`

  This only generates JSON-like data to be passed into
  `keyconfig_import_from_data`, allowing other presets to load and
  manipulate the default keymap.

- Each preset defines 'keyconfig_data'
  which can be shared between presets.

- Some of the utility functions for generating keymap items still
  need to be ported over to Python.

- Some keymap items can be made into loops (marked as TODO).

See: D3907

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

M	release/scripts/modules/bpy/utils/__init__.py
M	release/scripts/modules/bpy_extras/keyconfig_utils.py
M	release/scripts/modules/bpy_extras/keyconfig_utils_experimental.py
A	release/scripts/presets/keyconfig/blender.py
M	release/scripts/presets/keyconfig/blender_27x.py
A	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/editors/animation/anim_channels_edit.c
M	source/blender/editors/animation/anim_markers.c
M	source/blender/editors/animation/anim_ops.c
M	source/blender/editors/armature/armature_ops.c
M	source/blender/editors/curve/curve_ops.c
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/include/ED_markers.h
M	source/blender/editors/include/ED_object.h
M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/interface/interface_eyedropper.c
M	source/blender/editors/interface/interface_ops.c
M	source/blender/editors/interface/view2d_ops.c
M	source/blender/editors/lattice/lattice_ops.c
M	source/blender/editors/mask/mask_edit.c
M	source/blender/editors/mesh/editmesh_knife.c
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/editors/mesh/mesh_ops.c
M	source/blender/editors/metaball/mball_ops.c
M	source/blender/editors/object/object_ops.c
M	source/blender/editors/physics/physics_ops.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_ops.c
M	source/blender/editors/sculpt_paint/paint_stroke.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/space_action/action_ops.c
M	source/blender/editors/space_action/space_action.c
M	source/blender/editors/space_api/spacetypes.c
M	source/blender/editors/space_buttons/space_buttons.c
M	source/blender/editors/space_clip/space_clip.c
M	source/blender/editors/space_console/space_console.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/editors/space_graph/graph_ops.c
M	source/blender/editors/space_image/space_image.c
M	source/blender/editors/space_info/space_info.c
M	source/blender/editors/space_logic/space_logic.c
M	source/blender/editors/space_nla/nla_ops.c
M	source/blender/editors/space_node/node_ops.c
M	source/blender/editors/space_outliner/outliner_ops.c
M	source/blender/editors/space_sequencer/sequencer_ops.c
M	source/blender/editors/space_text/space_text.c
M	source/blender/editors/space_time/time_ops.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_fly.c
M	source/blender/editors/space_view3d/view3d_ops.c
M	source/blender/editors/space_view3d/view3d_walk.c
M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform_ops.c
M	source/blender/editors/util/CMakeLists.txt
M	source/blender/editors/uvedit/uvedit_ops.c
M	source/blender/windowmanager/WM_keymap.h
M	source/blender/windowmanager/intern/wm_keymap_utils.c
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index bb1ba5eb719..eb1b93002a9 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -261,6 +261,11 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
         _addon_utils.reset_all(reload_scripts=reload_scripts)
     del _initialize
 
+    # Load the default key configuration.
+    filepath = preset_find("blender", "keyconfig")
+    if filepath:
+        keyconfig_set(filepath)
+
     # run the active integration preset
     filepath = preset_find(_user_preferences.inputs.active_keyconfig,
                            "keyconfig")
diff --git a/release/scripts/modules/bpy_extras/keyconfig_utils.py b/release/scripts/modules/bpy_extras/keyconfig_utils.py
index 3caf45a72af..1cad1c965b0 100644
--- a/release/scripts/modules/bpy_extras/keyconfig_utils.py
+++ b/release/scripts/modules/bpy_extras/keyconfig_utils.py
@@ -477,4 +477,5 @@ def keyconfig_test(kc):
 from .keyconfig_utils_experimental import (
     keyconfig_export_as_data,
     keyconfig_import_from_data,
+    keyconfig_module_from_preset,
 )
diff --git a/release/scripts/modules/bpy_extras/keyconfig_utils_experimental.py b/release/scripts/modules/bpy_extras/keyconfig_utils_experimental.py
index cd82460e8e0..b93da5ec6da 100644
--- a/release/scripts/modules/bpy_extras/keyconfig_utils_experimental.py
+++ b/release/scripts/modules/bpy_extras/keyconfig_utils_experimental.py
@@ -21,6 +21,7 @@
 __all__ = (
     "keyconfig_export_as_data",
     "keyconfig_import_from_data",
+    "keyconfig_module_from_preset",
 )
 
 
@@ -242,3 +243,22 @@ def keyconfig_import_from_data(name, keyconfig_data):
                     kmi_props = kmi.properties
                     for attr, value in kmi_props_data:
                         kmi_props_setattr(kmi_props, attr, value)
+
+
+def keyconfig_module_from_preset(name, preset_reference_filename=None):
+    import os
+    import importlib.util
+    if preset_reference_filename is not None:
+        preset_path = os.path.join(os.path.dirname(preset_reference_filename), name + ".py")
+    else:
+        preset_path = None
+
+    # External presets may want to re-use other presets too.
+    if not (preset_path and os.path.exists(preset_path)):
+        preset_path = bpy.utils.preset_find(name, "keyconfig")
+
+    # module name isn't used or added to 'sys.modules'.
+    mod_spec = importlib.util.spec_from_file_location("__bl_keymap__", preset_path)
+    mod = importlib.util.module_from_spec(mod_spec)
+    mod_spec.loader.exec_module(mod)
+    return mod
diff --git a/release/scripts/presets/keyconfig/blender.py b/release/scripts/presets/keyconfig/blender.py
new file mode 100644
index 00000000000..66db91d9186
--- /dev/null
+++ b/release/scripts/presets/keyconfig/blender.py
@@ -0,0 +1,12 @@
+
+import os
+from bpy_extras.keyconfig_utils import (
+    keyconfig_import_from_data,
+    keyconfig_module_from_preset,
+)
+
+_mod = keyconfig_module_from_preset(os.path.join("keymap_data", "blender_default"), __file__)
+keyconfig_data = _mod.generate_keymaps()
+
+if __name__ == "__main__":
+    keyconfig_import_from_data("Blender", keyconfig_data)
diff --git a/release/scripts/presets/keyconfig/blender_27x.py b/release/scripts/presets/keyconfig/blender_27x.py
index 3cb6388e43e..2d9ea9d8f44 100644
--- a/release/scripts/presets/keyconfig/blender_27x.py
+++ b/release/scripts/presets/keyconfig/blender_27x.py
@@ -1,8654 +1,11 @@
-keyconfig_data = \
-[("Window",
-  {"space_type": 'EMPTY', "region_type": 'WINDOW'},
-  {"items":
-   [("wm.window_new", {"type": 'W', "value": 'PRESS', "ctrl": True, "alt": True}, None),
-    ("wm.read_homefile", {"type": 'N', "value": 'PRESS', "ctrl": True}, None),
-    ("wm.save_homefile", {"type": 'U', "value": 'PRESS', "ctrl": True}, None),
-    ("wm.call_menu",
-     {"type": 'O', "value": 'PRESS', "shift": True, "ctrl": True},
-     {"properties":
-      [("name", 'TOPBAR_MT_file_open_recent'),
-       ],
-      },
-     ),
-    ("wm.open_mainfile", {"type": 'O', "value": 'PRESS', "ctrl": True}, None),
-    ("wm.open_mainfile", {"type": 'F1', "value": 'PRESS'}, None),
-    ("wm.link", {"type": 'O', "value": 'PRESS', "ctrl": True, "alt": True}, None),
-    ("wm.append", {"type": 'F1', "value": 'PRESS', "shift": True}, None),
-    ("wm.save_mainfile", {"type": 'S', "value": 'PRESS', "ctrl": True}, None),
-    ("wm.save_mainfile", {"type": 'W', "value": 'PRESS', "ctrl": True}, None),
-    ("wm.save_as_mainfile", {"type": 'S', "value": 'PRESS', "shift": True, "ctrl": True}, None),
-    ("wm.save_as_mainfile", {"type": 'F2', "value": 'PRESS'}, None),
-    ("wm.save_as_mainfile",
-     {"type": 'S', "value": 'PRESS', "ctrl": True, "alt": True},
-     {"properties":
-      [("copy", True),
-       ],
-      },
-     ),
-    ("wm.window_fullscreen_toggle", {"type": 'F11', "value": 'PRESS', "alt": True}, None),
-    ("wm.quit_blender", {"type": 'Q', "value": 'PRESS', "ctrl": True}, None),
-    ("wm.doc_view_manual_ui_context", {"type": 'F1', "value": 'PRESS', "alt": True}, None),
-    ("wm.redraw_timer", {"type": 'T', "value": 'PRESS', "ctrl": True, "alt": True}, None),
-    ("wm.debug_menu", {"type": 'D', "value": 'PRESS', "ctrl": True, "alt": True}, None),
-    ("wm.call_menu",
-     {"type": 'NDOF_BUTTON_MENU', "value": 'PRESS'},
-     {"properties":
-      [("name", 'USERPREF_MT_ndof_settings'),
-       ],
-      },
-     ),
-    ("wm.search_menu", {"type": 'SPACE', "value": 'PRESS'}, None),
-    ("wm.context_set_enum",
-     {"type": 'F3', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'area.type'),
-       ("value", 'NODE_EDITOR'),
-       ],
-      },
-     ),
-    ("wm.context_set_enum",
-     {"type": 'F4', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'area.type'),
-       ("value", 'CONSOLE'),
-       ],
-      },
-     ),
-    ("wm.context_set_enum",
-     {"type": 'F5', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'area.type'),
-       ("value", 'VIEW_3D'),
-       ],
-      },
-     ),
-    ("wm.context_set_enum",
-     {"type": 'F6', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'area.type'),
-       ("value", 'GRAPH_EDITOR'),
-       ],
-      },
-     ),
-    ("wm.context_set_enum",
-     {"type": 'F7', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'area.type'),
-       ("value", 'PROPERTIES'),
-       ],
-      },
-     ),
-    ("wm.context_set_enum",
-     {"type": 'F8', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'area.type'),
-       ("value", 'SEQUENCE_EDITOR'),
-       ],
-      },
-     ),
-    ("wm.context_set_enum",
-     {"type": 'F9', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'area.type'),
-       ("value", 'OUTLINER'),
-       ],
-      },
-     ),
-    ("wm.context_set_enum",
-     {"type": 'F10', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'area.type'),
-       ("value", 'IMAGE_EDITOR'),
-       ],
-      },
-     ),
-    ("wm.context_set_enum",
-     {"type": 'F11', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'area.type'),
-       ("value", 'TEXT_EDITOR'),
-       ],
-      },
-     ),
-    ("wm.context_set_enum",
-     {"type": 'F12', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'area.type'),
-       ("value", 'DOPESHEET_EDITOR'),
-       ],
-      },
-     ),
-    ("wm.context_scale_float",
-     {"type": 'NDOF_BUTTON_PLUS', "value": 'PRESS'},
-     {"properties":
-      [("data_path", 'user_preferences.inputs.ndof_sensitivity'),
-       ("value", 1.1),
-       ],
-      },
-     ),
-    ("wm.context_scale_float",
-     {"type": 'NDOF_BUTTON_MINUS', "value": 'PRESS'},
-     {"properties":
-      [("data_path", 'user_preferences.inputs.ndof_sensitivity'),
-       ("value", 1.0),
-       ],
-      },
-     ),
-    ("wm.context_scale_float",
-     {"type": 'NDOF_BUTTON_PLUS', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'user_preferences.inputs.ndof_sensitivity'),
-       ("value", 1.5),
-       ],
-      },
-     ),
-    ("wm.context_scale_float",
-     {"type": 'NDOF_BUTTON_MINUS', "value": 'PRESS', "shift": True},
-     {"properties":
-      [("data_path", 'user_preferences.inputs.ndof_sensitivity'),
-       ("value", 0.6666667),
-       ],
-      },
-     ),
-    ("info.reports_display_update", {"type": 'TIMER_REPORT', "value": 'ANY', "any": True}, None),
-    ],
-   },
-  ),
- ("Screen",
-  {"space_type": 'EMPTY', "region_type": 'WINDOW'},
-  {"items":
-   [("screen.animation_step", {"type": 'TIMER0', "value": 'ANY', "any": True}, None),
-    ("screen.region_blend", {"type": 'TIMERREGION', "value": 'ANY', "any": True}, None),
-    ("screen.screen_set",
-     {"type": 'RIGHT_ARROW', "value": 'PRESS', "ctrl": True},
-     {"properties":
-      [("delta", 1),
-       ],
-      },
-     ),
-    ("screen.screen_set",
-     {"type": 'LEFT_ARROW', "value": 'PRESS', "ctrl": True},
-     {"properties":
-      [("delta", -1),
-       ],
-      },
-     ),
-    ("screen.screen_full_area", {"type": 'SPACE', "value": 'PRESS', "shift": True}, None),
-    ("screen.screen_full_area",
-     {"type": 'SPACE', "value": 'PRESS', "shift": True, "ctrl": True},
-     {"properties":
-      [("use_hide_panels", True),
-       ],
-      },
-     ),
-    ("screen.screenshot", {"type": 'F3', "value": 'PRESS', "ctrl": True}, None),
-    ("screen.screencast", {"type": 'F3', "value": 'PRESS', "alt": True}, None),
-    ("screen.space_context_cycle",
-     {"type": 'TAB', "value": 'PRESS', "ctrl": True},
-     {"properties":
-      [("direction", 'NEXT'),
-       ],
-      },
-     ),
-    ("screen.space_context_cycle",
-     {"type": 'TAB', "value": 'PRESS', "shift": True, "ctrl": True},
-     {"properties":
-      [("direction", 'PREV'),
-       ],
-      },
-     ),
-    ("screen.region_quadview", {"type": 'Q', "value": 'PRESS', "ctrl": True, "alt": True}, None),
-    ("screen.repeat_history", {"type": 'F3', "value": 'PRESS'}, None),
-  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list