This patch adds support in bpy.props for getter/setter callback functions. We already have update callbacks, but generic get/set functions can come in handy in some cases where the functionality is too complex to use a single value.

The current C callback functions are too simple allow a straightforward implementation, in particular they don't receive the PropertyRNA pointer itself as an argument, which means the callback cannot directly access the PropertyRNA's py_data pointers which store the python function objects. For this reason a second runtime variant of these callbacks has been added. It is only used for runtime callbacks and not in makesrna, but otherwise works the same way.
This commit is contained in:
Lukas Toenne
2013-01-05 14:56:37 +00:00
parent 5ee3cd6c86
commit e8b415bdb4
9 changed files with 2195 additions and 768 deletions

View File

@@ -112,6 +112,54 @@ int PyC_AsArray(void *array, PyObject *value, const Py_ssize_t length,
return 0;
}
/* array utility function */
PyObject *PyC_FromArray(const void *array, int length, const PyTypeObject *type,
const short is_double, const char *error_prefix)
{
PyObject *tuple;
int i;
tuple = PyTuple_New(length);
/* for each type */
if (type == &PyFloat_Type) {
if (is_double) {
const double *array_double = array;
for (i = 0; i < length; ++i) {
PyTuple_SET_ITEM(tuple, i, PyFloat_FromDouble(array_double[i]));
}
}
else {
const float *array_float = array;
for (i = 0; i < length; ++i) {
PyTuple_SET_ITEM(tuple, i, PyFloat_FromDouble(array_float[i]));
}
}
}
else if (type == &PyLong_Type) {
/* could use is_double for 'long int' but no use now */
const int *array_int = array;
for (i = 0; i < length; ++i) {
PyTuple_SET_ITEM(tuple, i, PyLong_FromLong(array_int[i]));
}
}
else if (type == &PyBool_Type) {
const int *array_bool = array;
for (i = 0; i < length; ++i) {
PyTuple_SET_ITEM(tuple, i, PyBool_FromLong(array_bool[i]));
}
}
else {
Py_DECREF(tuple);
PyErr_Format(PyExc_TypeError,
"%s: internal error %s is invalid",
error_prefix, type->tp_name);
return NULL;
}
return tuple;
}
/* for debugging */
void PyC_ObSpit(const char *name, PyObject *var)