[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25329] trunk/blender/source/blender/ python/intern/bpy_rna.c: use tp_getset rather then checking the string on getattr for 'id_data' attribute
Campbell Barton
ideasman42 at gmail.com
Sun Dec 13 11:46:35 CET 2009
Revision: 25329
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25329
Author: campbellbarton
Date: 2009-12-13 11:46:34 +0100 (Sun, 13 Dec 2009)
Log Message:
-----------
use tp_getset rather then checking the string on getattr for 'id_data' attribute
Modified Paths:
--------------
trunk/blender/source/blender/python/intern/bpy_rna.c
Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c 2009-12-13 03:20:29 UTC (rev 25328)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c 2009-12-13 10:46:34 UTC (rev 25329)
@@ -1658,14 +1658,6 @@
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 @@
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 @@
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 @@
};
#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 @@
/*** 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; */
More information about the Bf-blender-cvs
mailing list