[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57380] trunk/blender/release/scripts: fix [#35574] Export Key Map issue

Campbell Barton ideasman42 at gmail.com
Tue Jun 11 17:11:56 CEST 2013


Revision: 57380
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57380
Author:   campbellbarton
Date:     2013-06-11 15:11:55 +0000 (Tue, 11 Jun 2013)
Log Message:
-----------
fix [#35574] Export Key Map issue

problem was the keymap failed to import but didnt give any feedback, now it displays error message.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy/utils.py
    trunk/blender/release/scripts/startup/bl_operators/wm.py

Modified: trunk/blender/release/scripts/modules/bpy/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/utils.py	2013-06-11 14:15:46 UTC (rev 57379)
+++ trunk/blender/release/scripts/modules/bpy/utils.py	2013-06-11 15:11:55 UTC (rev 57380)
@@ -482,8 +482,9 @@
                 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 @@
         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):

Modified: trunk/blender/release/scripts/startup/bl_operators/wm.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/wm.py	2013-06-11 14:15:46 UTC (rev 57379)
+++ trunk/blender/release/scripts/startup/bl_operators/wm.py	2013-06-11 15:11:55 UTC (rev 57380)
@@ -1199,10 +1199,11 @@
             )
 
     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"
     bl_label = "Default Application Configuration"
@@ -1386,10 +1387,11 @@
             return {'CANCELLED'}
 
         # sneaky way to check we're actually running the code.
-        bpy.utils.keyconfig_set(path)
+        if bpy.utils.keyconfig_set(path, report=self.report):
+            return {'FINISHED'}
+        else:
+            return {'CANCELLED'}
 
-        return {'FINISHED'}
-
     def invoke(self, context, event):
         wm = context.window_manager
         wm.fileselect_add(self)




More information about the Bf-blender-cvs mailing list