diff options
Diffstat (limited to 'release/scripts/modules/rna_prop_ui.py')
-rw-r--r-- | release/scripts/modules/rna_prop_ui.py | 139 |
1 files changed, 8 insertions, 131 deletions
diff --git a/release/scripts/modules/rna_prop_ui.py b/release/scripts/modules/rna_prop_ui.py index 246fa4bdb7d..4ee0b40faa8 100644 --- a/release/scripts/modules/rna_prop_ui.py +++ b/release/scripts/modules/rna_prop_ui.py @@ -61,7 +61,7 @@ def rna_idprop_ui_prop_clear(item, prop): def draw(layout, context, context_member, use_edit=True): def assign_props(prop, val, key): - prop.path = context_member + prop.data_path = context_member prop.property = key try: @@ -81,7 +81,7 @@ def draw(layout, context, context_member, use_edit=True): if use_edit: row = layout.row() props = row.operator("wm.properties_add", text="Add") - props.path = context_member + props.data_path = context_member del row for key, val in items: @@ -124,141 +124,18 @@ def draw(layout, context, context_member, use_edit=True): assign_props(prop, val_draw, key) -class PropertyPanel(bpy.types.Panel): +class PropertyPanel(): """ The subclass should have its own poll function and the variable '_context_path' MUST be set. """ bl_label = "Custom Properties" - bl_default_closed = True + bl_options = {'DEFAULT_CLOSED'} + + @classmethod + def poll(cls, context): + return bool(eval("context.%s" % cls._context_path)) def draw(self, context): draw(self.layout, context, self._context_path) - -from bpy.props import * - - -rna_path = StringProperty(name="Property Edit", - description="Property path edit", maxlen=1024, default="", options={'HIDDEN'}) - -rna_value = StringProperty(name="Property Value", - description="Property value edit", maxlen=1024, default="") - -rna_property = StringProperty(name="Property Name", - description="Property name edit", maxlen=1024, default="") - -rna_min = FloatProperty(name="Min", default=0.0, precision=3) -rna_max = FloatProperty(name="Max", default=1.0, precision=3) - - -class WM_OT_properties_edit(bpy.types.Operator): - '''Internal use (edit a property path)''' - bl_idname = "wm.properties_edit" - bl_label = "Edit Property" - - path = rna_path - property = rna_property - value = rna_value - min = rna_min - max = rna_max - description = StringProperty(name="Tip", default="") - - def execute(self, context): - path = self.properties.path - value = self.properties.value - prop = self.properties.property - prop_old = self._last_prop[0] - - try: - value_eval = eval(value) - except: - value_eval = value - - # First remove - item = eval("context.%s" % path) - - rna_idprop_ui_prop_clear(item, prop_old) - exec_str = "del item['%s']" % prop_old - # print(exec_str) - exec(exec_str) - - - # Reassign - exec_str = "item['%s'] = %s" % (prop, repr(value_eval)) - # print(exec_str) - exec(exec_str) - self._last_prop[:] = [prop] - - prop_type = type(item[prop]) - - prop_ui = rna_idprop_ui_prop_get(item, prop) - - if prop_type in (float, int): - - prop_ui['soft_min'] = prop_ui['min'] = prop_type(self.properties.min) - prop_ui['soft_max'] = prop_ui['max'] = prop_type(self.properties.max) - - prop_ui['description'] = self.properties.description - - return {'FINISHED'} - - def invoke(self, context, event): - - self._last_prop = [self.properties.property] - - item = eval("context.%s" % self.properties.path) - - # setup defaults - prop_ui = rna_idprop_ui_prop_get(item, self.properties.property, False) # dont create - if prop_ui: - self.properties.min = prop_ui.get("min", -1000000000) - self.properties.max = prop_ui.get("max", 1000000000) - self.properties.description = prop_ui.get("description", "") - - wm = context.manager - # This crashes, TODO - fix - #return wm.invoke_props_popup(self, event) - - wm.invoke_props_popup(self, event) - return {'RUNNING_MODAL'} - - -class WM_OT_properties_add(bpy.types.Operator): - '''Internal use (edit a property path)''' - bl_idname = "wm.properties_add" - bl_label = "Add Property" - - path = rna_path - - def execute(self, context): - item = eval("context.%s" % self.properties.path) - - def unique_name(names): - prop = 'prop' - prop_new = prop - i = 1 - while prop_new in names: - prop_new = prop + str(i) - i += 1 - - return prop_new - - property = unique_name(item.keys()) - - item[property] = 1.0 - return {'FINISHED'} - - -class WM_OT_properties_remove(bpy.types.Operator): - '''Internal use (edit a property path)''' - bl_idname = "wm.properties_remove" - bl_label = "Add Property" - - path = rna_path - property = rna_property - - def execute(self, context): - item = eval("context.%s" % self.properties.path) - del item[self.properties.property] - return {'FINISHED'} |