diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-03-23 16:28:42 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-03-23 16:28:42 +0300 |
commit | e04b27ca423fa05ca12b873abc73de56427e4327 (patch) | |
tree | 9ffcf5a47fc3b9c410bcb69bc15443352255002b /source | |
parent | 9310c92e5316f446c0b7a912dd21181e0eedde8d (diff) |
Python
* Add support for setting RNA pointers.
* Fix __repr__ for structs and properties, it was printing
a garbage string here, but not sure I did what was intended.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index dfa8d8dd968..d847cc445e6 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -70,16 +70,39 @@ static PyObject *pyrna_prop_richcmp(BPy_PropertyRNA * a, BPy_PropertyRNA * b, in /*----------------------repr--------------------------------------------*/ static PyObject *pyrna_struct_repr( BPy_StructRNA * self ) { + PropertyRNA *prop; char str[512]; - RNA_string_get(&self->ptr, "identifier", str); - return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(&self->ptr), str); + + /* print name if available */ + prop= RNA_struct_name_property(&self->ptr); + if(prop) { + RNA_property_string_get(&self->ptr, prop, str); + return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(&self->ptr), str); + } + + return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\"]", RNA_struct_identifier(&self->ptr)); } static PyObject *pyrna_prop_repr( BPy_PropertyRNA * self ) { + PropertyRNA *prop; + PointerRNA ptr; char str[512]; - RNA_string_get(&self->ptr, "identifier", str); - return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\" -> \"%s\" ]", RNA_struct_identifier(&self->ptr), str, RNA_property_identifier(&self->ptr, self->prop) ); + + /* if a pointer, try to print name of pointer target too */ + if(RNA_property_type(&self->ptr, self->prop) == PROP_POINTER) { + ptr= RNA_property_pointer_get(&self->ptr, self->prop); + + if(ptr.data) { + prop= RNA_struct_name_property(&ptr); + if(prop) { + RNA_property_string_get(&ptr, prop, str); + return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\" -> \"%s\" ]", RNA_struct_identifier(&self->ptr), RNA_property_identifier(&self->ptr, self->prop), str); + } + } + } + + return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(&self->ptr), RNA_property_identifier(&self->ptr, self->prop)); } static long pyrna_struct_hash( BPy_StructRNA * self ) @@ -354,8 +377,25 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) } case PROP_POINTER: { - PyErr_SetString(PyExc_AttributeError, "cant assign pointers yet"); - return -1; + StructRNA *ptype= RNA_property_pointer_type(ptr, prop); + + if(!BPy_StructRNA_Check(value)) { + PointerRNA tmp; + RNA_pointer_create(NULL, ptype, NULL, &tmp); + PyErr_Format(PyExc_TypeError, "expected a %s type", RNA_struct_identifier(&tmp)); + return -1; + } else { + BPy_StructRNA *param= (BPy_StructRNA*)value; + + if(RNA_struct_is_a(¶m->ptr, ptype)) { + RNA_property_pointer_set(ptr, prop, param->ptr); + } else { + PointerRNA tmp; + RNA_pointer_create(NULL, ptype, NULL, &tmp); + PyErr_Format(PyExc_TypeError, "expected a %s type", RNA_struct_identifier(&tmp)); + return -1; + } + } break; } case PROP_COLLECTION: @@ -1135,7 +1175,6 @@ PyObject* pyrna_struct_Subtype(PointerRNA *ptr) PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr ) { BPy_StructRNA *pyrna= NULL; - int tp_init= 0; if (ptr->data==NULL && ptr->type==NULL) { /* Operator RNA has NULL data */ Py_RETURN_NONE; |