[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2782] contrib/py/scripts/addons/ render_copy_settings: Update of render_copy_settings addon:

Bastien Montagne montagne29 at wanadoo.fr
Thu Dec 15 21:48:10 CET 2011


Revision: 2782
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2782
Author:   mont29
Date:     2011-12-15 20:48:07 +0000 (Thu, 15 Dec 2011)
Log Message:
-----------
Update of render_copy_settings addon:
* Made it work again! (was using old template_list var name...).
* Factorized quite a bit of code.
* Made the list display UI names in addition to py names of properties.

Modified Paths:
--------------
    contrib/py/scripts/addons/render_copy_settings/__init__.py
    contrib/py/scripts/addons/render_copy_settings/operator.py
    contrib/py/scripts/addons/render_copy_settings/panel.py

Added Paths:
-----------
    contrib/py/scripts/addons/render_copy_settings/presets.py

Modified: contrib/py/scripts/addons/render_copy_settings/__init__.py
===================================================================
--- contrib/py/scripts/addons/render_copy_settings/__init__.py	2011-12-15 20:26:13 UTC (rev 2781)
+++ contrib/py/scripts/addons/render_copy_settings/__init__.py	2011-12-15 20:48:07 UTC (rev 2782)
@@ -63,9 +63,9 @@
 bl_info = {
     "name": "Copy Settings",
     "author": "Bastien Montagne",
-    "version": (0, 1, 3),
-    "blender": (2, 5, 9),
-    "api": 36380,
+    "version": (0, 1, 4),
+    "blender": (2, 6, 1),
+    "api": 42648,
     "location": "Render buttons (Properties window)",
     "description": "Allows to copy a selection of render settings from current scene to others.",
     "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
@@ -100,6 +100,7 @@
 
 
 class RenderCopySettingsSetting(bpy.types.PropertyGroup):
+    strid = StringProperty(default="")
     copy = BoolProperty(default=False)
 
     # A string of identifiers (colon delimited) which property’s controls should be displayed

Modified: contrib/py/scripts/addons/render_copy_settings/operator.py
===================================================================
--- contrib/py/scripts/addons/render_copy_settings/operator.py	2011-12-15 20:26:13 UTC (rev 2781)
+++ contrib/py/scripts/addons/render_copy_settings/operator.py	2011-12-15 20:48:07 UTC (rev 2782)
@@ -19,6 +19,7 @@
 # <pep8 compliant>
 
 import bpy
+from . import presets
 
 # These operators are only defined because it seems impossible to directly edit properties from
 # UI code…
@@ -63,22 +64,24 @@
         cp_sett = context.scene.render_copy_settings
 
         # Get all available render settings, and update accordingly affected_settings…
-        props = set()
+        props = {}
         for prop in context.scene.render.bl_rna.properties:
             if prop.identifier in {'rna_type'}:
                 continue
             if prop.is_readonly:
                 continue
-            props.add(prop.identifier)
+            props[prop.identifier] = prop.name
+        corr = 0
         for i, sett in enumerate(cp_sett.affected_settings):
-            if sett.name not in props:
-                cp_sett.affected_settings.remove(i)
+            if sett.strid not in props:
+                cp_sett.affected_settings.remove(i-corr)
+                corr += 1
             else:
-                props.remove(sett.name)
-        for prop in props:
+                del props[sett.strid]
+        for strid, name in props.items():
             sett = cp_sett.affected_settings.add()
-            sett.name = prop
-#            sett.init_TemplateListControls()
+            sett.name = "{} [{}]".format(name, strid)
+            sett.strid = strid
         collection_property_sort(cp_sett.affected_settings, "name")
 
         # Get all available scenes, and update accordingly allowed_scenes…
@@ -113,7 +116,6 @@
         for scene in scenes:
             sett = cp_sett.allowed_scenes.add()
             sett.name = scene
-#            sett.init_TemplateListControls()
         collection_property_sort(cp_sett.allowed_scenes, "name")
 
         return {'FINISHED'}
@@ -132,65 +134,30 @@
     # Enable undo…
     bl_option = {'REGISTER', 'UNDO'}
 
-    presets = EnumProperty(items=(("resolution", "Render Resolution", "Render resolution and aspect ratio settings"),
-                                  ("scale", "Render Scale", "The “Render Scale” setting."),
-                                  ("osa", "Render OSA", "The OSA toggle and sample settings."),
-                                  ("threads", "Render Threads", "The thread mode and number settings."),
-                                  ("fields", "Render Fields", "The Fields settings."),
-                                  ("stamp", "Render Stamp", "The Stamp toggle."),
-                                 ),
+    presets = EnumProperty(items=(p.rna_enum for p in presets.presets),
                            default=set(),
                            options={"ENUM_FLAG"})
 
+    @staticmethod
+    def process_elements(settings, elts):
+        setts = []
+        val = True
+        for sett in settings:
+            if sett.strid in elts:
+                setts.append(sett)
+                val = val and sett.copy
+        for e in setts:
+            e.copy = not val
+
     @classmethod
     def poll(cls, context):
         return context.scene != None
 
     def execute(self, context):
         cp_sett = context.scene.render_copy_settings
-        if "resolution" in self.presets:
-            res_x = cp_sett.affected_settings["resolution_x"]
-            res_y = cp_sett.affected_settings["resolution_y"]
-            asp_x = cp_sett.affected_settings["pixel_aspect_x"]
-            asp_y = cp_sett.affected_settings["pixel_aspect_y"]
-            if res_x.copy and res_y.copy and asp_x.copy and asp_y.copy:
-                res_x.copy = res_y.copy = asp_x.copy = asp_y.copy = False
-            else:
-                res_x.copy = res_y.copy = asp_x.copy = asp_y.copy = True
-        if "scale" in self.presets:
-            scale = cp_sett.affected_settings["resolution_percentage"]
-            if scale.copy:
-                scale.copy = False
-            else:
-                scale.copy = True
-        if "osa" in self.presets:
-            osa = cp_sett.affected_settings["use_antialiasing"]
-            osa_lvl = cp_sett.affected_settings["antialiasing_samples"]
-            if osa.copy and osa_lvl.copy:
-                osa.copy = osa_lvl.copy = False
-            else:
-                osa.copy = osa_lvl.copy = True
-        if "threads" in self.presets:
-            thrd_mode = cp_sett.affected_settings["threads_mode"]
-            threads = cp_sett.affected_settings["threads"]
-            if thrd_mode.copy and threads.copy:
-                thrd_mode.copy = threads.copy = False
-            else:
-                thrd_mode.copy = threads.copy = True
-        if "fields" in self.presets:
-            fields = cp_sett.affected_settings["use_fields"]
-            field_ord = cp_sett.affected_settings["field_order"]
-            fields_still = cp_sett.affected_settings["use_fields_still"]
-            if fields.copy and field_ord.copy and fields_still.copy:
-                fields.copy = field_ord.copy = fields_still.copy = False
-            else:
-                fields.copy = field_ord.copy = fields_still.copy = True
-        if "stamp" in self.presets:
-            stamp = cp_sett.affected_settings["use_stamp"]
-            if stamp.copy:
-                stamp.copy = False
-            else:
-                stamp.copy = True
+        for p in presets.presets:
+            if p.rna_enum[0] in self.presets:
+                self.process_elements(cp_sett.affected_settings, p.elements)
         return {'FINISHED'}
 
 
@@ -198,17 +165,15 @@
 
 def do_copy(context, affected_settings, allowed_scenes):
     # Stores render settings from current scene.
-    p = dict((n, None) for n in affected_settings)
+    p = {sett: getattr(context.scene.render, sett) for sett in affected_settings}
     # put it in all other (valid) scenes’ render settings!
     for scene in bpy.data.scenes:
         # If scene not in allowed scenes, skip.
         if scene.name not in allowed_scenes:
             continue
         # Propagate all affected settings.
-        for sett in affected_settings:
-            if p[sett] is None:
-                p[sett] = getattr(context.scene.render, sett)
-            setattr(scene.render, sett, p[sett])
+        for sett, val in p.items():
+            setattr(scene.render, sett, val)
 
 
 class RenderCopySettings(bpy.types.Operator):
@@ -227,7 +192,7 @@
     def execute(self, context):
         regex = None
         cp_sett = context.scene.render_copy_settings
-        affected_settings = set([sett.name for sett in cp_sett.affected_settings if sett.copy])
+        affected_settings = set([sett.strid for sett in cp_sett.affected_settings if sett.copy])
         allowed_scenes = set([sce.name for sce in cp_sett.allowed_scenes if sce.allowed])
         do_copy(context, affected_settings=affected_settings, allowed_scenes=allowed_scenes)
         return {'FINISHED'}

Modified: contrib/py/scripts/addons/render_copy_settings/panel.py
===================================================================
--- contrib/py/scripts/addons/render_copy_settings/panel.py	2011-12-15 20:26:13 UTC (rev 2781)
+++ contrib/py/scripts/addons/render_copy_settings/panel.py	2011-12-15 20:48:07 UTC (rev 2782)
@@ -19,6 +19,7 @@
 # <pep8 compliant>
 
 import bpy
+from . import presets
 
 
 class RENDER_PT_copy_settings(bpy.types.Panel):
@@ -42,46 +43,17 @@
 
         split = layout.split(0.75)
         split.template_list(cp_sett, "affected_settings", cp_sett, "aff_sett_idx",
-                            enum_ctrls_name="template_list_controls", rows=6)
+                            prop_list="template_list_controls", rows=6)
+
         col = split.column()
-        label = ""
-        if (cp_sett.affected_settings["resolution_x"].copy and
-            cp_sett.affected_settings["resolution_y"].copy and
-            cp_sett.affected_settings["pixel_aspect_x"].copy and
-            cp_sett.affected_settings["pixel_aspect_y"].copy):
-            label = "Clear Resolution"
-        else:
-            label = "Set Resolution"
-        col.operator("scene.render_copy_settings_preset", text=label, ).presets = {"resolution"}
-        if cp_sett.affected_settings["resolution_percentage"].copy:
-            label = "Clear Scale"
-        else:
-            label = "Set Scale"
-        col.operator("scene.render_copy_settings_preset", text=label).presets = {"scale"}
-        if (cp_sett.affected_settings["use_antialiasing"].copy and
-            cp_sett.affected_settings["antialiasing_samples"].copy):
-            label = "Clear OSA"
-        else:
-            label = "Set OSA"
-        col.operator("scene.render_copy_settings_preset", text=label).presets = {"osa"}
-        if (cp_sett.affected_settings["threads_mode"].copy and
-            cp_sett.affected_settings["threads"].copy):
-            label = "Clear Threads"
-        else:
-            label = "Set Threads"
-        col.operator("scene.render_copy_settings_preset", text=label).presets = {"threads"}
-        if (cp_sett.affected_settings["use_fields"].copy and
-            cp_sett.affected_settings["field_order"].copy and

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list