Cleanup: remove unused operator args
[blender-addons.git] / system_property_chart.py
blob9bf87085d5c7a1e65646eb0099ab70505d1dbaf6
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # <pep8 compliant>
21 bl_info = {
22 "name": "Property Chart",
23 "author": "Campbell Barton (ideasman42)",
24 "version": (0, 1),
25 "blender": (2, 57, 0),
26 "location": "Tool Shelf",
27 "description": ("Edit arbitrary selected properties for "
28 "objects/sequence strips of the same type"),
29 "warning": "",
30 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
31 "Scripts/System/Object Property Chart",
32 "category": "System",
35 """List properties of selected objects"""
37 import bpy
38 from bl_operators.presets import AddPresetBase
41 class AddPresetProperties(AddPresetBase, bpy.types.Operator):
42 """Add an properties preset"""
43 bl_idname = "scene.properties_preset_add"
44 bl_label = "Add Properties Preset"
45 preset_menu = "SCENE_MT_properties_presets"
47 preset_defines = [
48 "scene = bpy.context.scene",
51 def pre_cb(self, context):
52 space_type = context.space_data.type
53 if space_type == 'VIEW_3D':
54 self.preset_subdir = "system_property_chart_view3d"
55 self.preset_values = ["scene.view3d_edit_props"]
56 else:
57 self.preset_subdir = "system_property_chart_sequencer"
58 self.preset_values = ["scene.sequencer_edit_props"]
61 class SCENE_MT_properties_presets(bpy.types.Menu):
62 bl_label = "Properties Presets"
63 preset_operator = "script.execute_preset"
65 def draw(self, context):
66 space_type = context.space_data.type
68 if space_type == 'VIEW_3D':
69 self.preset_subdir = "system_property_chart_view3d"
70 else:
71 self.preset_subdir = "system_property_chart_sequencer"
73 bpy.types.Menu.draw_preset(self, context)
76 def _property_chart_data_get(self, context):
77 # eg. context.active_object
78 obj = eval("context.%s" % self.context_data_path_active)
80 if obj is None:
81 return None, None
83 # eg. context.selected_objects[:]
84 selected_objects = eval("context.%s" % self.context_data_path_selected)[:]
86 if not selected_objects:
87 return None, None
89 return obj, selected_objects
92 def _property_chart_draw(self, context):
93 """
94 This function can run for different types.
95 """
96 obj, selected_objects = _property_chart_data_get(self, context)
98 if not obj:
99 return
101 # active first
102 try:
103 active_index = selected_objects.index(obj)
104 except ValueError:
105 active_index = -1
107 if active_index > 0: # not the first already
108 selected_objects[0], selected_objects[active_index] = selected_objects[active_index], selected_objects[0]
110 id_storage = context.scene
112 strings = getattr(id_storage, self._PROP_STORAGE_ID)
114 # Collected all props, now display them all
115 layout = self.layout
117 if strings:
119 def obj_prop_get(obj, attr_string):
120 """return a pair (rna_base, "rna_property") to give to the rna UI property function"""
121 attrs = attr_string.split(".")
122 val_new = obj
123 for i, attr in enumerate(attrs):
124 val_old = val_new
125 val_new = getattr(val_old, attr, Ellipsis)
127 if val_new == Ellipsis:
128 return None, None
129 return val_old, attrs[-1]
131 strings = strings.split()
133 prop_all = []
135 for obj in selected_objects:
136 prop_pairs = []
137 prop_found = False
138 for attr_string in strings:
139 prop_pairs.append(obj_prop_get(obj, attr_string))
140 if prop_found is False and prop_pairs[-1] != (None, None):
141 prop_found = True
143 if prop_found:
144 prop_all.append((obj, prop_pairs))
146 row = layout.row(align=True)
148 col = row.column(align=True)
149 col.label(text="name")
150 for obj, prop_pairs in prop_all:
151 col.prop(obj, "name", text="")
153 for i in range(len(strings)):
154 col = row.column(align=True)
156 # name and copy button
157 rowsub = col.row(align=False)
158 rowsub.label(text=strings[i].rsplit(".", 1)[-1])
159 props = rowsub.operator("wm.chart_copy", text="", icon='PASTEDOWN', emboss=False)
160 props.data_path_active = self.context_data_path_active
161 props.data_path_selected = self.context_data_path_selected
162 props.data_path = strings[i]
164 for obj, prop_pairs in prop_all:
165 data, attr = prop_pairs[i]
166 if data:
167 col.prop(data, attr, text="") # , emboss=obj==active_object
168 else:
169 col.label(text="<missing>")
171 # Presets for properties
172 col = layout.column()
173 col.label(text="Properties")
174 row = col.row(align=True)
175 row.menu("SCENE_MT_properties_presets", text=bpy.types.SCENE_MT_properties_presets.bl_label)
176 row.operator("scene.properties_preset_add", text="", icon="ZOOMIN")
177 row.operator("scene.properties_preset_add", text="", icon="ZOOMOUT").remove_active = True
178 # edit the display props
179 col.prop(id_storage, self._PROP_STORAGE_ID, text="")
182 class View3DEditProps(bpy.types.Panel):
183 bl_space_type = 'VIEW_3D'
184 bl_region_type = 'UI'
186 bl_label = "Property Chart"
187 bl_context = "objectmode"
189 _PROP_STORAGE_ID = "view3d_edit_props"
190 _PROP_STORAGE_DEFAULT = "data data.name"
192 # _property_chart_draw needs these
193 context_data_path_active = "active_object"
194 context_data_path_selected = "selected_objects"
196 draw = _property_chart_draw
199 class SequencerEditProps(bpy.types.Panel):
200 bl_space_type = 'SEQUENCE_EDITOR'
201 bl_region_type = 'UI'
203 bl_label = "Property Chart"
205 _PROP_STORAGE_ID = "sequencer_edit_props"
206 _PROP_STORAGE_DEFAULT = "blend_type blend_alpha"
208 # _property_chart_draw needs these
209 context_data_path_active = "scene.sequence_editor.active_strip"
210 context_data_path_selected = "selected_sequences"
212 draw = _property_chart_draw
214 @classmethod
215 def poll(cls, context):
216 return context.scene.sequence_editor is not None
218 # Operator to copy properties
221 def _property_chart_copy(self, context):
222 obj, selected_objects = _property_chart_data_get(self, context)
224 if not obj:
225 return
227 data_path = self.data_path
229 # quick & nasty method!
230 for obj_iter in selected_objects:
231 if obj != obj_iter:
232 try:
233 exec("obj_iter.%s = obj.%s" % (data_path, data_path))
234 except:
235 # just in case we need to know what went wrong!
236 import traceback
237 traceback.print_exc()
239 from bpy.props import StringProperty
242 class CopyPropertyChart(bpy.types.Operator):
243 "Open a path in a file browser"
244 bl_idname = "wm.chart_copy"
245 bl_label = "Copy properties from active to selected"
247 data_path_active = StringProperty()
248 data_path_selected = StringProperty()
249 data_path = StringProperty()
251 def execute(self, context):
252 # so attributes are found for '_property_chart_data_get()'
253 self.context_data_path_active = self.data_path_active
254 self.context_data_path_selected = self.data_path_selected
256 _property_chart_copy(self, context)
258 return {'FINISHED'}
261 def register():
262 bpy.utils.register_module(__name__)
264 Scene = bpy.types.Scene
266 for cls in View3DEditProps, SequencerEditProps:
267 setattr(Scene,
268 cls._PROP_STORAGE_ID,
269 StringProperty(
270 name="Scene Name",
271 description="Name of POV-Ray scene to create. Empty " \
272 "name will use the name of the blend file",
273 default=cls._PROP_STORAGE_DEFAULT, maxlen=1024),
277 def unregister():
278 bpy.utils.unregister_module(__name__)
280 Scene = bpy.types.Scene
282 for cls in View3DEditProps, SequencerEditProps:
283 delattr(Scene,
284 cls._PROP_STORAGE_ID,
288 if __name__ == "__main__":
289 register()