* 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.
This commit is contained in:
2009-03-19 19:03:38 +00:00
parent 77e0199dc3
commit 1b94cb752c
25 changed files with 268 additions and 190 deletions

View File

@@ -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;