[Bf-blender-cvs] [97e2d62] master: Fix T42581: Add 'icon_value' feature to UI Py/RNA's operator button and items of enums.

Bastien Montagne noreply at git.blender.org
Sun Nov 16 15:59:45 CET 2014


Commit: 97e2d62c79fc30eacdbcb7d0464ed6d1726833a5
Author: Bastien Montagne
Date:   Sun Nov 16 15:45:00 2014 +0100
Branches: master
https://developer.blender.org/rB97e2d62c79fc30eacdbcb7d0464ed6d1726833a5

Fix T42581: Add 'icon_value' feature to UI Py/RNA's operator button and items of enums.

Rather straightforward, allows for 'DATA' icons (like mat or tex 'previews')
to be used as icon for operator button or items of an enum.

Patch by Simon Lušenc, with minor cleanup by self.

===================================================================

M	source/blender/makesrna/intern/rna_ui_api.c
M	source/blender/python/intern/bpy_props.c

===================================================================

diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index b13bded..33c3531 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -178,7 +178,7 @@ static void rna_uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const c
 }
 
 static PointerRNA rna_uiItemO(uiLayout *layout, const char *opname, const char *name, const char *text_ctxt,
-                              int translate, int icon, int emboss)
+                              int translate, int icon, int emboss, int icon_value)
 {
 	wmOperatorType *ot;
 	int flag;
@@ -192,6 +192,10 @@ static PointerRNA rna_uiItemO(uiLayout *layout, const char *opname, const char *
 	/* Get translated name (label). */
 	name = rna_translate_ui_text(name, text_ctxt, ot->srna, NULL, translate);
 
+	if (icon_value && !icon) {
+		icon = icon_value;
+	}
+
 	flag = UI_ITEM_O_RETURN_PROPS;
 	flag |= (emboss) ? 0 : UI_ITEM_R_NO_BG;
 
@@ -551,6 +555,10 @@ void RNA_api_ui_layout(StructRNA *srna)
 	func = RNA_def_function(srna, "operator", "rna_uiItemO");
 	api_ui_item_op_common(func);
 	RNA_def_boolean(func, "emboss", true, "", "Draw the button itself, just the icon/text");
+	parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_ui_text(parm, "Icon Value",
+	                         "Override automatic icon of the item "
+	                         "(use it e.g. with custom material icons returned by icon()...)");
 	parm = RNA_def_pointer(func, "properties", "OperatorProperties", "",
 	                       "Operator properties to fill in, return when 'properties' is set to true");
 	RNA_def_property_flag(parm, PROP_REQUIRED | PROP_RNAPTR);
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index 0bffe2c..b0232a4 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -1374,7 +1374,8 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
 		    (tmp.description = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size)) &&
 		    /* TODO, number isn't ensured to be unique from the script author */
 		    (item_size != 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value) != -1) &&
-		    (item_size != 5 || ((tmp_icon = _PyUnicode_AsString(PyTuple_GET_ITEM(item, 3))) &&
+		    (item_size != 5 || ((py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.icon) != -1 ||
+		                         (tmp_icon = _PyUnicode_AsString(PyTuple_GET_ITEM(item, 3)))) &&
 		                        py_long_as_int(PyTuple_GET_ITEM(item, 4), &tmp.value) != -1)))
 		{
 			if (is_enum_flag) {
@@ -2610,8 +2611,8 @@ PyDoc_STRVAR(BPy_EnumProperty_doc,
 "      [(identifier, name, description, icon, number), ...] where the identifier is used\n"
 "      for python access and other values are used for the interface.\n"
 "      The three first elements of the tuples are mandatory.\n"
-"      The forth one is either the (unique!) number id of the item or, if followed by a fith element \n"
-"      (which must be the numid), an icon string identifier.\n"
+"      The forth one is either the (unique!) number id of the item or, if followed by a fith element\n"
+"      (which must be the numid), an icon string identifier or integer icon value (e.g. returned by icon()...).\n"
 "      Note the item is optional.\n"
 "      For dynamic values a callback can be passed which returns a list in\n"
 "      the same format as the static list.\n"




More information about the Bf-blender-cvs mailing list