Merging r39312 through r39329 from trunk into soc-2011-tomato
[blender.git] / release / scripts / startup / bl_operators / presets.py
index aa6a11407af0a37d87ee8099210a21fa755a2add..060780771d2ec942e61afbebab6810172079ef14 100644 (file)
 #
 # ##### END GPL LICENSE BLOCK #####
 
-# <pep8 compliant>
+# <pep8-80 compliant>
 
 import bpy
+from bpy.types import Menu, Operator
 
 
 class AddPresetBase():
@@ -30,8 +31,15 @@ class AddPresetBase():
     # bl_label = "Add a Python Preset"
     bl_options = {'REGISTER'}  # only because invoke_props_popup requires.
 
-    name = bpy.props.StringProperty(name="Name", description="Name of the preset, used to make the path name", maxlen=64, default="")
-    remove_active = bpy.props.BoolProperty(default=False, options={'HIDDEN'})
+    name = bpy.props.StringProperty(
+            name="Name",
+            description="Name of the preset, used to make the path name",
+            maxlen=64,
+            )
+    remove_active = bpy.props.BoolProperty(
+            default=False,
+            options={'HIDDEN'},
+            )
 
     @staticmethod
     def as_filename(name):  # could reuse for other presets
@@ -48,13 +56,16 @@ class AddPresetBase():
         preset_menu_class = getattr(bpy.types, self.preset_menu)
 
         if not self.remove_active:
-
-            if not self.name:
+            name = self.name.strip()
+            if not name:
                 return {'FINISHED'}
 
-            filename = self.as_filename(self.name)
+            filename = self.as_filename(name)
 
-            target_path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", self.preset_subdir), create=True)
+            target_path = os.path.join("presets", self.preset_subdir)
+            target_path = bpy.utils.user_resource('SCRIPTS',
+                                                  target_path,
+                                                  create=True)
 
             if not target_path:
                 self.report({'WARNING'}, "Failed to create presets path")
@@ -95,7 +106,9 @@ class AddPresetBase():
             filepath = bpy.utils.preset_find(preset_active, self.preset_subdir)
 
             if not filepath:
-                filepath = bpy.utils.preset_find(preset_active, self.preset_subdir, display_name=True)
+                filepath = bpy.utils.preset_find(preset_active,
+                                                 self.preset_subdir,
+                                                 display_name=True)
 
             if not filepath:
                 return {'CANCELLED'}
@@ -118,7 +131,7 @@ class AddPresetBase():
         return {'FINISHED'}
 
     def check(self, context):
-        self.name = self.as_filename(self.name)
+        self.name = self.as_filename(self.name.strip())
 
     def invoke(self, context, event):
         if not self.remove_active:
@@ -128,13 +141,20 @@ class AddPresetBase():
             return self.execute(context)
 
 
-class ExecutePreset(bpy.types.Operator):
+class ExecutePreset(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="")
-    menu_idname = bpy.props.StringProperty(name="Menu ID Name", description="ID name of the menu this was called from", default="")
+    filepath = bpy.props.StringProperty(
+            name="Path",
+            description="Path of the Python file to execute",
+            maxlen=512,
+            )
+    menu_idname = bpy.props.StringProperty(
+            name="Menu ID Name",
+            description="ID name of the menu this was called from",
+            )
 
     def execute(self, context):
         from os.path import basename
@@ -149,7 +169,7 @@ class ExecutePreset(bpy.types.Operator):
         return {'FINISHED'}
 
 
-class AddPresetRender(AddPresetBase, bpy.types.Operator):
+class AddPresetRender(AddPresetBase, Operator):
     '''Add a Render Preset'''
     bl_idname = "render.preset_add"
     bl_label = "Add Render Preset"
@@ -175,14 +195,34 @@ class AddPresetRender(AddPresetBase, bpy.types.Operator):
     preset_subdir = "render"
 
 
-class AddPresetSSS(AddPresetBase, bpy.types.Operator):
+class AddPresetCamera(AddPresetBase, bpy.types.Operator):
+    '''Add a Camera Preset'''
+    bl_idname = "camera.preset_add"
+    bl_label = "Add Camera Preset"
+    preset_menu = "CAMERA_MT_presets"
+
+    preset_defines = [
+        "cam = bpy.context.object.data"
+    ]
+
+    preset_values = [
+        "cam.sensor_width"
+    ]
+
+    preset_subdir = "camera"
+
+
+class AddPresetSSS(AddPresetBase, Operator):
     '''Add a Subsurface Scattering Preset'''
     bl_idname = "material.sss_preset_add"
     bl_label = "Add SSS Preset"
     preset_menu = "MATERIAL_MT_sss_presets"
 
     preset_defines = [
-        "material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material)"
+        ("material = "
+         "bpy.context.material.active_node_material "
+         "if bpy.context.material.active_node_material "
+         "else bpy.context.material")
     ]
 
     preset_values = [
@@ -200,7 +240,7 @@ class AddPresetSSS(AddPresetBase, bpy.types.Operator):
     preset_subdir = "sss"
 
 
-class AddPresetCloth(AddPresetBase, bpy.types.Operator):
+class AddPresetCloth(AddPresetBase, Operator):
     '''Add a Cloth Preset'''
     bl_idname = "cloth.preset_add"
     bl_label = "Add Cloth Preset"
@@ -222,7 +262,7 @@ class AddPresetCloth(AddPresetBase, bpy.types.Operator):
     preset_subdir = "cloth"
 
 
-class AddPresetSunSky(AddPresetBase, bpy.types.Operator):
+class AddPresetSunSky(AddPresetBase, Operator):
     '''Add a Sky & Atmosphere Preset'''
     bl_idname = "lamp.sunsky_preset_add"
     bl_label = "Add Sunsky Preset"
@@ -251,7 +291,7 @@ class AddPresetSunSky(AddPresetBase, bpy.types.Operator):
     preset_subdir = "sunsky"
 
 
-class AddPresetInteraction(AddPresetBase, bpy.types.Operator):
+class AddPresetInteraction(AddPresetBase, Operator):
     '''Add an Application Interaction Preset'''
     bl_idname = "wm.interaction_preset_add"
     bl_label = "Add Interaction Preset"
@@ -277,7 +317,48 @@ class AddPresetInteraction(AddPresetBase, bpy.types.Operator):
     preset_subdir = "interaction"
 
 
-class AddPresetKeyconfig(AddPresetBase, bpy.types.Operator):
+class AddPresetTrackingCamera(AddPresetBase, bpy.types.Operator):
+    '''Add a Tracking Camera Intrinsics  Preset'''
+    bl_idname = "clip.camera_preset_add"
+    bl_label = "Add Camera Preset"
+    preset_menu = "CLIP_MT_camera_presets"
+
+    preset_defines = [
+        "camera = bpy.context.edit_movieclip.tracking.camera"
+    ]
+
+    preset_values = [
+        "camera.sensor_width",
+        "camera.units",
+        "camera.focal_length",
+        "camera.pixel_aspect",
+        "camera.k1",
+        "camera.k2",
+        "camera.k3"
+    ]
+
+    preset_subdir = "tracking_camera"
+
+
+class AddPresetTrackingTrackColor(AddPresetBase, bpy.types.Operator):
+    '''Add a Clip Track Color Preset'''
+    bl_idname = "clip.track_color_preset_add"
+    bl_label = "Add Track Color Preset"
+    preset_menu = "CLIP_MT_track_color_presets"
+
+    preset_defines = [
+        "track = bpy.context.edit_movieclip.tracking.active_track"
+    ]
+
+    preset_values = [
+        "track.color",
+        "track.use_custom_color"
+    ]
+
+    preset_subdir = "tracking_track_color"
+
+
+class AddPresetKeyconfig(AddPresetBase, Operator):
     '''Add a Keyconfig Preset'''
     bl_idname = "wm.keyconfig_preset_add"
     bl_label = "Add Keyconfig Preset"
@@ -300,13 +381,17 @@ class AddPresetKeyconfig(AddPresetBase, bpy.types.Operator):
             keyconfigs.remove(keyconfigs.active)
 
 
-class AddPresetOperator(AddPresetBase, bpy.types.Operator):
+class AddPresetOperator(AddPresetBase, Operator):
     '''Add an Application Interaction Preset'''
     bl_idname = "wm.operator_preset_add"
     bl_label = "Operator Preset"
     preset_menu = "WM_MT_operator_presets"
 
-    operator = bpy.props.StringProperty(name="Operator", maxlen=64, options={'HIDDEN'})
+    operator = bpy.props.StringProperty(
+            name="Operator",
+            maxlen=64,
+            options={'HIDDEN'},
+            )
 
     # XXX, not ideal
     preset_defines = [
@@ -315,18 +400,21 @@ class AddPresetOperator(AddPresetBase, bpy.types.Operator):
 
     @property
     def preset_subdir(self):
-        return __class__.operator_path(self.operator)
+        return AddPresetOperator.operator_path(self.operator)
 
     @property
     def preset_values(self):
-        properties_blacklist = bpy.types.Operator.bl_rna.properties.keys()
+        properties_blacklist = Operator.bl_rna.properties.keys()
 
         prefix, suffix = self.operator.split("_OT_", 1)
-        operator_rna = getattr(getattr(bpy.ops, prefix.lower()), suffix).get_rna().bl_rna
+        op = getattr(getattr(bpy.ops, prefix.lower()), suffix)
+        operator_rna = op.get_rna().bl_rna
+        del op
 
         ret = []
         for prop_id, prop in operator_rna.properties.items():
-            if (not prop.is_hidden) and prop_id not in properties_blacklist:
+            if not (prop.is_hidden or prop.is_skip_save):
+                if prop_id not in properties_blacklist:
                     ret.append("op.%s" % prop_id)
 
         return ret
@@ -338,12 +426,12 @@ class AddPresetOperator(AddPresetBase, bpy.types.Operator):
         return os.path.join("operator", "%s.%s" % (prefix.lower(), suffix))
 
 
-class WM_MT_operator_presets(bpy.types.Menu):
+class WM_MT_operator_presets(Menu):
     bl_label = "Operator Presets"
 
     def draw(self, context):
         self.operator = context.space_data.operator.bl_idname
-        bpy.types.Menu.draw_preset(self, context)
+        Menu.draw_preset(self, context)
 
     @property
     def preset_subdir(self):