ID properties that are displayed via RNA can now define their own UI settings,
authorCampbell Barton <ideasman42@gmail.com>
Wed, 18 Nov 2009 20:01:35 +0000 (20:01 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 18 Nov 2009 20:01:35 +0000 (20:01 +0000)
 only implimented min/max precision & step.

at the moment there is no way to edit these other then via python

example of setting UI limits...

>>> C.object['foo'] = 0.5
>>> C.object['_RNA_UI'] = {'foo': {'step': 0.5, 'soft_max': 10.0, 'soft_min': 0.0, 'precision': 2, 'description': 'Some setting'}}

Also fixed typo's: precission -> precision

12 files changed:
release/scripts/modules/rna_prop_ui.py
release/scripts/ui/properties_object.py
release/scripts/ui/space_view3d.py
source/blender/blenkernel/BKE_idprop.h
source/blender/blenkernel/intern/idprop.c
source/blender/editors/interface/interface.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/editors/space_view3d/drawobject.c
source/blender/imbuf/intern/jp2.c
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_internal_types.h
source/blender/python/intern/bpy_rna.c

index 8ef50e20d76413def5f63b0578bc806411bab2c9..7f741e46bd0bc3bbd639f25d9913b63d001960b4 100644 (file)
@@ -36,7 +36,7 @@ def evil_prop_init():
         Scene.StringProperty(attr=EVIL_PROP_PROP_ORIG)
 
 
-def draw(layout, context, context_member):
+def draw(layout, context, context_member, use_edit = True):
     
     def assign_props(prop, val, key):
         prop.path = context_member
@@ -63,11 +63,17 @@ def draw(layout, context, context_member):
     items = rna_item.items()
     items.sort()
     
-    row = layout.row()
-    props = row.itemO("wm.properties_add", properties=True, text="Add")
-    props.path = context_member
-    
+    if use_edit:
+        row = layout.row()
+        props = row.itemO("wm.properties_add", properties=True, text="Add")
+        props.path = context_member
+        del row
+
     for key, val in items:
+        
+        if key == '_RNA_UI':
+            continue
+        
         row = layout.row()
         convert_to_pyobject = getattr(val, "convert_to_pyobject", None)
         
@@ -80,7 +86,7 @@ def draw(layout, context, context_member):
 
         box = row.box()
         
-        if key == global_prop_orig and context_member == global_path:
+        if use_edit and key == global_prop_orig and context_member == global_path:
             split = box.split(percentage=0.75)
             
             row = split.row()
@@ -92,8 +98,12 @@ def draw(layout, context, context_member):
             assign_props(prop, val_draw, key)
             
         else:
-            split = box.split(percentage=0.75)
-            row = split.row()
+            if use_edit:
+                split = box.split(percentage=0.75)
+                row = split.row()
+            else:
+                row = box.row()
+            
             row.itemL(text=key)
             
             # explicit exception for arrays
@@ -102,13 +112,13 @@ def draw(layout, context, context_member):
             else:
                 row.itemR(rna_item, '["%s"]' % key, text="")
                 
-            
-            row = split.row(align=True)
-            prop = row.itemO("wm.properties_edit_begin", properties=True, text="edit")
-            assign_props(prop, val_draw, key)
-            
-            prop = row.itemO("wm.properties_remove", properties=True, text="", icon='ICON_ZOOMOUT')
-            assign_props(prop, val_draw, key)
+            if use_edit:
+                row = split.row(align=True)
+                prop = row.itemO("wm.properties_edit_begin", properties=True, text="edit")
+                assign_props(prop, val_draw, key)
+                
+                prop = row.itemO("wm.properties_remove", properties=True, text="", icon='ICON_ZOOMOUT')
+                assign_props(prop, val_draw, key)
     
 
 from bpy.props import *
index c7d3f77caed60c7fb446f43a072980e377b2f893..71a05792ee4b03fa71e59370efd7540e1b4899bb 100644 (file)
@@ -300,7 +300,7 @@ class OBJECT_PT_properties(ObjectButtonsPanel):
     def draw(self, context):
         import rna_prop_ui
         # reload(rna_prop_ui)
-        
+
         rna_prop_ui.draw(self.layout, context, "object")
 
 bpy.types.register(OBJECT_PT_context_object)
index 82d56aa693bd8c00a5251d3202d05182e8b30559..817bd5fa43f7dd5b6ed3d45b008df8477a31c4b2 100644 (file)
@@ -1629,6 +1629,29 @@ class VIEW3D_PT_etch_a_ton(bpy.types.Panel):
             col.itemR(toolsettings, "etch_side")
 
 
+class VIEW3D_PT_context_properties(bpy.types.Panel):
+    bl_space_type = 'VIEW_3D'
+    bl_region_type = 'UI'
+    bl_label = "Properties"
+    bl_default_closed = True
+
+    def draw(self, context):
+        import rna_prop_ui
+        # reload(rna_prop_ui)
+        obj = context.object
+        if obj:
+            mode = obj.mode
+            if mode == 'POSE':
+                item = "active_pchan"
+            elif mode == 'EDIT' and obj.type == 'ARMATURE':
+                item = "active_bone"
+            else:
+                item = "object"
+
+            # Draw with no edit button
+            rna_prop_ui.draw(self.layout, context, item, False)
+
+
 # Operators
 from bpy.props import *
 
@@ -1757,4 +1780,6 @@ bpy.types.register(VIEW3D_PT_background_image)
 bpy.types.register(VIEW3D_PT_transform_orientations)
 bpy.types.register(VIEW3D_PT_etch_a_ton)
 
+bpy.types.register(VIEW3D_PT_context_properties)
+
 bpy.ops.add(OBJECT_OT_select_pattern)
index 1980ba78c86e45b987add277ed4dd12df30d5a1e..9c7460851cbbfd5b3aca867436d216c6fc1c14f0 100644 (file)
@@ -117,7 +117,7 @@ int IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous,
 */
 void IDP_RemFromGroup(struct IDProperty *group, struct IDProperty *prop);
 
-IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, char *name);
+IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, const char *name);
 
 /*Get an iterator to iterate over the members of an id property group.
  Note that this will automatically free the iterator once iteration is complete;
index 3cff82f522a507c03037b3d52ac79abbd6c3d85d..7e081982f2486f369deeb48341c921213e659ec8 100644 (file)
@@ -442,7 +442,7 @@ void IDP_RemFromGroup(IDProperty *group, IDProperty *prop)
        BLI_remlink(&group->data.group, prop);
 }
 
-IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, char *name)
+IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, const char *name)
 {
        IDProperty *loop;
        for (loop=prop->data.group.first; loop; loop=loop->next) {
index 51c38ee859f6b669d3ea753e7ea9333988754c79..b9f809463452f8e08de246ebb6d406bcb901c8b8 100644 (file)
@@ -1355,15 +1355,15 @@ static void ui_get_but_string_unit(uiBut *but, char *str, int len_max, double va
        Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
        int do_split= scene->unit.flag & USER_UNIT_OPT_SPLIT;
        int unit_type=  RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop));
-       int precission= but->a2;
+       int precision= but->a2;
 
        if(scene->unit.scale_length<0.0001) scene->unit.scale_length= 1.0; // XXX do_versions
 
        /* Sanity checks */
-       if(precission>4)                precission= 4;
-       else if(precission==0)  precission= 2;
+       if(precision>4)         precision= 4;
+       else if(precision==0)   precision= 2;
 
-       bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precission, scene->unit.system, unit_type, do_split, pad);
+       bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precision, scene->unit.system, unit_type, do_split, pad);
 }
 
 static float ui_get_but_step_unit(uiBut *but, double value, float step_default)
index 80c1ed2fe95aa9de0e1a1e08deac3cadf71a671a..56c9165c6a18b8491ad78b8cdb0d0129c5b441eb 100644 (file)
@@ -525,7 +525,7 @@ static void draw_shadedstrip(Sequence *seq, char *col, float x1, float y1, float
 /*
 Draw a sequence strip, bounds check alredy made
 ARegion is currently only used to get the windows width in pixels
-so wave file sample drawing precission is zoom adjusted
+so wave file sample drawing precision is zoom adjusted
 */
 static void draw_seq_strip(Scene *scene, ARegion *ar, SpaceSeq *sseq, Sequence *seq, int outline_tint, float pixelx)
 {
index 339dc83001643ceacbe402280f9a7f5848d0cfe5..23cd6f0c7d9846e53c94a5a35c0a010c39dc472b 100644 (file)
@@ -2234,7 +2234,7 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
        if(G.f & (G_RENDER_OGL|G_RENDER_SHADOW))
                return;
 
-       /* make the precission of the pronted value proportionate to the gridsize */
+       /* make the precision of the pronted value proportionate to the gridsize */
 
        if (grid < 0.01f)
                strcpy(conv_float, "%.6f");
index 2583a155d6a0f5914da7cb205e4fa1b016599a34..a6591adfff1197e23fe929ee56f231220a8f8933 100644 (file)
@@ -91,7 +91,7 @@ void info_callback(const char *msg, void *client_data) {
 struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags)
 {
        struct ImBuf *ibuf = 0;
-       int use_float = 0; /* for precissions higher then 8 use float */
+       int use_float = 0; /* for precision higher then 8 use float */
        unsigned char *rect= NULL;
        float *rect_float= NULL;
        
index 422c4d9befe8ecbe6117ee71f7c2f73edb74a0e2..155f2ff594dcdd2157c80617e37cffaa0f1a721d 100644 (file)
@@ -190,6 +190,29 @@ PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *da
 
 /* ID Properties */
 
+/* return a UI local ID prop definition for this prop */
+IDProperty *rna_idproperty_ui(PropertyRNA *prop)
+{
+       IDProperty *idprop;
+
+       for(idprop= ((IDProperty *)prop)->prev; idprop; idprop= idprop->prev) {
+               if (strcmp(RNA_IDP_UI, idprop->name)==0)
+                       break;
+       }
+
+       if(idprop==NULL) {
+               for(idprop= ((IDProperty *)prop)->next; idprop; idprop= idprop->next) {
+                       if (strcmp(RNA_IDP_UI, idprop->name)==0)
+                               break;
+               }
+       }
+
+       if (idprop)
+               return IDP_GetPropertyFromGroup(idprop, ((IDProperty *)prop)->name);
+
+       return NULL;
+}
+
 IDProperty *RNA_struct_idproperties(PointerRNA *ptr, int create)
 {
        StructRNA *type= ptr->type;
@@ -396,8 +419,17 @@ static const char *rna_ensure_property_description(PropertyRNA *prop)
 {
        if(prop->magic == RNA_MAGIC)
                return prop->description;
-       else
+       else {
+               /* attempt to get the local ID values */
+               IDProperty *idp_ui= rna_idproperty_ui(prop);
+
+               if(idp_ui) { /* TODO, type checking on ID props */
+                       IDProperty *item= IDP_GetPropertyFromGroup(idp_ui, "description");
+                       return item ? ((IDProperty*)prop)->name : item->data.pointer;
+               }
+
                return ((IDProperty*)prop)->name; /* XXX - not correct */
+       }
 }
 
 static const char *rna_ensure_property_name(PropertyRNA *prop)
@@ -668,6 +700,22 @@ void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, in
 {
        IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop);
 
+       if(prop->magic != RNA_MAGIC) {
+               /* attempt to get the local ID values */
+               IDProperty *idp_ui= rna_idproperty_ui(prop);
+               IDProperty *item;
+
+               if(idp_ui) { /* TODO, type checking on ID props */
+                       item= IDP_GetPropertyFromGroup(idp_ui, "min");
+                       *hardmin= item ? item->data.val : INT_MIN;
+
+                       item= IDP_GetPropertyFromGroup(idp_ui, "max");
+                       *hardmax= item ? item->data.val : INT_MAX;
+
+                       return;
+               }
+       }
+
        if(iprop->range) {
                iprop->range(ptr, hardmin, hardmax);
        }
@@ -682,6 +730,25 @@ void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin,
        IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop);
        int hardmin, hardmax;
        
+       if(prop->magic != RNA_MAGIC) {
+               /* attempt to get the local ID values */
+               IDProperty *idp_ui= rna_idproperty_ui(prop);
+               IDProperty *item;
+
+               if(idp_ui) { /* TODO, type checking on ID props */
+                       item= IDP_GetPropertyFromGroup(idp_ui, "soft_min");
+                       *softmin= item ? item->data.val : INT_MIN;
+
+                       item= IDP_GetPropertyFromGroup(idp_ui, "soft_max");
+                       *softmax= item ? item->data.val : INT_MAX;
+
+                       item= IDP_GetPropertyFromGroup(idp_ui, "step");
+                       *step= item ? item->data.val : 1;
+
+                       return;
+               }
+       }
+
        if(iprop->range) {
                iprop->range(ptr, &hardmin, &hardmax);
                *softmin= MAX2(iprop->softmin, hardmin);
@@ -699,6 +766,22 @@ void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin
 {
        FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop);
 
+       if(prop->magic != RNA_MAGIC) {
+               /* attempt to get the local ID values */
+               IDProperty *idp_ui= rna_idproperty_ui(prop);
+               IDProperty *item;
+
+               if(idp_ui) { /* TODO, type checking on ID props */
+                       item= IDP_GetPropertyFromGroup(idp_ui, "min");
+                       *hardmin= item ? *(double*)&item->data.val : FLT_MIN;
+
+                       item= IDP_GetPropertyFromGroup(idp_ui, "max");
+                       *hardmax= item ? *(double*)&item->data.val : FLT_MAX;
+
+                       return;
+               }
+       }
+
        if(fprop->range) {
                fprop->range(ptr, hardmin, hardmax);
        }
@@ -713,6 +796,28 @@ void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *soft
        FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop);
        float hardmin, hardmax;
 
+       if(prop->magic != RNA_MAGIC) {
+               /* attempt to get the local ID values */
+               IDProperty *idp_ui= rna_idproperty_ui(prop);
+               IDProperty *item;
+
+               if(idp_ui) { /* TODO, type checking on ID props */
+                       item= IDP_GetPropertyFromGroup(idp_ui, "soft_min");
+                       *softmin= item ? *(double*)&item->data.val : FLT_MIN;
+
+                       item= IDP_GetPropertyFromGroup(idp_ui, "soft_max");
+                       *softmax= item ? *(double*)&item->data.val : FLT_MAX;
+
+                       item= IDP_GetPropertyFromGroup(idp_ui, "step");
+                       *step= item ? *(double*)&item->data.val : 1.0f;
+
+                       item= IDP_GetPropertyFromGroup(idp_ui, "precision");
+                       *precision= item ? *(double*)&item->data.val : 3.0f;
+
+                       return;
+               }
+       }
+
        if(fprop->range) {
                fprop->range(ptr, &hardmin, &hardmax);
                *softmin= MAX2(fprop->softmin, hardmin);
index db2063b899cda4315c475a6489d2f973d872f8df..46ed1fa055f6781c2325ae0a4e5aef4e63a6a246 100644 (file)
@@ -47,6 +47,10 @@ struct GHash;
 
 #define RNA_MAX_ARRAY_DIMENSION 3
 
+
+/* store local properties here */
+#define RNA_IDP_UI "_RNA_UI"
+
 /* Function Callbacks */
 
 typedef void (*UpdateFunc)(struct bContext *C, struct PointerRNA *ptr);
index ba268201b814982a196eb9a4e6530bced9a1478f..d12de5f2e466f020134d9abf5de217887d491dad 100644 (file)
@@ -3252,9 +3252,10 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
 
 PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
 {
-       static char *kwlist[] = {"attr", "name", "description", "min", "max", "soft_min", "soft_max", "default", NULL};
+       static char *kwlist[] = {"attr", "name", "description", "min", "max", "soft_min", "soft_max", "step", "precision", "default", NULL};
        char *id=NULL, *name="", *description="";
-       float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, def=0.0f;
+       float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def=0.0f;
+       int precision= 1;
        PropertyRNA *prop;
        StructRNA *srna;
        
@@ -3269,10 +3270,11 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
        }
        else if(srna) {
 
-               if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssfffff:FloatProperty", kwlist, &id, &name, &description, &min, &max, &soft_min, &soft_max, &def))
+               if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssfffffif:FloatProperty", kwlist, &id, &name, &description, &min, &max, &soft_min, &soft_max, &step, &precision, &def))
                        return NULL;
 
                prop= RNA_def_float(srna, id, def, min, max, name, description, soft_min, soft_max);
+               RNA_def_property_ui_range(prop, min, max, step, precision);
                RNA_def_property_duplicate_pointers(prop);
                Py_RETURN_NONE;
        }