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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # ##### END GPL LICENSE BLOCK #####
23 EVIL_PROP = "act_property"
24 EVIL_PROP_PATH = EVIL_PROP + '_path'
25 EVIL_PROP_VALUE = EVIL_PROP + '_value'
26 EVIL_PROP_PROP = EVIL_PROP + '_prop'
27 EVIL_PROP_PROP_ORIG = EVIL_PROP + '_prop_orig'
29 # nasty!, use a scene property to store the active edit item
31 Scene = bpy.types.Scene
32 if EVIL_PROP_PROP_ORIG not in Scene.bl_rna.properties:
33 Scene.StringProperty(attr=EVIL_PROP_PATH)
34 Scene.StringProperty(attr=EVIL_PROP_VALUE)
35 Scene.StringProperty(attr=EVIL_PROP_PROP)
36 Scene.StringProperty(attr=EVIL_PROP_PROP_ORIG)
39 def draw(layout, context, context_member):
41 def assign_props(prop, val, key):
42 prop.path = context_member
50 rna_item = eval("context." + context_member)
56 global_path = getattr(scene, EVIL_PROP_PATH)
57 global_value = getattr(scene, EVIL_PROP_VALUE)
58 global_prop = getattr(scene, EVIL_PROP_PROP)
59 global_prop_orig = getattr(scene, EVIL_PROP_PROP_ORIG)
61 # print((global_path, global_value, global_prop, global_prop_orig))
63 items = rna_item.items()
67 props = row.itemO("wm.properties_add", properties=True, text="Add")
68 props.path = context_member
70 for key, val in items:
72 convert_to_pyobject = getattr(val, "convert_to_pyobject", None)
75 if convert_to_pyobject:
76 val_draw = val = val.convert_to_pyobject()
77 val_draw = str(val_draw)
83 if key == global_prop_orig and context_member == global_path:
84 split = box.split(percentage=0.75)
87 row.itemR(scene, EVIL_PROP_PROP)
88 row.itemR(scene, EVIL_PROP_VALUE)
91 prop = row.itemO("wm.properties_edit_end", properties=True, text="done")
92 assign_props(prop, val_draw, key)
95 split = box.split(percentage=0.75)
99 # explicit exception for arrays
100 if convert_to_pyobject and not hasattr(val_orig, "len"):
101 row.itemL(text=val_draw)
103 row.itemR(rna_item, '["%s"]' % key, text="")
106 row = split.row(align=True)
107 prop = row.itemO("wm.properties_edit_begin", properties=True, text="edit")
108 assign_props(prop, val_draw, key)
110 prop = row.itemO("wm.properties_remove", properties=True, text="", icon='ICON_ZOOMOUT')
111 assign_props(prop, val_draw, key)
114 from bpy.props import *
117 rna_path = StringProperty(name="Property Edit",
118 description="Property path edit", maxlen=1024, default="")
120 rna_value = StringProperty(name="Property Value",
121 description="Property value edit", maxlen=1024, default="")
123 rna_property = StringProperty(name="Property Name",
124 description="Property name edit", maxlen=1024, default="")
126 class WM_OT_properties_edit_begin(bpy.types.Operator):
127 '''Internal use (edit a property path)'''
128 bl_idname = "wm.properties_edit_begin"
129 bl_label = "Edit Property"
133 property = rna_property
135 def execute(self, context):
136 scene = context.scene
138 setattr(scene, EVIL_PROP_PATH, self.path)
139 setattr(scene, EVIL_PROP_VALUE, self.value)
140 setattr(scene, EVIL_PROP_PROP, self.property)
141 setattr(scene, EVIL_PROP_PROP_ORIG, self.property)
146 class WM_OT_properties_edit_end(bpy.types.Operator):
147 '''Internal use (edit a property path)'''
148 bl_idname = "wm.properties_edit_end"
149 bl_label = "Edit Property"
153 property = rna_property
155 def execute(self, context):
157 scene = context.scene
158 global_path = getattr(scene, EVIL_PROP_PATH)
159 global_value = getattr(scene, EVIL_PROP_VALUE)
160 global_prop = getattr(scene, EVIL_PROP_PROP)
162 setattr(scene, EVIL_PROP_PATH, "")
163 setattr(scene, EVIL_PROP_VALUE, "")
164 setattr(scene, EVIL_PROP_PROP, "")
165 setattr(scene, EVIL_PROP_PROP_ORIG, "")
168 value = eval(global_value)
172 if type(value) == str:
173 value = '"' + value + '"'
177 exec_str = "del context.%s['%s']" % (global_path, self.property)
183 exec_str = "context.%s['%s'] = %s" % (global_path, global_prop, value)
190 class WM_OT_properties_add(bpy.types.Operator):
191 '''Internal use (edit a property path)'''
192 bl_idname = "wm.properties_add"
193 bl_label = "Add Property"
197 def execute(self, context):
198 item = eval("context.%s" % self.path)
200 def unique_name(names):
204 while prop_new in names:
205 prop_new = prop + str(i)
210 property = unique_name(item.keys())
215 class WM_OT_properties_remove(bpy.types.Operator):
216 '''Internal use (edit a property path)'''
217 bl_idname = "wm.properties_remove"
218 bl_label = "Add Property"
221 property = rna_property
223 def execute(self, context):
224 item = eval("context.%s" % self.path)
225 del item[self.property]