diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-07-13 23:33:59 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-07-13 23:33:59 +0400 |
commit | 2ba8b72157d22ee92359e87e88860443a1f5cef2 (patch) | |
tree | b2347faeae5aed1c99681fe1803969ff8af57e8b /source/blender/python | |
parent | 1334ed303816531240294d17457575736bdd212b (diff) |
RNA & PyAPI
* support for dynamic enums to be inspected enumProp.items() from python.
* fix, enums check for a separator was flipped, meant no enums were in docs.
* dynamic enum functions now check for a NULL context and return all possible options for the "items" attribute used for docs.
* added an arg for rna arrays to free the array there looping over (needed to free dynamically allocated enum items)
* python api checks for NULL items since this can happen in some cases.
* python api, When getting an enum ID from an int in an array - If it failed it would get the first enum identifier and return that. Brecht? dont understand, making it return an empty string in these cases.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 49bca247431..9ce9ec8e838 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -225,10 +225,16 @@ static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop) { EnumPropertyItem *item; char *result; - int free; + int free= 0; RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free); - result= (char*)BPy_enum_as_string(item); + if(item) { + result= (char*)BPy_enum_as_string(item); + } + else { + result= ""; + } + if(free) MEM_freeN(item); @@ -319,12 +325,12 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) ret = PyUnicode_FromString( identifier ); } else { EnumPropertyItem *item; - int free; + int free= 0; /* don't throw error here, can't trust blender 100% to give the * right values, python code should not generate error for that */ RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free); - if(item->identifier) { + if(item && item->identifier) { ret = PyUnicode_FromString( item->identifier ); } else { @@ -1831,20 +1837,12 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data) if (RNA_property_enum_identifier(BPy_GetContext(), ptr, prop, val, &identifier)) { ret = PyUnicode_FromString( identifier ); } else { - EnumPropertyItem *item; - int free; - - /* don't throw error here, can't trust blender 100% to give the - * right values, python code should not generate error for that */ - RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free); - if(item[0].identifier) - ret = PyUnicode_FromString( item[0].identifier ); - else - ret = PyUnicode_FromString( "" ); - - if(free) - MEM_freeN(item); - + /* prefer not fail silently incase of api errors, maybe disable it later */ + char error_str[128]; + sprintf(error_str, "RNA Warning: Current value \"%d\" matches no enum", val); + PyErr_Warn(PyExc_RuntimeWarning, error_str); + + ret = PyUnicode_FromString( "" ); /*PyErr_Format(PyExc_AttributeError, "RNA Error: Current value \"%d\" matches no enum", val); ret = NULL;*/ } |