diff options
Diffstat (limited to 'release/scripts/op/presets.py')
-rw-r--r-- | release/scripts/op/presets.py | 63 |
1 files changed, 55 insertions, 8 deletions
diff --git a/release/scripts/op/presets.py b/release/scripts/op/presets.py index 1a8e57f7c32..f80c5e69ddd 100644 --- a/release/scripts/op/presets.py +++ b/release/scripts/op/presets.py @@ -27,8 +27,8 @@ class AddPresetBase(bpy.types.Operator): subclasses must define - preset_values - preset_subdir ''' - bl_idname = "render.preset_add" - bl_label = "Add Render Preset" + # bl_idname = "script.preset_base_add" + # bl_label = "Add a Python Preset" name = bpy.props.StringProperty(name="Name", description="Name of the preset, used to make the path name", maxlen=64, default="") @@ -46,14 +46,18 @@ class AddPresetBase(bpy.types.Operator): target_path = bpy.utils.preset_paths(self.preset_subdir)[0] # we need some way to tell the user and system preset path - file_preset = open(os.path.join(target_path, filename), 'w') + filepath = os.path.join(target_path, filename) + if getattr(self, "save_keyconfig", False): + bpy.ops.wm.keyconfig_export(filepath=filepath, kc_name=self.properties.name) + file_preset = open(filepath, 'a') + file_preset.write("wm.active_keyconfig = kc\n\n") + else: + file_preset = open(filepath, 'w') + file_preset.write("import bpy\n") for rna_path in self.preset_values: value = eval(rna_path) - if type(value) == str: - value = "'%s'" % value - - file_preset.write("%s = %s\n" % (rna_path, value)) + file_preset.write("%s = %s\n" % (rna_path, repr(value))) file_preset.close() @@ -68,6 +72,25 @@ class AddPresetBase(bpy.types.Operator): return {'RUNNING_MODAL'} +class ExecutePreset(bpy.types.Operator): + ''' Executes a preset ''' + bl_idname = "script.execute_preset" + bl_label = "Execute a Python Preset" + + filepath = bpy.props.StringProperty(name="Path", description="Path of the Python file to execute", maxlen=512, default="") + preset_name = bpy.props.StringProperty(name="Preset Name", description="Name of the Preset being executed", default="") + menu_idname = bpy.props.StringProperty(name="Menu ID Name", description="ID name of the menu this was called from", default="") + + def execute(self, context): + # change the menu title to the most recently chosen option + preset_class = getattr(bpy.types, self.properties.menu_idname) + preset_class.bl_label = self.properties.preset_name + + # execute the preset using script.python_file_run + bpy.ops.script.python_file_run(filepath=self.properties.filepath) + return {'FINISHED'} + + class AddPresetRender(AddPresetBase): '''Add a Render Preset''' bl_idname = "render.preset_add" @@ -158,11 +181,35 @@ class AddPresetSunSky(AddPresetBase): preset_subdir = "sunsky" +class AddPresetInteraction(AddPresetBase): + '''Add an Application Interaction Preset''' + bl_idname = "wm.interaction_preset_add" + bl_label = "Add Interaction Preset" + name = AddPresetBase.name + save_keyconfig = True + + preset_values = [ + "bpy.context.user_preferences.edit.drag_immediately", + "bpy.context.user_preferences.edit.insertkey_xyz_to_rgb", + "bpy.context.user_preferences.inputs.select_mouse", + "bpy.context.user_preferences.inputs.zoom_style", + "bpy.context.user_preferences.inputs.zoom_axis", + "bpy.context.user_preferences.inputs.view_rotation", + "bpy.context.user_preferences.inputs.invert_zoom_direction", + "bpy.context.user_preferences.inputs.emulate_numpad", + "bpy.context.user_preferences.inputs.emulate_3_button_mouse", + "bpy.context.user_preferences.inputs.continuous_mouse", + ] + + preset_subdir = "interaction" + classes = [ + ExecutePreset, AddPresetRender, AddPresetSSS, AddPresetCloth, - AddPresetSunSky] + AddPresetSunSky, + AddPresetInteraction] def register(): |