fix [#35574] Export Key Map issue

problem was the keymap failed to import but didnt give any feedback, now it displays error message.
This commit is contained in:
2013-06-11 15:11:55 +00:00
parent e895e2e0d1
commit c8f30bc7f0
2 changed files with 34 additions and 20 deletions

View File

@@ -482,8 +482,9 @@ def preset_find(name, preset_path, display_name=False, ext=".py"):
return filepath
def keyconfig_set(filepath):
def keyconfig_set(filepath, report=None):
from os.path import basename, splitext
from itertools import chain
if _bpy.app.debug_python:
print("loading preset:", filepath)
@@ -496,25 +497,36 @@ def keyconfig_set(filepath):
keyfile = open(filepath)
exec(compile(keyfile.read(), filepath, "exec"), {"__file__": filepath})
keyfile.close()
error_msg = ""
except:
import traceback
traceback.print_exc()
error_msg = traceback.format_exc()
kc_new = [kc for kc in keyconfigs if kc not in keyconfigs_old][0]
if error_msg:
if report is not None:
report({'ERROR'}, error_msg)
print(error_msg)
kc_new.name = ""
kc_new = next(chain(iter(kc for kc in keyconfigs if kc not in keyconfigs_old), (None,)))
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
# 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
kc_new.name = name
keyconfigs.active = kc_new
return True
def user_resource(resource_type, path="", create=False):

View File

@@ -1199,9 +1199,10 @@ class WM_OT_keyconfig_activate(Operator):
)
def execute(self, context):
bpy.utils.keyconfig_set(self.filepath)
return {'FINISHED'}
if bpy.utils.keyconfig_set(self.filepath, report=self.report):
return {'FINISHED'}
else:
return {'CANCELLED'}
class WM_OT_appconfig_default(Operator):
bl_idname = "wm.appconfig_default"
@@ -1386,9 +1387,10 @@ class WM_OT_keyconfig_import(Operator):
return {'CANCELLED'}
# sneaky way to check we're actually running the code.
bpy.utils.keyconfig_set(path)
return {'FINISHED'}
if bpy.utils.keyconfig_set(path, report=self.report):
return {'FINISHED'}
else:
return {'CANCELLED'}
def invoke(self, context, event):
wm = context.window_manager