[Bf-blender-cvs] [337b718] master: Fix T47371 - add access to 'static' enum items.

Bastien Montagne noreply at git.blender.org
Tue Feb 9 12:51:19 CET 2016


Commit: 337b718695c8b31dadc22438b9f1af40d225e0ad
Author: Bastien Montagne
Date:   Tue Feb 9 12:44:06 2016 +0100
Branches: master
https://developer.blender.org/rB337b718695c8b31dadc22438b9f1af40d225e0ad

Fix T47371 - add access to 'static' enum items.

Some dynamic enums, which do not need a valid context pointer, have their 'itemf'
callback always called. This is annoying for introspection tools (like the ones generating
translations, or API documentation), because it means they never have access to all possible
options (enum items).

So now, there is also an `enum_items_static` accessor to get only statically-defined
enum items.

Note: only i18n tools take advantage of this currently, others are still to be updated.

Reviewers: campbellbarton, sergey

Differential Revision: https://developer.blender.org/D1782

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

M	release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_access.c
M	source/blender/makesrna/intern/rna_rna.c

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

diff --git a/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py b/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
index ce09b15..5a3eda5 100644
--- a/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
+++ b/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
@@ -322,8 +322,20 @@ def dump_rna_messages(msgs, reports, settings, verbose=False):
                 process_msg(msgs, default_context, prop.description, msgsrc, reports, check_ctxt_rna_tip, settings)
 
             if isinstance(prop, bpy.types.EnumProperty):
+                done_items = set()
                 for item in prop.enum_items:
                     msgsrc = "bpy.types.{}.{}:'{}'".format(bl_rna.identifier, prop.identifier, item.identifier)
+                    done_items.add(item.identifier)
+                    if item.name and item.name != item.identifier:
+                        process_msg(msgs, msgctxt, item.name, msgsrc, reports, check_ctxt_rna, settings)
+                    if item.description:
+                        process_msg(msgs, default_context, item.description, msgsrc, reports, check_ctxt_rna_tip,
+                                    settings)
+                for item in prop.enum_items_static:
+                    if item.identifier in done_items:
+                        continue
+                    msgsrc = "bpy.types.{}.{}:'{}'".format(bl_rna.identifier, prop.identifier, item.identifier)
+                    done_items.add(item.identifier)
                     if item.name and item.name != item.identifier:
                         process_msg(msgs, msgctxt, item.name, msgsrc, reports, check_ctxt_rna, settings)
                     if item.description:
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 050c55b..6dee89e 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -818,6 +818,9 @@ bool RNA_enum_description(EnumPropertyItem *item, const int value, const char **
 int  RNA_enum_from_value(EnumPropertyItem *item, const int value);
 int  RNA_enum_from_identifier(EnumPropertyItem *item, const char *identifier);
 
+void RNA_property_enum_items_ex(
+        struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const bool use_static,
+        EnumPropertyItem **item, int *r_totitem, bool *r_free);
 void RNA_property_enum_items(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop,
                              EnumPropertyItem **item, int *r_totitem, bool *r_free);
 void RNA_property_enum_items_gettexted(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop,
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index b1038f8..e617871 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1215,14 +1215,15 @@ EnumPropertyItem DummyRNA_DEFAULT_items[] = {
 	{0, NULL, 0, NULL, NULL}
 };
 
-void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **r_item,
-                             int *r_totitem, bool *r_free)
+void RNA_property_enum_items_ex(
+        bContext *C, PointerRNA *ptr, PropertyRNA *prop, const bool use_static,
+        EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
 {
 	EnumPropertyRNA *eprop = (EnumPropertyRNA *)rna_ensure_property(prop);
 
 	*r_free = false;
 
-	if (eprop->itemf && (C != NULL || (prop->flag & PROP_ENUM_NO_CONTEXT))) {
+	if (!use_static && eprop->itemf && (C != NULL || (prop->flag & PROP_ENUM_NO_CONTEXT))) {
 		EnumPropertyItem *item;
 
 		if (prop->flag & PROP_ENUM_NO_CONTEXT)
@@ -1250,6 +1251,12 @@ void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, En
 	}
 }
 
+void RNA_property_enum_items(
+        bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
+{
+	RNA_property_enum_items_ex(C, ptr, prop, false, r_item, r_totitem, r_free);
+}
+
 #ifdef WITH_INTERNATIONAL
 static void property_enum_translate(PropertyRNA *prop, EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
 {
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index 382258f..f04aa3c 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -854,7 +854,8 @@ static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, Point
 	rna_idproperty_check(&prop, ptr);
 	/* eprop = (EnumPropertyRNA *)prop; */
 	
-	RNA_property_enum_items(NULL, ptr, prop, &item, &totitem, &free);
+	RNA_property_enum_items_ex(
+	            NULL, ptr, prop, STREQ(iter->prop->identifier, "enum_items_static"), &item, &totitem, &free);
 	rna_iterator_array_begin(iter, (void *)item, sizeof(EnumPropertyItem), totitem, free, rna_enum_check_separator);
 }
 
@@ -1423,6 +1424,14 @@ static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna)
 	                                  "rna_iterator_array_end", "rna_iterator_array_get", NULL, NULL, NULL, NULL);
 	RNA_def_property_ui_text(prop, "Items", "Possible values for the property");
 
+	prop = RNA_def_property(srna, "enum_items_static", PROP_COLLECTION, PROP_NONE);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_struct_type(prop, "EnumPropertyItem");
+	RNA_def_property_collection_funcs(prop, "rna_EnumProperty_items_begin", "rna_iterator_array_next",
+	                                  "rna_iterator_array_end", "rna_iterator_array_get", NULL, NULL, NULL, NULL);
+	RNA_def_property_ui_text(prop, "Static Items",
+	                         "Possible values for the property (never calls optional dynamic generation of those)");
+
 	srna = RNA_def_struct(brna, "EnumPropertyItem", NULL);
 	RNA_def_struct_ui_text(srna, "Enum Item Definition", "Definition of a choice in an RNA enum property");
 	RNA_def_struct_ui_icon(srna, ICON_RNA);




More information about the Bf-blender-cvs mailing list