Merging r40265 through r40492 from trunk into soc-2011-tomato
[blender.git] / release / scripts / startup / bl_ui / space_userpref_keymap.py
index 1cc9c4b..d7b5c10 100644 (file)
@@ -18,7 +18,7 @@
 
 # <pep8 compliant>
 import bpy
-from bpy.types import Menu, Operator, OperatorProperties
+from bpy.types import Menu, OperatorProperties
 import os
 
 
@@ -204,7 +204,7 @@ class InputKeyMapPanel:
                 subcol = self.indented_layout(col, level + 1)
                 subrow = subcol.row()
                 subrow.prop(km, "show_expanded_items", text="", emboss=False)
-                subrow.label(text="%s (Global)" % km.name)
+                subrow.label(text="%s " % km.name + "(Global)")
             else:
                 km.show_expanded_items = True
 
@@ -404,9 +404,6 @@ class InputKeyMapPanel:
             self.draw_hierarchy(display_keymaps, col)
 
 
-from bpy.props import StringProperty, BoolProperty, IntProperty
-
-
 def export_properties(prefix, properties, lines=None):
     if lines is None:
         lines = []
@@ -422,397 +419,5 @@ def export_properties(prefix, properties, lines=None):
                     lines.append("%s.%s = %s\n" % (prefix, pname, value))
     return lines
 
-
-class WM_OT_keyconfig_test(Operator):
-    "Test keyconfig for conflicts"
-    bl_idname = "wm.keyconfig_test"
-    bl_label = "Test Key Configuration for Conflicts"
-
-    def testEntry(self, kc, entry, src=None, parent=None):
-        result = False
-
-        def kmistr(kmi):
-            if km.is_modal:
-                s = ["kmi = km.keymap_items.new_modal(\'%s\', \'%s\', \'%s\'" % (kmi.propvalue, kmi.type, kmi.value)]
-            else:
-                s = ["kmi = km.keymap_items.new(\'%s\', \'%s\', \'%s\'" % (kmi.idname, kmi.type, kmi.value)]
-
-            if kmi.any:
-                s.append(", any=True")
-            else:
-                if kmi.shift:
-                    s.append(", shift=True")
-                if kmi.ctrl:
-                    s.append(", ctrl=True")
-                if kmi.alt:
-                    s.append(", alt=True")
-                if kmi.oskey:
-                    s.append(", oskey=True")
-            if kmi.key_modifier and kmi.key_modifier != 'NONE':
-                s.append(", key_modifier=\'%s\'" % kmi.key_modifier)
-
-            s.append(")\n")
-
-            props = kmi.properties
-
-            if props is not None:
-                export_properties("kmi.properties", props, s)
-
-            return "".join(s).strip()
-
-        idname, spaceid, regionid, children = entry
-
-        km = kc.keymaps.find(idname, space_type=spaceid, region_type=regionid)
-
-        if km:
-            km = km.active()
-
-            if src:
-                for item in km.keymap_items:
-                    if src.compare(item):
-                        print("===========")
-                        print(parent.name)
-                        print(kmistr(src))
-                        print(km.name)
-                        print(kmistr(item))
-                        result = True
-
-                for child in children:
-                    if self.testEntry(kc, child, src, parent):
-                        result = True
-            else:
-                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.keymap_items) - i - 1):
-                        item = km.keymap_items[j + i + 1]
-                        if src.compare(item):
-                            print("===========")
-                            print(km.name)
-                            print(kmistr(src))
-                            print(kmistr(item))
-                            result = True
-
-                for child in children:
-                    if self.testEntry(kc, child):
-                        result = True
-
-        return result
-
-    def testConfig(self, kc):
-        result = False
-        for entry in KM_HIERARCHY:
-            if self.testEntry(kc, entry):
-                result = True
-        return result
-
-    def execute(self, context):
-        wm = context.window_manager
-        kc = wm.keyconfigs.default
-
-        if self.testConfig(kc):
-            print("CONFLICT")
-
-        return {'FINISHED'}
-
-
-def _string_value(value):
-    if isinstance(value, str) or isinstance(value, bool) or isinstance(value, float) or isinstance(value, int):
-        result = repr(value)
-    elif getattr(value, '__len__', False):
-        return repr(list(value))
-    else:
-        print("Export key configuration: can't write ", value)
-
-    return result
-
-
-class WM_OT_keyconfig_import(Operator):
-    "Import key configuration from a python script"
-    bl_idname = "wm.keyconfig_import"
-    bl_label = "Import Key Configuration..."
-
-    filepath = StringProperty(
-            name="File Path",
-            description="Filepath to write file to",
-            default="keymap.py",
-            )
-    filter_folder = BoolProperty(
-            name="Filter folders",
-            default=True,
-            options={'HIDDEN'},
-            )
-    filter_text = BoolProperty(
-            name="Filter text",
-            default=True,
-            options={'HIDDEN'},
-            )
-    filter_python = BoolProperty(
-            name="Filter python",
-            default=True,
-            options={'HIDDEN'},
-            )
-    keep_original = BoolProperty(
-            name="Keep original",
-            description="Keep original file after copying to configuration folder",
-            default=True,
-            )
-
-    def execute(self, context):
-        from os.path import basename
-        import shutil
-
-        if not self.filepath:
-            self.report({'ERROR'}, "Filepath not set")
-            return {'CANCELLED'}
-
-        config_name = basename(self.filepath)
-
-        path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", "keyconfig"), create=True)
-        path = os.path.join(path, config_name)
-
-        try:
-            if self.keep_original:
-                shutil.copy(self.filepath, path)
-            else:
-                shutil.move(self.filepath, path)
-        except Exception as e:
-            self.report({'ERROR'}, "Installing keymap failed: %s" % e)
-            return {'CANCELLED'}
-
-        # sneaky way to check we're actually running the code.
-        bpy.utils.keyconfig_set(path)
-
-        return {'FINISHED'}
-
-    def invoke(self, context, event):
-        wm = context.window_manager
-        wm.fileselect_add(self)
-        return {'RUNNING_MODAL'}
-
-# This operator is also used by interaction presets saving - AddPresetBase
-
-
-class WM_OT_keyconfig_export(Operator):
-    "Export key configuration to a python script"
-    bl_idname = "wm.keyconfig_export"
-    bl_label = "Export Key Configuration..."
-
-    filepath = StringProperty(
-            name="File Path",
-            description="Filepath to write file to",
-            default="keymap.py",
-            )
-    filter_folder = BoolProperty(
-            name="Filter folders",
-            default=True,
-            options={'HIDDEN'},
-            )
-    filter_text = BoolProperty(
-            name="Filter text",
-            default=True,
-            options={'HIDDEN'},
-            )
-    filter_python = BoolProperty(
-            name="Filter python",
-            default=True,
-            options={'HIDDEN'},
-            )
-
-    def execute(self, context):
-        if not self.filepath:
-            raise Exception("Filepath not set")
-
-        if not self.filepath.endswith('.py'):
-            self.filepath += '.py'
-
-        f = open(self.filepath, "w")
-        if not f:
-            raise Exception("Could not open file")
-
-        wm = context.window_manager
-        kc = wm.keyconfigs.active
-
-        f.write("import bpy\n")
-        f.write("import os\n\n")
-        f.write("wm = bpy.context.window_manager\n")
-        f.write("kc = wm.keyconfigs.new(os.path.splitext(os.path.basename(__file__))[0])\n\n")  # keymap must be created by caller
-
-        # 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.
-        #
-        # 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 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 = _merge_keymaps(edited_kc, kc)
-        else:
-            export_keymaps = _merge_keymaps(edited_kc, edited_kc)
-
-        for km, kc_x in export_keymaps:
-
-            km = km.active()
-
-            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.keymap_items:
-                if km.is_modal:
-                    f.write("kmi = km.keymap_items.new_modal('%s', '%s', '%s'" % (kmi.propvalue, kmi.type, kmi.value))
-                else:
-                    f.write("kmi = km.keymap_items.new('%s', '%s', '%s'" % (kmi.idname, kmi.type, kmi.value))
-                if kmi.any:
-                    f.write(", any=True")
-                else:
-                    if kmi.shift:
-                        f.write(", shift=True")
-                    if kmi.ctrl:
-                        f.write(", ctrl=True")
-                    if kmi.alt:
-                        f.write(", alt=True")
-                    if kmi.oskey:
-                        f.write(", oskey=True")
-                if kmi.key_modifier and kmi.key_modifier != 'NONE':
-                    f.write(", key_modifier='%s'" % kmi.key_modifier)
-                f.write(")\n")
-
-                props = kmi.properties
-
-                if props is not None:
-                    f.write("".join(export_properties("kmi.properties", props)))
-
-            f.write("\n")
-
-        f.close()
-
-        return {'FINISHED'}
-
-    def invoke(self, context, event):
-        wm = context.window_manager
-        wm.fileselect_add(self)
-        return {'RUNNING_MODAL'}
-
-
-class WM_OT_keymap_restore(Operator):
-    "Restore key map(s)"
-    bl_idname = "wm.keymap_restore"
-    bl_label = "Restore Key Map(s)"
-
-    all = BoolProperty(
-            name="All Keymaps",
-            description="Restore all keymaps to default",
-            )
-
-    def execute(self, context):
-        wm = context.window_manager
-
-        if self.all:
-            for km in wm.keyconfigs.user.keymaps:
-                km.restore_to_default()
-        else:
-            km = context.keymap
-            km.restore_to_default()
-
-        return {'FINISHED'}
-
-
-class WM_OT_keyitem_restore(Operator):
-    "Restore key map item"
-    bl_idname = "wm.keyitem_restore"
-    bl_label = "Restore Key Map Item"
-
-    item_id = IntProperty(
-            name="Item Identifier",
-            description="Identifier of the item to remove",
-            )
-
-    @classmethod
-    def poll(cls, context):
-        keymap = getattr(context, "keymap", None)
-        return keymap
-
-    def execute(self, context):
-        km = context.keymap
-        kmi = km.keymap_items.from_id(self.item_id)
-
-        if (not kmi.is_user_defined) and kmi.is_user_modified:
-            km.restore_item_to_default(kmi)
-
-        return {'FINISHED'}
-
-
-class WM_OT_keyitem_add(Operator):
-    "Add key map item"
-    bl_idname = "wm.keyitem_add"
-    bl_label = "Add Key Map Item"
-
-    def execute(self, context):
-        km = context.keymap
-
-        if km.is_modal:
-            km.keymap_items.new_modal("", 'A', 'PRESS')  # kmi
-        else:
-            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 != "":
-            context.space_data.filter_text = ""
-            km.show_expanded_items = True
-            km.show_expanded_children = True
-
-        return {'FINISHED'}
-
-
-class WM_OT_keyitem_remove(Operator):
-    "Remove key map item"
-    bl_idname = "wm.keyitem_remove"
-    bl_label = "Remove Key Map Item"
-
-    item_id = IntProperty(
-            name="Item Identifier",
-            description="Identifier of the item to remove",
-            )
-
-    @classmethod
-    def poll(cls, context):
-        return hasattr(context, "keymap")
-
-    def execute(self, context):
-        km = context.keymap
-        kmi = km.keymap_items.from_id(self.item_id)
-        km.keymap_items.remove(kmi)
-        return {'FINISHED'}
-
-
-class WM_OT_keyconfig_remove(Operator):
-    "Remove key config"
-    bl_idname = "wm.keyconfig_remove"
-    bl_label = "Remove Key Config"
-
-    @classmethod
-    def poll(cls, context):
-        wm = context.window_manager
-        keyconf = wm.keyconfigs.active
-        return keyconf and keyconf.is_user_defined
-
-    def execute(self, context):
-        wm = context.window_manager
-        keyconfig = wm.keyconfigs.active
-        wm.keyconfigs.remove(keyconfig)
-        return {'FINISHED'}
-
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)