diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-03-12 17:32:30 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-03-12 17:32:30 +0300 |
commit | c678bd2d7de115945e5df83b11742a62582c4d40 (patch) | |
tree | bb8dc096906800c6f1d2a3c617dfb1473784f295 /source/blender/python/intern | |
parent | 460bdf1f598fa38dc88aa562f50c285e8e980d96 (diff) |
py/rna, ability to have python static methods in collections.
Diffstat (limited to 'source/blender/python/intern')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 8544a6b493e..f7f451b50ad 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -76,6 +76,7 @@ #define USE_MATHUTILS #define USE_STRING_COERCE +static PyObject* pyrna_struct_Subtype(PointerRNA *ptr); static PyObject *pyrna_prop_collection_values(BPy_PropertyRNA *self); int pyrna_struct_validity_check(BPy_StructRNA *pysrna) @@ -3126,8 +3127,36 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject } } - /* The error raised here will be displayed */ +#if 0 return PyObject_GenericGetAttr((PyObject *)self, pyname); +#else + { + /* Could just do this except for 1 awkward case. + * PyObject_GenericGetAttr((PyObject *)self, pyname); + * so as to support 'bpy.data.library.load()' + * note, this _only_ supports static methods */ + + PyObject *ret= PyObject_GenericGetAttr((PyObject *)self, pyname); + + if(ret == NULL) { + /* since this is least common case, handle it last */ + PointerRNA r_ptr; + PyObject *error_type, *error_value, *error_traceback; + PyErr_Fetch(&error_type, &error_value, &error_traceback); + PyErr_Clear(); + + if(RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) { + PyObject *cls= pyrna_struct_Subtype(&r_ptr); /* borrows */ + ret= PyObject_GenericGetAttr(cls, pyname); + if(ret == NULL) { + PyErr_Restore(error_type, error_value, error_traceback); + } + } + } + + return ret; + } +#endif } //--------------- setattr------------------------------------------- |