110
135
row.label(text=key)
112
137
# explicit exception for arrays
113
if convert_to_pyobject and not hasattr(val_orig, "len"):
138
if to_dict or to_list:
114
139
row.label(text=val_draw)
116
row.prop(rna_item, '["%s"]' % key, text="")
141
if key in rna_properties:
142
row.prop(rna_item, key, text="")
144
row.prop(rna_item, '["%s"]' % key, text="")
119
147
row = split.row(align=True)
120
prop = row.operator("wm.properties_edit", text="edit")
121
assign_props(prop, val_draw, key)
123
prop = row.operator("wm.properties_remove", text="", icon='ZOOMOUT')
124
assign_props(prop, val_draw, key)
127
class PropertyPanel(bpy.types.Panel):
148
props = row.operator("wm.properties_edit", text="edit")
149
assign_props(props, val_draw, key)
151
props = row.operator("wm.properties_remove", text="", icon='ZOOMOUT')
152
assign_props(props, val_draw, key)
155
class PropertyPanel():
129
157
The subclass should have its own poll function
130
158
and the variable '_context_path' MUST be set.
132
160
bl_label = "Custom Properties"
133
bl_default_closed = True
161
bl_options = {'DEFAULT_CLOSED'}
164
def poll(cls, context):
165
rna_item, context_member = rna_idprop_context_value(context, cls._context_path, cls._property_type)
166
return bool(rna_item)
169
def draw_header(self, context):
170
rna_item, context_member = rna_idprop_context_value(context, self._context_path, self._property_type)
171
tot = len(rna_item.keys())
173
self.layout().label("%d:" % tot)
135
176
def draw(self, context):
136
draw(self.layout, context, self._context_path)
139
from bpy.props import *
142
rna_path = StringProperty(name="Property Edit",
143
description="Property data_path edit", maxlen=1024, default="", options={'HIDDEN'})
145
rna_value = StringProperty(name="Property Value",
146
description="Property value edit", maxlen=1024, default="")
148
rna_property = StringProperty(name="Property Name",
149
description="Property name edit", maxlen=1024, default="")
151
rna_min = FloatProperty(name="Min", default=0.0, precision=3)
152
rna_max = FloatProperty(name="Max", default=1.0, precision=3)
155
class WM_OT_properties_edit(bpy.types.Operator):
156
'''Internal use (edit a property data_path)'''
157
bl_idname = "wm.properties_edit"
158
bl_label = "Edit Property"
161
property = rna_property
165
description = StringProperty(name="Tip", default="")
167
def execute(self, context):
168
data_path = self.properties.data_path
169
value = self.properties.value
170
prop = self.properties.property
171
prop_old = self._last_prop[0]
174
value_eval = eval(value)
179
item = eval("context.%s" % data_path)
181
rna_idprop_ui_prop_clear(item, prop_old)
182
exec_str = "del item['%s']" % prop_old
188
exec_str = "item['%s'] = %s" % (prop, repr(value_eval))
191
self._last_prop[:] = [prop]
193
prop_type = type(item[prop])
195
prop_ui = rna_idprop_ui_prop_get(item, prop)
197
if prop_type in (float, int):
199
prop_ui['soft_min'] = prop_ui['min'] = prop_type(self.properties.min)
200
prop_ui['soft_max'] = prop_ui['max'] = prop_type(self.properties.max)
202
prop_ui['description'] = self.properties.description
206
def invoke(self, context, event):
208
self._last_prop = [self.properties.property]
210
item = eval("context.%s" % self.properties.data_path)
213
prop_ui = rna_idprop_ui_prop_get(item, self.properties.property, False) # dont create
215
self.properties.min = prop_ui.get("min", -1000000000)
216
self.properties.max = prop_ui.get("max", 1000000000)
217
self.properties.description = prop_ui.get("description", "")
220
# This crashes, TODO - fix
221
#return wm.invoke_props_popup(self, event)
223
wm.invoke_props_popup(self, event)
224
return {'RUNNING_MODAL'}
227
class WM_OT_properties_add(bpy.types.Operator):
228
'''Internal use (edit a property data_path)'''
229
bl_idname = "wm.properties_add"
230
bl_label = "Add Property"
234
def execute(self, context):
235
item = eval("context.%s" % self.properties.data_path)
237
def unique_name(names):
241
while prop_new in names:
242
prop_new = prop + str(i)
247
property = unique_name(item.keys())
253
class WM_OT_properties_remove(bpy.types.Operator):
254
'''Internal use (edit a property data_path)'''
255
bl_idname = "wm.properties_remove"
256
bl_label = "Remove Property"
259
property = rna_property
261
def execute(self, context):
262
item = eval("context.%s" % self.properties.data_path)
263
del item[self.properties.property]
177
draw(self.layout, context, self._context_path, self._property_type)