diff options
Diffstat (limited to 'source/blender/python/intern/bpy_rna.c')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 7c8f28d0979..2174241eeda 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1424,7 +1424,8 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha totkw = kw ? PyDict_Size(kw) : 0; - RNA_STRUCT_BEGIN (ptr, prop) { + RNA_STRUCT_BEGIN (ptr, prop) + { arg_name = RNA_property_identifier(prop); if (strcmp(arg_name, "rna_type") == 0) continue; @@ -2203,7 +2204,8 @@ int pyrna_prop_collection_subscript_str_lib_pair_ptr(BPy_PropertyRNA *self, PyOb /* lib is either a valid poniter or NULL, * either way can do direct comparison with id.lib */ - RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) + { ID *id = itemptr.data; /* always an ID */ if (id->lib == lib && (strncmp(keyname, id->name + 2, sizeof(id->name) - 2) == 0)) { found = TRUE; @@ -3346,7 +3348,8 @@ static void pyrna_dir_members_rna(PyObject *list, PointerRNA *ptr) RNA_pointer_create(NULL, &RNA_Struct, ptr->type, &tptr); iterprop = RNA_struct_find_property(&tptr, "functions"); - RNA_PROP_BEGIN (&tptr, itemptr, iterprop) { + RNA_PROP_BEGIN (&tptr, itemptr, iterprop) + { idname = RNA_function_identifier(itemptr.data); pystring = PyUnicode_FromString(idname); @@ -3365,7 +3368,8 @@ static void pyrna_dir_members_rna(PyObject *list, PointerRNA *ptr) iterprop = RNA_struct_iterator_property(ptr->type); - RNA_PROP_BEGIN (ptr, itemptr, iterprop) { + RNA_PROP_BEGIN (ptr, itemptr, iterprop) + { nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); if (nameptr) { @@ -3980,7 +3984,8 @@ static PyObject *pyrna_prop_collection_keys(BPy_PropertyRNA *self) char name[256], *nameptr; int namelen; - RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) + { nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); if (nameptr) { @@ -4017,7 +4022,8 @@ static PyObject *pyrna_prop_collection_items(BPy_PropertyRNA *self) int namelen; int i = 0; - RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) + { if (itemptr.data) { /* add to python list */ item = PyTuple_New(2); @@ -4189,7 +4195,8 @@ static PyObject *pyrna_prop_collection_find(BPy_PropertyRNA *self, PyObject *key PYRNA_PROP_CHECK_OBJ(self); - RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) + { nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); if (nameptr) { @@ -4220,7 +4227,8 @@ static void foreach_attr_type(BPy_PropertyRNA *self, const char *attr, *attr_signed = FALSE; /* note: this is fail with zero length lists, so don't let this get caled in that case */ - RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) + { prop = RNA_struct_find_property(&itemptr, attr); *raw_type = RNA_property_raw_type(prop); *attr_tot = RNA_property_array_length(&itemptr, prop); @@ -6246,6 +6254,31 @@ PyObject *pyrna_prop_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop) return (PyObject *)pyrna; } +/* utility func to be used by external modules, *sneaky!* */ +PyObject *pyrna_id_CreatePyObject(ID *id) +{ + if (id) { + PointerRNA ptr; + RNA_id_pointer_create(id, &ptr); + return pyrna_struct_CreatePyObject(&ptr); + } + else { + Py_RETURN_NONE; + } +} + +int pyrna_id_FromPyObject(PyObject *obj, ID **id) +{ + if (BPy_StructRNA_Check(obj) && (RNA_struct_is_ID(((BPy_StructRNA *)obj)->ptr.type))) { + *id = ((BPy_StructRNA *)obj)->ptr.id.data; + return TRUE; + } + else { + *id = NULL; + return FALSE; + } +} + void BPY_rna_init(void) { #ifdef USE_MATHUTILS // register mathutils callbacks, ok to run more then once. @@ -6401,7 +6434,8 @@ static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self) PyObject *ret = PyList_New(0); PyObject *item; - RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) + { StructRNA *srna = itemptr.data; StructRNA *srna_base = RNA_struct_base(itemptr.data); /* skip own operators, these double up [#29666] */ @@ -7189,7 +7223,8 @@ void pyrna_alloc_types(void) RNA_blender_rna_pointer_create(&ptr); prop = RNA_struct_find_property(&ptr, "structs"); - RNA_PROP_BEGIN (&ptr, itemptr, prop) { + RNA_PROP_BEGIN (&ptr, itemptr, prop) + { PyObject *item = pyrna_struct_Subtype(&itemptr); if (item == NULL) { if (PyErr_Occurred()) { @@ -7217,7 +7252,8 @@ void pyrna_free_types(void) prop = RNA_struct_find_property(&ptr, "structs"); - RNA_PROP_BEGIN (&ptr, itemptr, prop) { + RNA_PROP_BEGIN (&ptr, itemptr, prop) + { StructRNA *srna = srna_from_ptr(&itemptr); void *py_ptr = RNA_struct_py_type_get(srna); @@ -7475,9 +7511,9 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla prop_rna = RNA_struct_find_property(&ptr_rna, "structs"); - /* loop over all structs */ - RNA_PROP_BEGIN (&ptr_rna, itemptr, prop_rna) { + RNA_PROP_BEGIN (&ptr_rna, itemptr, prop_rna) + { srna_iter = itemptr.data; if (pyrna_srna_contains_pointer_prop_srna(srna_iter, srna, &prop_identifier)) { break; |