diff options
Diffstat (limited to 'release/scripts/modules/bpy/utils/__init__.py')
-rw-r--r-- | release/scripts/modules/bpy/utils/__init__.py | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py index b76050395da..835cbe6c110 100644 --- a/release/scripts/modules/bpy/utils/__init__.py +++ b/release/scripts/modules/bpy/utils/__init__.py @@ -26,6 +26,7 @@ not associated with blenders internal data. __all__ = ( "blend_paths", "escape_identifier", + "keyconfig_init", "keyconfig_set", "load_scripts", "modules_from_path", @@ -262,21 +263,6 @@ def load_scripts(reload_scripts=False, refresh_scripts=False): _addon_utils.reset_all(reload_scripts=reload_scripts) del _initialize - if not is_background: - # 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", - ) - - if filepath: - keyconfig_set(filepath) - if reload_scripts: import gc print("gc.collect() -> %d" % gc.collect()) @@ -570,6 +556,22 @@ def preset_find(name, preset_path, display_name=False, ext=".py"): return filepath +def keyconfig_init(): + # Key configuration initialization and refresh, called from the Blender + # window manager on startup and refresh. + active_config = _user_preferences.inputs.active_keyconfig + + # Load the default key configuration. + default_filepath = preset_find("blender", "keyconfig") + keyconfig_set(default_filepath) + + # Set the active key configuration if different + filepath = preset_find(active_config, "keyconfig") + + if filepath and filepath != default_filepath: + keyconfig_set(filepath) + + def keyconfig_set(filepath, report=None): from os.path import basename, splitext from itertools import chain @@ -602,23 +604,18 @@ def keyconfig_set(filepath, report=None): kc_new = next(chain(iter(kc for kc in keyconfigs if kc not in keyconfigs_old), (None,))) + + # Get name, exception for default keymap to keep backwards compatibility. + name = splitext(basename(filepath))[0] + if name == 'blender': + name = 'Blender' + + kc_new = keyconfigs.get(name) if kc_new is None: if report is not None: report({'ERROR'}, "Failed to load keymap %r" % filepath) return False else: - kc_new.name = "" - - # remove duplicates - name = splitext(basename(filepath))[0] - while True: - kc_dupe = keyconfigs.get(name) - if kc_dupe: - keyconfigs.remove(kc_dupe) - else: - break - - kc_new.name = name keyconfigs.active = kc_new return True |