Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Poirier <theeth@yahoo.com>2010-01-28 22:54:06 +0300
committerMartin Poirier <theeth@yahoo.com>2010-01-28 22:54:06 +0300
commitb81cb0200ba11a1f656712fd521c47e8e3a192b8 (patch)
tree7b8dbe8fb68060cfc4b27057aed5b2c2cc23035f /release
parent6f3dfe81c0ff9d998528df7cc4bf94965270ed10 (diff)
Keyconfig import and remove
- Keyconfig are now marked as user_defined when it is the case - Import keyconfig operator: select an exported keyconfig .py file, copies it to the scripts folder (keep the original copy if wanted, default True), imports and select as active config. The active keyconfig is stored in the user default file, so that still has to be saved after import. - Remove keyconfig operator and button next to the keyconfig name (poll False if not user_defined). Removes the keyconfig from the list and deletes the file from the folder. Remaining bug: The file is copied in the user defined script folder (if present) or the /scripts/ui folder. The problem is that it might be imported before operators defined in python are imported themselves. One solution would be to use a separate folder for keyconfigs that is imported after all others.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/ui/space_userpref.py111
1 files changed, 97 insertions, 14 deletions
diff --git a/release/scripts/ui/space_userpref.py b/release/scripts/ui/space_userpref.py
index a8b49cafc47..52b8d6583ea 100644
--- a/release/scripts/ui/space_userpref.py
+++ b/release/scripts/ui/space_userpref.py
@@ -18,7 +18,7 @@
# <pep8 compliant>
import bpy
-import os.path
+import os, re, shutil
# General UI Theme Settings (User Interface)
def ui_items_general(col, context):
@@ -164,6 +164,8 @@ class USERPREF_HT_header(bpy.types.Header):
layout.operator_context = 'INVOKE_DEFAULT'
op = layout.operator("wm.keyconfig_export", "Export Key Configuration...")
op.path = "keymap.py"
+ op = layout.operator("wm.keyconfig_import", "Import Key Configuration...")
+ op.path = "keymap.py"
class USERPREF_PT_tabs(bpy.types.Panel):
@@ -1306,10 +1308,13 @@ class USERPREF_PT_input(bpy.types.Panel):
subsplit = sub.split()
subcol = subsplit.column()
- subcol.prop_object(wm, "active_keyconfig", wm, "keyconfigs", text="Configuration:")
+ row = subcol.row()
+ row.prop_object(wm, "active_keyconfig", wm, "keyconfigs", text="Configuration:")
- subcol = subsplit.column()
- subcol.prop(kc, "filter", icon="VIEWZOOM")
+ layout.set_context_pointer("keyconfig", wm.active_keyconfig)
+ row.operator("wm.keyconfig_remove", text="", icon='X')
+
+ row.prop(kc, "filter", icon="VIEWZOOM")
col.separator()
@@ -1465,7 +1470,62 @@ def _string_value(value):
return result
+class WM_OT_keyconfig_import(bpy.types.Operator):
+ "Import key configuration from a python script."
+ bl_idname = "wm.keyconfig_import"
+ bl_label = "Import Key Configuration..."
+
+ path = bpy.props.StringProperty(name="File Path", description="File path to write file to.")
+ filename = bpy.props.StringProperty(name="File Name", description="Name of the file.")
+ directory = bpy.props.StringProperty(name="Directory", description="Directory of the file.")
+ filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, hidden=True)
+ filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, hidden=True)
+ filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, hidden=True)
+
+ keep_original = bpy.props.BoolProperty(name="Keep original", description="Keep original file after copying to configuration folder", default=True)
+
+ def execute(self, context):
+ if not self.properties.path:
+ raise Exception("File path not set.")
+
+ f = open(self.properties.path, "r")
+ if not f:
+ raise Exception("Could not open file.")
+
+ name_pattern = re.compile("^kc = wm.add_keyconfig\('(.*)'\)$")
+
+ for line in f.readlines():
+ match = name_pattern.match(line)
+
+ if match:
+ config_name = match.groups()[0]
+
+ f.close()
+
+ path = bpy.context.user_preferences.filepaths.python_scripts_directory
+
+ if not path:
+ path = os.path.split(__file__)[0]
+
+ path += os.path.sep + config_name + ".py"
+
+ if self.properties.keep_original:
+ shutil.copy(self.properties.path, path)
+ else:
+ shutil.move(self.properties.path, path)
+
+ __import__(config_name)
+
+ wm = bpy.data.window_managers[0]
+ wm.active_keyconfig = wm.keyconfigs[config_name]
+
+ return {'FINISHED'}
+ def invoke(self, context, event):
+ wm = context.manager
+ wm.add_fileselect(self)
+ return {'RUNNING_MODAL'}
+
class WM_OT_keyconfig_export(bpy.types.Operator):
"Export key configuration to a python script."
bl_idname = "wm.keyconfig_export"
@@ -1474,9 +1534,9 @@ class WM_OT_keyconfig_export(bpy.types.Operator):
path = bpy.props.StringProperty(name="File Path", description="File path to write file to.")
filename = bpy.props.StringProperty(name="File Name", description="Name of the file.")
directory = bpy.props.StringProperty(name="Directory", description="Directory of the file.")
- filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True)
- filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True)
- filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True)
+ filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, hidden=True)
+ filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, hidden=True)
+ filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, hidden=True)
def execute(self, context):
if not self.properties.path:
@@ -1494,20 +1554,21 @@ class WM_OT_keyconfig_export(bpy.types.Operator):
else:
name = kc.name
- f.write('# Configuration %s\n' % name)
+ f.write("# Configuration %s\n" % name)
+ f.write("import bpy\n\n")
f.write("wm = bpy.data.window_managers[0]\n")
- f.write("kc = wm.add_keyconfig(\'%s\')\n\n" % name)
+ f.write("kc = wm.add_keyconfig('%s')\n\n" % name)
for km in kc.keymaps:
km = km.active()
f.write("# Map %s\n" % km.name)
- f.write("km = kc.add_keymap(\'%s\', space_type=\'%s\', region_type=\'%s\', modal=%s)\n\n" % (km.name, km.space_type, km.region_type, km.modal))
+ f.write("km = kc.add_keymap('%s', space_type='%s', region_type='%s', modal=%s)\n\n" % (km.name, km.space_type, km.region_type, km.modal))
for kmi in km.items:
if km.modal:
- f.write("kmi = km.add_modal_item(\'%s\', \'%s\', \'%s\'" % (kmi.propvalue, kmi.type, kmi.value))
+ f.write("kmi = km.add_modal_item('%s', '%s', '%s'" % (kmi.propvalue, kmi.type, kmi.value))
else:
- f.write("kmi = km.add_item(\'%s\', \'%s\', \'%s\'" % (kmi.idname, kmi.type, kmi.value))
+ f.write("kmi = km.add_item('%s', '%s', '%s'" % (kmi.idname, kmi.type, kmi.value))
if kmi.any:
f.write(", any=True")
else:
@@ -1520,7 +1581,7 @@ class WM_OT_keyconfig_export(bpy.types.Operator):
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(", key_modifier='%s'" % kmi.key_modifier)
f.write(")\n")
def export_properties(prefix, properties):
@@ -1541,7 +1602,6 @@ class WM_OT_keyconfig_export(bpy.types.Operator):
f.write("\n")
- f.write("wm.active_keyconfig = wm.keyconfigs[\'%s\']\n" % name)
f.close()
return {'FINISHED'}
@@ -1640,8 +1700,31 @@ class WM_OT_keyitem_remove(bpy.types.Operator):
km.remove_item(kmi)
return {'FINISHED'}
+class WM_OT_keyconfig_remove(bpy.types.Operator):
+ "Remove key config."
+ bl_idname = "wm.keyconfig_remove"
+ bl_label = "Remove Key Config"
+
+ def poll(self, context):
+ wm = context.manager
+ return wm.active_keyconfig.user_defined
+
+ def execute(self, context):
+ wm = context.manager
+
+ keyconfig = wm.active_keyconfig
+
+ module = __import__(keyconfig.name)
+
+ os.remove(module.__file__)
+
+ wm.remove_keyconfig(keyconfig)
+ return {'FINISHED'}
+
bpy.types.register(WM_OT_keyconfig_export)
+bpy.types.register(WM_OT_keyconfig_import)
bpy.types.register(WM_OT_keyconfig_test)
+bpy.types.register(WM_OT_keyconfig_remove)
bpy.types.register(WM_OT_keymap_edit)
bpy.types.register(WM_OT_keymap_restore)
bpy.types.register(WM_OT_keyitem_add)