Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/intern/bpy_rna.c
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
| Show First 20 Lines • Show All 2,194 Lines • ▼ Show 20 Lines | |||||
| static int pyrna_prop_collection_bool(BPy_PropertyRNA *self) | static int pyrna_prop_collection_bool(BPy_PropertyRNA *self) | ||||
| { | { | ||||
| PYRNA_PROP_CHECK_INT(self); | PYRNA_PROP_CHECK_INT(self); | ||||
| return !RNA_property_collection_is_empty(&self->ptr, self->prop); | return !RNA_property_collection_is_empty(&self->ptr, self->prop); | ||||
| } | } | ||||
| static bool pyrna_prop_collection_subscript_supported_or_error(BPy_PropertyRNA *self) | |||||
| { | |||||
| if (RNA_property_collection_flag(self->prop) & PROP_COLLECTION_ITERATE_ONLY) { | |||||
| PyErr_Format(PyExc_TypeError, | |||||
| "'%.200s' object is not subscriptable (only iteration is supported)", | |||||
| Py_TYPE(self)->tp_name); | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| /* notice getting the length of the collection is avoided unless negative | /* notice getting the length of the collection is avoided unless negative | ||||
| * index is used or to detect internal error with a valid index. | * index is used or to detect internal error with a valid index. | ||||
| * This is done for faster lookups. */ | * This is done for faster lookups. */ | ||||
| #define PYRNA_PROP_COLLECTION_ABS_INDEX(ret_err) \ | #define PYRNA_PROP_COLLECTION_ABS_INDEX(ret_err) \ | ||||
| if (keynum < 0) { \ | if (keynum < 0) { \ | ||||
| keynum_abs += RNA_property_collection_length(&self->ptr, self->prop); \ | keynum_abs += RNA_property_collection_length(&self->ptr, self->prop); \ | ||||
| if (keynum_abs < 0) { \ | if (keynum_abs < 0) { \ | ||||
| PyErr_Format(PyExc_IndexError, "bpy_prop_collection[%d]: out of range.", keynum); \ | PyErr_Format(PyExc_IndexError, "bpy_prop_collection[%d]: out of range.", keynum); \ | ||||
| return ret_err; \ | return ret_err; \ | ||||
| } \ | } \ | ||||
| } \ | } \ | ||||
| (void)0 | (void)0 | ||||
| /* Internal use only. */ | /* Internal use only. */ | ||||
| static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_ssize_t keynum) | static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_ssize_t keynum) | ||||
| { | { | ||||
| PointerRNA newptr; | PointerRNA newptr; | ||||
| Py_ssize_t keynum_abs = keynum; | Py_ssize_t keynum_abs = keynum; | ||||
| PYRNA_PROP_CHECK_OBJ(self); | PYRNA_PROP_CHECK_OBJ(self); | ||||
| PYRNA_PROP_COLLECTION_ABS_INDEX(NULL); | PYRNA_PROP_COLLECTION_ABS_INDEX(NULL); | ||||
| if (!pyrna_prop_collection_subscript_supported_or_error(self)) { | |||||
| return NULL; | |||||
| } | |||||
| if (RNA_property_collection_lookup_int(&self->ptr, self->prop, keynum_abs, &newptr)) { | if (RNA_property_collection_lookup_int(&self->ptr, self->prop, keynum_abs, &newptr)) { | ||||
| return pyrna_struct_CreatePyObject(&newptr); | return pyrna_struct_CreatePyObject(&newptr); | ||||
| } | } | ||||
| const int len = RNA_property_collection_length(&self->ptr, self->prop); | const int len = RNA_property_collection_length(&self->ptr, self->prop); | ||||
| if (keynum_abs >= len) { | if (keynum_abs >= len) { | ||||
| PyErr_Format(PyExc_IndexError, | PyErr_Format(PyExc_IndexError, | ||||
| "bpy_prop_collection[index]: " | "bpy_prop_collection[index]: " | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static PyObject *pyrna_prop_collection_subscript_str(BPy_PropertyRNA *self, const char *keyname) | static PyObject *pyrna_prop_collection_subscript_str(BPy_PropertyRNA *self, const char *keyname) | ||||
| { | { | ||||
| PointerRNA newptr; | PointerRNA newptr; | ||||
| PYRNA_PROP_CHECK_OBJ(self); | PYRNA_PROP_CHECK_OBJ(self); | ||||
| if (!pyrna_prop_collection_subscript_supported_or_error(self)) { | |||||
| return NULL; | |||||
| } | |||||
| if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) { | if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) { | ||||
| return pyrna_struct_CreatePyObject(&newptr); | return pyrna_struct_CreatePyObject(&newptr); | ||||
| } | } | ||||
| PyErr_Format(PyExc_KeyError, "bpy_prop_collection[key]: key \"%.200s\" not found", keyname); | PyErr_Format(PyExc_KeyError, "bpy_prop_collection[key]: key \"%.200s\" not found", keyname); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| // static PyObject *pyrna_prop_array_subscript_str(BPy_PropertyRNA *self, char *keyname) | // static PyObject *pyrna_prop_array_subscript_str(BPy_PropertyRNA *self, char *keyname) | ||||
| ▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | static PyObject *pyrna_prop_collection_subscript_slice(BPy_PropertyRNA *self, | ||||
| CollectionPropertyIterator rna_macro_iter; | CollectionPropertyIterator rna_macro_iter; | ||||
| int count; | int count; | ||||
| PyObject *list; | PyObject *list; | ||||
| PyObject *item; | PyObject *item; | ||||
| PYRNA_PROP_CHECK_OBJ(self); | PYRNA_PROP_CHECK_OBJ(self); | ||||
| if (!pyrna_prop_collection_subscript_supported_or_error(self)) { | |||||
| return NULL; | |||||
| } | |||||
| list = PyList_New(0); | list = PyList_New(0); | ||||
| /* Skip to start. */ | /* Skip to start. */ | ||||
| RNA_property_collection_begin(&self->ptr, self->prop, &rna_macro_iter); | RNA_property_collection_begin(&self->ptr, self->prop, &rna_macro_iter); | ||||
| RNA_property_collection_skip(&rna_macro_iter, start); | RNA_property_collection_skip(&rna_macro_iter, start); | ||||
| /* Add items until stop. */ | /* Add items until stop. */ | ||||
| for (count = start; rna_macro_iter.valid; RNA_property_collection_next(&rna_macro_iter)) { | for (count = start; rna_macro_iter.valid; RNA_property_collection_next(&rna_macro_iter)) { | ||||
| ▲ Show 20 Lines • Show All 6,776 Lines • Show Last 20 Lines | |||||