Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-12-13 13:46:34 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-12-13 13:46:34 +0300
commitb3f03250de655751a116ec9aaea96a22a943d8c5 (patch)
tree9812224f9ffd6c9533f82ba3ba7b4cac19e10aed /source/blender/python
parenta224803fb7c3b3a69f9ac63aaac593532432202a (diff)
use tp_getset rather then checking the string on getattr for 'id_data' attribute
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_rna.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index f90dbef9836..9142aaed9ea 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -1658,14 +1658,6 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA *self)
BLI_freelistN(&lb);
}
-
- /* Hard coded names */
- if(self->ptr.id.data) {
- pystring = PyUnicode_FromString("id_data");
- PyList_Append(ret, pystring);
- Py_DECREF(pystring);
- }
-
return ret;
}
@@ -1732,17 +1724,6 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA *self, PyObject *pyname )
BLI_freelistN(&newlb);
}
- else if (strcmp(name, "id_data")==0) { /* XXX - hard coded */
- if(self->ptr.id.data) {
- PointerRNA id_ptr;
- RNA_id_pointer_create((ID *)self->ptr.id.data, &id_ptr);
- ret = pyrna_struct_CreatePyObject(&id_ptr);
- }
- else {
- ret = Py_None;
- Py_INCREF(ret);
- }
- }
else {
#if 0
PyErr_Format( PyExc_AttributeError, "StructRNA - Attribute \"%.200s\" not found", name);
@@ -1914,6 +1895,17 @@ static PyObject *pyrna_prop_remove(BPy_PropertyRNA *self, PyObject *value)
return ret;
}
+static PyObject *pyrna_struct_get_id_data(BPy_StructRNA *self)
+{
+ if(self->ptr.id.data) {
+ PointerRNA id_ptr;
+ RNA_id_pointer_create((ID *)self->ptr.id.data, &id_ptr);
+ return pyrna_struct_CreatePyObject(&id_ptr);
+ }
+
+ Py_RETURN_NONE;
+}
+
/*****************************************************************************/
/* Python attributes get/set structure: */
/*****************************************************************************/
@@ -1924,6 +1916,11 @@ static PyGetSetDef pyrna_prop_getseters[] = {
};
#endif
+static PyGetSetDef pyrna_struct_getseters[] = {
+ {"id_data", (getter)pyrna_struct_get_id_data, (setter)NULL, "The ID data this datablock is from, (not available for all data)", NULL},
+ {NULL,NULL,NULL,NULL,NULL} /* Sentinel */
+};
+
static PyObject *pyrna_prop_keys(BPy_PropertyRNA *self)
{
PyObject *ret;
@@ -2787,7 +2784,7 @@ PyTypeObject pyrna_struct_Type = {
/*** Attribute descriptor and subclassing stuff ***/
pyrna_struct_methods, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
- NULL, /* struct PyGetSetDef *tp_getset; */
+ pyrna_struct_getseters, /* struct PyGetSetDef *tp_getset; */
NULL, /* struct _typeobject *tp_base; */
NULL, /* PyObject *tp_dict; */
NULL, /* descrgetfunc tp_descr_get; */