make python3.3 compatible, __class__ is no longer in the class methods namespace.
[blender.git] / release / scripts / startup / bl_ui / space_userpref_keymap.py
index e401a895a23c38c157f7a375879dbccc3132e7c2..85764c5530481807d0b46e6bd60ca900487df530 100644 (file)
@@ -138,7 +138,7 @@ class USERPREF_MT_keyconfigs(bpy.types.Menu):
         bpy.types.Menu.draw_preset(self, context)
 
 
-class InputKeyMapPanel(bpy.types.Panel):
+class InputKeyMapPanel:
     bl_space_type = 'USER_PREFERENCES'
     bl_label = "Input"
     bl_region_type = 'WINDOW'
@@ -189,9 +189,9 @@ class InputKeyMapPanel(bpy.types.Panel):
         if km.is_modal:
             row.label(text="", icon='LINKED')
         if km.is_user_defined:
-            op = row.operator("wm.keymap_restore", text="Restore")
+            row.operator("wm.keymap_restore", text="Restore")
         else:
-            op = row.operator("wm.keymap_edit", text="Edit")
+            row.operator("wm.keymap_edit", text="Edit")
 
         if km.show_expanded_children:
             if children:
@@ -206,14 +206,14 @@ class InputKeyMapPanel(bpy.types.Panel):
 
             # Key Map items
             if km.show_expanded_items:
-                for kmi in km.items:
+                for kmi in km.keymap_items:
                     self.draw_kmi(display_keymaps, kc, km, kmi, col, level + 1)
 
                 # "Add New" at end of keymap item list
                 col = self.indented_layout(col, level + 1)
                 subcol = col.split(percentage=0.2).column()
                 subcol.enabled = km.is_user_defined
-                op = subcol.operator("wm.keyitem_add", text="Add New", icon='ZOOMIN')
+                subcol.operator("wm.keyitem_add", text="Add New", icon='ZOOMIN')
 
             col.separator()
 
@@ -234,7 +234,7 @@ class InputKeyMapPanel(bpy.types.Panel):
         for pname, value in properties.bl_rna.properties.items():
             if pname != "rna_type" and not properties.is_property_hidden(pname):
                 if isinstance(value, bpy.types.OperatorProperties):
-                    __class__.draw_kmi_properties(box, value, title=pname)
+                    InputKeyMapPanel.draw_kmi_properties(box, value, title=pname)
                 else:
                     flow.prop(properties, pname)
 
@@ -325,7 +325,7 @@ class InputKeyMapPanel(bpy.types.Panel):
             # Operator properties
             props = kmi.properties
             if props is not None:
-                __class__.draw_kmi_properties(box, props)
+                InputKeyMapPanel.draw_kmi_properties(box, props)
 
             # Modal key maps attached to this operator
             if not km.is_modal:
@@ -339,7 +339,7 @@ class InputKeyMapPanel(bpy.types.Panel):
             km = km.active()
             layout.context_pointer_set("keymap", km)
 
-            filtered_items = [kmi for kmi in km.items if filter_text in kmi.name.lower()]
+            filtered_items = [kmi for kmi in km.keymap_items if filter_text in kmi.name.lower()]
 
             if len(filtered_items) != 0:
                 col = layout.column()
@@ -351,9 +351,9 @@ class InputKeyMapPanel(bpy.types.Panel):
                 row.label()
 
                 if km.is_user_defined:
-                    op = row.operator("wm.keymap_restore", text="Restore")
+                    row.operator("wm.keymap_restore", text="Restore")
                 else:
-                    op = row.operator("wm.keymap_edit", text="Edit")
+                    row.operator("wm.keymap_edit", text="Edit")
 
                 for kmi in filtered_items:
                     self.draw_kmi(display_keymaps, kc, km, kmi, col, 1)
@@ -362,7 +362,7 @@ class InputKeyMapPanel(bpy.types.Panel):
                 col = self.indented_layout(layout, 1)
                 subcol = col.split(percentage=0.2).column()
                 subcol.enabled = km.is_user_defined
-                op = subcol.operator("wm.keyitem_add", text="Add New", icon='ZOOMIN')
+                subcol.operator("wm.keyitem_add", text="Add New", icon='ZOOMIN')
 
     def draw_hierarchy(self, display_keymaps, layout):
         for entry in KM_HIERARCHY:
@@ -411,8 +411,8 @@ def export_properties(prefix, properties, lines=None):
     if lines is None:
         lines = []
 
-    for pname in properties.keys():
-        if not properties.is_property_hidden(pname):
+    for pname in properties.bl_rna.properties.keys():
+        if pname != "rna_type" and not properties.is_property_hidden(pname):
             value = getattr(properties, pname)
             if isinstance(value, bpy.types.OperatorProperties):
                 export_properties(prefix + "." + pname, value, lines)
@@ -433,9 +433,9 @@ class WM_OT_keyconfig_test(bpy.types.Operator):
 
         def kmistr(kmi):
             if km.is_modal:
-                s = ["kmi = km.items.new_modal(\'%s\', \'%s\', \'%s\'" % (kmi.propvalue, kmi.type, kmi.value)]
+                s = ["kmi = km.keymap_items.new_modal(\'%s\', \'%s\', \'%s\'" % (kmi.propvalue, kmi.type, kmi.value)]
             else:
-                s = ["kmi = km.items.new(\'%s\', \'%s\', \'%s\'" % (kmi.idname, kmi.type, kmi.value)]
+                s = ["kmi = km.keymap_items.new(\'%s\', \'%s\', \'%s\'" % (kmi.idname, kmi.type, kmi.value)]
 
             if kmi.any:
                 s.append(", any=True")
@@ -468,7 +468,7 @@ class WM_OT_keyconfig_test(bpy.types.Operator):
             km = km.active()
 
             if src:
-                for item in km.items:
+                for item in km.keymap_items:
                     if src.compare(item):
                         print("===========")
                         print(parent.name)
@@ -481,15 +481,15 @@ class WM_OT_keyconfig_test(bpy.types.Operator):
                     if self.testEntry(kc, child, src, parent):
                         result = True
             else:
-                for i in range(len(km.items)):
-                    src = km.items[i]
+                for i in range(len(km.keymap_items)):
+                    src = km.keymap_items[i]
 
                     for child in children:
                         if self.testEntry(kc, child, src, km):
                             result = True
 
-                    for j in range(len(km.items) - i - 1):
-                        item = km.items[j + i + 1]
+                    for j in range(len(km.keymap_items) - i - 1):
+                        item = km.keymap_items[j + i + 1]
                         if src.compare(item):
                             print("===========")
                             print(km.name)
@@ -555,13 +555,7 @@ class WM_OT_keyconfig_import(bpy.types.Operator):
 
         config_name = basename(self.filepath)
 
-        path = bpy.utils.preset_paths("keyconfig")[0]  # we need some way to tell the user and system preset path
-        print(path)
-
-        # create config folder if needed
-        if not os.path.exists(path):
-            os.mkdir(path)
-
+        path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", "keyconfig"), create=True)
         path = os.path.join(path, config_name)
 
         if self.keep_original:
@@ -633,11 +627,11 @@ class WM_OT_keyconfig_export(bpy.types.Operator):
 
             f.write("# Map %s\n" % km.name)
             f.write("km = kc.keymaps.new('%s', space_type='%s', region_type='%s', modal=%s)\n\n" % (km.name, km.space_type, km.region_type, km.is_modal))
-            for kmi in km.items:
+            for kmi in km.keymap_items:
                 if km.is_modal:
-                    f.write("kmi = km.items.new_modal('%s', '%s', '%s'" % (kmi.propvalue, kmi.type, kmi.value))
+                    f.write("kmi = km.keymap_items.new_modal('%s', '%s', '%s'" % (kmi.propvalue, kmi.type, kmi.value))
                 else:
-                    f.write("kmi = km.items.new('%s', '%s', '%s'" % (kmi.idname, kmi.type, kmi.value))
+                    f.write("kmi = km.keymap_items.new('%s', '%s', '%s'" % (kmi.idname, kmi.type, kmi.value))
                 if kmi.any:
                     f.write(", any=True")
                 else:
@@ -715,7 +709,7 @@ class WM_OT_keyitem_restore(bpy.types.Operator):
 
     def execute(self, context):
         km = context.keymap
-        kmi = km.items.from_id(self.item_id)
+        kmi = km.keymap_items.from_id(self.item_id)
 
         if not kmi.is_user_defined:
             km.restore_item_to_default(kmi)
@@ -729,14 +723,12 @@ class WM_OT_keyitem_add(bpy.types.Operator):
     bl_label = "Add Key Map Item"
 
     def execute(self, context):
-        wm = context.window_manager
         km = context.keymap
-        kc = wm.keyconfigs.default
 
         if km.is_modal:
-            km.items.new_modal("", 'A', 'PRESS')  # kmi
+            km.keymap_items.new_modal("", 'A', 'PRESS')  # kmi
         else:
-            km.items.new("none", 'A', 'PRESS')  # kmi
+            km.keymap_items.new("none", 'A', 'PRESS')  # kmi
 
         # clear filter and expand keymap so we can see the newly added item
         if context.space_data.filter_text != "":
@@ -760,8 +752,8 @@ class WM_OT_keyitem_remove(bpy.types.Operator):
 
     def execute(self, context):
         km = context.keymap
-        kmi = km.items.from_id(self.item_id)
-        km.items.remove(kmi)
+        kmi = km.keymap_items.from_id(self.item_id)
+        km.keymap_items.remove(kmi)
         return {'FINISHED'}
 
 
@@ -781,3 +773,6 @@ class WM_OT_keyconfig_remove(bpy.types.Operator):
         keyconfig = wm.keyconfigs.active
         wm.keyconfigs.remove(keyconfig)
         return {'FINISHED'}
+
+if __name__ == "__main__":  # only for live edit.
+    bpy.utils.register_module(__name__)