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
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user