diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-08-24 07:02:27 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-08-24 07:02:27 +0400 |
commit | 5c604e5524ace49caeda7c0bff9443afc43b236f (patch) | |
tree | aab6dd5d645b92a7d451b3d62a16d0d0e716d318 /source/blender/python | |
parent | 48e34b995686d50177932660ec422528eb4a6da8 (diff) |
remove recently added rna function uilayout.prop_search_self() and instead allow collections to be coerced into rna structs when they define a type.
eg:
row.prop_search_self(scene, "active", "keying_sets", text="")
...becomes
row.prop_search(scene.keying_sets, "active", scene, "keying_sets", text="")
This is more flexible since it works for other UI functions too.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 43f11d25e55..40e4fae2d91 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1016,6 +1016,8 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v } case PROP_POINTER: { + PyObject *value_new= NULL; + StructRNA *ptype= RNA_property_pointer_type(ptr, prop); int flag = RNA_property_flag(prop); @@ -1025,15 +1027,29 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v return pyrna_pydict_to_props(&opptr, value, 0, error_prefix); } + /* another exception, allow to pass a collection as an RNA property */ + if(Py_TYPE(value)==&pyrna_prop_collection_Type) { + PointerRNA c_ptr; + BPy_PropertyRNA *value_prop= (BPy_PropertyRNA *)value; + if(RNA_property_collection_type_get(&value_prop->ptr, value_prop->prop, &c_ptr)) { + value= pyrna_struct_CreatePyObject(&c_ptr); + value_new= value; + } + else { + PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s collection has no type, cant be used as a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(ptype)); + return -1; + } + } + if(!BPy_StructRNA_Check(value) && value != Py_None) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(ptype)); - return -1; + Py_XDECREF(value_new); return -1; } else if((flag & PROP_NEVER_NULL) && value == Py_None) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s does not support a 'None' assignment %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(ptype)); - return -1; + Py_XDECREF(value_new); return -1; } else if(value != Py_None && ((flag & PROP_ID_SELF_CHECK) && ptr->id.data == ((BPy_StructRNA*)value)->ptr.id.data)) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s ID type does not support assignment to its self", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop)); - return -1; + Py_XDECREF(value_new); return -1; } else { BPy_StructRNA *param= (BPy_StructRNA*)value; int raise_error= FALSE; @@ -1069,7 +1085,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v PointerRNA tmp; RNA_pointer_create(NULL, ptype, NULL, &tmp); PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(tmp.type)); - return -1; + Py_XDECREF(value_new); return -1; } } @@ -1077,9 +1093,10 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v PointerRNA tmp; RNA_pointer_create(NULL, ptype, NULL, &tmp); PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(tmp.type)); - return -1; + Py_XDECREF(value_new); return -1; } } + break; } case PROP_COLLECTION: |