[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1902] contrib/py/scripts/addons: Adding Render Copy Settings addon in Contrib.

Bastien Montagne montagne29 at wanadoo.fr
Sat May 7 18:05:12 CEST 2011


Revision: 1902
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1902
Author:   mont29
Date:     2011-05-07 16:05:12 +0000 (Sat, 07 May 2011)
Log Message:
-----------
Adding Render Copy Settings addon in Contrib.

Added Paths:
-----------
    contrib/py/scripts/addons/render_copy_settings/
    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: contrib/py/scripts/addons/render_copy_settings/__init__.py
===================================================================
--- contrib/py/scripts/addons/render_copy_settings/__init__.py	                        (rev 0)
+++ contrib/py/scripts/addons/render_copy_settings/__init__.py	2011-05-07 16:05:12 UTC (rev 1902)
@@ -0,0 +1,167 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+# ##### CHANGELOG #####
+#
+#  0.0.1
+#      Initial release.
+#
+#  0.0.2
+#      Updates to follow Blender API:
+#        * bl_addon_info renamed in bl_info!
+#        * adding bpy.utils.(un)register_module calls.
+#      Also, in standard import, using “from . import …” now.
+#
+#  0.1.0
+#      Renamed in “Render Copy Settings”.
+#      Huge changes:
+#        * It is now possible to individually copy each render setting.
+#        * It is now possible to individually select each affected scene, and then filter them out
+#          even further with a regex.
+#      WARNING: this addon now needs a Blender patched with the ui_template_list diff, else it won’t
+#               be fully functional…
+#
+#  0.1.1
+#      Minor changes:
+#        * PEP8 compliant.
+#        * Moved to contrib…
+#      WARNING: this addon now needs a Blender patched with the ui_template_list diff, else it won’t
+#               be fully functional (even though working)…
+#
+# ##### END OF CHANGELOG #####
+
+bl_info = {
+    "name": "Copy Settings",
+    "author": "Bastien Montagne",
+    "version": (0, 1, 1),
+    "blender": (2, 5, 7),
+    "api": 36380,
+    "location": "Render buttons (Properties window)",
+    "description": "Allows to copy a selection of render settings from current scene to others.",
+    "warning": "beta",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
+                "Scripts/Render/Copy Settings",
+    "tracker_url": "http://projects.blender.org/tracker/index.php?func=detail&aid=25832",
+    "category": "Render"}
+
+
+if "bpy" in locals():
+    import imp
+    imp.reload(operator)
+    imp.reload(panel)
+
+else:
+    from . import operator, panel
+
+
+import bpy
+from bpy.props import StringProperty, BoolProperty, IntProperty, CollectionProperty
+
+
+# XXX This should be somehow a BPY-wide class…
+class TemplateListControl(bpy.types.PropertyGroup):
+    identifier = StringProperty()
+
+
+####################################################################################################
+# Global properties for the script, for UI (as there’s no way to let them in the operator…).
+####################################################################################################
+
+class RenderCopySettingsScene(bpy.types.PropertyGroup):
+    allowed = BoolProperty(default=True)
+
+    # A collection of identifiers (as strings) which property’s controls should be displayed
+    # in a template_list.
+    # XXX: The initialization of this collection is done via a dedicated
+    #      init_TemplateListControls() func.
+    #      This isn’t really nice, but there seems to be no ways to specify a default set of
+    #      items for a collection. User has to define and call this func manually…
+    #      There should be a way to automatize all this, but I’m not skilled enough with BPY
+    #      to figure it (seems inheritance and/or __init__ and/or __new__ don’t work here…).
+    template_list_controls = CollectionProperty(type=TemplateListControl, options={"HIDDEN"})
+
+    def init_TemplateListControls(self):
+        self.template_list_controls.add().identifier = "allowed"
+
+
+class RenderCopySettingsSetting(bpy.types.PropertyGroup):
+    copy = BoolProperty(default=False)
+
+    # A collection of identifiers (as strings) which property’s controls should be displayed
+    # in a template_list.
+    # XXX: The initialization of this collection is done via a dedicated
+    #      init_TemplateListControls() func.
+    #      This isn’t really nice, but there seems to be no ways to specify a default set of
+    #      items for a collection. User has to define and call this func manually…
+    #      There should be a way to automatize all this, but I’m not skilled enough with BPY
+    #      to figure it (seems inheritance and/or __init__ and/or __new__ don’t work here…).
+    template_list_controls = CollectionProperty(type=TemplateListControl, options={"HIDDEN"})
+
+    def init_TemplateListControls(self):
+        self.template_list_controls.add().identifier = "copy"
+
+
+class RenderCopySettings(bpy.types.PropertyGroup):
+    # XXX: The consistency of this collection is delegated to the UI code.
+    #      It should only contain one element for each render setting.
+    affected_settings = CollectionProperty(type=RenderCopySettingsSetting,
+                                           name="Affected Settings",
+                                           description="The list of all available render settings.")
+    # XXX Unused, but needed for template_list…
+    aff_sett_idx = IntProperty()
+
+    # XXX: The consistency of this collection is delegated to the UI code.
+    #      It should only contain one element for each scene.
+    allowed_scenes = CollectionProperty(type=RenderCopySettingsScene,
+                                        name="Allowed Scenes",
+                                        description="The list all scenes in the file.")
+    # XXX Unused, but needed for template_list…
+    allw_scenes_idx = IntProperty()
+
+    filter_scene = StringProperty(name="Filter Scene",
+                                  description="Regex to only affect scenes which name matches it.",
+                                  default="")
+
+
+def register():
+    # Register properties.
+    bpy.utils.register_class(TemplateListControl)
+    bpy.utils.register_class(RenderCopySettingsScene)
+    bpy.utils.register_class(RenderCopySettingsSetting)
+    bpy.utils.register_class(RenderCopySettings)
+    bpy.types.Scene.render_copy_settings = \
+        bpy.props.PointerProperty(type=RenderCopySettings)
+
+    bpy.utils.register_module(__name__)
+
+
+def unregister():
+    # Unregister properties.
+    bpy.utils.unregister_class(TemplateListControl)
+    bpy.utils.unregister_class(RenderCopySettingsScene)
+    bpy.utils.unregister_class(RenderCopySettingsSetting)
+    bpy.utils.unregister_class(RenderCopySettings)
+    del bpy.types.Scene.render_copy_settings
+
+    bpy.utils.unregister_module(__name__)
+
+
+if __name__ == "__main__":
+    register()

Added: contrib/py/scripts/addons/render_copy_settings/operator.py
===================================================================
--- contrib/py/scripts/addons/render_copy_settings/operator.py	                        (rev 0)
+++ contrib/py/scripts/addons/render_copy_settings/operator.py	2011-05-07 16:05:12 UTC (rev 1902)
@@ -0,0 +1,238 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+import bpy
+
+# These operators are only defined because it seems impossible to directly edit properties from
+# UI code…
+
+
+# A sorting func for collections (working in-place).
+# XXX Not optimized at all…
+# XXX If some items in the collection do not have the sortkey property, they are just ignored…
+def collection_property_sort(collection, sortkey, start_idx=0):
+    while start_idx + 1 < len(collection):
+        while not hasattr(collection[start_idx], sortkey):
+            start_idx += 1
+            if start_idx + 1 >= len(collection):
+                return collection
+        min_idx = start_idx
+        min_prop = collection[start_idx]
+        for i, prop in enumerate(collection[start_idx + 1:]):
+            if not hasattr(prop, sortkey):
+                continue
+            if getattr(prop, sortkey) < getattr(min_prop, sortkey):
+                min_prop = prop
+                min_idx = i + start_idx + 1
+        collection.move(min_idx, start_idx)
+        start_idx += 1
+    return collection
+
+
+class RenderCopySettingsPrepare(bpy.types.Operator):
+    '''
+    Prepare internal data for render_copy_settings (gathering all existing render settings,
+    and scenes).
+    '''
+    bl_idname = "scene.render_copy_settings_prepare"
+    bl_label = "Render: Copy Settings Prepare"
+    bl_option = {'REGISTER'}
+
+    @classmethod
+    def poll(cls, context):
+        return context.scene != None
+
+    def execute(self, context):
+        cp_sett = context.scene.render_copy_settings
+
+        # Get all available render settings, and update accordingly affected_settings…
+        props = set()
+        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)
+        for i, sett in enumerate(cp_sett.affected_settings):
+            if sett.name not in props:
+                cp_sett.affected_settings.remove(i)

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list