[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [761] trunk/py/scripts/addons/ space_view3d_property_chart.py: - enable this for the sequencer

Campbell Barton ideasman42 at gmail.com
Thu Jul 8 14:56:08 CEST 2010


Revision: 761
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=761
Author:   campbellbarton
Date:     2010-07-08 14:56:08 +0200 (Thu, 08 Jul 2010)

Log Message:
-----------
- enable this for the sequencer
- added option to copy from active to selected
- made the active display first

Modified Paths:
--------------
    trunk/py/scripts/addons/space_view3d_property_chart.py

Modified: trunk/py/scripts/addons/space_view3d_property_chart.py
===================================================================
--- trunk/py/scripts/addons/space_view3d_property_chart.py	2010-07-06 18:06:00 UTC (rev 760)
+++ trunk/py/scripts/addons/space_view3d_property_chart.py	2010-07-08 12:56:08 UTC (rev 761)
@@ -35,7 +35,111 @@
 
 import bpy
 
+def _property_chart_data_get(self, context):
+    # eg. context.active_object
+    obj = eval("context.%s" % self.context_data_path_active)
 
+    if obj is None:
+        return None, None
+    
+    # eg. context.selected_objects[:]
+    selected_objects = eval("context.%s" % self.context_data_path_selected)[:]
+
+    if not selected_objects:
+        return None, None
+    
+    return obj, selected_objects
+
+
+def _property_chart_draw(self, context):
+    '''
+    This function can run for different types.
+    '''
+    obj, selected_objects = _property_chart_data_get(self, context)
+    
+    if not obj:
+        return
+
+    # active first
+    try:
+        active_index = selected_objects.index(obj)
+    except ValueError:
+        active_index = -1
+    
+    if active_index > 0: # not the first alredy
+        selected_objects[0], selected_objects[active_index] = selected_objects[active_index], selected_objects[0]
+    
+    id_storage = context.scene
+    
+    strings = id_storage.get(self._PROP_STORAGE_ID)
+    
+    if strings is None:
+        strings = id_storage[self._PROP_STORAGE_ID] = "data data.name"
+
+    if strings:
+
+        def obj_prop_get(obj, attr_string):
+            """return a pair (rna_base, "rna_property") to give to the rna UI property function"""
+            attrs = attr_string.split(".")
+            val_new = obj
+            for i, attr in enumerate(attrs):
+                val_old = val_new
+                val_new = getattr(val_old, attr, Ellipsis)
+                
+                if val_new == Ellipsis:
+                    return None, None                        
+            return val_old, attrs[-1]
+
+        strings = strings.split()
+
+        prop_all = []
+
+        for obj in selected_objects:
+            prop_pairs = []
+            prop_found = False
+            for attr_string in strings:
+                prop_pairs.append(obj_prop_get(obj, attr_string))
+                if prop_found == False and prop_pairs[-1] != (None, None): 
+                    prop_found = True
+
+            if prop_found:
+                prop_all.append((obj, prop_pairs))
+
+
+        # Collected all props, now display them all
+        layout = self.layout
+
+        row = layout.row(align=True)
+
+        col = row.column()
+        col.label(text="name")
+        for obj, prop_pairs in prop_all:
+            col.prop(obj, "name", text="")
+
+        for i in range(len(strings)):
+            col = row.column()
+
+            # name and copy button
+            rowsub = col.row(align=False)
+            rowsub.label(text=strings[i].rsplit(".", 1)[-1])
+            props = rowsub.operator("wm.chart_copy", text="", icon='PASTEDOWN', emboss=False)
+            props.data_path_active = self.context_data_path_active
+            props.data_path_selected = self.context_data_path_selected
+            props.data_path_storage = self._PROP_STORAGE_ID
+
+            for obj, prop_pairs in prop_all:
+                data, attr = prop_pairs[i]
+                if data:
+                    col.prop(data, attr, text="")# , emboss=obj==active_object
+                else:
+                    col.label(text="<missing>")
+
+    # edit the display props
+    col = layout.column()
+    col.label(text="Object Properties")
+    col.prop(id_storage, '["%s"]' % self._PROP_STORAGE_ID, text="")
+
+
 class View3DEditProps(bpy.types.Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'UI'
@@ -44,88 +148,88 @@
     bl_context = "objectmode"
     
     _PROP_STORAGE_ID = "view3d_edit_props"
+    
+    # _property_chart_draw needs these
+    context_data_path_active = "active_object"
+    context_data_path_selected = "selected_objects"
 
-    def draw(self, context):
-        layout = self.layout
-        obj = context.object
-        
-        if obj is None:
-            return
+    draw = _property_chart_draw
 
-        selected_objects = context.selected_objects
 
-        if not selected_objects:
-            return
+class SequencerEditProps(bpy.types.Panel):
+    bl_space_type = 'SEQUENCE_EDITOR'
+    bl_region_type = 'UI'
+    
+    bl_label = "Property Chart"
+    
+    _PROP_STORAGE_ID = "sequencer_edit_props"
+    
+    # _property_chart_draw needs these
+    context_data_path_active = "scene.sequence_editor.active_strip"
+    context_data_path_selected = "selected_sequences"
 
-        # box = layout.separator()
-        
-        id_storage = context.scene
-        
-        strings = id_storage.get(self._PROP_STORAGE_ID)
-        
-        if strings is None:
-            strings = id_storage[self._PROP_STORAGE_ID] = "data data.name"
+    draw = _property_chart_draw
 
-        if strings:
-            
-            def obj_prop_get(obj, attr_string):
-                """return a pair (rna_base, "rna_property") to give to the rna UI property function"""
-                attrs = attr_string.split(".")
-                val_new = obj
-                for i, attr in enumerate(attrs):
-                    val_old = val_new
-                    val_new = getattr(val_old, attr, Ellipsis)
-                    
-                    if val_new == Ellipsis:
-                        return None, None                        
-                return val_old, attrs[-1]
 
-            strings = strings.split()
+# Operator to copy properties
 
-            prop_all = []
 
-            for obj in selected_objects:
-                prop_pairs = []
-                prop_found = False
-                for attr_string in strings:
-                    prop_pairs.append(obj_prop_get(obj, attr_string))
-                    if prop_found == False and prop_pairs[-1] != (None, None): 
-                        prop_found = True
+def _property_chart_copy(self, context):
+    obj, selected_objects = _property_chart_data_get(self, context)
+    
+    if not obj:
+        return
 
-                if prop_found:
-                    prop_all.append((obj, prop_pairs))
+    id_storage = context.scene
+    
+    strings = id_storage.get(self.properties.data_path_storage)
+    
+    if strings:
+        strings = strings.split()
 
+        # quick & nasty method!
+        for obj_iter in selected_objects:
+            if obj != obj_iter:
+                for prop_path in strings:
+                    try:
+                        exec("obj_iter.%s = obj.%s" % (prop_path, prop_path))
+                    except:
+                        # just incase we need to know what went wrong!
+                        import traceback
+                        traceback.print_exc()
 
-            # Collected all props, now display them all
-            row = layout.row()
+from bpy.props import StringProperty
 
-            col = row.column()
-            col.label(text="name")
-            for obj, prop_pairs in prop_all:
-                col.prop(obj, "name", text="")
 
-            for i in range(len(strings)):
-                col = row.column()
-                col.label(text=strings[i].rsplit(".", 1)[-1])
-                for obj, prop_pairs in prop_all:
-                    data, attr = prop_pairs[i]
-                    if data:
-                        col.prop(data, attr, text="")
-                    else:
-                        col.label(text="<missing>")
+class CopyPropertyChart(bpy.types.Operator):
+    "Open a path in a file browser"
+    bl_idname = "wm.chart_copy"
+    bl_label = "Copy properties from active to selected"
 
-        # edit the display props
-        col = layout.column()
-        col.label(text="Object Properties")
-        col.prop(id_storage, '["%s"]' % self._PROP_STORAGE_ID, text="")
+    data_path_active = StringProperty()
+    data_path_selected = StringProperty()
+    data_path_storage = StringProperty()
 
-	
+    def execute(self, context):
+        # so attributes are found for '_property_chart_data_get()'
+        self.context_data_path_active = self.properties.data_path_active
+        self.context_data_path_selected = self.properties.data_path_selected
+
+        _property_chart_copy(self, context)
+
+        return {'FINISHED'}
+
+
 def register():
     bpy.types.register(View3DEditProps)
+    bpy.types.register(SequencerEditProps)
+    bpy.types.register(CopyPropertyChart)
 
 
 def unregister():
     bpy.types.unregister(View3DEditProps)
+    bpy.types.unregister(SequencerEditProps)
+    bpy.types.unregister(CopyPropertyChart)
 
 if __name__ == "__main__":
     register()




More information about the Bf-extensions-cvs mailing list