diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-03-19 22:03:38 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-03-19 22:03:38 +0300 |
commit | 1b94cb752ca18aac122b444261e76dc63022f99f (patch) | |
tree | c0d4ec35be53898e07462f41bb50f7629a3d323e /source/blender/python | |
parent | 77e0199dc386c26aa106a884f24b336fce82d351 (diff) |
Context
* Made it based on string lookups rather than fixed enum, to make
it extensible by python scripts.
* Context callbacks now also have to specify RNA type when returning
pointers or collections. For non-RNA wrapped data, UnknownType can
be used.
* RNA wrapped context. The WM entries are fixed, for data context
only main and scene are defined properties. Other data entries have
to be dynamically looked up.
* I've added some special code in python for the dynamic context
lookups. Tried to hide it behind RNA but didn't find a clean way to
do it yet. Still unused/untested.
* Also minor fix for warning about propertional edit property in
transform code, and fix for usage of operator poll with checking if
it was NULL.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 650475bae96..6215ab86500 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -26,11 +26,13 @@ #include "bpy_compat.h" //#include "blendef.h" #include "BLI_dynstr.h" +#include "BLI_listbase.h" #include "float.h" /* FLT_MIN/MAX */ #include "RNA_define.h" /* for defining our own rna */ #include "MEM_guardedalloc.h" +#include "BKE_context.h" #include "BKE_global.h" /* evil G.* */ static int pyrna_struct_compare( BPy_StructRNA * a, BPy_StructRNA * b ) @@ -640,6 +642,34 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA * self, PyObject *pyname ) if (prop) { ret = pyrna_prop_to_py(&self->ptr, prop); } + else if (self->ptr.type == &RNA_Context) { + PointerRNA newptr; + ListBase newlb; + + CTX_data_get(self->ptr.data, name, &newptr, &newlb); + + if (newptr.data) { + ret = pyrna_struct_CreatePyObject(&newptr); + } + else if (newlb.first) { + CollectionPointerLink *link; + PyObject *linkptr; + + ret = PyList_New(0); + + for(link=newlb.first; link; link=link->next) { + linkptr= pyrna_struct_CreatePyObject(&link->ptr); + PyList_Append(ret, linkptr); + Py_DECREF(linkptr); + } + } + else { + ret = Py_None; + Py_INCREF(ret); + } + + BLI_freelistN(&newlb); + } else { PyErr_Format( PyExc_AttributeError, "StructRNA - Attribute \"%s\" not found", name); ret = NULL; |