diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-06-17 09:45:46 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-06-17 09:45:46 +0400 |
commit | 7cbc4c0dd7cf5c69eb74b36cd01c8321ad1a085f (patch) | |
tree | c26ea63790369630896a174700e3f79e38bd490d /source/blender/python/intern | |
parent | ac089ddd15c0d5400274076dd857f0c22c460a54 (diff) |
IDProperty python module update
- add support for IDProp array slicing, but not resizing.
- rename array attribute type to typecode and use chars 'f', 'd', 'i' which match pythons array module. (was using int's which only have a meaning internally).
- rename function 'convert_to_pyobject' to 'to_dict' and 'to_list' for IDProp group and array types respectively.
- remove 'len' array attribute, calling len(array) is fine.
Diffstat (limited to 'source/blender/python/intern')
-rw-r--r-- | source/blender/python/intern/bpy_props.c | 6 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_util.c | 60 |
2 files changed, 3 insertions, 63 deletions
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index 8ed4e41de3e..0ba80bf0850 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -459,7 +459,7 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject return NULL; } - if(pydef && PyC_AsArray(def, pydef, size, &PyBool_Type, "BoolVectorProperty(default=sequence)") < 0) + if(pydef && PyC_AsArray(def, pydef, size, &PyBool_Type, FALSE, "BoolVectorProperty(default=sequence)") < 0) return NULL; if (bpy_prop_callback_check(update_cb, 2) == -1) { @@ -603,7 +603,7 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject return NULL; } - if(pydef && PyC_AsArray(def, pydef, size, &PyLong_Type, "IntVectorProperty(default=sequence)") < 0) + if(pydef && PyC_AsArray(def, pydef, size, &PyLong_Type, FALSE, "IntVectorProperty(default=sequence)") < 0) return NULL; if (bpy_prop_callback_check(update_cb, 2) == -1) { @@ -759,7 +759,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec return NULL; } - if(pydef && PyC_AsArray(def, pydef, size, &PyFloat_Type, "FloatVectorProperty(default=sequence)") < 0) + if(pydef && PyC_AsArray(def, pydef, size, &PyFloat_Type, FALSE, "FloatVectorProperty(default=sequence)") < 0) return NULL; if (bpy_prop_callback_check(update_cb, 2) == -1) { diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c index 6e321015bc6..1450621d59e 100644 --- a/source/blender/python/intern/bpy_util.c +++ b/source/blender/python/intern/bpy_util.c @@ -122,63 +122,3 @@ short BPy_errors_to_report(ReportList *reports) Py_DECREF(pystring_format); // workaround return 1; } - -/* array utility function */ -int PyC_AsArray(void *array, PyObject *value, int length, PyTypeObject *type, const char *error_prefix) -{ - PyObject *value_fast; - int value_len; - int i; - - if(!(value_fast=PySequence_Fast(value, error_prefix))) { - return -1; - } - - value_len= PySequence_Fast_GET_SIZE(value_fast); - - if(value_len != length) { - Py_DECREF(value); - PyErr_Format(PyExc_TypeError, - "%.200s: invalid sequence length. expected %d, got %d", - error_prefix, length, value_len); - return -1; - } - - /* for each type */ - if(type == &PyFloat_Type) { - float *array_float= array; - for(i=0; i<length; i++) { - array_float[i]= PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i)); - } - } - else if(type == &PyLong_Type) { - int *array_int= array; - for(i=0; i<length; i++) { - array_int[i]= PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i)); - } - } - else if(type == &PyBool_Type) { - int *array_bool= array; - for(i=0; i<length; i++) { - array_bool[i]= (PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i)) != 0); - } - } - else { - Py_DECREF(value_fast); - PyErr_Format(PyExc_TypeError, - "%s: internal error %s is invalid", - error_prefix, type->tp_name); - return -1; - } - - Py_DECREF(value_fast); - - if(PyErr_Occurred()) { - PyErr_Format(PyExc_TypeError, - "%s: one or more items could not be used as a %s", - error_prefix, type->tp_name); - return -1; - } - - return 0; -} |