[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22710] branches/blender2.5/blender/source /blender/python/intern/bpy_rna.c: 2.5: Python subclasses can now define RNA properties by making
Brecht Van Lommel
brecht at blender.org
Sat Aug 22 19:30:47 CEST 2009
Revision: 22710
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22710
Author: blendix
Date: 2009-08-22 19:30:47 +0200 (Sat, 22 Aug 2009)
Log Message:
-----------
2.5: Python subclasses can now define RNA properties by making
a __props__ list in the class, same as for operators.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c 2009-08-22 17:19:31 UTC (rev 22709)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c 2009-08-22 17:30:47 UTC (rev 22710)
@@ -2940,12 +2940,12 @@
srna= srna_from_self(value);
if(!srna) {
- PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup (1)");
+ PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup");
return NULL;
}
if(!RNA_struct_is_a(srna, &RNA_IDPropertyGroup)) {
- PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup (3)");
+ PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup");
return NULL;
}
@@ -3022,6 +3022,52 @@
return NULL;
}
+static int deferred_register_props(PyObject *py_class, StructRNA *srna)
+{
+ PyObject *props, *dummy_args, *item;
+ int i;
+
+ props= PyObject_GetAttrString(py_class, "__props__");
+
+ if(!props) {
+ PyErr_Clear();
+ return 1;
+ }
+
+ dummy_args = PyTuple_New(0);
+
+ for(i=0; i<PyList_Size(props); i++) {
+ PyObject *py_func_ptr, *py_kw, *py_srna_cobject, *py_ret;
+ item = PyList_GET_ITEM(props, i);
+
+ if(PyArg_ParseTuple(item, "O!O!", &PyCObject_Type, &py_func_ptr, &PyDict_Type, &py_kw)) {
+ PyObject *(*pyfunc)(PyObject *, PyObject *, PyObject *);
+ pyfunc = PyCObject_AsVoidPtr(py_func_ptr);
+ py_srna_cobject = PyCObject_FromVoidPtr(srna, NULL);
+
+ py_ret = pyfunc(py_srna_cobject, dummy_args, py_kw);
+ Py_DECREF(py_srna_cobject);
+
+ if(py_ret) {
+ Py_DECREF(py_ret);
+ }
+ else {
+ Py_DECREF(dummy_args);
+ return 0;
+ }
+ }
+ else {
+ PyErr_Clear();
+ PyErr_SetString(PyExc_AttributeError, "expected list of dicts for __props__.");
+ Py_DECREF(dummy_args);
+ return 0;
+ }
+ }
+
+ Py_DECREF(dummy_args);
+ return 1;
+}
+
/*-------------------- Type Registration ------------------------*/
static int rna_function_arg_count(FunctionRNA *func)
@@ -3382,6 +3428,9 @@
// Py_DECREF(py_class); // shuld be able to do this XXX since the old rna adds a new ref.
}
+ if(!deferred_register_props(py_class, srna_new))
+ return NULL;
+
Py_RETURN_NONE;
}
@@ -3405,7 +3454,6 @@
/* get the context, so register callback can do necessary refreshes */
C= BPy_GetContext();
-
/* call unregister */
unreg(C, srna); /* calls bpy_class_free, this decref's py_class */
More information about the Bf-blender-cvs
mailing list