Revision: 41338
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41338
Author:   mont29
Date:     2011-10-28 13:09:43 +0000 (Fri, 28 Oct 2011)
Log Message:
-----------
UI list template: committing patch [#26629].

This adds the ability (esp. for py scripts) to add some controls for each list 
element. See 
http://wiki.blender.org/index.php/User:Mont29/UI_Template_List_Enhancement for 
details.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/UI_interface.h
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/makesrna/intern/rna_ui_api.c

Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h 2011-10-28 
13:07:11 UTC (rev 41337)
+++ trunk/blender/source/blender/editors/include/UI_interface.h 2011-10-28 
13:09:43 UTC (rev 41338)
@@ -749,7 +749,7 @@
 void uiTemplateReportsBanner(uiLayout *layout, struct bContext *C);
 void uiTemplateKeymapItemProperties(uiLayout *layout, struct PointerRNA *ptr);
 
-void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA 
*ptr, const char *propname, struct PointerRNA *activeptr, const char 
*activeprop, int rows, int maxrows, int type);
+void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA 
*ptr, const char *propname, struct PointerRNA *activeptr, const char 
*activeprop, const char *prop_list, int rows, int maxrows, int type);
 
 /* items */
 void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname);

Modified: trunk/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_templates.c        
2011-10-28 13:07:11 UTC (rev 41337)
+++ trunk/blender/source/blender/editors/interface/interface_templates.c        
2011-10-28 13:09:43 UTC (rev 41338)
@@ -2059,7 +2059,7 @@
        return rnaicon;
 }
 
-static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, 
PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA 
*activeprop)
+static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, 
PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA 
*activeprop, const char *prop_list)
 {
        uiBlock *block= uiLayoutGetBlock(layout);
        uiBut *but;
@@ -2164,6 +2164,52 @@
                /* nothing else special to do... */
                uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */
        }
+       /* There is a last chance to display custom controls (in addition to 
the name/label):
+        * If the given item property group features a string property named as 
prop_list,
+        * this tries to add controls for all properties of the item listed in 
that string property.
+        * (colon-separated names).
+        *
+        * This is especially useful for python. E.g., if you list a collection 
of this property
+        * group:
+        *
+        * class TestPropertyGroup(bpy.types.PropertyGroup):
+        *     bool    = BoolProperty(default=False)
+        *     integer = IntProperty()
+        *     string  = StringProperty()
+        * 
+        *     # A string of all identifiers (colon-separated) which property’s 
controls should be
+        *     # displayed in a template_list.
+        *     template_list_controls = 
StringProperty(default="integer:bool:string", options={"HIDDEN"})
+        *
+        * … you’ll get a numfield for the integer prop, a check box for the 
bool prop, and a textfield
+        * for the string prop, after the name of each item of the collection.
+        */
+       else if (prop_list) {
+               PropertyRNA *prop_ctrls;
+               row = uiLayoutRow(sub, 1);
+               uiItemL(row, name, icon);
+
+               /* XXX: Check, as sometimes we get an itemptr looking like
+                *      {id = {data = 0x0}, type = 0x0, data = 0x0}
+                *      which would obviously produce a sigsev… */
+               if (itemptr->type) {
+                       /* If the special property is set for the item, and it 
is a collection… */
+                       prop_ctrls = RNA_struct_find_property(itemptr, 
prop_list);
+                       if(prop_ctrls) {
+                               if(RNA_property_type(prop_ctrls) == 
PROP_STRING) {
+                                       char *prop_names = 
RNA_property_string_get_alloc(itemptr, prop_ctrls, NULL, 0, NULL);
+                                       char *id = NULL;
+                                       char *ctx = NULL;
+                                       for(id = BLI_strtok_r(prop_names, ":", 
&ctx); id; id = BLI_strtok_r(NULL, ":", &ctx)) {
+                                               uiItemR(row, itemptr, id, 0, 
NULL, 0);
+                                               MEM_freeN(id);
+                                       }
+                                       MEM_freeN(prop_names);
+                               }
+                       }
+               }
+       }
+
        else
                uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */
 
@@ -2172,7 +2218,7 @@
                MEM_freeN(namebuf);
 }
 
-void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char 
*propname, PointerRNA *activeptr, const char *activepropname, int rows, int 
maxrows, int listtype)
+void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char 
*propname, PointerRNA *activeptr, const char *activepropname, const char 
*prop_list, int rows, int maxrows, int listtype)
 {
        //Scene *scene= CTX_data_scene(C);
        PropertyRNA *prop= NULL, *activeprop;
@@ -2326,7 +2372,7 @@
                        /* create list items */
                        RNA_PROP_BEGIN(ptr, itemptr, prop) {
                                if(i >= pa->list_scroll && 
i<pa->list_scroll+items)
-                                       list_item_row(C, col, ptr, &itemptr, i, 
rnaicon, activeptr, activeprop);
+                                       list_item_row(C, col, ptr, &itemptr, i, 
rnaicon, activeptr, activeprop, prop_list);
 
                                i++;
                        }

Modified: trunk/blender/source/blender/makesrna/intern/rna_ui_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_ui_api.c   2011-10-28 
13:07:11 UTC (rev 41337)
+++ trunk/blender/source/blender/makesrna/intern/rna_ui_api.c   2011-10-28 
13:09:43 UTC (rev 41338)
@@ -408,6 +408,9 @@
        RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR|PROP_NEVER_NULL);
        parm= RNA_def_string(func, "active_property", "", 0, "", "Identifier of 
property in data, for the active element");
        RNA_def_property_flag(parm, PROP_REQUIRED);
+       parm= RNA_def_string(func, "prop_list", "", 0, "",
+                            "Identifier of a string property in each data 
member, specifying which "
+                            "of its properties should have a widget displayed 
in its row.");
        RNA_def_int(func, "rows", 5, 0, INT_MAX, "", "Number of rows to 
display", 0, INT_MAX);
        RNA_def_int(func, "maxrows", 5, 0, INT_MAX, "", "Maximum number of rows 
to display", 0, INT_MAX);
        RNA_def_enum(func, "type", list_type_items, 0, "Type", "Type of list to 
use");

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to