[Bf-blender-cvs] [d3e352a7ece] xr-actions-D9124: Keymap I/O: Add "exec" versions of import/export
Peter Kim
noreply at git.blender.org
Sun Nov 22 11:42:20 CET 2020
Commit: d3e352a7ece07ce1ecb7dde2e6abf4d33991fc3e
Author: Peter Kim
Date: Sun Nov 22 18:52:17 2020 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rBd3e352a7ece07ce1ecb7dde2e6abf4d33991fc3e
Keymap I/O: Add "exec" versions of import/export
The new "exec" functions are added for the sake of the VR Scene
Inspection add-on and do not affect the behavior of the existing
keymap I/O functions.
keyconfig_export_as_data_exec() enables exporting a specified keymap
instead of all user-modified keymaps. The VR add-on uses this to
selectively export the "XR Session" add-on keymap.
keyconfig_import_as_data_exec() enables adding keymap data to an
existing keyconfig instead of creating a new keyconfig. The VR add-on
uses this to add the "XR Session" keymap to the add-on keyconfig.
===================================================================
M release/scripts/modules/bl_keymap_utils/io.py
===================================================================
diff --git a/release/scripts/modules/bl_keymap_utils/io.py b/release/scripts/modules/bl_keymap_utils/io.py
index 0af07a79042..4bce843aa38 100644
--- a/release/scripts/modules/bl_keymap_utils/io.py
+++ b/release/scripts/modules/bl_keymap_utils/io.py
@@ -23,7 +23,9 @@
__all__ = (
"keyconfig_export_as_data",
+ "keyconfig_export_as_data_exec",
"keyconfig_import_from_data",
+ "keyconfig_import_from_data_exec",
"keyconfig_init_from_data",
"keyconfig_merge",
"keymap_init_from_data",
@@ -139,37 +141,7 @@ def _kmi_attrs_or_none(level, kmi):
return "".join(lines)
-def keyconfig_export_as_data(wm, kc, filepath, *, all_keymaps=False):
- # Alternate format
-
- # Generate a list of keymaps to export:
- #
- # First add all user_modified keymaps (found in keyconfigs.user.keymaps list),
- # then add all remaining keymaps from the currently active custom keyconfig.
- #
- # Sort the resulting list according to top context name,
- # while this isn't essential, it makes comparing keymaps simpler.
- #
- # This will create a final list of keymaps that can be used as a "diff" against
- # the default blender keyconfig, recreating the current setup from a fresh blender
- # without needing to export keymaps which haven't been edited.
-
- class FakeKeyConfig:
- keymaps = []
- edited_kc = FakeKeyConfig()
- for km in wm.keyconfigs.user.keymaps:
- if all_keymaps or km.is_user_modified:
- edited_kc.keymaps.append(km)
- # merge edited keymaps with non-default keyconfig, if it exists
- if kc != wm.keyconfigs.default:
- export_keymaps = keyconfig_merge(edited_kc, kc)
- else:
- export_keymaps = keyconfig_merge(edited_kc, edited_kc)
-
- # Sort the keymap list by top context name before exporting,
- # not essential, just convenient to order them predictably.
- export_keymaps.sort(key=lambda k: k[0].name)
-
+def keyconfig_export_as_data_exec(export_keymaps, filepath):
with open(filepath, "w", encoding="utf-8") as fh:
fw = fh.write
@@ -237,6 +209,40 @@ def keyconfig_export_as_data(wm, kc, filepath, *, all_keymaps=False):
fw(" )\n")
+def keyconfig_export_as_data(wm, kc, filepath, *, all_keymaps=False):
+ # Alternate format
+
+ # Generate a list of keymaps to export:
+ #
+ # First add all user_modified keymaps (found in keyconfigs.user.keymaps list),
+ # then add all remaining keymaps from the currently active custom keyconfig.
+ #
+ # Sort the resulting list according to top context name,
+ # while this isn't essential, it makes comparing keymaps simpler.
+ #
+ # This will create a final list of keymaps that can be used as a "diff" against
+ # the default blender keyconfig, recreating the current setup from a fresh blender
+ # without needing to export keymaps which haven't been edited.
+
+ class FakeKeyConfig:
+ keymaps = []
+ edited_kc = FakeKeyConfig()
+ for km in wm.keyconfigs.user.keymaps:
+ if all_keymaps or km.is_user_modified:
+ edited_kc.keymaps.append(km)
+ # merge edited keymaps with non-default keyconfig, if it exists
+ if kc != wm.keyconfigs.default:
+ export_keymaps = keyconfig_merge(edited_kc, kc)
+ else:
+ export_keymaps = keyconfig_merge(edited_kc, edited_kc)
+
+ # Sort the keymap list by top context name before exporting,
+ # not essential, just convenient to order them predictably.
+ export_keymaps.sort(key=lambda k: k[0].name)
+
+ keyconfig_export_as_data_exec(export_keymaps, filepath)
+
+
# -----------------------------------------------------------------------------
# Import Functions
@@ -286,6 +292,14 @@ def keyconfig_init_from_data(kc, keyconfig_data):
keymap_init_from_data(km, km_items, is_modal=km_args.get("modal", False))
+def keyconfig_import_from_data_exec(kc, keyconfig_data, keyconfig_version=(0, 0, 0)):
+ if keyconfig_version is not None:
+ from .versioning import keyconfig_update
+ keyconfig_data = keyconfig_update(keyconfig_data, keyconfig_version)
+ keyconfig_init_from_data(kc, keyconfig_data)
+ return kc
+
+
def keyconfig_import_from_data(name, keyconfig_data, *, keyconfig_version=(0, 0, 0)):
# Load data in the format defined above.
#
@@ -294,11 +308,7 @@ def keyconfig_import_from_data(name, keyconfig_data, *, keyconfig_version=(0, 0,
import bpy
wm = bpy.context.window_manager
kc = wm.keyconfigs.new(name)
- if keyconfig_version is not None:
- from .versioning import keyconfig_update
- keyconfig_data = keyconfig_update(keyconfig_data, keyconfig_version)
- keyconfig_init_from_data(kc, keyconfig_data)
- return kc
+ keyconfig_import_from_data_exec(kc, keyconfig_data, keyconfig_version)
# -----------------------------------------------------------------------------
More information about the Bf-blender-cvs
mailing list