Blender V5.3
bpy_props.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12
13/* Future-proof, See https://docs.python.org/3/c-api/arg.html#strings-and-buffers */
14#define PY_SSIZE_T_CLEAN
15
16#include <algorithm>
17#include <string>
18
19#include <Python.h>
20
21#include "RNA_types.hh"
22
23#include "BLI_array.hh"
24#include "BLI_listbase.hh"
25#include "BLI_utildefines.hh"
26
27#include "bpy_capi_utils.hh"
28#include "bpy_props.hh"
29#include "bpy_rna.hh"
30
31#include "RNA_access.hh"
32#include "RNA_define.hh" /* for defining our own rna */
33#include "RNA_enum_types.hh"
34#include "RNA_prototypes.hh"
35
36#include "MEM_guardedalloc.h"
37
38#include "DNA_ID.h" /* MAX_IDPROP_NAME */
39
42#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
44
45namespace blender {
46
47/* Disabled duplicating strings because the array can still be freed and
48 * the strings from it referenced, for now we can't support dynamically
49 * created strings from Python. */
50// #define USE_ENUM_COPY_STRINGS
51
52/* -------------------------------------------------------------------- */
55
56#define BPY_PROPDEF_OPTIONS_DOC \
57 " :param options: Enumerator in :ref:`rna_enum_property_flag_items`.\n" \
58 " :type options: set[str]\n"
59
60#define BPY_PROPDEF_OPTIONS_ENUM_DOC \
61 " :param options: Enumerator in :ref:`rna_enum_property_flag_enum_items`.\n" \
62 " :type options: set[str]\n"
63
64#define BPY_PROPDEF_OPTIONS_OVERRIDE_DOC \
65 " :param override: Enumerator in :ref:`rna_enum_property_override_flag_items`.\n" \
66 " :type override: set[str]\n"
67
68#define BPY_PROPDEF_OPTIONS_OVERRIDE_COLLECTION_DOC \
69 " :param override: Enumerator in :ref:`rna_enum_property_override_flag_collection_items`.\n" \
70 " :type override: set[str]\n"
71
72#define BPY_PROPDEF_SUBTYPE_STRING_DOC \
73 " :param subtype: Enumerator in :ref:`rna_enum_property_subtype_string_items`.\n" \
74 " :type subtype: str\n"
75
76#define BPY_PROPDEF_SUBTYPE_NUMBER_DOC \
77 " :param subtype: Enumerator in :ref:`rna_enum_property_subtype_number_items`.\n" \
78 " :type subtype: str\n"
79
80#define BPY_PROPDEF_SUBTYPE_NUMBER_ARRAY_DOC \
81 " :param subtype: Enumerator in :ref:`rna_enum_property_subtype_number_array_items`.\n" \
82 " :type subtype: str\n"
83
85
86/* -------------------------------------------------------------------- */
91
126
131 struct {
151 PyObject *get_fn;
152 PyObject *set_fn;
153 PyObject *get_transform_fn;
154 PyObject *set_transform_fn;
156 PyObject *update_fn;
157
159 union {
161 struct {
163 PyObject *itemf_fn;
164 } enum_data;
165
166 struct {
168 PyObject *poll_fn;
169 } pointer_data;
170
171 struct {
173 PyObject *search_fn;
174 } string_data;
175 };
177};
178
179#define BPY_PROP_STORE_PY_DATA_SIZE (sizeof(BPyPropStore::py_data) / sizeof(PyObject *))
180
181#define ASSIGN_PYOBJECT_INCREF(a, b) \
182 { \
183 BLI_assert((a) == nullptr); \
184 Py_INCREF(b); \
185 a = b; \
186 } \
187 ((void)0)
188
193static ListBaseT<BPyPropStore> g_bpy_prop_store_list = {nullptr, nullptr};
194
196{
197 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
198 if (prop_store == nullptr) {
199 prop_store = MEM_new_zeroed<BPyPropStore>(__func__);
200 RNA_def_py_data(prop, prop_store);
202 }
203 return prop_store;
204}
205
210{
211 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
212 if (prop_store == nullptr) {
213 return;
214 }
215
216 PyObject **py_data = reinterpret_cast<PyObject **>(&prop_store->py_data);
217 for (int i = 0; i < BPY_PROP_STORE_PY_DATA_SIZE; i++) {
218 Py_XDECREF(py_data[i]);
219 }
221}
222
224
225/* -------------------------------------------------------------------- */
232
234{
235 PyObject_GC_UnTrack(self);
236 Py_CLEAR(self->kw);
237 PyObject_GC_Del(self);
238}
239
240static int bpy_prop_deferred_traverse(BPy_PropDeferred *self, visitproc visit, void *arg)
241{
242 Py_VISIT(self->kw);
243 return 0;
244}
245
247{
248 Py_CLEAR(self->kw);
249 return 0;
250}
251
253{
254 return PyUnicode_FromFormat("<%.200s, %R, %R>", Py_TYPE(self)->tp_name, self->fn, self->kw);
255}
256
263static PyObject *bpy_prop_deferred_call(BPy_PropDeferred * /*self*/,
264 PyObject * /*args*/,
265 PyObject * /*kw*/)
266{
267 /* Dummy value. */
268 Py_RETURN_NONE;
269}
270
271/* Get/Set Items. */
272
274 /* Wrap. */
275 bpy_prop_deferred_function_doc,
276 "The property registration function (e.g. :func:`bpy.props.IntProperty`).\n"
277 "\n"
278 ":type: Callable\n");
283static PyObject *bpy_prop_deferred_function_get(BPy_PropDeferred *self, void * /*closure*/)
284{
285 PyObject *ret = static_cast<PyObject *>(self->fn);
286 Py_IncRef(ret);
287 return ret;
288}
289
291 /* Wrap. */
292 bpy_prop_deferred_keywords_doc,
293 "The keyword arguments passed to the property registration function.\n"
294 "\n"
295 ":type: dict[str, Any]\n");
296
301static PyObject *bpy_prop_deferred_keywords_get(BPy_PropDeferred *self, void * /*closure*/)
302{
303 PyObject *ret = self->kw;
304 Py_IncRef(ret);
305 return ret;
306}
307
312static PyGetSetDef bpy_prop_deferred_getset[] = {
313 {"function",
314 reinterpret_cast<getter>(bpy_prop_deferred_function_get),
315 static_cast<setter>(nullptr),
316 bpy_prop_deferred_function_doc,
317 nullptr},
318 {"keywords",
319 reinterpret_cast<getter>(bpy_prop_deferred_keywords_get),
320 static_cast<setter>(nullptr),
321 bpy_prop_deferred_keywords_doc,
322 nullptr},
323 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
324};
325
327 /* Wrap. */
328 bpy_prop_deferred_doc,
329 "Intermediate storage for properties before registration.\n"
330 "\n"
331 ".. note::\n"
332 "\n"
333 " This is not part of the stable API and may change between releases.\n");
335 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
336 /*tp_name*/ "_PropertyDeferred",
337 /*tp_basicsize*/ sizeof(BPy_PropDeferred),
338 /*tp_itemsize*/ 0,
339 /*tp_dealloc*/ reinterpret_cast<destructor>(bpy_prop_deferred_dealloc),
340 /*tp_vectorcall_offset*/ 0,
341 /*tp_getattr*/ nullptr,
342 /*tp_setattr*/ nullptr,
343 /*tp_as_async*/ nullptr,
344 /*tp_repr*/ reinterpret_cast<reprfunc>(bpy_prop_deferred_repr),
345 /*tp_as_number*/ nullptr,
346 /*tp_as_sequence*/ nullptr,
347 /*tp_as_mapping*/ nullptr,
348 /*tp_hash*/ nullptr,
349 /*tp_call*/ reinterpret_cast<ternaryfunc>(bpy_prop_deferred_call),
350 /*tp_str*/ nullptr,
351 /*tp_getattro*/ nullptr,
352 /*tp_setattro*/ nullptr,
353 /*tp_as_buffer*/ nullptr,
354 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
355 /*tp_doc*/ bpy_prop_deferred_doc,
356 /*tp_traverse*/ reinterpret_cast<traverseproc>(bpy_prop_deferred_traverse),
357 /*tp_clear*/ reinterpret_cast<inquiry>(bpy_prop_deferred_clear),
358 /*tp_richcompare*/ nullptr,
359 /*tp_weaklistoffset*/ 0,
360 /*tp_iter*/ nullptr,
361 /*tp_iternext*/ nullptr,
362 /*tp_methods*/ nullptr,
363 /*tp_members*/ nullptr,
364 /*tp_getset*/ bpy_prop_deferred_getset,
365 /*tp_base*/ nullptr,
366 /*tp_dict*/ nullptr,
367 /*tp_descr_get*/ nullptr,
368 /*tp_descr_set*/ nullptr,
369 /*tp_dictoffset*/ 0,
370 /*tp_init*/ nullptr,
371 /*tp_alloc*/ nullptr,
372 /*tp_new*/ nullptr,
373 /*tp_free*/ nullptr,
374 /*tp_is_gc*/ nullptr,
375 /*tp_bases*/ nullptr,
376 /*tp_mro*/ nullptr,
377 /*tp_cache*/ nullptr,
378 /*tp_subclasses*/ nullptr,
379 /*tp_weaklist*/ nullptr,
380 /*tp_del*/ nullptr,
381 /*tp_version_tag*/ 0,
382 /*tp_finalize*/ nullptr,
383 /*tp_vectorcall*/ nullptr,
384};
385
386static PyObject *bpy_prop_deferred_data_CreatePyObject(PyObject *fn, PyObject *kw)
387{
389 self->fn = fn;
390 if (kw == nullptr) {
391 kw = PyDict_New();
392 }
393 else {
394 Py_INCREF(kw);
395 }
396 self->kw = kw;
397 BLI_assert(!PyObject_GC_IsTracked((PyObject *)self));
398 PyObject_GC_Track(self);
399 return reinterpret_cast<PyObject *>(self);
400}
401
403
404/* -------------------------------------------------------------------- */
407
408/* PyObject's */
409static PyObject *pymeth_BoolProperty = nullptr;
410static PyObject *pymeth_BoolVectorProperty = nullptr;
411static PyObject *pymeth_IntProperty = nullptr;
412static PyObject *pymeth_IntVectorProperty = nullptr;
413static PyObject *pymeth_FloatProperty = nullptr;
414static PyObject *pymeth_FloatVectorProperty = nullptr;
415static PyObject *pymeth_StringProperty = nullptr;
416static PyObject *pymeth_EnumProperty = nullptr;
417static PyObject *pymeth_PointerProperty = nullptr;
418static PyObject *pymeth_CollectionProperty = nullptr;
419static PyObject *pymeth_RemoveProperty = nullptr;
420
422{
423 PyObject *self = nullptr;
424 /* first get self */
425 /* operators can store their own instance for later use */
426 if (*ptr) {
427 void **instance = RNA_struct_instance(ptr);
428
429 if (instance) {
430 if (*instance) {
431 self = static_cast<PyObject *>(*instance);
432 Py_INCREF(self);
433 }
434 }
435 }
436
437 /* in most cases this will run */
438 if (self == nullptr) {
439 self = pyrna_struct_CreatePyObject(ptr);
440 }
441
442 return self;
443}
444
445static void bpy_prop_assign_flag(PropertyRNA *prop, int flag)
446{
447 /* Map `READ_ONLY` to `EDITABLE`. */
448 flag ^= PROP_EDITABLE;
449
450 /* The default is editable. */
451 const int flag_mask_set = (flag & ~PROP_EDITABLE);
452 const int flag_mask_clear = ((PROP_ANIMATABLE | PROP_EDITABLE) & ~flag);
453
454 if (flag_mask_set) {
455 RNA_def_property_flag(prop, PropertyFlag(flag_mask_set));
456 }
457
458 if (flag_mask_clear) {
459 RNA_def_property_clear_flag(prop, PropertyFlag(flag_mask_clear));
460 }
461}
462
463static void bpy_prop_assign_flag_override(PropertyRNA *prop, const int flag_override)
464{
466}
467
468/* These utility functions de-duplicate boiler plate code used by most property callbacks.
469 * It's important they're at the beginning & end of the callbacks and both are always called. */
470
472 PyGILState_STATE gilstate;
474};
475
477{
478 /* It's important to acquire the lock before reading other state information, see: #127767. */
479 const PyGILState_STATE gilstate = PyGILState_Ensure();
480 const bool is_write_ok = pyrna_write_check();
481 return {
482 /*gilstate*/ gilstate,
483 /*is_write_ok*/ is_write_ok,
484 };
485}
486
488{
489 if (!prop_state.is_write_ok) {
490 pyrna_write_set(false);
491 }
492 PyGILState_Release(prop_state.gilstate);
493}
494
496
497/* -------------------------------------------------------------------- */
500
502 int len_total = 0;
505 int dims_len = 0;
506
509 {
510 this->len_total = RNA_property_array_length(ptr, prop);
511 this->dims_len = RNA_property_array_dimension(ptr, prop, this->dims);
512 }
513
514 bool operator==(const BPyPropArrayLength &other) const
515 {
516 if ((this->len_total != other.len_total) || (this->dims_len != other.dims_len)) {
517 return false;
518 }
519 for (int i = 0; i < this->dims_len; i++) {
520 if (this->dims[i] != other.dims[i]) {
521 return false;
522 }
523 }
524 return true;
525 }
526};
527
531static int bpy_prop_array_length_parse(PyObject *o, void *p)
532{
533 BPyPropArrayLength *array_len_info = static_cast<BPyPropArrayLength *>(p);
534
535 if (PyLong_CheckExact(o)) {
536 int size;
537 if ((size = PyLong_AsLong(o)) == -1) {
538 PyErr_Format(
539 PyExc_ValueError, "expected number or sequence of numbers, got %s", Py_TYPE(o)->tp_name);
540 return 0;
541 }
542 if (size < 1 || size > PYRNA_STACK_ARRAY) {
543 PyErr_Format(
544 PyExc_TypeError, "(size=%d) must be between 1 and " STRINGIFY(PYRNA_STACK_ARRAY), size);
545 return 0;
546 }
547 array_len_info->len_total = size;
548
549 /* Don't use this value. */
550 array_len_info->dims_len = 0;
551 }
552 else {
553 PyObject *seq_fast;
554 if (!(seq_fast = PySequence_Fast(o, "size must be a number of a sequence of numbers"))) {
555 return 0;
556 }
557 const int seq_len = PySequence_Fast_GET_SIZE(seq_fast);
558 if (seq_len < 1 || seq_len > RNA_MAX_ARRAY_DIMENSION) {
559 PyErr_Format(
560 PyExc_TypeError,
561 "(len(size)=%d) length must be between 1 and " STRINGIFY(RNA_MAX_ARRAY_DIMENSION),
562 seq_len);
563 Py_DECREF(seq_fast);
564 return 0;
565 }
566
567 PyObject **seq_items = PySequence_Fast_ITEMS(seq_fast);
568 array_len_info->len_total = 1;
569 for (int i = 0; i < seq_len; i++) {
570 int size;
571 if ((size = PyLong_AsLong(seq_items[i])) == -1) {
572 Py_DECREF(seq_fast);
573 PyErr_Format(PyExc_ValueError,
574 "expected number in sequence, got %s at index %d",
575 Py_TYPE(o)->tp_name,
576 i);
577 return 0;
578 }
579 if (size < 1 || size > PYRNA_STACK_ARRAY) {
580 Py_DECREF(seq_fast);
581 PyErr_Format(PyExc_TypeError,
582 "(size[%d]=%d) must be between 1 and " STRINGIFY(PYRNA_STACK_ARRAY),
583 i,
584 size);
585 return 0;
586 }
587
588 array_len_info->dims[i] = size;
589 array_len_info->dims_len = seq_len;
590 array_len_info->len_total *= size;
591 }
592 Py_DECREF(seq_fast);
593 }
594 return 1;
595}
596
600static int bpy_prop_array_from_py_with_dims(void *values,
601 size_t values_elem_size,
602 PyObject *py_values,
603 const BPyPropArrayLength *array_len_info,
604 const PyTypeObject *type,
605 const char *error_str)
606{
607 if (array_len_info->dims_len == 0) {
608 return PyC_AsArray(
609 values, values_elem_size, py_values, array_len_info->len_total, type, error_str);
610 }
611 const int *dims = array_len_info->dims;
612 const int dims_len = array_len_info->dims_len;
613 return PyC_AsArray_Multi(values, values_elem_size, py_values, dims, dims_len, type, error_str);
614}
615
616/* NOTE: Always increases refcount of the returned value. */
617static PyObject *bpy_py_object_from_prop_array_with_dims(const void *values,
618 const BPyPropArrayLength &array_len_info,
619 const PyTypeObject &type)
620{
621 PyObject *py_values = nullptr;
622
623 if (&type == &PyBool_Type) {
624 if (array_len_info.dims_len == 0) {
625 py_values = PyC_Tuple_PackArray_Bool(static_cast<const bool *>(values),
626 uint(array_len_info.len_total));
627 }
628 else {
630 static_cast<const bool *>(values), array_len_info.dims, array_len_info.dims_len);
631 }
632 }
633 else if (&type == &PyLong_Type) {
634 if (array_len_info.dims_len == 0) {
635 py_values = PyC_Tuple_PackArray_I32(static_cast<const int *>(values),
636 uint(array_len_info.len_total));
637 }
638 else {
640 static_cast<const int *>(values), array_len_info.dims, array_len_info.dims_len);
641 }
642 }
643 else if (&type == &PyFloat_Type) {
644 if (array_len_info.dims_len == 0) {
645 py_values = PyC_Tuple_PackArray_F32(static_cast<const float *>(values),
646 uint(array_len_info.len_total));
647 }
648 else {
649 /* No need for matrix column/row swapping here unless the matrix data is read directly. */
651 static_cast<const float *>(values), array_len_info.dims, array_len_info.dims_len);
652 }
653 }
654 else {
656 }
657
658 return py_values;
659}
660
662 const BPyPropArrayLength *array_len_info)
663{
664 return ((subtype == PROP_MATRIX) && (array_len_info->dims_len == 2) &&
665 ((array_len_info->dims[0] >= 2) && (array_len_info->dims[0] <= 4)) &&
666 ((array_len_info->dims[1] >= 2) && (array_len_info->dims[1] <= 4)));
667}
668
670 const BPyPropArrayLength *array_len_info)
671{
674}
675
680 const float *values_src,
681 const BPyPropArrayLength *array_len_info)
682{
683 BLI_assert(values_dst != values_src);
684 const int dim0 = array_len_info->dims[0], dim1 = array_len_info->dims[1];
685 BLI_assert(dim0 <= 4 && dim1 <= 4);
686 for (int i = 0; i < dim0; i++) {
687 for (int j = 0; j < dim1; j++) {
688 values_dst[(j * dim0) + i] = values_src[(i * dim1) + j];
689 }
690 }
691}
692
694 const BPyPropArrayLength *array_len_info)
695{
696 const int dim0 = array_len_info->dims[0], dim1 = array_len_info->dims[1];
697 BLI_assert(dim0 <= 4 && dim1 <= 4);
698 float values_orig[4 * 4];
699 memcpy(values_orig, values, sizeof(float) * (dim0 * dim1));
700 bpy_prop_array_matrix_swap_row_column_vn_vn(values, values_orig, array_len_info);
701}
702
704
705/* -------------------------------------------------------------------- */
710
711/* callbacks */
713{
714 PyGILState_STATE gilstate;
715 bpy_context_set(C, &gilstate);
716 const bool is_write_ok = pyrna_write_check();
717 if (!is_write_ok) {
718 pyrna_write_set(true);
719 }
720
721 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
722 PyObject *py_func;
723 PyObject *ret;
724
725 BLI_assert(prop_store != nullptr);
726
727 py_func = prop_store->py_data.update_fn;
728
729 {
730 PyObject *args = PyTuple_New(2);
731 PyObject *self = pyrna_struct_as_instance(ptr);
732 PyTuple_SET_ITEMS(args, self, reinterpret_cast<PyObject *>(bpy_context_module));
733 Py_INCREF(bpy_context_module);
734
735 ret = PyObject_CallObject(py_func, args);
736
737 Py_DECREF(args);
738 }
739
740 if (ret == nullptr) {
741 PyC_Err_PrintWithFunc(py_func);
742 }
743 else {
744 if (ret != Py_None) {
745 PyErr_SetString(PyExc_ValueError, "the return value must be None");
746 PyC_Err_PrintWithFunc(py_func);
747 }
748
749 Py_DECREF(ret);
750 }
751
752 if (!is_write_ok) {
753 pyrna_write_set(false);
754 }
755
756 bpy_context_clear(C, &gilstate);
757}
758
760
761/* -------------------------------------------------------------------- */
764
766{
768
769 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
770 PyObject *py_func;
771 PyObject *ret;
772 bool value;
773
774 BLI_assert(prop_store != nullptr);
775
776 py_func = prop_store->py_data.get_fn;
777
778 {
779 PyObject *args = PyTuple_New(1);
780 PyObject *self = pyrna_struct_as_instance(ptr);
781 PyTuple_SET_ITEMS(args, self);
782
783 ret = PyObject_CallObject(py_func, args);
784
785 Py_DECREF(args);
786 }
787
788 if (ret == nullptr) {
789 PyC_Err_PrintWithFunc(py_func);
790 value = false;
791 }
792 else {
793 const int value_i = PyC_Long_AsBool(ret);
794
795 if (value_i == -1 && PyErr_Occurred()) {
796 PyC_Err_PrintWithFunc(py_func);
797 value = false;
798 }
799 else {
800 value = bool(value_i);
801 }
802
803 Py_DECREF(ret);
804 }
805
807
808 return value;
809}
810
812 PropertyRNA *prop,
813 bool curr_value,
814 bool is_set)
815{
817
818 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
819 PyObject *py_func;
820 PyObject *ret;
821
822 BLI_assert(prop_store != nullptr);
823
824 py_func = prop_store->py_data.get_transform_fn;
825
826 {
827 PyObject *args = PyTuple_New(3);
828 PyObject *self = pyrna_struct_as_instance(ptr);
829 PyTuple_SET_ITEMS(args, self, PyBool_FromLong(curr_value), PyBool_FromLong(is_set));
830
831 ret = PyObject_CallObject(py_func, args);
832
833 Py_DECREF(args);
834 }
835
836 bool ret_value = curr_value;
837 if (ret == nullptr) {
838 PyC_Err_PrintWithFunc(py_func);
839 }
840 else {
841 const int value_i = PyC_Long_AsBool(ret);
842
843 if (value_i == -1 && PyErr_Occurred()) {
844 PyC_Err_PrintWithFunc(py_func);
845 }
846 else {
847 ret_value = bool(value_i);
848 }
849
850 Py_DECREF(ret);
851 }
852
854
855 return ret_value;
856}
857
858static void bpy_prop_boolean_set_fn(PointerRNA *ptr, PropertyRNA *prop, bool value)
859{
861
862 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
863 PyObject *py_func;
864 PyObject *ret;
865
866 BLI_assert(prop_store != nullptr);
867
868 py_func = prop_store->py_data.set_fn;
869
870 {
871 PyObject *args = PyTuple_New(2);
872 PyObject *self = pyrna_struct_as_instance(ptr);
873 PyTuple_SET_ITEMS(args, self, PyBool_FromLong(value));
874
875 ret = PyObject_CallObject(py_func, args);
876
877 Py_DECREF(args);
878 }
879
880 if (ret == nullptr) {
881 PyC_Err_PrintWithFunc(py_func);
882 }
883 else {
884 if (ret != Py_None) {
885 PyErr_SetString(PyExc_ValueError, "the return value must be None");
886 PyC_Err_PrintWithFunc(py_func);
887 }
888
889 Py_DECREF(ret);
890 }
891
893}
894
896 PointerRNA *ptr, PropertyRNA *prop, bool new_value, bool curr_value, bool is_set)
897{
899
900 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
901 PyObject *py_func;
902 PyObject *ret;
903
904 BLI_assert(prop_store != nullptr);
905
906 py_func = prop_store->py_data.set_transform_fn;
907
908 {
909 PyObject *args = PyTuple_New(4);
910 PyObject *self = pyrna_struct_as_instance(ptr);
912 self,
913 PyBool_FromLong(new_value),
914 PyBool_FromLong(curr_value),
915 PyBool_FromLong(is_set));
916
917 ret = PyObject_CallObject(py_func, args);
918
919 Py_DECREF(args);
920 }
921
922 bool ret_value = curr_value;
923 if (ret == nullptr) {
924 PyC_Err_PrintWithFunc(py_func);
925 }
926 else {
927 const int value_i = PyC_Long_AsBool(ret);
928
929 if (value_i == -1 && PyErr_Occurred()) {
930 PyC_Err_PrintWithFunc(py_func);
931 }
932 else {
933 ret_value = bool(value_i);
934 }
935
936 Py_DECREF(ret);
937 }
938
940
941 return ret_value;
942}
943
944static void bpy_prop_boolean_array_from_callback_or_error(PyObject *bool_array_obj,
945 const BPyPropArrayLength &array_len_info,
946 PyObject *py_func,
947 bool *r_values)
948{
949 bool is_values_set = false;
950
951 if (bool_array_obj != nullptr) {
953 sizeof(*r_values),
954 bool_array_obj,
955 &array_len_info,
956 &PyBool_Type,
957 "BoolVectorProperty get callback") == -1)
958 {
959 PyC_Err_PrintWithFunc(py_func);
960 }
961 else {
962 is_values_set = true;
963 }
964 }
965
966 if (is_values_set == false) {
967 /* This is the flattened length for multi-dimensional arrays. */
968 for (int i = 0; i < array_len_info.len_total; i++) {
969 r_values[i] = false;
970 }
971 }
972
973 Py_XDECREF(bool_array_obj);
974}
975
976static void bpy_prop_boolean_array_get_fn(PointerRNA *ptr, PropertyRNA *prop, bool *values)
977{
979
980 const BPyPropArrayLength array_len_info{ptr, prop};
981 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
982 PyObject *py_func;
983 PyObject *ret;
984
985 BLI_assert(prop_store != nullptr);
986
987 py_func = prop_store->py_data.get_fn;
988
989 {
990 PyObject *args = PyTuple_New(1);
991 PyObject *self = pyrna_struct_as_instance(ptr);
992 PyTuple_SET_ITEMS(args, self);
993
994 ret = PyObject_CallObject(py_func, args);
995
996 Py_DECREF(args);
997 }
998
999 bpy_prop_boolean_array_from_callback_or_error(ret, array_len_info, py_func, values);
1000
1002}
1003
1005 PointerRNA *ptr, PropertyRNA *prop, const bool *curr_values, bool is_set, bool *r_values)
1006{
1008
1009 const BPyPropArrayLength array_len_info{ptr, prop};
1010 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1011 PyObject *py_func;
1012 PyObject *ret;
1013
1014 BLI_assert(prop_store != nullptr);
1015
1016 py_func = prop_store->py_data.get_transform_fn;
1017
1018 {
1019 PyObject *args = PyTuple_New(3);
1020 PyObject *self = pyrna_struct_as_instance(ptr);
1022 args,
1023 self,
1024 bpy_py_object_from_prop_array_with_dims(curr_values, array_len_info, PyBool_Type),
1025 PyBool_FromLong(is_set));
1026
1027 ret = PyObject_CallObject(py_func, args);
1028
1029 Py_DECREF(args);
1030 }
1031
1032 bpy_prop_boolean_array_from_callback_or_error(ret, array_len_info, py_func, r_values);
1033
1035}
1036
1037static void bpy_prop_boolean_array_set_fn(PointerRNA *ptr, PropertyRNA *prop, const bool *values)
1038{
1040
1041 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1042 PyObject *py_func;
1043 PyObject *ret;
1044
1045 const BPyPropArrayLength array_len_info{ptr, prop};
1046
1047 BLI_assert(prop_store != nullptr);
1048
1049 py_func = prop_store->py_data.set_fn;
1050
1051 {
1052 PyObject *args = PyTuple_New(2);
1053 PyObject *self = pyrna_struct_as_instance(ptr);
1055 args, self, bpy_py_object_from_prop_array_with_dims(values, array_len_info, PyBool_Type));
1056
1057 ret = PyObject_CallObject(py_func, args);
1058
1059 Py_DECREF(args);
1060 }
1061
1062 if (ret == nullptr) {
1063 PyC_Err_PrintWithFunc(py_func);
1064 }
1065 else {
1066 if (ret != Py_None) {
1067 PyErr_SetString(PyExc_ValueError, "the return value must be None");
1068 PyC_Err_PrintWithFunc(py_func);
1069 }
1070
1071 Py_DECREF(ret);
1072 }
1073
1075}
1076
1078 PropertyRNA *prop,
1079 const bool *new_values,
1080 const bool *curr_values,
1081 bool is_set,
1082 bool *r_final_values)
1083{
1085
1086 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1087 PyObject *py_func;
1088 PyObject *ret;
1089
1090 const BPyPropArrayLength array_len_info{ptr, prop};
1091
1092 BLI_assert(prop_store != nullptr);
1093
1094 py_func = prop_store->py_data.set_transform_fn;
1095
1096 {
1097 PyObject *args = PyTuple_New(4);
1098 PyObject *self = pyrna_struct_as_instance(ptr);
1100 args,
1101 self,
1102 bpy_py_object_from_prop_array_with_dims(new_values, array_len_info, PyBool_Type),
1103 bpy_py_object_from_prop_array_with_dims(curr_values, array_len_info, PyBool_Type),
1104 PyBool_FromLong(is_set));
1105
1106 ret = PyObject_CallObject(py_func, args);
1107
1108 Py_DECREF(args);
1109 }
1110
1111 bpy_prop_boolean_array_from_callback_or_error(ret, array_len_info, py_func, r_final_values);
1112
1114}
1115
1117
1118/* -------------------------------------------------------------------- */
1121
1123{
1125
1126 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1127 PyObject *py_func;
1128 PyObject *ret;
1129 int value;
1130
1131 BLI_assert(prop_store != nullptr);
1132
1133 py_func = prop_store->py_data.get_fn;
1134
1135 {
1136 PyObject *args = PyTuple_New(1);
1137 PyObject *self = pyrna_struct_as_instance(ptr);
1138 PyTuple_SET_ITEMS(args, self);
1139
1140 ret = PyObject_CallObject(py_func, args);
1141
1142 Py_DECREF(args);
1143 }
1144
1145 if (ret == nullptr) {
1146 PyC_Err_PrintWithFunc(py_func);
1147 value = 0;
1148 }
1149 else {
1150 value = PyC_Long_AsI32(ret);
1151
1152 if (value == -1 && PyErr_Occurred()) {
1153 PyC_Err_PrintWithFunc(py_func);
1154 value = 0;
1155 }
1156
1157 Py_DECREF(ret);
1158 }
1159
1161
1162 return value;
1163}
1164
1166 PropertyRNA *prop,
1167 int curr_value,
1168 bool is_set)
1169{
1171
1172 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1173 PyObject *py_func;
1174 PyObject *ret;
1175
1176 BLI_assert(prop_store != nullptr);
1177
1178 py_func = prop_store->py_data.get_transform_fn;
1179
1180 {
1181 PyObject *args = PyTuple_New(3);
1182 PyObject *self = pyrna_struct_as_instance(ptr);
1183 PyTuple_SET_ITEMS(args, self, PyLong_FromLong(curr_value), PyBool_FromLong(is_set));
1184
1185 ret = PyObject_CallObject(py_func, args);
1186
1187 Py_DECREF(args);
1188 }
1189
1190 int ret_value = curr_value;
1191 if (ret == nullptr) {
1192 PyC_Err_PrintWithFunc(py_func);
1193 }
1194 else {
1195 ret_value = PyC_Long_AsI32(ret);
1196
1197 if (ret_value == -1 && PyErr_Occurred()) {
1198 PyC_Err_PrintWithFunc(py_func);
1199 ret_value = curr_value;
1200 }
1201
1202 Py_DECREF(ret);
1203 }
1204
1206
1207 return ret_value;
1208}
1209
1210static void bpy_prop_int_set_fn(PointerRNA *ptr, PropertyRNA *prop, int value)
1211{
1213
1214 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1215 PyObject *py_func;
1216 PyObject *ret;
1217
1218 BLI_assert(prop_store != nullptr);
1219
1220 py_func = prop_store->py_data.set_fn;
1221
1222 {
1223 PyObject *args = PyTuple_New(2);
1224 PyObject *self = pyrna_struct_as_instance(ptr);
1225 PyTuple_SET_ITEMS(args, self, PyLong_FromLong(value));
1226
1227 ret = PyObject_CallObject(py_func, args);
1228
1229 Py_DECREF(args);
1230 }
1231
1232 if (ret == nullptr) {
1233 PyC_Err_PrintWithFunc(py_func);
1234 }
1235 else {
1236 if (ret != Py_None) {
1237 PyErr_SetString(PyExc_ValueError, "the return value must be None");
1238 PyC_Err_PrintWithFunc(py_func);
1239 }
1240
1241 Py_DECREF(ret);
1242 }
1243
1245}
1246
1248 PointerRNA *ptr, PropertyRNA *prop, int new_value, int curr_value, bool is_set)
1249{
1251
1252 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1253 PyObject *py_func;
1254 PyObject *ret;
1255
1256 BLI_assert(prop_store != nullptr);
1257
1258 py_func = prop_store->py_data.set_transform_fn;
1259
1260 {
1261 PyObject *args = PyTuple_New(4);
1262 PyObject *self = pyrna_struct_as_instance(ptr);
1263 PyTuple_SET_ITEMS(args,
1264 self,
1265 PyLong_FromLong(new_value),
1266 PyLong_FromLong(curr_value),
1267 PyBool_FromLong(is_set));
1268
1269 ret = PyObject_CallObject(py_func, args);
1270
1271 Py_DECREF(args);
1272 }
1273
1274 int ret_value = curr_value;
1275 if (ret == nullptr) {
1276 PyC_Err_PrintWithFunc(py_func);
1277 }
1278 else {
1279 ret_value = PyC_Long_AsI32(ret);
1280
1281 if (ret_value == -1 && PyErr_Occurred()) {
1282 PyC_Err_PrintWithFunc(py_func);
1283 ret_value = curr_value;
1284 }
1285
1286 Py_DECREF(ret);
1287 }
1288
1290
1291 return ret_value;
1292}
1293
1294static void bpy_prop_int_array_from_callback_or_error(PyObject *int_array_obj,
1295 const BPyPropArrayLength &array_len_info,
1296 PyObject *py_func,
1297 int *r_values)
1298{
1299 bool is_values_set = false;
1300
1301 if (int_array_obj != nullptr) {
1303 sizeof(*r_values),
1304 int_array_obj,
1305 &array_len_info,
1306 &PyLong_Type,
1307 "IntVectorProperty get callback") == -1)
1308 {
1309 PyC_Err_PrintWithFunc(py_func);
1310 }
1311 else {
1312 is_values_set = true;
1313 }
1314 }
1315
1316 if (is_values_set == false) {
1317 /* This is the flattened length for multi-dimensional arrays. */
1318 for (int i = 0; i < array_len_info.len_total; i++) {
1319 r_values[i] = 0;
1320 }
1321 }
1322
1323 Py_XDECREF(int_array_obj);
1324}
1325
1326static void bpy_prop_int_array_get_fn(PointerRNA *ptr, PropertyRNA *prop, int *values)
1327{
1329
1330 const BPyPropArrayLength array_len_info{ptr, prop};
1331 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1332 PyObject *py_func;
1333 PyObject *ret;
1334
1335 BLI_assert(prop_store != nullptr);
1336
1337 py_func = prop_store->py_data.get_fn;
1338
1339 {
1340 PyObject *args = PyTuple_New(1);
1341 PyObject *self = pyrna_struct_as_instance(ptr);
1342 PyTuple_SET_ITEMS(args, self);
1343
1344 ret = PyObject_CallObject(py_func, args);
1345
1346 Py_DECREF(args);
1347 }
1348
1349 bpy_prop_int_array_from_callback_or_error(ret, array_len_info, py_func, values);
1350
1352}
1353
1355 PointerRNA *ptr, PropertyRNA *prop, const int *curr_values, bool is_set, int *r_values)
1356{
1358
1359 const BPyPropArrayLength array_len_info{ptr, prop};
1360 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1361 PyObject *py_func;
1362 PyObject *ret;
1363
1364 BLI_assert(prop_store != nullptr);
1365
1366 py_func = prop_store->py_data.get_transform_fn;
1367
1368 {
1369 PyObject *args = PyTuple_New(3);
1370 PyObject *self = pyrna_struct_as_instance(ptr);
1372 args,
1373 self,
1374 bpy_py_object_from_prop_array_with_dims(curr_values, array_len_info, PyLong_Type),
1375 PyBool_FromLong(is_set));
1376
1377 ret = PyObject_CallObject(py_func, args);
1378
1379 Py_DECREF(args);
1380 }
1381
1382 bpy_prop_int_array_from_callback_or_error(ret, array_len_info, py_func, r_values);
1383
1385}
1386
1387static void bpy_prop_int_array_set_fn(PointerRNA *ptr, PropertyRNA *prop, const int *values)
1388{
1390
1391 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1392 PyObject *py_func;
1393 PyObject *ret;
1394
1395 const BPyPropArrayLength array_len_info{ptr, prop};
1396
1397 BLI_assert(prop_store != nullptr);
1398
1399 py_func = prop_store->py_data.set_fn;
1400
1401 {
1402 PyObject *args = PyTuple_New(2);
1403 PyObject *self = pyrna_struct_as_instance(ptr);
1405 args, self, bpy_py_object_from_prop_array_with_dims(values, array_len_info, PyLong_Type));
1406
1407 ret = PyObject_CallObject(py_func, args);
1408
1409 Py_DECREF(args);
1410 }
1411
1412 if (ret == nullptr) {
1413 PyC_Err_PrintWithFunc(py_func);
1414 }
1415 else {
1416 if (ret != Py_None) {
1417 PyErr_SetString(PyExc_ValueError, "the return value must be None");
1418 PyC_Err_PrintWithFunc(py_func);
1419 }
1420
1421 Py_DECREF(ret);
1422 }
1423
1425}
1426
1428 PropertyRNA *prop,
1429 const int *new_values,
1430 const int *curr_values,
1431 bool is_set,
1432 int *r_final_values)
1433{
1435
1436 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1437 PyObject *py_func;
1438 PyObject *ret;
1439
1440 const BPyPropArrayLength array_len_info{ptr, prop};
1441
1442 BLI_assert(prop_store != nullptr);
1443
1444 py_func = prop_store->py_data.set_transform_fn;
1445
1446 {
1447 PyObject *args = PyTuple_New(4);
1448 PyObject *self = pyrna_struct_as_instance(ptr);
1450 args,
1451 self,
1452 bpy_py_object_from_prop_array_with_dims(new_values, array_len_info, PyLong_Type),
1453 bpy_py_object_from_prop_array_with_dims(curr_values, array_len_info, PyLong_Type),
1454 PyBool_FromLong(is_set));
1455
1456 ret = PyObject_CallObject(py_func, args);
1457
1458 Py_DECREF(args);
1459 }
1460
1461 bpy_prop_int_array_from_callback_or_error(ret, array_len_info, py_func, r_final_values);
1462
1464}
1465
1467
1468/* -------------------------------------------------------------------- */
1471
1473{
1475
1476 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1477 PyObject *py_func;
1478 PyObject *ret;
1479 float value;
1480
1481 BLI_assert(prop_store != nullptr);
1482
1483 py_func = prop_store->py_data.get_fn;
1484
1485 {
1486 PyObject *args = PyTuple_New(1);
1487 PyObject *self = pyrna_struct_as_instance(ptr);
1488 PyTuple_SET_ITEMS(args, self);
1489
1490 ret = PyObject_CallObject(py_func, args);
1491
1492 Py_DECREF(args);
1493 }
1494
1495 if (ret == nullptr) {
1496 PyC_Err_PrintWithFunc(py_func);
1497 value = 0.0f;
1498 }
1499 else {
1500 value = PyFloat_AsDouble(ret);
1501
1502 if (value == -1.0f && PyErr_Occurred()) {
1503 PyC_Err_PrintWithFunc(py_func);
1504 value = 0.0f;
1505 }
1506
1507 Py_DECREF(ret);
1508 }
1509
1511
1512 return value;
1513}
1514
1516 PropertyRNA *prop,
1517 float curr_value,
1518 bool is_set)
1519{
1521
1522 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1523 PyObject *py_func;
1524 PyObject *ret;
1525
1526 BLI_assert(prop_store != nullptr);
1527
1528 py_func = prop_store->py_data.get_transform_fn;
1529
1530 {
1531 PyObject *args = PyTuple_New(3);
1532 PyObject *self = pyrna_struct_as_instance(ptr);
1533 PyTuple_SET_ITEMS(args, self, PyFloat_FromDouble(curr_value), PyBool_FromLong(is_set));
1534
1535 ret = PyObject_CallObject(py_func, args);
1536
1537 Py_DECREF(args);
1538 }
1539
1540 float ret_value = curr_value;
1541 if (ret == nullptr) {
1542 PyC_Err_PrintWithFunc(py_func);
1543 }
1544 else {
1545 ret_value = PyFloat_AsDouble(ret);
1546
1547 if (ret_value == -1.0f && PyErr_Occurred()) {
1548 PyC_Err_PrintWithFunc(py_func);
1549 ret_value = curr_value;
1550 }
1551
1552 Py_DECREF(ret);
1553 }
1554
1556
1557 return ret_value;
1558}
1559
1560static void bpy_prop_float_set_fn(PointerRNA *ptr, PropertyRNA *prop, float value)
1561{
1563
1564 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1565 PyObject *py_func;
1566 PyObject *ret;
1567
1568 BLI_assert(prop_store != nullptr);
1569
1570 py_func = prop_store->py_data.set_fn;
1571
1572 {
1573 PyObject *args = PyTuple_New(2);
1574 PyObject *self = pyrna_struct_as_instance(ptr);
1575 PyTuple_SET_ITEMS(args, self, PyFloat_FromDouble(value));
1576
1577 ret = PyObject_CallObject(py_func, args);
1578
1579 Py_DECREF(args);
1580 }
1581
1582 if (ret == nullptr) {
1583 PyC_Err_PrintWithFunc(py_func);
1584 }
1585 else {
1586 if (ret != Py_None) {
1587 PyErr_SetString(PyExc_ValueError, "the return value must be None");
1588 PyC_Err_PrintWithFunc(py_func);
1589 }
1590
1591 Py_DECREF(ret);
1592 }
1593
1595}
1596
1598 PointerRNA *ptr, PropertyRNA *prop, float new_value, float curr_value, bool is_set)
1599{
1601
1602 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1603 PyObject *py_func;
1604 PyObject *ret;
1605
1606 BLI_assert(prop_store != nullptr);
1607
1608 py_func = prop_store->py_data.set_transform_fn;
1609
1610 {
1611 PyObject *args = PyTuple_New(4);
1612 PyObject *self = pyrna_struct_as_instance(ptr);
1613 PyTuple_SET_ITEMS(args,
1614 self,
1615 PyFloat_FromDouble(new_value),
1616 PyFloat_FromDouble(curr_value),
1617 PyBool_FromLong(is_set));
1618
1619 ret = PyObject_CallObject(py_func, args);
1620
1621 Py_DECREF(args);
1622 }
1623
1624 float ret_value = curr_value;
1625 if (ret == nullptr) {
1626 PyC_Err_PrintWithFunc(py_func);
1627 }
1628 else {
1629 ret_value = PyFloat_AsDouble(ret);
1630
1631 if (ret_value == -1.0f && PyErr_Occurred()) {
1632 PyC_Err_PrintWithFunc(py_func);
1633 ret_value = curr_value;
1634 }
1635
1636 Py_DECREF(ret);
1637 }
1638
1640
1641 return ret_value;
1642}
1643
1645 PyObject *float_array_obj,
1646 const BPyPropArrayLength &array_len_info,
1647 PyObject *py_func,
1648 const bool do_matrix_row_col_swap,
1649 float *r_values)
1650{
1651 bool is_values_set = false;
1652
1653 if (float_array_obj != nullptr) {
1655 sizeof(*r_values),
1656 float_array_obj,
1657 &array_len_info,
1658 &PyFloat_Type,
1659 "FloatVectorProperty get callback") == -1)
1660 {
1661 PyC_Err_PrintWithFunc(py_func);
1662 }
1663 else {
1664 /* Only for float types. */
1665 /* TODO: Clear and complete explanations about this matrix swap? */
1666 if (do_matrix_row_col_swap && bpy_prop_array_is_matrix_compatible(prop, &array_len_info)) {
1667 bpy_prop_array_matrix_swap_row_column_vn(r_values, &array_len_info);
1668 }
1669 is_values_set = true;
1670 }
1671 }
1672
1673 if (is_values_set == false) {
1674 /* This is the flattened length for multi-dimensional arrays. */
1675 for (int i = 0; i < array_len_info.len_total; i++) {
1676 r_values[i] = 0.0f;
1677 }
1678 }
1679
1680 Py_XDECREF(float_array_obj);
1681}
1682
1683static void bpy_prop_float_array_get_fn(PointerRNA *ptr, PropertyRNA *prop, float *values)
1684{
1686
1687 const BPyPropArrayLength array_len_info{ptr, prop};
1688 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1689 PyObject *py_func;
1690 PyObject *ret;
1691
1692 BLI_assert(prop_store != nullptr);
1693
1694 py_func = prop_store->py_data.get_fn;
1695
1696 {
1697 PyObject *args = PyTuple_New(1);
1698 PyObject *self = pyrna_struct_as_instance(ptr);
1699 PyTuple_SET_ITEMS(args, self);
1700
1701 ret = PyObject_CallObject(py_func, args);
1702
1703 Py_DECREF(args);
1704 }
1705
1706 /* Custom getter always needs to perform the matrix row/col swap. */
1707 bpy_prop_float_array_from_callback_or_error(prop, ret, array_len_info, py_func, true, values);
1708
1710}
1711
1713 PointerRNA *ptr, PropertyRNA *prop, const float *curr_values, bool is_set, float *r_values)
1714{
1716
1717 const BPyPropArrayLength array_len_info{ptr, prop};
1718 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1719 PyObject *py_func;
1720 PyObject *ret;
1721
1722 BLI_assert(prop_store != nullptr);
1723
1724 py_func = prop_store->py_data.get_transform_fn;
1725
1726 {
1727 PyObject *args = PyTuple_New(3);
1728 PyObject *self = pyrna_struct_as_instance(ptr);
1730 args,
1731 self,
1732 bpy_py_object_from_prop_array_with_dims(curr_values, array_len_info, PyFloat_Type),
1733 PyBool_FromLong(is_set));
1734
1735 ret = PyObject_CallObject(py_func, args);
1736
1737 Py_DECREF(args);
1738 }
1739
1740 /* If there is a custom py-defined 'get' callback, the row/col matrix swap has already been
1741 * performed, otherwise it needs to be done here. */
1742 const bool do_matrix_row_col_swap = prop_store->py_data.get_fn == nullptr;
1744 prop, ret, array_len_info, py_func, do_matrix_row_col_swap, r_values);
1745
1747}
1748
1749static void bpy_prop_float_array_set_fn(PointerRNA *ptr, PropertyRNA *prop, const float *values)
1750{
1752
1753 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1754 PyObject *py_func;
1755 PyObject *ret;
1756
1757 const BPyPropArrayLength array_len_info{ptr, prop};
1758
1759 BLI_assert(prop_store != nullptr);
1760
1761 py_func = prop_store->py_data.set_fn;
1762
1763 {
1764 PyObject *args = PyTuple_New(2);
1765 PyObject *self = pyrna_struct_as_instance(ptr);
1767 args, self, bpy_py_object_from_prop_array_with_dims(values, array_len_info, PyFloat_Type));
1768
1769 ret = PyObject_CallObject(py_func, args);
1770
1771 Py_DECREF(args);
1772 }
1773
1774 if (ret == nullptr) {
1775 PyC_Err_PrintWithFunc(py_func);
1776 }
1777 else {
1778 if (ret != Py_None) {
1779 PyErr_SetString(PyExc_ValueError, "the return value must be None");
1780 PyC_Err_PrintWithFunc(py_func);
1781 }
1782
1783 Py_DECREF(ret);
1784 }
1785
1787}
1788
1790 PropertyRNA *prop,
1791 const float *new_values,
1792 const float *curr_values,
1793 bool is_set,
1794 float *r_final_values)
1795{
1797
1798 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1799 PyObject *py_func;
1800 PyObject *ret;
1801
1802 const BPyPropArrayLength array_len_info{ptr, prop};
1803
1804 BLI_assert(prop_store != nullptr);
1805
1806 py_func = prop_store->py_data.set_transform_fn;
1807
1808 {
1809 PyObject *args = PyTuple_New(4);
1810 PyObject *self = pyrna_struct_as_instance(ptr);
1812 args,
1813 self,
1814 bpy_py_object_from_prop_array_with_dims(new_values, array_len_info, PyFloat_Type),
1815 bpy_py_object_from_prop_array_with_dims(curr_values, array_len_info, PyFloat_Type),
1816 PyBool_FromLong(is_set));
1817
1818 ret = PyObject_CallObject(py_func, args);
1819
1820 Py_DECREF(args);
1821 }
1822
1823 /* No need for matrix column/row swapping here unless the matrix data is read directly. */
1825 prop, ret, array_len_info, py_func, false, r_final_values);
1826
1828}
1829
1831
1832/* -------------------------------------------------------------------- */
1835
1836static std::optional<std::string> bpy_prop_string_from_callback_or_error(PyObject *str_obj,
1837 const size_t max_length,
1838 PyObject *py_func)
1839{
1840 std::optional<std::string> ret_value{};
1841
1842 /* TODO: handle bytes strings. */
1843 if (str_obj == nullptr) {
1844 PyC_Err_PrintWithFunc(py_func);
1845 }
1846 else if (!PyUnicode_Check(str_obj)) {
1847 PyErr_Format(
1848 PyExc_TypeError, "return value must be a string, not %.200s", Py_TYPE(str_obj)->tp_name);
1849 PyC_Err_PrintWithFunc(py_func);
1850 }
1851 else {
1852 /* NOTE: Python returns the length _without_ the `\0` terminator. */
1853 Py_ssize_t length;
1854 const char *ret_cstr = PyUnicode_AsUTF8AndSize(str_obj, &length);
1855 if (max_length && size_t(length) + 1 > max_length) {
1856 PyErr_Format(PyExc_ValueError,
1857 "return string must be of max length %zu, not %d",
1858 max_length - 1,
1859 length);
1860 PyC_Err_PrintWithFunc(py_func);
1861 }
1862 else {
1863 ret_value = {ret_cstr, size_t(length)};
1864 }
1865 }
1866
1867 Py_XDECREF(str_obj);
1868 return ret_value;
1869}
1870
1872{
1873 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1874 PyObject *py_func;
1875 PyObject *ret;
1876
1877 BLI_assert(prop_store != nullptr);
1878
1879 py_func = prop_store->py_data.get_fn;
1880
1881 {
1882 PyObject *args = PyTuple_New(1);
1883 PyObject *self = pyrna_struct_as_instance(ptr);
1884 PyTuple_SET_ITEMS(args, self);
1885
1886 ret = PyObject_CallObject(py_func, args);
1887
1888 Py_DECREF(args);
1889 }
1890
1892 .value_or("");
1893}
1894
1895static std::string bpy_prop_string_get_fn(PointerRNA *ptr, PropertyRNA *prop)
1896{
1898
1899 std::string ret_value = bpy_prop_string_get_locked_fn(ptr, prop);
1900
1902
1903 return ret_value;
1904}
1905
1907 PropertyRNA *prop,
1908 const std::string &curr_value,
1909 bool is_set)
1910{
1911 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1912 PyObject *py_func;
1913 PyObject *ret;
1914
1915 BLI_assert(prop_store != nullptr);
1916
1917 /* TODO: handle bytes strings. */
1918 py_func = prop_store->py_data.get_transform_fn;
1919
1920 {
1921 PyObject *args = PyTuple_New(3);
1922 PyObject *self = pyrna_struct_as_instance(ptr);
1924 args,
1925 self,
1926 PyUnicode_FromStringAndSize(curr_value.c_str(), Py_ssize_t(curr_value.size())),
1927 PyBool_FromLong(is_set));
1928
1929 ret = PyObject_CallObject(py_func, args);
1930
1931 Py_DECREF(args);
1932 }
1933
1935 .value_or(curr_value);
1936}
1937
1939 PropertyRNA *prop,
1940 const std::string &curr_value,
1941 bool is_set)
1942{
1944
1945 std::string ret_value = bpy_prop_string_get_transform_locked_fn(ptr, prop, curr_value, is_set);
1946
1948
1949 return ret_value;
1950}
1951
1953{
1955
1956 /* This bpyprops-specific length callback is only called when there is a custom `get` function.
1957 */
1958 std::string ret = bpy_prop_string_get_locked_fn(ptr, prop);
1959 const int length = int(ret.size());
1960
1962
1963 return length;
1964}
1965
1966static void bpy_prop_string_set_fn(PointerRNA *ptr, PropertyRNA *prop, const std::string &value)
1967{
1969
1970 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
1971 PyObject *py_func;
1972 PyObject *ret;
1973
1974 BLI_assert(prop_store != nullptr);
1975
1976 py_func = prop_store->py_data.set_fn;
1977
1978 {
1979 PyObject *args = PyTuple_New(2);
1980 PyObject *self = pyrna_struct_as_instance(ptr);
1981
1982 /* TODO: handle bytes strings. */
1983 const size_t max_length = RNA_property_string_maxlength(prop);
1984 if (max_length && value.size() >= max_length) {
1985 PyErr_Format(PyExc_ValueError,
1986 "the given string must be of max length %zu, not %zu",
1987 max_length - 1,
1988 value.size());
1989 PyC_Err_PrintWithFunc(py_func);
1990 }
1991 PyObject *py_value = PyUnicode_FromStringAndSize(value.c_str(), value.size());
1992 if (!py_value) {
1993 PyErr_SetString(PyExc_ValueError,
1994 "the given string value cannot be converted into a python string");
1995 PyC_Err_PrintWithFunc(py_func);
1996 py_value = Py_None;
1997 Py_INCREF(py_value);
1998 }
1999 PyTuple_SET_ITEMS(args, self, py_value);
2000
2001 ret = PyObject_CallObject(py_func, args);
2002
2003 Py_DECREF(args);
2004 }
2005
2006 if (ret == nullptr) {
2007 PyC_Err_PrintWithFunc(py_func);
2008 }
2009 else {
2010 if (ret != Py_None) {
2011 PyErr_SetString(PyExc_ValueError, "the return value must be None");
2012 PyC_Err_PrintWithFunc(py_func);
2013 }
2014
2015 Py_DECREF(ret);
2016 }
2017
2019}
2020
2022 PropertyRNA *prop,
2023 const std::string &new_value,
2024 const std::string &curr_value,
2025 bool is_set)
2026{
2028
2029 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
2030 PyObject *py_func;
2031 PyObject *ret;
2032
2033 BLI_assert(prop_store != nullptr);
2034
2035 py_func = prop_store->py_data.set_transform_fn;
2036
2037 {
2038 PyObject *args = PyTuple_New(4);
2039 PyObject *self = pyrna_struct_as_instance(ptr);
2041 args,
2042 self,
2043 PyUnicode_FromStringAndSize(new_value.c_str(), Py_ssize_t(new_value.size())),
2044 PyUnicode_FromStringAndSize(curr_value.c_str(), Py_ssize_t(curr_value.size())),
2045 PyBool_FromLong(is_set));
2046
2047 ret = PyObject_CallObject(py_func, args);
2048
2049 Py_DECREF(args);
2050 }
2051
2052 std::string ret_value = bpy_prop_string_from_callback_or_error(
2053 ret, RNA_property_string_maxlength(prop), py_func)
2054 .value_or(curr_value);
2055
2057
2058 return ret_value;
2059}
2060
2062 PyObject *py_func, PyObject *item, FunctionRef<void(StringPropertySearchVisitParams)> visit_fn)
2063{
2064 const char *text;
2065 const char *info = nullptr;
2066
2067 if (PyTuple_CheckExact(item)) {
2068 /* Positional only. */
2069 static const char *_keywords[] = {
2070 "",
2071 "",
2072 nullptr,
2073 };
2074 static _PyArg_Parser _parser = {
2075 "s" /* `text` */
2076 "s" /* `info` */
2077 ":search",
2078 _keywords,
2079 nullptr,
2080 };
2081 if (!_PyArg_ParseTupleAndKeywordsFast(item, nullptr, &_parser, &text, &info)) {
2082 PyC_Err_PrintWithFunc(py_func);
2083 return false;
2084 }
2085 }
2086 else {
2087 text = PyUnicode_AsUTF8(item);
2088 if (text == nullptr) [[unlikely]] {
2089 PyErr_Clear();
2090 PyErr_Format(PyExc_TypeError,
2091 "expected sequence of strings or tuple pairs of strings, not %.200s",
2092 Py_TYPE(item)->tp_name);
2093 PyC_Err_PrintWithFunc(py_func);
2094 return false;
2095 }
2096 }
2097
2098 StringPropertySearchVisitParams visit_params{};
2099 visit_params.text = text;
2100 visit_params.info = info ? info : "";
2101 visit_fn(visit_params);
2102 return true;
2103}
2104
2106 const bContext *C,
2107 PointerRNA *ptr,
2108 PropertyRNA *prop,
2109 const char *edit_text,
2111{
2112 PyGILState_STATE gilstate;
2113 if (C) {
2114 bpy_context_set(const_cast<bContext *>(C), &gilstate);
2115 }
2116 else {
2117 gilstate = PyGILState_Ensure();
2118 }
2119
2120 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
2121 PyObject *py_func;
2122 PyObject *ret;
2123
2124 BLI_assert(prop_store != nullptr);
2125
2126 py_func = prop_store->py_data.string_data.search_fn;
2127
2128 {
2129 PyObject *args = PyTuple_New(3);
2130 PyObject *self = pyrna_struct_as_instance(ptr);
2131 PyObject *py_context = reinterpret_cast<PyObject *>(bpy_context_module);
2132 PyObject *py_edit_text = PyUnicode_FromString(edit_text);
2133 Py_INCREF(py_context);
2134 PyTuple_SET_ITEMS(args, self, py_context, py_edit_text);
2135
2136 ret = PyObject_CallObject(py_func, args);
2137
2138 Py_DECREF(args);
2139 }
2140
2141 if (ret == nullptr) {
2142 PyC_Err_PrintWithFunc(py_func);
2143 }
2144 else {
2145 if (PyIter_Check(ret)) {
2146 /* Iterators / generator types. */
2147 PyObject *it;
2148 PyObject *(*iternext)(PyObject *);
2149 it = PyObject_GetIter(ret);
2150 if (it == nullptr) {
2151 PyC_Err_PrintWithFunc(py_func);
2152 }
2153 else {
2154 iternext = *Py_TYPE(it)->tp_iternext;
2155 for (;;) {
2156 PyObject *py_text = iternext(it);
2157 if (py_text == nullptr) {
2158 break;
2159 }
2160 const bool ok = bpy_prop_string_visit_fn_call(py_func, py_text, visit_fn);
2161 Py_DECREF(py_text);
2162 if (!ok) {
2163 break;
2164 }
2165 }
2166 Py_DECREF(it);
2167 if (PyErr_Occurred()) {
2168 if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
2169 PyErr_Clear();
2170 }
2171 else {
2172 PyC_Err_PrintWithFunc(py_func);
2173 }
2174 }
2175 }
2176 }
2177 else {
2178 /* Sequence (typically list/tuple). */
2179 PyObject *ret_fast = PySequence_Fast(
2180 ret,
2181 "StringProperty(...): "
2182 "return value from search callback was not a sequence, iterator or generator");
2183 if (ret_fast == nullptr) {
2184 PyC_Err_PrintWithFunc(py_func);
2185 }
2186 else {
2187 const Py_ssize_t ret_num = PySequence_Fast_GET_SIZE(ret_fast);
2188 PyObject **ret_fast_items = PySequence_Fast_ITEMS(ret_fast);
2189 for (Py_ssize_t i = 0; i < ret_num; i++) {
2190 const bool ok = bpy_prop_string_visit_fn_call(py_func, ret_fast_items[i], visit_fn);
2191 if (!ok) {
2192 break;
2193 }
2194 }
2195 Py_DECREF(ret_fast);
2196 }
2197 }
2198
2199 Py_DECREF(ret);
2200 }
2201
2202 if (C) {
2203 bpy_context_clear(const_cast<bContext *>(C), &gilstate);
2204 }
2205 else {
2206 PyGILState_Release(gilstate);
2207 }
2208}
2209
2211
2212/* -------------------------------------------------------------------- */
2215
2216static bool bpy_prop_pointer_poll_fn(PointerRNA *self, PointerRNA candidate, PropertyRNA *prop)
2217{
2219
2220 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
2221 PyObject *py_func;
2222 PyObject *ret;
2223 bool result;
2224
2225 BLI_assert(self != nullptr);
2226
2227 py_func = prop_store->py_data.pointer_data.poll_fn;
2228
2229 {
2230 PyObject *args = PyTuple_New(2);
2231 PyObject *py_self = pyrna_struct_as_instance(self);
2232 PyObject *py_candidate = pyrna_struct_as_instance(&candidate);
2233 PyTuple_SET_ITEMS(args, py_self, py_candidate);
2234
2235 ret = PyObject_CallObject(py_func, args);
2236
2237 Py_DECREF(args);
2238 }
2239
2240 if (ret == nullptr) {
2241 PyC_Err_PrintWithFunc(py_func);
2242 result = false;
2243 }
2244 else {
2245 result = PyObject_IsTrue(ret);
2246 Py_DECREF(ret);
2247 }
2248
2250
2251 return result;
2252}
2253
2255
2256/* -------------------------------------------------------------------- */
2259
2261{
2263
2264 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
2265 PyObject *py_func;
2266 PyObject *ret;
2267 int value;
2268
2269 BLI_assert(prop_store != nullptr);
2270
2271 py_func = prop_store->py_data.get_fn;
2272
2273 {
2274 PyObject *args = PyTuple_New(1);
2275 PyObject *self = pyrna_struct_as_instance(ptr);
2276 PyTuple_SET_ITEMS(args, self);
2277
2278 ret = PyObject_CallObject(py_func, args);
2279
2280 Py_DECREF(args);
2281 }
2282
2283 if (ret == nullptr) {
2284 PyC_Err_PrintWithFunc(py_func);
2285 value = RNA_property_enum_get_default(ptr, prop);
2286 }
2287 else {
2288 value = PyC_Long_AsI32(ret);
2289
2290 if (value == -1 && PyErr_Occurred()) {
2291 PyC_Err_PrintWithFunc(py_func);
2292 value = RNA_property_enum_get_default(ptr, prop);
2293 }
2294
2295 Py_DECREF(ret);
2296 }
2297
2299
2300 return value;
2301}
2302
2304 PropertyRNA *prop,
2305 int curr_value,
2306 bool is_set)
2307{
2309
2310 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
2311 PyObject *py_func;
2312 PyObject *ret;
2313
2314 BLI_assert(prop_store != nullptr);
2315
2316 py_func = prop_store->py_data.get_transform_fn;
2317
2318 {
2319 PyObject *args = PyTuple_New(3);
2320 PyObject *self = pyrna_struct_as_instance(ptr);
2321 PyTuple_SET_ITEMS(args, self, PyLong_FromLong(curr_value), PyBool_FromLong(is_set));
2322
2323 ret = PyObject_CallObject(py_func, args);
2324
2325 Py_DECREF(args);
2326 }
2327
2328 int ret_value = curr_value;
2329 if (ret == nullptr) {
2330 PyC_Err_PrintWithFunc(py_func);
2331 }
2332 else {
2333 ret_value = PyC_Long_AsI32(ret);
2334
2335 if (ret_value == -1 && PyErr_Occurred()) {
2336 PyC_Err_PrintWithFunc(py_func);
2337 ret_value = curr_value;
2338 }
2339
2340 Py_DECREF(ret);
2341 }
2342
2344
2345 return ret_value;
2346}
2347
2348static void bpy_prop_enum_set_fn(PointerRNA *ptr, PropertyRNA *prop, int value)
2349{
2351
2352 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
2353 PyObject *py_func;
2354 PyObject *ret;
2355
2356 BLI_assert(prop_store != nullptr);
2357
2358 py_func = prop_store->py_data.set_fn;
2359
2360 {
2361 PyObject *args = PyTuple_New(2);
2362 PyObject *self = pyrna_struct_as_instance(ptr);
2363 PyTuple_SET_ITEMS(args, self, PyLong_FromLong(value));
2364
2365 ret = PyObject_CallObject(py_func, args);
2366
2367 Py_DECREF(args);
2368 }
2369
2370 if (ret == nullptr) {
2371 PyC_Err_PrintWithFunc(py_func);
2372 }
2373 else {
2374 if (ret != Py_None) {
2375 PyErr_SetString(PyExc_ValueError, "the return value must be None");
2376 PyC_Err_PrintWithFunc(py_func);
2377 }
2378
2379 Py_DECREF(ret);
2380 }
2381
2383}
2384
2386 PointerRNA *ptr, PropertyRNA *prop, int new_value, int curr_value, bool is_set)
2387{
2389
2390 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
2391 PyObject *py_func;
2392 PyObject *ret;
2393
2394 BLI_assert(prop_store != nullptr);
2395
2396 py_func = prop_store->py_data.set_transform_fn;
2397
2398 {
2399 PyObject *args = PyTuple_New(4);
2400 PyObject *self = pyrna_struct_as_instance(ptr);
2401 PyTuple_SET_ITEMS(args,
2402 self,
2403 PyLong_FromLong(new_value),
2404 PyLong_FromLong(curr_value),
2405 PyBool_FromLong(is_set));
2406
2407 ret = PyObject_CallObject(py_func, args);
2408
2409 Py_DECREF(args);
2410 }
2411
2412 int ret_value = curr_value;
2413 if (ret == nullptr) {
2414 PyC_Err_PrintWithFunc(py_func);
2415 }
2416 else {
2417 ret_value = PyC_Long_AsI32(ret);
2418
2419 if (ret_value == -1 && PyErr_Occurred()) {
2420 PyC_Err_PrintWithFunc(py_func);
2421 ret_value = curr_value;
2422 }
2423
2424 Py_DECREF(ret);
2425 }
2426
2428
2429 return ret_value;
2430}
2431
2432/* utility function we need for parsing int's in an if statement */
2433static bool py_long_as_int(PyObject *py_long, int *r_int)
2434{
2435 if (PyLong_CheckExact(py_long)) {
2436 *r_int = int(PyLong_AS_LONG(py_long));
2437 return true;
2438 }
2439
2440 return false;
2441}
2442
2443#ifdef USE_ENUM_COPY_STRINGS
2444/* copies orig to buf, then sets orig to buf, returns copy length */
2445static size_t strswapbufcpy(char *buf, const char **orig)
2446{
2447 const char *src = *orig;
2448 char *dst = buf;
2449 size_t i = 0;
2450 *orig = buf;
2451 while ((*dst = *src)) {
2452 dst++;
2453 src++;
2454 i++;
2455 }
2456 return i + 1; /* include '\0' */
2457}
2458#endif
2459
2460static int icon_id_from_name(const char *name)
2461{
2462 const EnumPropertyItem *item;
2463
2464 if (name[0]) {
2465 for (item = rna_enum_icon_items; item->identifier; item++) {
2466 if (STREQ(item->name, name)) {
2467 return item->value;
2468 }
2469 }
2470 }
2471
2472 return 0;
2473}
2474
2475static const EnumPropertyItem *enum_items_from_py(PyObject *seq_fast,
2476 const bool is_enum_flag,
2477 PyObject *default_py,
2478 int *r_default_value)
2479{
2480 EnumPropertyItem *items;
2481 PyObject *item;
2482 const Py_ssize_t seq_len = PySequence_Fast_GET_SIZE(seq_fast);
2483 PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
2484 int i;
2485#ifdef USE_ENUM_COPY_STRINGS
2486 Py_ssize_t totbuf = 0;
2487#endif
2488 short default_used = 0;
2489 const char *default_str_cmp = nullptr;
2490 int default_int_cmp = 0;
2491
2492 if (is_enum_flag) {
2493 if (seq_len > RNA_ENUM_BITFLAG_SIZE) {
2494 PyErr_SetString(PyExc_TypeError,
2495 "EnumProperty(...): maximum " STRINGIFY(
2496 RNA_ENUM_BITFLAG_SIZE) " members for a ENUM_FLAG type property");
2497 return nullptr;
2498 }
2499 if (default_py && !PySet_Check(default_py)) {
2500 PyErr_Format(PyExc_TypeError,
2501 "EnumProperty(...): default option must be a 'set' "
2502 "type when ENUM_FLAG is enabled, not a '%.200s'",
2503 Py_TYPE(default_py)->tp_name);
2504 return nullptr;
2505 }
2506 }
2507 else {
2508 if (default_py) {
2509 if (!py_long_as_int(default_py, &default_int_cmp)) {
2510 default_str_cmp = PyUnicode_AsUTF8(default_py);
2511 if (default_str_cmp == nullptr) {
2512 PyErr_Format(PyExc_TypeError,
2513 "EnumProperty(...): default option must be a 'str' or 'int' "
2514 "type when ENUM_FLAG is disabled, not a '%.200s'",
2515 Py_TYPE(default_py)->tp_name);
2516 return nullptr;
2517 }
2518 }
2519 }
2520 }
2521
2522 /* blank value */
2523 *r_default_value = 0;
2524
2525 items = MEM_new_array_zeroed<EnumPropertyItem>(size_t(seq_len) + 1, "enum_items_from_py1");
2526
2527 for (i = 0; i < seq_len; i++) {
2528 EnumPropertyItem tmp = {0, "", 0, "", ""};
2529 const char *tmp_icon = nullptr;
2530 Py_ssize_t item_size;
2531 Py_ssize_t id_str_len;
2532 Py_ssize_t name_str_len;
2533 Py_ssize_t desc_str_len;
2534
2535 item = seq_fast_items[i];
2536
2537 if (PyTuple_CheckExact(item) && (item_size = PyTuple_GET_SIZE(item)) &&
2538 (item_size >= 3 && item_size <= 5) &&
2539 (tmp.identifier = PyUnicode_AsUTF8AndSize(PyTuple_GET_ITEM(item, 0), &id_str_len)) &&
2540 (tmp.name = PyUnicode_AsUTF8AndSize(PyTuple_GET_ITEM(item, 1), &name_str_len)) &&
2541 (tmp.description = PyUnicode_AsUTF8AndSize(PyTuple_GET_ITEM(item, 2), &desc_str_len)) &&
2542 /* TODO: number isn't ensured to be unique from the script author. */
2543 (item_size != 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value)) &&
2544 (item_size != 5 || ((py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.icon) ||
2545 (tmp_icon = PyUnicode_AsUTF8(PyTuple_GET_ITEM(item, 3)))) &&
2546 py_long_as_int(PyTuple_GET_ITEM(item, 4), &tmp.value))))
2547 {
2548 if (is_enum_flag) {
2549 if (item_size < 4) {
2550 tmp.value = 1 << i;
2551 }
2552
2553 if (default_py && PySet_Contains(default_py, PyTuple_GET_ITEM(item, 0))) {
2554 *r_default_value |= tmp.value;
2555 default_used++;
2556 }
2557 }
2558 else {
2559 if (item_size < 4) {
2560 tmp.value = i;
2561 }
2562
2563 if (default_py && default_used == 0) {
2564 if ((default_str_cmp != nullptr && STREQ(default_str_cmp, tmp.identifier)) ||
2565 (default_str_cmp == nullptr && default_int_cmp == tmp.value))
2566 {
2567 *r_default_value = tmp.value;
2568 default_used++; /* only ever 1 */
2569 }
2570 }
2571 }
2572
2573 if (tmp_icon) {
2574 tmp.icon = icon_id_from_name(tmp_icon);
2575 }
2576
2577 items[i] = tmp;
2578
2579#ifdef USE_ENUM_COPY_STRINGS
2580 /* Calculate combine string length. */
2581 totbuf += id_str_len + name_str_len + desc_str_len + 3; /* 3 is for '\0's */
2582#endif
2583 }
2584 else if (item == Py_None) {
2585 /* Only set since the rest is cleared. */
2586 items[i].identifier = "";
2587 }
2588 else {
2589 MEM_delete(items);
2590 PyErr_SetString(PyExc_TypeError,
2591 "EnumProperty(...): expected a tuple containing "
2592 "(identifier, name, description) and optionally an "
2593 "icon name and unique number");
2594 return nullptr;
2595 }
2596 }
2597
2598 if (is_enum_flag) {
2599 /* strict check that all set members were used */
2600 if (default_py && default_used != PySet_GET_SIZE(default_py)) {
2601 MEM_delete(items);
2602
2603 PyErr_Format(PyExc_TypeError,
2604 "EnumProperty(..., default={...}): set has %d unused member(s)",
2605 PySet_GET_SIZE(default_py) - default_used);
2606 return nullptr;
2607 }
2608 }
2609 else {
2610 if (default_py && default_used == 0) {
2611 MEM_delete(items);
2612
2613 if (default_str_cmp) {
2614 PyErr_Format(PyExc_TypeError,
2615 "EnumProperty(..., default=\'%s\'): not found in enum members",
2616 default_str_cmp);
2617 }
2618 else {
2619 PyErr_Format(PyExc_TypeError,
2620 "EnumProperty(..., default=%d): not found in enum members",
2621 default_int_cmp);
2622 }
2623 return nullptr;
2624 }
2625 }
2626
2627#ifdef USE_ENUM_COPY_STRINGS
2628 /* This would all work perfectly _but_ the python strings may be freed immediately after use,
2629 * so we need to duplicate them, ugh. annoying because it works most of the time without this. */
2630 {
2632 (sizeof(EnumPropertyItem) * (seq_len + 1)) + (sizeof(char) * totbuf),
2633 "enum_items_from_py2");
2634 EnumPropertyItem *items_ptr = items_dup;
2635 char *buf = ((char *)items_dup) + (sizeof(EnumPropertyItem) * (seq_len + 1));
2636 memcpy(items_dup, items, sizeof(EnumPropertyItem) * (seq_len + 1));
2637 for (i = 0; i < seq_len; i++, items_ptr++) {
2638 buf += strswapbufcpy(buf, &items_ptr->identifier);
2639 buf += strswapbufcpy(buf, &items_ptr->name);
2640 buf += strswapbufcpy(buf, &items_ptr->description);
2641 }
2642 MEM_delete(items);
2643 items = items_dup;
2644 }
2645/* end string duplication */
2646#endif
2647
2648 return items;
2649}
2650
2652 PointerRNA *ptr,
2653 PropertyRNA *prop,
2654 bool *r_free)
2655{
2656 PyGILState_STATE gilstate;
2657 if (C) {
2658 bpy_context_set(C, &gilstate);
2659 }
2660 else {
2661 gilstate = PyGILState_Ensure();
2662 }
2663
2664 BPyPropStore *prop_store = static_cast<BPyPropStore *>(RNA_property_py_data_get(prop));
2665 PyObject *py_func = prop_store->py_data.enum_data.itemf_fn;
2666 PyObject *items; /* returned from the function call */
2667
2668 const EnumPropertyItem *eitems = nullptr;
2669 int err = 0;
2670
2671 {
2672 PyObject *args = PyTuple_New(2);
2673 PyObject *self = pyrna_struct_as_instance(ptr);
2674 PyObject *py_context = C ? reinterpret_cast<PyObject *>(bpy_context_module) : Py_None;
2675 Py_INCREF(py_context);
2676 PyTuple_SET_ITEMS(args, self, py_context);
2677
2678 items = PyObject_CallObject(py_func, args);
2679
2680 Py_DECREF(args);
2681 }
2682
2683 if (items == nullptr) {
2684 err = -1;
2685 }
2686 else {
2687 PyObject *items_fast;
2688 int default_value_dummy = 0;
2689
2690 if (!(items_fast = PySequence_Fast(items,
2691 "EnumProperty(...): "
2692 "return value from the callback was not a sequence")))
2693 {
2694 err = -1;
2695 }
2696 else {
2697 eitems = enum_items_from_py(items_fast,
2698 (RNA_property_flag(prop) & PROP_ENUM_FLAG) != 0,
2699 nullptr,
2700 &default_value_dummy);
2701
2702 Py_DECREF(items_fast);
2703
2704 if (!eitems) {
2705 err = -1;
2706 }
2707 }
2708
2709 Py_DECREF(items);
2710 }
2711
2712 if (err != -1) { /* worked */
2713 *r_free = true;
2714 }
2715 else {
2716 PyC_Err_PrintWithFunc(py_func);
2717
2719 }
2720
2721 if (C) {
2722 bpy_context_clear(C, &gilstate);
2723 }
2724 else {
2725 PyGILState_Release(gilstate);
2726 }
2727
2728 return eitems;
2729}
2730
2731static int bpy_prop_callback_check(PyObject *py_func, const char *keyword, int argcount)
2732{
2733 if (py_func && py_func != Py_None) {
2734 if (!PyFunction_Check(py_func)) {
2735 PyErr_Format(PyExc_TypeError,
2736 "%s keyword: expected a function type, not a %.200s",
2737 keyword,
2738 Py_TYPE(py_func)->tp_name);
2739 return -1;
2740 }
2741
2742 PyCodeObject *f_code = reinterpret_cast<PyCodeObject *>(PyFunction_GET_CODE(py_func));
2743 if (f_code->co_argcount != argcount) {
2744 PyErr_Format(PyExc_TypeError,
2745 "%s keyword: expected a function taking %d arguments, not %d",
2746 keyword,
2747 argcount,
2748 f_code->co_argcount);
2749 return -1;
2750 }
2751 }
2752
2753 return 0;
2754}
2755
2757
2758/* -------------------------------------------------------------------- */
2761
2762static void bpy_prop_callback_assign_update(PropertyRNA *prop, PyObject *update_fn)
2763{
2764 /* assume this is already checked for type and arg length */
2765 if (update_fn && update_fn != Py_None) {
2766 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2767
2769 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.update_fn, update_fn);
2770 }
2771}
2772
2773static void bpy_prop_callback_assign_pointer(PropertyRNA *prop, PyObject *poll_fn)
2774{
2775 if (poll_fn && poll_fn != Py_None) {
2776 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2777
2778 RNA_def_property_poll_runtime(prop, reinterpret_cast<const void *>(bpy_prop_pointer_poll_fn));
2779 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.pointer_data.poll_fn, poll_fn);
2780 }
2781}
2782
2784 PyObject *get_fn,
2785 PyObject *set_fn,
2786 PyObject *get_transform_fn,
2787 PyObject *set_transform_fn)
2788{
2789 BooleanPropertyGetFunc rna_get_fn = nullptr;
2790 BooleanPropertySetFunc rna_set_fn = nullptr;
2791 BooleanPropertyGetTransformFunc rna_get_transform_fn = nullptr;
2792 BooleanPropertySetTransformFunc rna_set_transform_fn = nullptr;
2793
2794 if (get_fn && get_fn != Py_None) {
2795 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2796
2797 rna_get_fn = bpy_prop_boolean_get_fn;
2798 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_fn, get_fn);
2799 }
2800
2801 if (set_fn && set_fn != Py_None) {
2802 if (!rna_get_fn) {
2803 PyErr_SetString(PyExc_ValueError,
2804 "The `set` callback is defined without a matching `get` function, this is "
2805 "not supported. `set_transform` should probably be used instead?");
2806 return false;
2807 }
2808
2809 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2810
2811 rna_set_fn = bpy_prop_boolean_set_fn;
2812 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_fn, set_fn);
2813 }
2814
2815 if (get_transform_fn && get_transform_fn != Py_None) {
2816 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2817
2818 rna_get_transform_fn = bpy_prop_boolean_get_transform_fn;
2819 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_transform_fn, get_transform_fn);
2820 }
2821
2822 if (set_transform_fn && set_transform_fn != Py_None) {
2823 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2824
2825 rna_set_transform_fn = bpy_prop_boolean_set_transform_fn;
2826 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_transform_fn, set_transform_fn);
2827 }
2828
2830 prop, rna_get_fn, rna_set_fn, rna_get_transform_fn, rna_set_transform_fn);
2831
2832 return true;
2833}
2834
2836 PyObject *get_fn,
2837 PyObject *set_fn,
2838 PyObject *get_transform_fn,
2839 PyObject *set_transform_fn)
2840{
2841 BooleanArrayPropertyGetFunc rna_get_fn = nullptr;
2842 BooleanArrayPropertySetFunc rna_set_fn = nullptr;
2843 BooleanArrayPropertyGetTransformFunc rna_get_transform_fn = nullptr;
2844 BooleanArrayPropertySetTransformFunc rna_set_transform_fn = nullptr;
2845
2846 if (get_fn && get_fn != Py_None) {
2847 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2848
2849 rna_get_fn = bpy_prop_boolean_array_get_fn;
2850 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_fn, get_fn);
2851 }
2852
2853 if (set_fn && set_fn != Py_None) {
2854 if (!rna_get_fn) {
2855 PyErr_SetString(PyExc_ValueError,
2856 "The `set` callback is defined without a matching `get` function, this is "
2857 "not supported. `set_transform` should probably be used instead?");
2858 return false;
2859 }
2860
2861 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2862
2863 rna_set_fn = bpy_prop_boolean_array_set_fn;
2864 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_fn, set_fn);
2865 }
2866
2867 if (get_transform_fn && get_transform_fn != Py_None) {
2868 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2869
2870 rna_get_transform_fn = bpy_prop_boolean_array_get_transform_fn;
2871 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_transform_fn, get_transform_fn);
2872 }
2873
2874 if (set_transform_fn && set_transform_fn != Py_None) {
2875 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2876
2877 rna_set_transform_fn = bpy_prop_boolean_array_set_transform_fn;
2878 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_transform_fn, set_transform_fn);
2879 }
2880
2882 prop, rna_get_fn, rna_set_fn, rna_get_transform_fn, rna_set_transform_fn);
2883
2884 return true;
2885}
2886
2888 PyObject *get_fn,
2889 PyObject *set_fn,
2890 PyObject *get_transform_fn,
2891 PyObject *set_transform_fn)
2892{
2893 IntPropertyGetFunc rna_get_fn = nullptr;
2894 IntPropertySetFunc rna_set_fn = nullptr;
2895 IntPropertyGetTransformFunc rna_get_transform_fn = nullptr;
2896 IntPropertySetTransformFunc rna_set_transform_fn = nullptr;
2897
2898 if (get_fn && get_fn != Py_None) {
2899 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2900
2901 rna_get_fn = bpy_prop_int_get_fn;
2902 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_fn, get_fn);
2903 }
2904
2905 if (set_fn && set_fn != Py_None) {
2906 if (!rna_get_fn) {
2907 PyErr_SetString(PyExc_ValueError,
2908 "The `set` callback is defined without a matching `get` function, this is "
2909 "not supported. `set_transform` should probably be used instead?");
2910 return false;
2911 }
2912
2913 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2914
2915 rna_set_fn = bpy_prop_int_set_fn;
2916 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_fn, set_fn);
2917 }
2918
2919 if (get_transform_fn && get_transform_fn != Py_None) {
2920 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2921
2922 rna_get_transform_fn = bpy_prop_int_get_transform_fn;
2923 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_transform_fn, get_transform_fn);
2924 }
2925
2926 if (set_transform_fn && set_transform_fn != Py_None) {
2927 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2928
2929 rna_set_transform_fn = bpy_prop_int_set_transform_fn;
2930 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_transform_fn, set_transform_fn);
2931 }
2932
2934 prop, rna_get_fn, rna_set_fn, nullptr, rna_get_transform_fn, rna_set_transform_fn);
2935
2936 return true;
2937}
2938
2940 PyObject *get_fn,
2941 PyObject *set_fn,
2942 PyObject *get_transform_fn,
2943 PyObject *set_transform_fn)
2944{
2945 IntArrayPropertyGetFunc rna_get_fn = nullptr;
2946 IntArrayPropertySetFunc rna_set_fn = nullptr;
2947 IntArrayPropertyGetTransformFunc rna_get_transform_fn = nullptr;
2948 IntArrayPropertySetTransformFunc rna_set_transform_fn = nullptr;
2949
2950 if (get_fn && get_fn != Py_None) {
2951 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2952
2953 rna_get_fn = bpy_prop_int_array_get_fn;
2954 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_fn, get_fn);
2955 }
2956
2957 if (set_fn && set_fn != Py_None) {
2958 if (!rna_get_fn) {
2959 PyErr_SetString(PyExc_ValueError,
2960 "The `set` callback is defined without a matching `get` function, this is "
2961 "not supported. `set_transform` should probably be used instead?");
2962 }
2963
2964 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2965
2966 rna_set_fn = bpy_prop_int_array_set_fn;
2967 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_fn, set_fn);
2968 }
2969
2970 if (get_transform_fn && get_transform_fn != Py_None) {
2971 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2972
2973 rna_get_transform_fn = bpy_prop_int_array_get_transform_fn;
2974 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_transform_fn, get_transform_fn);
2975 }
2976
2977 if (set_transform_fn && set_transform_fn != Py_None) {
2978 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2979
2980 rna_set_transform_fn = bpy_prop_int_array_set_transform_fn;
2981 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_transform_fn, set_transform_fn);
2982 }
2983
2985 prop, rna_get_fn, rna_set_fn, nullptr, rna_get_transform_fn, rna_set_transform_fn);
2986}
2987
2989 PyObject *get_fn,
2990 PyObject *set_fn,
2991 PyObject *get_transform_fn,
2992 PyObject *set_transform_fn)
2993{
2994 FloatPropertyGetFunc rna_get_fn = nullptr;
2995 FloatPropertySetFunc rna_set_fn = nullptr;
2996 FloatPropertyGetTransformFunc rna_get_transform_fn = nullptr;
2997 FloatPropertySetTransformFunc rna_set_transform_fn = nullptr;
2998
2999 if (get_fn && get_fn != Py_None) {
3000 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3001
3002 rna_get_fn = bpy_prop_float_get_fn;
3003 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_fn, get_fn);
3004 }
3005
3006 if (set_fn && set_fn != Py_None) {
3007 if (!rna_get_fn) {
3008 PyErr_SetString(PyExc_ValueError,
3009 "The `set` callback is defined without a matching `get` function, this is "
3010 "not supported. `set_transform` should probably be used instead?");
3011 return false;
3012 }
3013
3014 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3015
3016 rna_set_fn = bpy_prop_float_set_fn;
3017 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_fn, set_fn);
3018 }
3019
3020 if (get_transform_fn && get_transform_fn != Py_None) {
3021 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3022
3023 rna_get_transform_fn = bpy_prop_float_get_transform_fn;
3024 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_transform_fn, get_transform_fn);
3025 }
3026
3027 if (set_transform_fn && set_transform_fn != Py_None) {
3028 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3029
3030 rna_set_transform_fn = bpy_prop_float_set_transform_fn;
3031 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_transform_fn, set_transform_fn);
3032 }
3033
3035 prop, rna_get_fn, rna_set_fn, nullptr, rna_get_transform_fn, rna_set_transform_fn);
3036
3037 return true;
3038}
3039
3041 PyObject *get_fn,
3042 PyObject *set_fn,
3043 PyObject *get_transform_fn,
3044 PyObject *set_transform_fn)
3045{
3046 FloatArrayPropertyGetFunc rna_get_fn = nullptr;
3047 FloatArrayPropertySetFunc rna_set_fn = nullptr;
3048 FloatArrayPropertyGetTransformFunc rna_get_transform_fn = nullptr;
3049 FloatArrayPropertySetTransformFunc rna_set_transform_fn = nullptr;
3050
3051 if (get_fn && get_fn != Py_None) {
3052 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3053
3054 rna_get_fn = bpy_prop_float_array_get_fn;
3055 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_fn, get_fn);
3056 }
3057
3058 if (set_fn && set_fn != Py_None) {
3059 if (!rna_get_fn) {
3060 PyErr_SetString(PyExc_ValueError,
3061 "The `set` callback is defined without a matching `get` function, this is "
3062 "not supported. `set_transform` should probably be used instead?");
3063 }
3064
3065 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3066
3067 rna_set_fn = bpy_prop_float_array_set_fn;
3068 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_fn, set_fn);
3069 }
3070
3071 if (get_transform_fn && get_transform_fn != Py_None) {
3072 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3073
3074 rna_get_transform_fn = bpy_prop_float_array_get_transform_fn;
3075 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_transform_fn, get_transform_fn);
3076 }
3077
3078 if (set_transform_fn && set_transform_fn != Py_None) {
3079 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3080
3081 rna_set_transform_fn = bpy_prop_float_array_set_transform_fn;
3082 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_transform_fn, set_transform_fn);
3083 }
3084
3086 prop, rna_get_fn, rna_set_fn, nullptr, rna_get_transform_fn, rna_set_transform_fn);
3087}
3088
3090 PyObject *get_fn,
3091 PyObject *set_fn,
3092 PyObject *get_transform_fn,
3093 PyObject *set_transform_fn,
3094 PyObject *search_fn,
3095 const eStringPropertySearchFlag search_flag)
3096{
3097 StringPropertyGetFunc rna_get_fn = nullptr;
3098 StringPropertyLengthFunc rna_length_fn = nullptr;
3099 StringPropertySetFunc rna_set_fn = nullptr;
3100 StringPropertySearchFunc rna_search_fn = nullptr;
3101 StringPropertyGetTransformFunc rna_get_transform_fn = nullptr;
3102 StringPropertySetTransformFunc rna_set_transform_fn = nullptr;
3103
3104 if (get_fn && get_fn != Py_None) {
3105 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3106
3107 rna_get_fn = bpy_prop_string_get_fn;
3108 rna_length_fn = bpy_prop_string_length_fn;
3109 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_fn, get_fn);
3110 }
3111
3112 if (set_fn && set_fn != Py_None) {
3113 if (!rna_get_fn) {
3114 PyErr_SetString(PyExc_ValueError,
3115 "The `set` callback is defined without a matching `get` function, this is "
3116 "not supported. `set_transform` should probably be used instead?");
3117 return false;
3118 }
3119
3120 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3121
3122 rna_set_fn = bpy_prop_string_set_fn;
3123 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_fn, set_fn);
3124 }
3125
3126 if (get_transform_fn && get_transform_fn != Py_None) {
3127 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3128
3129 rna_get_transform_fn = bpy_prop_string_get_transform_fn;
3130 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_transform_fn, get_transform_fn);
3131 }
3132
3133 if (set_transform_fn && set_transform_fn != Py_None) {
3134 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3135
3136 rna_set_transform_fn = bpy_prop_string_set_transform_fn;
3137 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_transform_fn, set_transform_fn);
3138 }
3139
3140 if (search_fn) {
3141 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3142
3144 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.string_data.search_fn, search_fn);
3145 }
3146
3148 prop, rna_get_fn, rna_length_fn, rna_set_fn, rna_get_transform_fn, rna_set_transform_fn);
3149 if (rna_search_fn) {
3150 RNA_def_property_string_search_func_runtime(prop, rna_search_fn, search_flag);
3151 }
3152
3153 return true;
3154}
3155
3157 PyObject *get_fn,
3158 PyObject *set_fn,
3159 PyObject *itemf_fn,
3160 PyObject *get_transform_fn,
3161 PyObject *set_transform_fn)
3162{
3163 EnumPropertyGetFunc rna_get_fn = nullptr;
3164 EnumPropertySetFunc rna_set_fn = nullptr;
3165 EnumPropertyGetTransformFunc rna_get_transform_fn = nullptr;
3166 EnumPropertySetTransformFunc rna_set_transform_fn = nullptr;
3167 EnumPropertyItemFunc rna_itemf_fn = nullptr;
3168
3169 if (get_fn && get_fn != Py_None) {
3170 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3171
3172 rna_get_fn = bpy_prop_enum_get_fn;
3173 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_fn, get_fn);
3174 }
3175
3176 if (set_fn && set_fn != Py_None) {
3177 if (!rna_get_fn) {
3178 PyErr_SetString(PyExc_ValueError,
3179 "The `set` callback is defined without a matching `get` function, this is "
3180 "not supported. `set_transform` should probably be used instead?");
3181 return false;
3182 }
3183
3184 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3185
3186 rna_set_fn = bpy_prop_enum_set_fn;
3187 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_fn, set_fn);
3188 }
3189
3190 if (itemf_fn && itemf_fn != Py_None) {
3191 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3192 rna_itemf_fn = bpy_prop_enum_itemf_fn;
3193 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.enum_data.itemf_fn, itemf_fn);
3194 }
3195
3196 if (get_transform_fn && get_transform_fn != Py_None) {
3197 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3198
3199 rna_get_transform_fn = bpy_prop_enum_get_transform_fn;
3200 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.get_transform_fn, get_transform_fn);
3201 }
3202
3203 if (set_transform_fn && set_transform_fn != Py_None) {
3204 BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
3205
3206 rna_set_transform_fn = bpy_prop_enum_set_transform_fn;
3207 ASSIGN_PYOBJECT_INCREF(prop_store->py_data.set_transform_fn, set_transform_fn);
3208 }
3209
3211 prop, rna_get_fn, rna_set_fn, rna_itemf_fn, rna_get_transform_fn, rna_set_transform_fn);
3212
3213 return true;
3214}
3215
3217
3218/* -------------------------------------------------------------------- */
3221
3236 PyObject *args,
3237 PyObject *kw,
3238 PyObject *method_object,
3239 PyObject **r_deferred_result)
3240{
3241 /* This must be the methods of one of the main property types defined in this file. */
3242 BLI_assert(PyCFunction_CheckExact(method_object));
3243
3244 const int args_len = PyTuple_GET_SIZE(args);
3245 PyMethodDef *method_def = (reinterpret_cast<PyCFunctionObject *>(method_object))->m_ml;
3246
3247 /* Call this function with the first argument set to `self`. */
3248 if (args_len == 1) {
3249 self = PyTuple_GET_ITEM(args, 0);
3250 args = PyTuple_New(0);
3251
3252 /* This will be #BPy_BoolProperty or one of the functions that define a type. */
3253 PyCFunctionWithKeywords method_fn = (PyCFunctionWithKeywords)(void *)method_def->ml_meth;
3254 *r_deferred_result = method_fn(self, args, kw);
3255 Py_DECREF(args);
3256 /* May be an error (depending on `r_deferred_result`). */
3257 return nullptr;
3258 }
3259
3260 const char *error_prefix = method_def->ml_name;
3261 if (args_len > 1) {
3262 PyErr_Format(PyExc_ValueError, "%s: all args must be keywords", error_prefix);
3263 *r_deferred_result = nullptr;
3264 /* An error. */
3265 return nullptr;
3266 }
3267
3268 StructRNA *srna = srna_from_self(self, error_prefix);
3269 if (srna == nullptr) {
3270 *r_deferred_result = PyErr_Occurred() ?
3271 nullptr :
3272 bpy_prop_deferred_data_CreatePyObject(method_object, kw);
3273 /* May be an error (depending on `r_deferred_result`). */
3274 return nullptr;
3275 }
3276
3277/* Crash if this is ever used by accident! */
3278#ifndef NDEBUG
3279 *r_deferred_result = reinterpret_cast<PyObject *>(intptr_t(1));
3280#endif
3281
3282 /* No error or deferred result, perform registration immediately. */
3283 return srna;
3284}
3285
3297
3301static int bpy_prop_arg_parse_id(PyObject *o, void *p)
3302{
3303 BPy_PropIDParse *parse_data = static_cast<BPy_PropIDParse *>(p);
3304 StructRNA *srna = parse_data->srna;
3305
3306 if (!PyUnicode_Check(o)) {
3307 PyErr_Format(PyExc_TypeError, "expected a string (got %.200s)", Py_TYPE(o)->tp_name);
3308 return 0;
3309 }
3310
3311 Py_ssize_t id_len;
3312 const char *id;
3313
3314 id = PyUnicode_AsUTF8AndSize(o, &id_len);
3315 if (id_len >= MAX_IDPROP_NAME) [[unlikely]] {
3316 PyErr_Format(PyExc_TypeError, "'%.200s' too long, max length is %d", id, MAX_IDPROP_NAME - 1);
3317 return 0;
3318 }
3319
3320 parse_data->prop_free_handle = nullptr;
3322 -1) [[unlikely]]
3323 {
3324 PyErr_Format(PyExc_TypeError,
3325 "'%s' is defined as a non-dynamic type for '%s'",
3326 id,
3327 RNA_struct_identifier(srna));
3328 return 0;
3329 }
3330 parse_data->value = id;
3331 return 1;
3332}
3333
3341
3346static int bpy_prop_arg_parse_tag_defines(PyObject *o, void *p)
3347{
3349 parse_data->base.items = RNA_struct_property_tag_defines(parse_data->srna);
3350 if (parse_data->base.items == nullptr) {
3351 PyErr_Format(PyExc_TypeError,
3352 "property-tags not available for '%s'",
3353 RNA_struct_identifier(parse_data->srna));
3354 return 0;
3355 }
3356 return pyrna_enum_bitfield_parse_set(o, &parse_data->base);
3357}
3358
3360
3361/* -------------------------------------------------------------------- */
3364
3365#define BPY_PROPDEF_NAME_DOC \
3366 " :param name: Name used in the user interface.\n" \
3367 " :type name: str\n"
3368
3369#define BPY_PROPDEF_DESC_DOC \
3370 " :param description: Text used for the tooltip and api documentation.\n" \
3371 " :type description: str\n"
3372
3373#define BPY_PROPDEF_CTXT_DOC \
3374 " :param translation_context: Text used as context to disambiguate translations.\n" \
3375 " :type translation_context: str\n"
3376
3377#define BPY_PROPDEF_UNIT_DOC \
3378 " :param unit: Enumerator in :ref:`rna_enum_property_unit_items`.\n" \
3379 " :type unit: str\n"
3380
3381#define BPY_PROPDEF_DEFAULT_DOC(ty) \
3382 " :param default: The default value for this property.\n" \
3383 " :type default: " ty "\n"
3384
3385#define BPY_PROPDEF_NUM_MIN_DOC_(ty) \
3386 " :param min: Hard minimum, trying to assign a value below " \
3387 "will silently assign this minimum instead.\n" \
3388 " :type min: " ty "\n"
3389
3390#define BPY_PROPDEF_NUM_MAX_DOC_(ty) \
3391 " :param max: Hard maximum, trying to assign a value above " \
3392 "will silently assign this maximum instead.\n" \
3393 " :type max: " ty "\n"
3394
3395#define BPY_PROPDEF_NUM_MINMAX_DOC(ty) BPY_PROPDEF_NUM_MIN_DOC_(ty) BPY_PROPDEF_NUM_MAX_DOC_(ty)
3396
3397#define BPY_PROPDEF_NUM_SOFT_MIN_DOC_(ty) \
3398 " :param soft_min: Soft minimum (>= *min*), " \
3399 "user won't be able to drag the widget below this value in the UI.\n" \
3400 " :type soft_min: " ty "\n"
3401
3402#define BPY_PROPDEF_NUM_SOFT_MAX_DOC_(ty) \
3403 " :param soft_max: Soft maximum (<= *max*), " \
3404 "user won't be able to drag the widget above this value in the UI.\n" \
3405 " :type soft_max: " ty "\n"
3406
3407#define BPY_PROPDEF_NUM_SOFT_MINMAX_DOC(ty) \
3408 BPY_PROPDEF_NUM_SOFT_MIN_DOC_(ty) BPY_PROPDEF_NUM_SOFT_MAX_DOC_(ty)
3409
3410#define BPY_PROPDEF_VECSIZE_DOC \
3411 " :param size: Vector dimensions in [1, " STRINGIFY(PYRNA_STACK_ARRAY) "]. " \
3412"An int sequence can be used to define multi-dimension arrays.\n" \
3413" :type size: int | Sequence[int]\n"
3414
3415#define BPY_PROPDEF_INT_STEP_DOC \
3416 " :param step: Step of increment/decrement in UI, " \
3417 "in [1, 100], defaults to 1 (WARNING: unused currently!).\n" \
3418 " :type step: int\n"
3419
3420#define BPY_PROPDEF_FLOAT_STEP_DOC \
3421 " :param step: Step of increment/decrement in UI, " \
3422 "in [1, 100], defaults to 3 (WARNING: actual value is /100).\n" \
3423 " :type step: float\n"
3424
3425#define BPY_PROPDEF_FLOAT_PREC_DOC \
3426 " :param precision: Maximum number of decimal digits to display, in [0, 6]. Fraction is " \
3427 "automatically hidden for exact integer values of fields with unit 'NONE' or 'TIME' (frame " \
3428 "count) and step divisible by 100.\n" \
3429 " :type precision: int\n"
3430
3431#define BPY_PROPDEF_UPDATE_DOC \
3432 " :param update: Function to be called when this value is modified,\n" \
3433 " This function must take 2 values (self, context) and return None.\n" \
3434 " *Warning* there are no safety checks to avoid infinite recursion.\n" \
3435 " :type update: Callable[[:class:`bpy.types.bpy_struct`, :class:`bpy.types.Context`], " \
3436 "None] | None\n"
3437
3438#define BPY_PROPDEF_POLL_DOC \
3439 " :param poll: Function that determines whether an item is valid for this property.\n" \
3440 " The function must take 2 values (self, object) and return a boolean.\n" \
3441 "\n" \
3442 " .. note:: The return value will be checked only when assigning an item from the UI, " \
3443 "but it is still possible to assign an \"invalid\" item to the property directly.\n" \
3444 "\n" \
3445 " :type poll: Callable[[:class:`bpy.types.bpy_struct`, :class:`bpy.types.ID`], " \
3446 "bool] | None\n"
3447
3448#define BPY_PROPDEF_GET_DOC(ty) \
3449 " :param get: Function to be called when this value is 'read', and the default,\n" \
3450 " system-defined storage is not used for this property.\n" \
3451 " This function must take 1 value (self) and return the value of the property.\n" \
3452 "\n" \
3453 " .. note:: Defining this callback without a matching ``set`` one will make " \
3454 "the property read-only (even if ``READ_ONLY`` option is not set)." \
3455 "\n" \
3456 " :type get: Callable[[:class:`bpy.types.bpy_struct`], " ty "] | None\n"
3457
3458#define BPY_PROPDEF_SET_DOC(ty) \
3459 " :param set: Function to be called when this value is 'written', and the default,\n" \
3460 " system-defined storage is not used for this property.\n" \
3461 " This function must take 2 values (self, value) and return None.\n" \
3462 "\n" \
3463 " .. note:: Defining this callback without a matching ``get`` one is invalid." \
3464 "\n" \
3465 " :type set: Callable[[:class:`bpy.types.bpy_struct`, " ty "], None] | None\n"
3466
3467#define BPY_PROPDEF_GET_TRANSFORM_DOC(ty) \
3468 " :param get_transform: Function to be called when this value is 'read',\n" \
3469 " if some additional processing must be performed on the stored value.\n" \
3470 " This function must take three arguments (self, the stored value,\n" \
3471 " and a boolean indicating if the property is currently set),\n" \
3472 " and return the final, transformed value of the property.\n" \
3473 "\n" \
3474 " .. note:: The callback is responsible to ensure that value limits of the property " \
3475 "(min/max, length...) are respected. Otherwise a ValueError exception is raised.\n" \
3476 "\n" \
3477 " :type get_transform: Callable[[:class:`bpy.types.bpy_struct`, " ty ", bool], " ty \
3478 "] | None\n"
3479
3480#define BPY_PROPDEF_SET_TRANSFORM_DOC(ty) \
3481 " :param set_transform: Function to be called when this value is 'written',\n" \
3482 " if some additional processing must be performed on the given value before storing it.\n" \
3483 " This function must take four arguments (self, the given value to store,\n" \
3484 " the currently stored value ('raw' value, without any ``get_transform`` applied to " \
3485 "it),\n" \
3486 " and a boolean indicating if the property is currently set),\n" \
3487 " and return the final, transformed value of the property.\n" \
3488 "\n" \
3489 " .. note:: The callback is responsible to ensure that value limits (min/max, " \
3490 "length...) are respected. Otherwise a ValueError exception is raised.\n" \
3491 "\n" \
3492 " :type set_transform: " \
3493 "Callable[[:class:`bpy.types.bpy_struct`, " ty ", " ty ", bool], " ty "] | None\n"
3494
3495#define BPY_PROPDEF_SEARCH_DOC \
3496 " :param search: Function to be called to show candidates " \
3497 "for this string (shown in the UI).\n" \
3498 " This function must take 3 values (self, context, edit_text)\n" \
3499 " and return a sequence, iterator or generator where each item must be:\n" \
3500 "\n" \
3501 " - A single string (representing a candidate to display).\n" \
3502 " - A tuple-pair of strings, where the first is a candidate and the second\n" \
3503 " is additional information about the candidate.\n" \
3504 " :type search: Callable[[:class:`bpy.types.bpy_struct`, :class:`bpy.types.Context`, str], " \
3505 "Iterable[str | tuple[str, str]]" \
3506 "] | None\n" \
3507 " :param search_options: Set of strings in:\n" \
3508 "\n" \
3509 " - 'SORT' sorts the resulting items.\n" \
3510 " - 'SUGGESTION' lets the user enter values not found in search candidates.\n" \
3511 " **WARNING** disabling this flag causes the search callback to run on redraw,\n" \
3512 " so only disable this flag if it's not likely to cause performance issues.\n" \
3513 "\n" \
3514 " :type search_options: set[str]\n"
3515
3516#define BPY_PROPDEF_POINTER_TYPE_DOC \
3517 " :param type: A subclass of PropertyGroup or ID.\n" \
3518 " :type type: type[:class:`bpy.types.PropertyGroup` | :class:`bpy.types.ID`]\n"
3519
3520#define BPY_PROPDEF_COLLECTION_TYPE_DOC \
3521 " :param type: A subclass of a property group.\n" \
3522 " :type type: type[:class:`bpy.types.PropertyGroup`]\n"
3523
3524#define BPY_PROPDEF_TAGS_DOC \
3525 " :param tags: Enumerator of tags that are defined by parent class.\n" \
3526 " :type tags: set[str]\n"
3527
3528#define BPY_PROPDEF_RETURN_DOC \
3529 " :return: Opaque type used for registration.\n" \
3530 " :rtype: :class:`_PropertyDeferred`\n"
3531
3532#if 0
3533static int bpy_struct_id_used(StructRNA *srna, char *identifier)
3534{
3535 PointerRNA ptr = RNA_pointer_create_discrete(nullptr, srna, nullptr);
3536 return (RNA_struct_find_property(&ptr, identifier) != nullptr);
3537}
3538#endif
3539
3541
3542/* -------------------------------------------------------------------- */
3552
3554 /* Wrap. */
3555 BPy_BoolProperty_doc,
3556 ".. function:: BoolProperty("
3557 "*, "
3558 "name=\"\", "
3559 "description=\"\", "
3560 "translation_context=\"*\", "
3561 "default=False, "
3562 "options={'ANIMATABLE'}, "
3563 "override=set(), "
3564 "tags=set(), "
3565 "subtype='NONE', "
3566 "update=None, "
3567 "get=None, "
3568 "set=None, "
3569 "get_transform=None, "
3570 "set_transform=None)\n"
3571 "\n"
3572 " Returns a new boolean property definition.\n"
3573 "\n"
3574 /* Auto-format wrapping result is hard to read. */
3575 /* clang-format off */
3585 BPY_PROPDEF_GET_DOC("bool")
3586 BPY_PROPDEF_SET_DOC("bool")
3590 /* clang-format on */
3591);
3592static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
3593{
3594 StructRNA *srna;
3595 { /* Keep this block first. */
3596 PyObject *deferred_result;
3597 srna = bpy_prop_deferred_data_or_srna(self, args, kw, pymeth_BoolProperty, &deferred_result);
3598 if (srna == nullptr) {
3599 return deferred_result;
3600 }
3601 }
3602
3603 BPy_PropIDParse id_data{};
3604 id_data.srna = srna;
3605
3606 const char *name = nullptr, *description = "";
3607 const char *translation_context = nullptr;
3608 bool default_value = false;
3609 PropertyRNA *prop;
3610 BPy_EnumProperty_Parse options_enum{};
3611 options_enum.items = rna_enum_property_flag_items;
3612 options_enum.value = 0;
3613
3614 BPy_EnumProperty_Parse override_enum{};
3616 override_enum.value = 0;
3617
3619 tags_enum.srna = srna;
3620
3621 BPy_EnumProperty_Parse subtype_enum{};
3623 subtype_enum.value = PROP_NONE;
3624
3625 PyObject *update_fn = nullptr;
3626 PyObject *get_fn = nullptr;
3627 PyObject *set_fn = nullptr;
3628
3629 PyObject *get_transform_fn = nullptr;
3630 PyObject *set_transform_fn = nullptr;
3631
3632 static const char *_keywords[] = {
3633 "attr",
3634 "name",
3635 "description",
3636 "translation_context",
3637 "default",
3638 "options",
3639 "override",
3640 "tags",
3641 "subtype",
3642 "update",
3643 "get",
3644 "set",
3645 "get_transform",
3646 "set_transform",
3647 nullptr,
3648 };
3649 static _PyArg_Parser _parser = {
3650 "O&" /* `attr` */
3651 "|$" /* Optional, keyword only arguments. */
3652 "s" /* `name` */
3653 "s" /* `description` */
3654 "s" /* `translation_context` */
3655 "O&" /* `default` */
3656 "O&" /* `options` */
3657 "O&" /* `override` */
3658 "O&" /* `tags` */
3659 "O&" /* `subtype` */
3660 "O" /* `update` */
3661 "O" /* `get` */
3662 "O" /* `set` */
3663 "O" /* `get_transform` */
3664 "O" /* `set_transform` */
3665 ":BoolProperty",
3666 _keywords,
3667 nullptr,
3668 };
3669 if (!_PyArg_ParseTupleAndKeywordsFast(args,
3670 kw,
3671 &_parser,
3673 &id_data,
3674 &name,
3675 &description,
3676 &translation_context,
3678 &default_value,
3680 &options_enum,
3682 &override_enum,
3684 &tags_enum,
3686 &subtype_enum,
3687 &update_fn,
3688 &get_fn,
3689 &set_fn,
3690 &get_transform_fn,
3691 &set_transform_fn))
3692 {
3693 return nullptr;
3694 }
3695
3696 if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
3697 return nullptr;
3698 }
3699 if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
3700 return nullptr;
3701 }
3702 if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
3703 return nullptr;
3704 }
3705 if (bpy_prop_callback_check(get_transform_fn, "get_transform", 3) == -1) {
3706 return nullptr;
3707 }
3708 if (bpy_prop_callback_check(set_transform_fn, "set_transform", 4) == -1) {
3709 return nullptr;
3710 }
3711
3712 if (id_data.prop_free_handle != nullptr) {
3714 }
3715 prop = RNA_def_property(srna, id_data.value, PROP_BOOLEAN, subtype_enum.value);
3716
3717 RNA_def_property_boolean_default(prop, default_value);
3718 RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
3719 if (translation_context) {
3720 RNA_def_property_translation_context(prop, translation_context);
3721 }
3722
3723 if (tags_enum.base.is_set) {
3724 RNA_def_property_tags(prop, tags_enum.base.value);
3725 }
3726 if (options_enum.is_set) {
3727 bpy_prop_assign_flag(prop, options_enum.value);
3728 }
3729 if (override_enum.is_set) {
3730 bpy_prop_assign_flag_override(prop, override_enum.value);
3731 }
3732 bpy_prop_callback_assign_update(prop, update_fn);
3733 if (!bpy_prop_callback_assign_boolean(prop, get_fn, set_fn, get_transform_fn, set_transform_fn))
3734 {
3735 return nullptr;
3736 }
3738
3739 Py_RETURN_NONE;
3740}
3741
3743 /* Wrap. */
3744 BPy_BoolVectorProperty_doc,
3745 ".. function:: BoolVectorProperty("
3746 "*, "
3747 "name=\"\", "
3748 "description=\"\", "
3749 "translation_context=\"*\", "
3750 "default=(False, False, False), "
3751 "options={'ANIMATABLE'}, "
3752 "override=set(), "
3753 "tags=set(), "
3754 "subtype='NONE', "
3755 "size=3, "
3756 "update=None, "
3757 "get=None, "
3758 "set=None, "
3759 "get_transform=None, "
3760 "set_transform=None)\n"
3761 "\n"
3762 " Returns a new vector boolean property definition.\n"
3763 "\n"
3764 /* Auto-format wrapping result is hard to read. */
3765 /* clang-format off */
3769 " :param default: sequence of booleans the length of *size*.\n"
3770 " :type default: Sequence[bool]\n"
3777 BPY_PROPDEF_GET_DOC("Sequence[bool]")
3778 BPY_PROPDEF_SET_DOC("tuple[bool, ...]")
3779 BPY_PROPDEF_GET_TRANSFORM_DOC("Sequence[bool]")
3780 BPY_PROPDEF_SET_TRANSFORM_DOC("Sequence[bool]")
3782 /* clang-format on */
3783);
3784static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
3785{
3786 StructRNA *srna;
3787 { /* Keep this block first. */
3788 PyObject *deferred_result;
3790 self, args, kw, pymeth_BoolVectorProperty, &deferred_result);
3791 if (srna == nullptr) {
3792 return deferred_result;
3793 }
3794 }
3795
3796 BPy_PropIDParse id_data{};
3797 id_data.srna = srna;
3798
3799 const char *name = nullptr, *description = "";
3800 const char *translation_context = nullptr;
3801 Array<bool, RNA_STACK_ARRAY> default_value;
3802 BPyPropArrayLength array_len_info{};
3803 array_len_info.len_total = 3;
3804 PropertyRNA *prop;
3805 PyObject *default_py = nullptr;
3806
3807 BPy_EnumProperty_Parse options_enum{};
3808 options_enum.items = rna_enum_property_flag_items;
3809 options_enum.value = 0;
3810
3811 BPy_EnumProperty_Parse override_enum{};
3813 override_enum.value = 0;
3814
3816 tags_enum.srna = srna;
3817
3818 BPy_EnumProperty_Parse subtype_enum{};
3820 subtype_enum.value = PROP_NONE;
3821
3822 PyObject *update_fn = nullptr;
3823 PyObject *get_fn = nullptr;
3824 PyObject *set_fn = nullptr;
3825 PyObject *get_transform_fn = nullptr;
3826 PyObject *set_transform_fn = nullptr;
3827
3828 static const char *_keywords[] = {
3829 "attr",
3830 "name",
3831 "description",
3832 "translation_context",
3833 "default",
3834 "options",
3835 "override",
3836 "tags",
3837 "subtype",
3838 "size",
3839 "update",
3840 "get",
3841 "set",
3842 "get_transform",
3843 "set_transform",
3844 nullptr,
3845 };
3846 static _PyArg_Parser _parser = {
3847 "O&" /* `attr` */
3848 "|$" /* Optional, keyword only arguments. */
3849 "s" /* `name` */
3850 "s" /* `description` */
3851 "s" /* `translation_context` */
3852 "O" /* `default` */
3853 "O&" /* `options` */
3854 "O&" /* `override` */
3855 "O&" /* `tags` */
3856 "O&" /* `subtype` */
3857 "O&" /* `size` */
3858 "O" /* `update` */
3859 "O" /* `get` */
3860 "O" /* `set` */
3861 "O" /* `get_transform` */
3862 "O" /* `set_transform` */
3863 ":BoolVectorProperty",
3864 _keywords,
3865 nullptr,
3866 };
3867 if (!_PyArg_ParseTupleAndKeywordsFast(args,
3868 kw,
3869 &_parser,
3871 &id_data,
3872 &name,
3873 &description,
3874 &translation_context,
3875 &default_py,
3877 &options_enum,
3879 &override_enum,
3881 &tags_enum,
3883 &subtype_enum,
3885 &array_len_info,
3886 &update_fn,
3887 &get_fn,
3888 &set_fn,
3889 &get_transform_fn,
3890 &set_transform_fn))
3891 {
3892 return nullptr;
3893 }
3894
3895 if (default_py != nullptr) {
3896 default_value.reinitialize(array_len_info.len_total);
3897 if (bpy_prop_array_from_py_with_dims(default_value.data(),
3898 sizeof(*default_value.data()),
3899 default_py,
3900 &array_len_info,
3901 &PyBool_Type,
3902 "BoolVectorProperty(default=sequence)") == -1)
3903 {
3904 return nullptr;
3905 }
3906 }
3907
3908 if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
3909 return nullptr;
3910 }
3911 if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
3912 return nullptr;
3913 }
3914 if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
3915 return nullptr;
3916 }
3917 if (bpy_prop_callback_check(get_transform_fn, "get_transform", 3) == -1) {
3918 return nullptr;
3919 }
3920 if (bpy_prop_callback_check(set_transform_fn, "set_transform", 4) == -1) {
3921 return nullptr;
3922 }
3923
3924 if (id_data.prop_free_handle != nullptr) {
3926 }
3927 prop = RNA_def_property(srna, id_data.value, PROP_BOOLEAN, subtype_enum.value);
3928
3929 if (array_len_info.dims_len == 0) {
3930 RNA_def_property_array(prop, array_len_info.len_total);
3931 if (default_py != nullptr) {
3932 RNA_def_property_boolean_array_default(prop, default_value.data());
3933 }
3934 }
3935 else {
3936 RNA_def_property_multi_array(prop, array_len_info.dims_len, array_len_info.dims);
3937 if (default_py != nullptr) {
3938 RNA_def_property_boolean_array_default(prop, default_value.data());
3939 }
3940 }
3941
3942 RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
3943 if (translation_context) {
3944 RNA_def_property_translation_context(prop, translation_context);
3945 }
3946
3947 if (tags_enum.base.is_set) {
3948 RNA_def_property_tags(prop, tags_enum.base.value);
3949 }
3950 if (options_enum.is_set) {
3951 bpy_prop_assign_flag(prop, options_enum.value);
3952 }
3953 if (override_enum.is_set) {
3954 bpy_prop_assign_flag_override(prop, override_enum.value);
3955 }
3956 bpy_prop_callback_assign_update(prop, update_fn);
3957 bpy_prop_callback_assign_boolean_array(prop, get_fn, set_fn, get_transform_fn, set_transform_fn);
3959
3960 Py_RETURN_NONE;
3961}
3962
3964 /* Wrap. */
3965 BPy_IntProperty_doc,
3966 ".. function:: IntProperty("
3967 "*, "
3968 "name=\"\", "
3969 "description=\"\", "
3970 "translation_context=\"*\", "
3971 "default=0, "
3972 "min=-2**31, max=2**31-1, "
3973 "soft_min=-2**31, soft_max=2**31-1, "
3974 "step=1, "
3975 "options={'ANIMATABLE'}, "
3976 "override=set(), "
3977 "tags=set(), "
3978 "subtype='NONE', "
3979 "update=None, "
3980 "get=None, "
3981 "set=None, "
3982 "get_transform=None, "
3983 "set_transform=None)\n"
3984 "\n"
3985 " Returns a new int property definition.\n"
3986 "\n"
3987 /* Auto-format wrapping result is hard to read. */
3988 /* clang-format off */
4001 BPY_PROPDEF_GET_DOC("int")
4002 BPY_PROPDEF_SET_DOC("int")
4006 /* clang-format on */
4007);
4008static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
4009{
4010 StructRNA *srna;
4011 { /* Keep this block first. */
4012 PyObject *deferred_result;
4013 srna = bpy_prop_deferred_data_or_srna(self, args, kw, pymeth_IntProperty, &deferred_result);
4014 if (srna == nullptr) {
4015 return deferred_result;
4016 }
4017 }
4018
4019 BPy_PropIDParse id_data{};
4020 id_data.srna = srna;
4021
4022 const char *name = nullptr, *description = "";
4023 const char *translation_context = nullptr;
4024 int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX;
4025 int step = 1;
4026 int default_value = 0;
4027 PropertyRNA *prop;
4028
4029 BPy_EnumProperty_Parse options_enum{};
4030 options_enum.items = rna_enum_property_flag_items;
4031 options_enum.value = 0;
4032
4033 BPy_EnumProperty_Parse override_enum{};
4035 override_enum.value = 0;
4036
4038 tags_enum.srna = srna;
4039
4040 BPy_EnumProperty_Parse subtype_enum{};
4042 subtype_enum.value = PROP_NONE;
4043
4044 PyObject *update_fn = nullptr;
4045 PyObject *get_fn = nullptr;
4046 PyObject *set_fn = nullptr;
4047 PyObject *get_transform_fn = nullptr;
4048 PyObject *set_transform_fn = nullptr;
4049
4050 static const char *_keywords[] = {
4051 "attr", "name", "description", "translation_context",
4052 "default", "min", "max", "soft_min",
4053 "soft_max", "step", "options", "override",
4054 "tags", "subtype", "update", "get",
4055 "set", "get_transform", "set_transform", nullptr,
4056 };
4057 static _PyArg_Parser _parser = {
4058 "O&" /* `attr` */
4059 "|$" /* Optional, keyword only arguments. */
4060 "s" /* `name` */
4061 "s" /* `description` */
4062 "s" /* `translation_context` */
4063 "i" /* `default` */
4064 "i" /* `min` */
4065 "i" /* `max` */
4066 "i" /* `soft_min` */
4067 "i" /* `soft_max` */
4068 "i" /* `step` */
4069 "O&" /* `options` */
4070 "O&" /* `override` */
4071 "O&" /* `tags` */
4072 "O&" /* `subtype` */
4073 "O" /* `update` */
4074 "O" /* `get` */
4075 "O" /* `set` */
4076 "O" /* `get_transform` */
4077 "O" /* `set_transform` */
4078 ":IntProperty",
4079 _keywords,
4080 nullptr,
4081 };
4082 if (!_PyArg_ParseTupleAndKeywordsFast(args,
4083 kw,
4084 &_parser,
4086 &id_data,
4087 &name,
4088 &description,
4089 &translation_context,
4090 &default_value,
4091 &min,
4092 &max,
4093 &soft_min,
4094 &soft_max,
4095 &step,
4097 &options_enum,
4099 &override_enum,
4101 &tags_enum,
4103 &subtype_enum,
4104 &update_fn,
4105 &get_fn,
4106 &set_fn,
4107 &get_transform_fn,
4108 &set_transform_fn))
4109 {
4110 return nullptr;
4111 }
4112
4113 if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
4114 return nullptr;
4115 }
4116 if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
4117 return nullptr;
4118 }
4119 if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
4120 return nullptr;
4121 }
4122 if (bpy_prop_callback_check(get_transform_fn, "get_transform", 3) == -1) {
4123 return nullptr;
4124 }
4125 if (bpy_prop_callback_check(set_transform_fn, "set_transform", 4) == -1) {
4126 return nullptr;
4127 }
4128
4129 if (id_data.prop_free_handle != nullptr) {
4131 }
4132 prop = RNA_def_property(srna, id_data.value, PROP_INT, subtype_enum.value);
4133
4134 RNA_def_property_int_default(prop, default_value);
4135 RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
4136 if (translation_context) {
4137 RNA_def_property_translation_context(prop, translation_context);
4138 }
4140 RNA_def_property_ui_range(prop, std::max(soft_min, min), std::min(soft_max, max), step, 3);
4141
4142 if (tags_enum.base.is_set) {
4143 RNA_def_property_tags(prop, tags_enum.base.value);
4144 }
4145 if (options_enum.is_set) {
4146 bpy_prop_assign_flag(prop, options_enum.value);
4147 }
4148 if (override_enum.is_set) {
4149 bpy_prop_assign_flag_override(prop, override_enum.value);
4150 }
4151 bpy_prop_callback_assign_update(prop, update_fn);
4152 bpy_prop_callback_assign_int(prop, get_fn, set_fn, get_transform_fn, set_transform_fn);
4154
4155 Py_RETURN_NONE;
4156}
4157
4159 /* Wrap. */
4160 BPy_IntVectorProperty_doc,
4161 ".. function:: IntVectorProperty("
4162 "*, "
4163 "name=\"\", "
4164 "description=\"\", "
4165 "translation_context=\"*\", "
4166 "default=(0, 0, 0), min=-2**31, max=2**31-1, "
4167 "soft_min=-2**31, "
4168 "soft_max=2**31-1, "
4169 "step=1, "
4170 "options={'ANIMATABLE'}, "
4171 "override=set(), "
4172 "tags=set(), "
4173 "subtype='NONE', "
4174 "size=3, "
4175 "update=None, "
4176 "get=None, "
4177 "set=None, "
4178 "get_transform=None, "
4179 "set_transform=None)\n"
4180 "\n"
4181 " Returns a new vector int property definition.\n"
4182 "\n"
4183 /* Auto-format wrapping result is hard to read. */
4184 /* clang-format off */
4188 " :param default: sequence of ints the length of *size*.\n"
4189 " :type default: Sequence[int]\n"
4199 BPY_PROPDEF_GET_DOC("Sequence[int]")
4200 BPY_PROPDEF_SET_DOC("tuple[int, ...]")
4201 BPY_PROPDEF_GET_TRANSFORM_DOC("Sequence[int]")
4202 BPY_PROPDEF_SET_TRANSFORM_DOC("Sequence[int]")
4204 /* clang-format on */
4205);
4206static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
4207{
4208 StructRNA *srna;
4209 { /* Keep this block first. */
4210 PyObject *deferred_result;
4212 self, args, kw, pymeth_IntVectorProperty, &deferred_result);
4213 if (srna == nullptr) {
4214 return deferred_result;
4215 }
4216 }
4217
4218 BPy_PropIDParse id_data{};
4219 id_data.srna = srna;
4220
4221 const char *name = nullptr, *description = "";
4222 const char *translation_context = nullptr;
4223 int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX;
4224 int step = 1;
4225 Array<int, RNA_STACK_ARRAY> default_value;
4226 BPyPropArrayLength array_len_info{};
4227 array_len_info.len_total = 3;
4228 PropertyRNA *prop;
4229 PyObject *default_py = nullptr;
4230
4231 BPy_EnumProperty_Parse options_enum{};
4232 options_enum.items = rna_enum_property_flag_items;
4233 options_enum.value = 0;
4234
4235 BPy_EnumProperty_Parse override_enum{};
4237 override_enum.value = 0;
4238
4240 tags_enum.srna = srna;
4241
4242 BPy_EnumProperty_Parse subtype_enum{};
4244 subtype_enum.value = PROP_NONE;
4245
4246 PyObject *update_fn = nullptr;
4247 PyObject *get_fn = nullptr;
4248 PyObject *set_fn = nullptr;
4249 PyObject *get_transform_fn = nullptr;
4250 PyObject *set_transform_fn = nullptr;
4251
4252 static const char *_keywords[] = {
4253 "attr", "name", "description", "translation_context",
4254 "default", "min", "max", "soft_min",
4255 "soft_max", "step", "options", "override",
4256 "tags", "subtype", "size", "update",
4257 "get", "set", "get_transform", "set_transform",
4258 nullptr,
4259 };
4260 static _PyArg_Parser _parser = {
4261 "O&" /* `attr` */
4262 "|$" /* Optional, keyword only arguments. */
4263 "s" /* `name` */
4264 "s" /* `description` */
4265 "s" /* `translation_context` */
4266 "O" /* `default` */
4267 "i" /* `min` */
4268 "i" /* `max` */
4269 "i" /* `soft_min` */
4270 "i" /* `soft_max` */
4271 "i" /* `step` */
4272 "O&" /* `options` */
4273 "O&" /* `override` */
4274 "O&" /* `tags` */
4275 "O&" /* `subtype` */
4276 "O&" /* `size` */
4277 "O" /* `update` */
4278 "O" /* `get` */
4279 "O" /* `set` */
4280 "O" /* `get_transform` */
4281 "O" /* `set_transform` */
4282 ":IntVectorProperty",
4283 _keywords,
4284 nullptr,
4285 };
4286 if (!_PyArg_ParseTupleAndKeywordsFast(args,
4287 kw,
4288 &_parser,
4290 &id_data,
4291 &name,
4292 &description,
4293 &translation_context,
4294 &default_py,
4295 &min,
4296 &max,
4297 &soft_min,
4298 &soft_max,
4299 &step,
4301 &options_enum,
4303 &override_enum,
4305 &tags_enum,
4307 &subtype_enum,
4309 &array_len_info,
4310 &update_fn,
4311 &get_fn,
4312 &set_fn,
4313 &get_transform_fn,
4314 &set_transform_fn))
4315 {
4316 return nullptr;
4317 }
4318
4319 if (default_py != nullptr) {
4320 default_value.reinitialize(array_len_info.len_total);
4321 if (bpy_prop_array_from_py_with_dims(default_value.data(),
4322 sizeof(*default_value.data()),
4323 default_py,
4324 &array_len_info,
4325 &PyLong_Type,
4326 "IntVectorProperty(default=sequence)") == -1)
4327 {
4328 return nullptr;
4329 }
4330 }
4331
4332 if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
4333 return nullptr;
4334 }
4335 if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
4336 return nullptr;
4337 }
4338 if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
4339 return nullptr;
4340 }
4341 if (bpy_prop_callback_check(get_transform_fn, "get_transform", 3) == -1) {
4342 return nullptr;
4343 }
4344 if (bpy_prop_callback_check(set_transform_fn, "set_transform", 4) == -1) {
4345 return nullptr;
4346 }
4347
4348 if (id_data.prop_free_handle != nullptr) {
4350 }
4351 prop = RNA_def_property(srna, id_data.value, PROP_INT, subtype_enum.value);
4352
4353 if (array_len_info.dims_len == 0) {
4354 RNA_def_property_array(prop, array_len_info.len_total);
4355 if (default_py != nullptr) {
4356 RNA_def_property_int_array_default(prop, default_value.data());
4357 }
4358 }
4359 else {
4360 RNA_def_property_multi_array(prop, array_len_info.dims_len, array_len_info.dims);
4361 if (default_py != nullptr) {
4362 RNA_def_property_int_array_default(prop, default_value.data());
4363 }
4364 }
4365
4367 RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
4368 if (translation_context) {
4369 RNA_def_property_translation_context(prop, translation_context);
4370 }
4371 RNA_def_property_ui_range(prop, std::max(soft_min, min), std::min(soft_max, max), step, 3);
4372
4373 if (tags_enum.base.is_set) {
4374 RNA_def_property_tags(prop, tags_enum.base.value);
4375 }
4376 if (options_enum.is_set) {
4377 bpy_prop_assign_flag(prop, options_enum.value);
4378 }
4379 if (override_enum.is_set) {
4380 bpy_prop_assign_flag_override(prop, override_enum.value);
4381 }
4382 bpy_prop_callback_assign_update(prop, update_fn);
4383 bpy_prop_callback_assign_int_array(prop, get_fn, set_fn, get_transform_fn, set_transform_fn);
4385
4386 Py_RETURN_NONE;
4387}
4388
4390 /* Wrap. */
4391 BPy_FloatProperty_doc,
4392 ".. function:: FloatProperty("
4393 "*, "
4394 "name=\"\", "
4395 "description=\"\", "
4396 "translation_context=\"*\", "
4397 "default=0.0, "
4398 "min=-3.402823e+38, max=3.402823e+38, "
4399 "soft_min=-3.402823e+38, soft_max=3.402823e+38, "
4400 "step=3, "
4401 "precision=2, "
4402 "options={'ANIMATABLE'}, "
4403 "override=set(), "
4404 "tags=set(), "
4405 "subtype='NONE', "
4406 "unit='NONE', "
4407 "update=None, "
4408 "get=None, "
4409 "set=None, "
4410 "get_transform=None, "
4411 "set_transform=None)\n"
4412 "\n"
4413 " Returns a new float (single precision) property definition.\n"
4414 "\n"
4415 /* Auto-format wrapping result is hard to read. */
4416 /* clang-format off */
4431 BPY_PROPDEF_GET_DOC("float")
4432 BPY_PROPDEF_SET_DOC("float")
4436 /* clang-format on */
4437);
4438static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
4439{
4440 StructRNA *srna;
4441 { /* Keep this block first. */
4442 PyObject *deferred_result;
4443 srna = bpy_prop_deferred_data_or_srna(self, args, kw, pymeth_FloatProperty, &deferred_result);
4444 if (srna == nullptr) {
4445 return deferred_result;
4446 }
4447 }
4448
4449 BPy_PropIDParse id_data{};
4450 id_data.srna = srna;
4451
4452 const char *name = nullptr, *description = "";
4453 const char *translation_context = nullptr;
4454 float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX;
4455 float step = 3;
4456 float default_value = 0.0f;
4457 int precision = 2;
4458 PropertyRNA *prop;
4459
4460 BPy_EnumProperty_Parse options_enum{};
4461 options_enum.items = rna_enum_property_flag_items;
4462 options_enum.value = 0;
4463
4464 BPy_EnumProperty_Parse override_enum{};
4466 override_enum.value = 0;
4467
4469 tags_enum.srna = srna;
4470
4471 BPy_EnumProperty_Parse subtype_enum{};
4473 subtype_enum.value = PROP_NONE;
4474
4475 BPy_EnumProperty_Parse unit_enum{};
4477 unit_enum.value = PROP_UNIT_NONE;
4478
4479 PyObject *update_fn = nullptr;
4480 PyObject *get_fn = nullptr;
4481 PyObject *set_fn = nullptr;
4482 PyObject *get_transform_fn = nullptr;
4483 PyObject *set_transform_fn = nullptr;
4484
4485 static const char *_keywords[] = {
4486 "attr", "name", "description", "translation_context",
4487 "default", "min", "max", "soft_min",
4488 "soft_max", "step", "precision", "options",
4489 "override", "tags", "subtype", "unit",
4490 "update", "get", "set", "get_transform",
4491 "set_transform", nullptr,
4492 };
4493 static _PyArg_Parser _parser = {
4494 "O&" /* `attr` */
4495 "|$" /* Optional, keyword only arguments. */
4496 "s" /* `name` */
4497 "s" /* `description` */
4498 "s" /* `translation_context` */
4499 "f" /* `default` */
4500 "f" /* `min` */
4501 "f" /* `max` */
4502 "f" /* `soft_min` */
4503 "f" /* `soft_max` */
4504 "f" /* `step` */
4505 "i" /* `precision` */
4506 "O&" /* `options` */
4507 "O&" /* `override` */
4508 "O&" /* `tags` */
4509 "O&" /* `subtype` */
4510 "O&" /* `unit` */
4511 "O" /* `update` */
4512 "O" /* `get` */
4513 "O" /* `set` */
4514 "O" /* `get_transform` */
4515 "O" /* `set_transform` */
4516 ":FloatProperty",
4517 _keywords,
4518 nullptr,
4519 };
4520 if (!_PyArg_ParseTupleAndKeywordsFast(args,
4521 kw,
4522 &_parser,
4524 &id_data,
4525 &name,
4526 &description,
4527 &translation_context,
4528 &default_value,
4529 &min,
4530 &max,
4531 &soft_min,
4532 &soft_max,
4533 &step,
4534 &precision,
4536 &options_enum,
4538 &override_enum,
4540 &tags_enum,
4542 &subtype_enum,
4544 &unit_enum,
4545 &update_fn,
4546 &get_fn,
4547 &set_fn,
4548 &get_transform_fn,
4549 &set_transform_fn))
4550 {
4551 return nullptr;
4552 }
4553
4554 if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
4555 return nullptr;
4556 }
4557 if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
4558 return nullptr;
4559 }
4560 if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
4561 return nullptr;
4562 }
4563 if (bpy_prop_callback_check(get_transform_fn, "get_transform", 3) == -1) {
4564 return nullptr;
4565 }
4566 if (bpy_prop_callback_check(set_transform_fn, "set_transform", 4) == -1) {
4567 return nullptr;
4568 }
4569
4570 if (id_data.prop_free_handle != nullptr) {
4572 }
4573 prop = RNA_def_property(srna, id_data.value, PROP_FLOAT, subtype_enum.value | unit_enum.value);
4574
4575 RNA_def_property_float_default(prop, default_value);
4577 RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
4578 if (translation_context) {
4579 RNA_def_property_translation_context(prop, translation_context);
4580 }
4582 prop, std::max(soft_min, min), std::min(soft_max, max), step, precision);
4583
4584 if (tags_enum.base.is_set) {
4585 RNA_def_property_tags(prop, tags_enum.base.value);
4586 }
4587 if (options_enum.is_set) {
4588 bpy_prop_assign_flag(prop, options_enum.value);
4589 }
4590 if (override_enum.is_set) {
4591 bpy_prop_assign_flag_override(prop, override_enum.value);
4592 }
4593 bpy_prop_callback_assign_update(prop, update_fn);
4594 bpy_prop_callback_assign_float(prop, get_fn, set_fn, get_transform_fn, set_transform_fn);
4596
4597 Py_RETURN_NONE;
4598}
4599
4601 /* Wrap. */
4602 BPy_FloatVectorProperty_doc,
4603 ".. function:: FloatVectorProperty("
4604 "*, "
4605 "name=\"\", "
4606 "description=\"\", "
4607 "translation_context=\"*\", "
4608 "default=(0.0, 0.0, 0.0), "
4609 "min=-sys.float_info.max, max=sys.float_info.max, "
4610 "soft_min=-sys.float_info.max, soft_max=sys.float_info.max, "
4611 "step=3, "
4612 "precision=2, "
4613 "options={'ANIMATABLE'}, "
4614 "override=set(), "
4615 "tags=set(), "
4616 "subtype='NONE', "
4617 "unit='NONE', "
4618 "size=3, "
4619 "update=None, "
4620 "get=None, "
4621 "set=None, "
4622 "get_transform=None, "
4623 "set_transform=None)\n"
4624 "\n"
4625 " Returns a new vector float property definition.\n"
4626 "\n"
4627 /* Auto-format wrapping result is hard to read. */
4628 /* clang-format off */
4632 " :param default: Sequence of floats the length of *size*.\n"
4633 " :type default: Sequence[float]\n"
4645 BPY_PROPDEF_GET_DOC("Sequence[float]")
4646 BPY_PROPDEF_SET_DOC("tuple[float, ...]")
4647 BPY_PROPDEF_GET_TRANSFORM_DOC("Sequence[float]")
4648 BPY_PROPDEF_SET_TRANSFORM_DOC("Sequence[float]")
4650 /* clang-format on */
4651);
4652static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
4653{
4654 StructRNA *srna;
4655 { /* Keep this block first. */
4656 PyObject *deferred_result;
4658 self, args, kw, pymeth_FloatVectorProperty, &deferred_result);
4659 if (srna == nullptr) {
4660 return deferred_result;
4661 }
4662 }
4663
4664 BPy_PropIDParse id_data{};
4665 id_data.srna = srna;
4666
4667 const char *name = nullptr, *description = "";
4668 const char *translation_context = nullptr;
4669 float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX;
4670 float step = 3;
4671 Array<float, RNA_STACK_ARRAY> default_value;
4672 int precision = 2;
4673 BPyPropArrayLength array_len_info{};
4674 array_len_info.len_total = 3;
4675 PropertyRNA *prop;
4676 PyObject *default_py = nullptr;
4677
4678 BPy_EnumProperty_Parse options_enum{};
4679 options_enum.items = rna_enum_property_flag_items;
4680 options_enum.value = 0;
4681
4682 BPy_EnumProperty_Parse override_enum{};
4684 override_enum.value = 0;
4685
4687 tags_enum.srna = srna;
4688
4689 BPy_EnumProperty_Parse subtype_enum{};
4691 subtype_enum.value = PROP_NONE;
4692
4693 BPy_EnumProperty_Parse unit_enum{};
4695 unit_enum.value = PROP_UNIT_NONE;
4696
4697 PyObject *update_fn = nullptr;
4698 PyObject *get_fn = nullptr;
4699 PyObject *set_fn = nullptr;
4700 PyObject *get_transform_fn = nullptr;
4701 PyObject *set_transform_fn = nullptr;
4702
4703 static const char *_keywords[] = {
4704 "attr", "name", "description", "translation_context",
4705 "default", "min", "max", "soft_min",
4706 "soft_max", "step", "precision", "options",
4707 "override", "tags", "subtype", "unit",
4708 "size", "update", "get", "set",
4709 "get_transform", "set_transform", nullptr,
4710 };
4711 static _PyArg_Parser _parser = {
4712 "O&" /* `attr` */
4713 "|$" /* Optional, keyword only arguments. */
4714 "s" /* `name` */
4715 "s" /* `description` */
4716 "s" /* `translation_context` */
4717 "O" /* `default` */
4718 "f" /* `min` */
4719 "f" /* `max` */
4720 "f" /* `soft_min` */
4721 "f" /* `soft_max` */
4722 "f" /* `step` */
4723 "i" /* `precision` */
4724 "O&" /* `options` */
4725 "O&" /* `override` */
4726 "O&" /* `tags` */
4727 "O&" /* `subtype` */
4728 "O&" /* `unit` */
4729 "O&" /* `size` */
4730 "O" /* `update` */
4731 "O" /* `get` */
4732 "O" /* `set` */
4733 "O" /* `get_transform` */
4734 "O" /* `set_transform` */
4735 ":FloatVectorProperty",
4736 _keywords,
4737 nullptr,
4738 };
4739 if (!_PyArg_ParseTupleAndKeywordsFast(args,
4740 kw,
4741 &_parser,
4743 &id_data,
4744 &name,
4745 &description,
4746 &translation_context,
4747 &default_py,
4748 &min,
4749 &max,
4750 &soft_min,
4751 &soft_max,
4752 &step,
4753 &precision,
4755 &options_enum,
4757 &override_enum,
4759 &tags_enum,
4761 &subtype_enum,
4763 &unit_enum,
4765 &array_len_info,
4766 &update_fn,
4767 &get_fn,
4768 &set_fn,
4769 &get_transform_fn,
4770 &set_transform_fn))
4771 {
4772 return nullptr;
4773 }
4774
4775 if (default_py != nullptr) {
4776 default_value.reinitialize(array_len_info.len_total);
4777 if (bpy_prop_array_from_py_with_dims(default_value.data(),
4778 sizeof(*default_value.data()),
4779 default_py,
4780 &array_len_info,
4781 &PyFloat_Type,
4782 "FloatVectorProperty(default=sequence)") == -1)
4783 {
4784 return nullptr;
4785 }
4786 if (bpy_prop_array_is_matrix_compatible_ex(subtype_enum.value, &array_len_info)) {
4787 bpy_prop_array_matrix_swap_row_column_vn(default_value.data(), &array_len_info);
4788 }
4789 }
4790
4791 if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
4792 return nullptr;
4793 }
4794 if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
4795 return nullptr;
4796 }
4797 if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
4798 return nullptr;
4799 }
4800 if (bpy_prop_callback_check(get_transform_fn, "get_transform", 3) == -1) {
4801 return nullptr;
4802 }
4803 if (bpy_prop_callback_check(set_transform_fn, "set_transform", 4) == -1) {
4804 return nullptr;
4805 }
4806
4807 if (id_data.prop_free_handle != nullptr) {
4809 }
4810 prop = RNA_def_property(srna, id_data.value, PROP_FLOAT, subtype_enum.value | unit_enum.value);
4811
4812 if (array_len_info.dims_len == 0) {
4813 RNA_def_property_array(prop, array_len_info.len_total);
4814 if (default_py != nullptr) {
4815 RNA_def_property_float_array_default(prop, default_value.data());
4816 }
4817 }
4818 else {
4819 RNA_def_property_multi_array(prop, array_len_info.dims_len, array_len_info.dims);
4820 if (default_py != nullptr) {
4821 RNA_def_property_float_array_default(prop, default_value.data());
4822 }
4823 }
4824
4826 RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
4827 if (translation_context) {
4828 RNA_def_property_translation_context(prop, translation_context);
4829 }
4831 prop, std::max(soft_min, min), std::min(soft_max, max), step, precision);
4832
4833 if (tags_enum.base.is_set) {
4834 RNA_def_property_tags(prop, tags_enum.base.value);
4835 }
4836 if (options_enum.is_set) {
4837 bpy_prop_assign_flag(prop, options_enum.value);
4838 }
4839 if (override_enum.is_set) {
4840 bpy_prop_assign_flag_override(prop, override_enum.value);
4841 }
4842 bpy_prop_callback_assign_update(prop, update_fn);
4843 bpy_prop_callback_assign_float_array(prop, get_fn, set_fn, get_transform_fn, set_transform_fn);
4845
4846 Py_RETURN_NONE;
4847}
4848
4850 /* Wrap. */
4851 BPy_StringProperty_doc,
4852 ".. function:: StringProperty("
4853 "*, "
4854 "name=\"\", "
4855 "description=\"\", "
4856 "translation_context=\"*\", "
4857 "default=\"\", "
4858 "maxlen=0, "
4859 "options={'ANIMATABLE'}, "
4860 "override=set(), "
4861 "tags=set(), "
4862 "subtype='NONE', "
4863 "update=None, "
4864 "get=None, "
4865 "set=None, "
4866 "get_transform=None, "
4867 "set_transform=None, "
4868 "search=None, "
4869 "search_options={'SUGGESTION'})\n"
4870 "\n"
4871 " Returns a new string property definition.\n"
4872 "\n"
4873 /* Auto-format wrapping result is hard to read. */
4874 /* clang-format off */
4878 " :param default: initializer string.\n"
4879 " :type default: str\n"
4880 " :param maxlen: maximum length of the string.\n"
4881 " :type maxlen: int\n"
4887 BPY_PROPDEF_GET_DOC("str")
4888 BPY_PROPDEF_SET_DOC("str")
4893 /* clang-format on */
4894);
4895static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
4896{
4897 StructRNA *srna;
4898 { /* Keep this block first. */
4899 PyObject *deferred_result;
4900 srna = bpy_prop_deferred_data_or_srna(self, args, kw, pymeth_StringProperty, &deferred_result);
4901 if (srna == nullptr) {
4902 return deferred_result;
4903 }
4904 }
4905
4906 BPy_PropIDParse id_data{};
4907 id_data.srna = srna;
4908
4909 const char *name = nullptr, *description = "";
4910 const char *translation_context = nullptr, *default_value = "";
4911 int maxlen = 0;
4912 PropertyRNA *prop;
4913
4914 BPy_EnumProperty_Parse options_enum{};
4915 options_enum.items = rna_enum_property_flag_items;
4916 options_enum.value = 0;
4917
4918 BPy_EnumProperty_Parse override_enum{};
4920 override_enum.value = 0;
4921
4923 tags_enum.srna = srna;
4924
4925 BPy_EnumProperty_Parse subtype_enum{};
4927 subtype_enum.value = PROP_NONE;
4928
4929 PyObject *update_fn = nullptr;
4930 PyObject *get_fn = nullptr;
4931 PyObject *set_fn = nullptr;
4932 PyObject *get_transform_fn = nullptr;
4933 PyObject *set_transform_fn = nullptr;
4934 PyObject *search_fn = nullptr;
4935 BPy_EnumProperty_Parse search_options_enum{};
4937 search_options_enum.value = PROP_STRING_SEARCH_SUGGESTION;
4938
4939 static const char *_keywords[] = {
4940 "attr",
4941 "name",
4942 "description",
4943 "translation_context",
4944 "default",
4945 "maxlen",
4946 "options",
4947 "override",
4948 "tags",
4949 "subtype",
4950 "update",
4951 "get",
4952 "set",
4953 "get_transform",
4954 "set_transform",
4955 "search",
4956 "search_options",
4957 nullptr,
4958 };
4959 static _PyArg_Parser _parser = {
4960 "O&" /* `attr` */
4961 "|$" /* Optional, keyword only arguments. */
4962 "s" /* `name` */
4963 "s" /* `description` */
4964 "s" /* `translation_context` */
4965 "s" /* `default` */
4966 "i" /* `maxlen` */
4967 "O&" /* `options` */
4968 "O&" /* `override` */
4969 "O&" /* `tags` */
4970 "O&" /* `subtype` */
4971 "O" /* `update` */
4972 "O" /* `get` */
4973 "O" /* `set` */
4974 "O" /* `get_transform` */
4975 "O" /* `set_transform` */
4976 "O" /* `search` */
4977 "O&" /* `search_options` */
4978 ":StringProperty",
4979 _keywords,
4980 nullptr,
4981 };
4982 if (!_PyArg_ParseTupleAndKeywordsFast(args,
4983 kw,
4984 &_parser,
4986 &id_data,
4987 &name,
4988 &description,
4989 &translation_context,
4990 &default_value,
4991 &maxlen,
4993 &options_enum,
4995 &override_enum,
4997 &tags_enum,
4999 &subtype_enum,
5000 &update_fn,
5001 &get_fn,
5002 &set_fn,
5003 &get_transform_fn,
5004 &set_transform_fn,
5005 &search_fn,
5007 &search_options_enum))
5008 {
5009 return nullptr;
5010 }
5011
5012 if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
5013 return nullptr;
5014 }
5015 if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
5016 return nullptr;
5017 }
5018 if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
5019 return nullptr;
5020 }
5021 if (bpy_prop_callback_check(get_transform_fn, "get_transform", 3) == -1) {
5022 return nullptr;
5023 }
5024 if (bpy_prop_callback_check(set_transform_fn, "set_transform", 4) == -1) {
5025 return nullptr;
5026 }
5027 if (bpy_prop_callback_check(search_fn, "search", 3) == -1) {
5028 return nullptr;
5029 }
5030
5031 if (id_data.prop_free_handle != nullptr) {
5033 }
5034 prop = RNA_def_property(srna, id_data.value, PROP_STRING, subtype_enum.value);
5035
5036 if (maxlen != 0) {
5037 /* +1 since it includes null terminator. */
5038 RNA_def_property_string_maxlength(prop, maxlen + 1);
5039 }
5040 if (default_value && default_value[0]) {
5041 RNA_def_property_string_default(prop, default_value);
5042 }
5043 RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
5044 if (translation_context) {
5045 RNA_def_property_translation_context(prop, translation_context);
5046 }
5047
5048 if (tags_enum.base.is_set) {
5049 RNA_def_property_tags(prop, tags_enum.base.value);
5050 }
5051 if (options_enum.is_set) {
5052 bpy_prop_assign_flag(prop, options_enum.value);
5053 }
5054 if (override_enum.is_set) {
5055 bpy_prop_assign_flag_override(prop, override_enum.value);
5056 }
5057 bpy_prop_callback_assign_update(prop, update_fn);
5059 get_fn,
5060 set_fn,
5061 get_transform_fn,
5062 set_transform_fn,
5063 search_fn,
5064 eStringPropertySearchFlag(search_options_enum.value));
5066
5067 Py_RETURN_NONE;
5068}
5069
5071 /* Wrap. */
5072 BPy_EnumProperty_doc,
5073 ".. function:: EnumProperty("
5074 "items, "
5075 "*, "
5076 "name=\"\", "
5077 "description=\"\", "
5078 "translation_context=\"*\", "
5079 "default=None, "
5080 "options={'ANIMATABLE'}, "
5081 "override=set(), "
5082 "tags=set(), "
5083 "update=None, "
5084 "get=None, "
5085 "set=None, "
5086 "get_transform=None, "
5087 "set_transform=None)\n"
5088 "\n"
5089 " Returns a new enumerator property definition.\n"
5090 "\n"
5091 " :param items: sequence of enum items formatted:\n"
5092 " ``[(identifier, name, description, icon, number), ...]``.\n"
5093 "\n"
5094 " The first three elements of the tuples are mandatory.\n"
5095 "\n"
5096 " :identifier: The identifier is used for Python access.\n"
5097 " An empty identifier means that the item is a separator\n"
5098 " :name: Name for the interface.\n"
5099 " :description: Used for documentation and tooltips.\n"
5100 " :icon: An icon string identifier or integer icon value\n"
5101 " (e.g. returned by :class:`bpy.types.UILayout.icon`)\n"
5102 " :number: Unique value used as the identifier for this item (stored in file data).\n"
5103 " Use when the identifier may need to change. If the *ENUM_FLAG* option is used,\n"
5104 " the values are bit-masks and should be powers of two.\n"
5105 "\n"
5106 " When an item only contains 4 items they define ``(identifier, name, description, "
5107 "number)``.\n"
5108 "\n"
5109 " Separators may be added using either None (nameless separator),\n"
5110 " or a regular item tuple with an empty identifier string, in which case the name,\n"
5111 " if non-empty, will be displayed in the UI above the separator line."
5112 "\n"
5113 " For dynamic values a callback can be passed which returns a list in\n"
5114 " the same format as the static list.\n"
5115 " This function must take 2 arguments ``(self, context)``, **context may be None**.\n"
5116 "\n"
5117 " .. warning::\n"
5118 "\n"
5119 " There is a known bug with using a callback,\n"
5120 " Python must keep a reference to the strings returned by the callback or Blender\n"
5121 " will misbehave or even crash."
5122 "\n"
5123 " :type items: Iterable["
5124 "tuple[str, str, str] | "
5125 "tuple[str, str, str, int] | "
5126 "tuple[str, str, str, str | int, int] | "
5127 "None] | "
5128 "Callable[[:class:`bpy.types.bpy_struct`, :class:`bpy.types.Context` | None], "
5129 /* NOTE(@ideasman42): a type alias would be useful here (same as above). */
5130 "Iterable["
5131 "tuple[str, str, str] | "
5132 "tuple[str, str, str, int] | "
5133 "tuple[str, str, str, str | int, int] | "
5134 "None]"
5135 "]\n"
5136 /* Auto-format wrapping result is hard to read. */
5137 /* clang-format off */
5141 " :param default: The default value for this enum, a string from the identifiers used in "
5142 "*items*, or integer matching an item number.\n"
5143 " If the *ENUM_FLAG* option is used this must be a set of such string identifiers "
5144 "instead.\n"
5145 " WARNING: Strings cannot be specified for dynamic enums\n"
5146 " (i.e. if a callback function is given as *items* parameter).\n"
5147 " :type default: str | int | set[str] | None\n"
5152 BPY_PROPDEF_GET_DOC("int")
5153 BPY_PROPDEF_SET_DOC("int")
5157 /* clang-format on */
5158);
5159static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
5160{
5161 StructRNA *srna;
5162 { /* Keep this block first. */
5163 PyObject *deferred_result;
5164 srna = bpy_prop_deferred_data_or_srna(self, args, kw, pymeth_EnumProperty, &deferred_result);
5165 if (srna == nullptr) {
5166 return deferred_result;
5167 }
5168 }
5169
5170 BPy_PropIDParse id_data{};
5171 id_data.srna = srna;
5172
5173 const char *name = nullptr, *description = "";
5174 const char *translation_context = nullptr;
5175 PyObject *default_py = nullptr;
5176 int default_value = 0;
5177 PyObject *items, *items_fast;
5178 const EnumPropertyItem *eitems;
5179 PropertyRNA *prop;
5180
5181 BPy_EnumProperty_Parse options_enum{};
5183 options_enum.value = 0;
5184
5185 BPy_EnumProperty_Parse override_enum{};
5187 override_enum.value = 0;
5188
5190 tags_enum.srna = srna;
5191
5192 bool is_itemf = false;
5193 PyObject *update_fn = nullptr;
5194 PyObject *get_fn = nullptr;
5195 PyObject *set_fn = nullptr;
5196 PyObject *get_transform_fn = nullptr;
5197 PyObject *set_transform_fn = nullptr;
5198
5199 static const char *_keywords[] = {
5200 "attr",
5201 "items",
5202 "name",
5203 "description",
5204 "translation_context",
5205 "default",
5206 "options",
5207 "override",
5208 "tags",
5209 "update",
5210 "get",
5211 "set",
5212 "get_transform",
5213 "set_transform",
5214 nullptr,
5215 };
5216 static _PyArg_Parser _parser = {
5217 "O&" /* `attr` */
5218 "O" /* `items` */
5219 "|$" /* Optional, keyword only arguments. */
5220 "s" /* `name` */
5221 "s" /* `description` */
5222 "s" /* `translation_context` */
5223 "O" /* `default` */
5224 "O&" /* `options` */
5225 "O&" /* `override` */
5226 "O&" /* `tags` */
5227 "O" /* `update` */
5228 "O" /* `get` */
5229 "O" /* `set` */
5230 "O" /* `get_transform` */
5231 "O" /* `set_transform` */
5232 ":EnumProperty",
5233 _keywords,
5234 nullptr,
5235 };
5236 if (!_PyArg_ParseTupleAndKeywordsFast(args,
5237 kw,
5238 &_parser,
5240 &id_data,
5241 &items,
5242 &name,
5243 &description,
5244 &translation_context,
5245 &default_py,
5247 &options_enum,
5249 &override_enum,
5251 &tags_enum,
5252 &update_fn,
5253 &get_fn,
5254 &set_fn,
5255 &get_transform_fn,
5256 &set_transform_fn))
5257 {
5258 return nullptr;
5259 }
5260
5261 if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
5262 return nullptr;
5263 }
5264 if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
5265 return nullptr;
5266 }
5267 if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
5268 return nullptr;
5269 }
5270 if (bpy_prop_callback_check(get_transform_fn, "get_transform", 3) == -1) {
5271 return nullptr;
5272 }
5273 if (bpy_prop_callback_check(set_transform_fn, "set_transform", 4) == -1) {
5274 return nullptr;
5275 }
5276
5277 if (default_py == Py_None) {
5278 /* This allows to get same behavior when explicitly passing None as default value,
5279 * and not defining a default value at all! */
5280 default_py = nullptr;
5281 }
5282
5283 /* Items can be a list or a callable.
5284 * NOTE: Don't use #PyCallable_Check because we need the function code for errors. */
5285 if (PyFunction_Check(items)) {
5286 PyCodeObject *f_code = reinterpret_cast<PyCodeObject *>(PyFunction_GET_CODE(items));
5287 if (f_code->co_argcount != 2) {
5288 PyErr_Format(PyExc_ValueError,
5289 "EnumProperty(...): expected 'items' function to take 2 arguments, not %d",
5290 f_code->co_argcount);
5291 return nullptr;
5292 }
5293
5294 if (default_py) {
5295 /* Only support getting integer default values here. */
5296 if (!py_long_as_int(default_py, &default_value)) {
5297 /* NOTE: using type error here is odd but python does this for invalid arguments. */
5298 PyErr_SetString(
5299 PyExc_TypeError,
5300 "EnumProperty(...): 'default' can only be an integer when 'items' is a function");
5301 return nullptr;
5302 }
5303 }
5304
5305 is_itemf = true;
5307 }
5308 else {
5309 if (!(items_fast = PySequence_Fast(
5310 items,
5311 "EnumProperty(...): "
5312 "expected a sequence of tuples for the enum items or a function")))
5313 {
5314 return nullptr;
5315 }
5316
5317 eitems = enum_items_from_py(
5318 items_fast, (options_enum.value & PROP_ENUM_FLAG) != 0, default_py, &default_value);
5319
5320 if (!eitems) {
5321 Py_DECREF(items_fast);
5322 return nullptr;
5323 }
5324 }
5325
5326 if (id_data.prop_free_handle != nullptr) {
5328 }
5329 if (options_enum.value & PROP_ENUM_FLAG) {
5330 prop = RNA_def_enum_flag(
5331 srna, id_data.value, eitems, default_value, name ? name : id_data.value, description);
5332 }
5333 else {
5334 prop = RNA_def_enum(
5335 srna, id_data.value, eitems, default_value, name ? name : id_data.value, description);
5336 }
5337 if (translation_context) {
5338 RNA_def_property_translation_context(prop, translation_context);
5339 }
5340
5341 if (tags_enum.base.is_set) {
5342 RNA_def_property_tags(prop, tags_enum.base.value);
5343 }
5344 if (options_enum.is_set) {
5345 bpy_prop_assign_flag(prop, options_enum.value);
5346 }
5347 if (override_enum.is_set) {
5348 bpy_prop_assign_flag_override(prop, override_enum.value);
5349 }
5350 bpy_prop_callback_assign_update(prop, update_fn);
5352 prop, get_fn, set_fn, (is_itemf ? items : nullptr), get_transform_fn, set_transform_fn);
5354
5355 if (is_itemf == false) {
5356 /* NOTE: this must be postponed until after #RNA_def_property_duplicate_pointers
5357 * otherwise if this is a generator it may free the strings before we copy them */
5358 Py_DECREF(items_fast);
5359
5360 MEM_delete(eitems);
5361 }
5362
5363 Py_RETURN_NONE;
5364}
5365
5366StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix)
5367{
5368 StructRNA *srna;
5369
5370 srna = srna_from_self(value, "");
5371 if (!srna) {
5372 if (PyErr_Occurred()) {
5373 PyObject *msg = PyC_ExceptionBuffer();
5374 const char *msg_char = PyUnicode_AsUTF8(msg);
5375 PyErr_Clear();
5376
5377 PyErr_Format(
5378 PyExc_TypeError, "%.200s expected an RNA type, failed with: %s", error_prefix, msg_char);
5379 Py_DECREF(msg);
5380 }
5381 else {
5382 PyErr_Format(PyExc_TypeError,
5383 "%.200s expected an RNA type, failed with type '%s'",
5384 error_prefix,
5385 Py_TYPE(value)->tp_name);
5386 }
5387 return nullptr;
5388 }
5389
5390 return srna;
5391}
5392
5394 /* Wrap. */
5395 BPy_PointerProperty_doc,
5396 ".. function:: PointerProperty("
5397 "type, "
5398 "*, "
5399 "name=\"\", "
5400 "description=\"\", "
5401 "translation_context=\"*\", "
5402 "options={'ANIMATABLE'}, "
5403 "override=set(), "
5404 "tags=set(), "
5405 "poll=None, "
5406 "update=None)\n"
5407 "\n"
5408 " Returns a new pointer property definition.\n"
5409 "\n"
5410 /* Auto-format wrapping result is hard to read. */
5411 /* clang-format off */
5422 /* clang-format on */
5423 "\n"
5424 ".. note:: Pointer properties do not support storing references to embedded IDs "
5425 "(e.g. :class:`bpy.types.Scene.collection`, :class:`bpy.types.Material.node_tree`).\n"
5426 " These should exclusively be referenced and accessed through their owner ID "
5427 "(e.g. the scene or material).\n");
5428PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
5429{
5430 StructRNA *srna;
5431 { /* Keep this block first. */
5432 PyObject *deferred_result;
5434 self, args, kw, pymeth_PointerProperty, &deferred_result);
5435 if (srna == nullptr) {
5436 return deferred_result;
5437 }
5438 }
5439
5440 BPy_PropIDParse id_data{};
5441 id_data.srna = srna;
5442
5443 const char *name = nullptr, *description = "";
5444 const char *translation_context = nullptr;
5445 PropertyRNA *prop;
5446 StructRNA *ptype;
5447 PyObject *type = Py_None;
5448
5449 BPy_EnumProperty_Parse options_enum{};
5450 options_enum.items = rna_enum_property_flag_items;
5451 options_enum.value = 0;
5452
5453 BPy_EnumProperty_Parse override_enum{};
5455 override_enum.value = 0;
5456
5458 tags_enum.srna = srna;
5459
5460 PyObject *update_fn = nullptr, *poll_fn = nullptr;
5461
5462 static const char *_keywords[] = {
5463 "attr",
5464 "type",
5465 "name",
5466 "description",
5467 "translation_context",
5468 "options",
5469 "override",
5470 "tags",
5471 "poll",
5472 "update",
5473 nullptr,
5474 };
5475 static _PyArg_Parser _parser = {
5476 "O&" /* `attr` */
5477 "O" /* `type` */
5478 "|$" /* Optional, keyword only arguments. */
5479 "s" /* `name` */
5480 "s" /* `description` */
5481 "s" /* `translation_context` */
5482 "O&" /* `options` */
5483 "O&" /* `override` */
5484 "O&" /* `tags` */
5485 "O" /* `poll` */
5486 "O" /* `update` */
5487 ":PointerProperty",
5488 _keywords,
5489 nullptr,
5490 };
5491 if (!_PyArg_ParseTupleAndKeywordsFast(args,
5492 kw,
5493 &_parser,
5495 &id_data,
5496 &type,
5497 &name,
5498 &description,
5499 &translation_context,
5501 &options_enum,
5503 &override_enum,
5505 &tags_enum,
5506 &poll_fn,
5507 &update_fn))
5508 {
5509 return nullptr;
5510 }
5511
5512 ptype = pointer_type_from_py(type, "PointerProperty(...)");
5513 if (!ptype) {
5514 return nullptr;
5515 }
5516 if (!RNA_struct_is_a(ptype, RNA_PropertyGroup) && !RNA_struct_is_ID(ptype)) {
5517 PyErr_Format(PyExc_TypeError,
5518 "PointerProperty(...) expected an RNA type derived from %.200s or %.200s",
5519 RNA_struct_ui_name(RNA_ID),
5521 return nullptr;
5522 }
5523 if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
5524 return nullptr;
5525 }
5526 if (bpy_prop_callback_check(poll_fn, "poll", 2) == -1) {
5527 return nullptr;
5528 }
5529
5530 if (id_data.prop_free_handle != nullptr) {
5532 }
5534 srna, id_data.value, ptype, name ? name : id_data.value, description);
5535 if (translation_context) {
5536 RNA_def_property_translation_context(prop, translation_context);
5537 }
5538
5539 if (tags_enum.base.is_set) {
5540 RNA_def_property_tags(prop, tags_enum.base.value);
5541 }
5542 if (options_enum.is_set) {
5543 bpy_prop_assign_flag(prop, options_enum.value);
5544 }
5545 if (override_enum.is_set) {
5546 bpy_prop_assign_flag_override(prop, override_enum.value);
5547 }
5548
5552 }
5553 }
5554 bpy_prop_callback_assign_update(prop, update_fn);
5555 bpy_prop_callback_assign_pointer(prop, poll_fn);
5557
5558 Py_RETURN_NONE;
5559}
5560
5562 /* Wrap. */
5563 BPy_CollectionProperty_doc,
5564 ".. function:: CollectionProperty("
5565 "type, "
5566 "*, "
5567 "name=\"\", "
5568 "description=\"\", "
5569 "translation_context=\"*\", "
5570 "options={'ANIMATABLE'}, "
5571 "override=set(), "
5572 "tags=set())\n"
5573 "\n"
5574 " Returns a new collection property definition.\n"
5575 "\n"
5576 /* Auto-format wrapping result is hard to read. */
5577 /* clang-format off */
5586 /* clang-format on */
5587);
5588PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
5589{
5590 StructRNA *srna;
5591 { /* Keep this block first. */
5592 PyObject *deferred_result;
5594 self, args, kw, pymeth_CollectionProperty, &deferred_result);
5595 if (srna == nullptr) {
5596 return deferred_result;
5597 }
5598 }
5599
5600 BPy_PropIDParse id_data{};
5601 id_data.srna = srna;
5602
5603 const char *name = nullptr, *description = "";
5604 const char *translation_context = nullptr;
5605 PropertyRNA *prop;
5606 StructRNA *ptype;
5607 PyObject *type = Py_None;
5608
5609 BPy_EnumProperty_Parse options_enum{};
5610 options_enum.items = rna_enum_property_flag_items;
5611 options_enum.value = 0;
5612
5613 BPy_EnumProperty_Parse override_enum{};
5615 override_enum.value = 0;
5616
5618 tags_enum.srna = srna;
5619
5620 static const char *_keywords[] = {
5621 "attr",
5622 "type",
5623 "name",
5624 "description",
5625 "translation_context",
5626 "options",
5627 "override",
5628 "tags",
5629 nullptr,
5630 };
5631 static _PyArg_Parser _parser = {
5632 "O&" /* `attr` */
5633 "O" /* `type` */
5634 "|$" /* Optional, keyword only arguments. */
5635 "s" /* `name` */
5636 "s" /* `description` */
5637 "s" /* `translation_context` */
5638 "O&" /* `options` */
5639 "O&" /* `override` */
5640 "O&" /* `tags` */
5641 ":CollectionProperty",
5642 _keywords,
5643 nullptr,
5644 };
5645 if (!_PyArg_ParseTupleAndKeywordsFast(args,
5646 kw,
5647 &_parser,
5649 &id_data,
5650 &type,
5651 &name,
5652 &description,
5653 &translation_context,
5655 &options_enum,
5657 &override_enum,
5659 &tags_enum))
5660 {
5661 return nullptr;
5662 }
5663
5664 ptype = pointer_type_from_py(type, "CollectionProperty(...):");
5665 if (!ptype) {
5666 return nullptr;
5667 }
5668
5669 if (!RNA_struct_is_a(ptype, RNA_PropertyGroup)) {
5670 PyErr_Format(PyExc_TypeError,
5671 "CollectionProperty(...) expected an RNA type derived from %.200s",
5673 return nullptr;
5674 }
5675
5676 if (id_data.prop_free_handle != nullptr) {
5678 }
5680 srna, id_data.value, ptype, name ? name : id_data.value, description);
5681 if (translation_context) {
5682 RNA_def_property_translation_context(prop, translation_context);
5683 }
5684
5685 if (tags_enum.base.is_set) {
5686 RNA_def_property_tags(prop, tags_enum.base.value);
5687 }
5688 if (options_enum.is_set) {
5689 bpy_prop_assign_flag(prop, options_enum.value);
5690 }
5691 if (override_enum.is_set) {
5692 bpy_prop_assign_flag_override(prop, override_enum.value);
5693 }
5694
5698 }
5699 }
5701
5702 Py_RETURN_NONE;
5703}
5704
5706 /* Wrap. */
5707 BPy_RemoveProperty_doc,
5708 ".. function:: RemoveProperty(cls, attr)\n"
5709 "\n"
5710 " Removes a dynamically defined property.\n"
5711 "\n"
5712 " :param cls: The class containing the property (must be a positional argument).\n"
5713 " :type cls: type[:class:`bpy.types.bpy_struct`]\n"
5714 " :param attr: Property name (must be passed as a keyword).\n"
5715 " :type attr: str\n"
5716 "\n"
5717 " .. note::\n"
5718 "\n"
5719 " Typically this function doesn't need to be accessed directly.\n"
5720 " Instead use ``del cls.attr``\n");
5721static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw)
5722{
5723 StructRNA *srna;
5724
5725 if (PyTuple_GET_SIZE(args) == 1) {
5726 PyObject *ret;
5727 self = PyTuple_GET_ITEM(args, 0);
5728 args = PyTuple_New(0);
5729 ret = BPy_RemoveProperty(self, args, kw);
5730 Py_DECREF(args);
5731 return ret;
5732 }
5733
5734 const PyMethodDef *method_def =
5735 (reinterpret_cast<const PyCFunctionObject *>(pymeth_RemoveProperty))->m_ml;
5736 const char *error_prefix = method_def->ml_name;
5737
5738 if (PyTuple_GET_SIZE(args) > 1) {
5739 PyErr_Format(
5740 PyExc_ValueError, "%s: expected one positional arg, one keyword arg", error_prefix);
5741 return nullptr;
5742 }
5743
5744 srna = srna_from_self(self, error_prefix);
5745 if (srna == nullptr && PyErr_Occurred()) {
5746 return nullptr; /* self's type was compatible but error getting the srna */
5747 }
5748 if (srna == nullptr) {
5749 PyErr_Format(PyExc_TypeError, "%s: struct rna not available for this type", error_prefix);
5750 return nullptr;
5751 }
5752
5753 const char *id = nullptr;
5754
5755 static const char *_keywords[] = {
5756 "attr",
5757 nullptr,
5758 };
5759 static _PyArg_Parser _parser = {
5760 "s" /* `attr` */
5761 ":RemoveProperty",
5762 _keywords,
5763 nullptr,
5764 };
5765 if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &id)) {
5766 return nullptr;
5767 }
5768
5769 if (RNA_def_property_free_identifier(srna, id) != 1) {
5770 PyErr_Format(PyExc_TypeError, "%s: '%s' not a defined dynamic property", error_prefix, id);
5771 return nullptr;
5772 }
5773
5774 Py_RETURN_NONE;
5775}
5776
5778
5779/* -------------------------------------------------------------------- */
5782
5783#ifdef __GNUC__
5784# ifdef __clang__
5785# pragma clang diagnostic push
5786# pragma clang diagnostic ignored "-Wcast-function-type"
5787# else
5788# pragma GCC diagnostic push
5789# pragma GCC diagnostic ignored "-Wcast-function-type"
5790# endif
5791#endif
5792
5793static PyMethodDef props_methods[] = {
5794 {"BoolProperty",
5795 reinterpret_cast<PyCFunction>(BPy_BoolProperty),
5796 METH_VARARGS | METH_KEYWORDS,
5797 BPy_BoolProperty_doc},
5798 {"BoolVectorProperty",
5799 reinterpret_cast<PyCFunction>(BPy_BoolVectorProperty),
5800 METH_VARARGS | METH_KEYWORDS,
5801 BPy_BoolVectorProperty_doc},
5802 {"IntProperty",
5803 reinterpret_cast<PyCFunction>(BPy_IntProperty),
5804 METH_VARARGS | METH_KEYWORDS,
5805 BPy_IntProperty_doc},
5806 {"IntVectorProperty",
5807 reinterpret_cast<PyCFunction>(BPy_IntVectorProperty),
5808 METH_VARARGS | METH_KEYWORDS,
5809 BPy_IntVectorProperty_doc},
5810 {"FloatProperty",
5811 reinterpret_cast<PyCFunction>(BPy_FloatProperty),
5812 METH_VARARGS | METH_KEYWORDS,
5813 BPy_FloatProperty_doc},
5814 {"FloatVectorProperty",
5815 reinterpret_cast<PyCFunction>(BPy_FloatVectorProperty),
5816 METH_VARARGS | METH_KEYWORDS,
5817 BPy_FloatVectorProperty_doc},
5818 {"StringProperty",
5819 reinterpret_cast<PyCFunction>(BPy_StringProperty),
5820 METH_VARARGS | METH_KEYWORDS,
5821 BPy_StringProperty_doc},
5822 {"EnumProperty",
5823 reinterpret_cast<PyCFunction>(BPy_EnumProperty),
5824 METH_VARARGS | METH_KEYWORDS,
5825 BPy_EnumProperty_doc},
5826 {"PointerProperty",
5827 reinterpret_cast<PyCFunction>(BPy_PointerProperty),
5828 METH_VARARGS | METH_KEYWORDS,
5829 BPy_PointerProperty_doc},
5830 {"CollectionProperty",
5831 reinterpret_cast<PyCFunction>(BPy_CollectionProperty),
5832 METH_VARARGS | METH_KEYWORDS,
5833 BPy_CollectionProperty_doc},
5834
5835 {"RemoveProperty",
5836 reinterpret_cast<PyCFunction>(BPy_RemoveProperty),
5837 METH_VARARGS | METH_KEYWORDS,
5838 BPy_RemoveProperty_doc},
5839 {nullptr, nullptr, 0, nullptr},
5840};
5841
5842#ifdef __GNUC__
5843# ifdef __clang__
5844# pragma clang diagnostic pop
5845# else
5846# pragma GCC diagnostic pop
5847# endif
5848#endif
5849
5850static int props_visit(PyObject * /*self*/, visitproc visit, void *arg)
5851{
5852 for (BPyPropStore &prop_store : g_bpy_prop_store_list) {
5853 PyObject **py_data = reinterpret_cast<PyObject **>(&prop_store.py_data);
5854 for (int i = 0; i < BPY_PROP_STORE_PY_DATA_SIZE; i++) {
5855 Py_VISIT(py_data[i]);
5856 }
5857 }
5858 return 0;
5859}
5860
5861static int props_clear(PyObject * /*self*/)
5862{
5863 for (BPyPropStore &prop_store : g_bpy_prop_store_list) {
5864 PyObject **py_data = reinterpret_cast<PyObject **>(&prop_store.py_data);
5865 for (int i = 0; i < BPY_PROP_STORE_PY_DATA_SIZE; i++) {
5866 Py_CLEAR(py_data[i]);
5867 }
5868 }
5869 return 0;
5870}
5871
5873 /* Wrap. */
5874 props_module_doc,
5875 "This module defines properties to extend Blender's internal data. The result of these "
5876 "functions"
5877 " is used to assign properties to classes registered with Blender and can't be used "
5878 "directly.\n"
5879 "\n"
5880 ".. note:: All parameters to these functions must be passed as keywords.\n");
5881static PyModuleDef props_module = {
5882 /*m_base*/ PyModuleDef_HEAD_INIT,
5883 /*m_name*/ "bpy.props",
5884 /*m_doc*/ props_module_doc,
5885 /*m_size*/ -1, /* multiple "initialization" just copies the module dict. */
5886 /*m_methods*/ props_methods,
5887 /*m_slots*/ nullptr,
5888 /*m_traverse*/ props_visit,
5889 /*m_clear*/ props_clear,
5890 /*m_free*/ nullptr,
5891};
5892
5893PyObject *BPY_rna_props()
5894{
5895 PyObject *submodule;
5896 PyObject *submodule_dict;
5897
5898 if (PyType_Ready(&bpy_prop_deferred_Type) < 0) {
5899 return nullptr;
5900 }
5901
5902 submodule = PyModule_Create(&props_module);
5903 PyDict_SetItemString(PyImport_GetModuleDict(), props_module.m_name, submodule);
5904
5905 /* API needs the PyObjects internally. */
5906 submodule_dict = PyModule_GetDict(submodule);
5907
5908#define ASSIGN_STATIC(_name) pymeth_##_name = PyDict_GetItemString(submodule_dict, #_name)
5909
5910 ASSIGN_STATIC(BoolProperty);
5911 ASSIGN_STATIC(BoolVectorProperty);
5912 ASSIGN_STATIC(IntProperty);
5913 ASSIGN_STATIC(IntVectorProperty);
5914 ASSIGN_STATIC(FloatProperty);
5915 ASSIGN_STATIC(FloatVectorProperty);
5916 ASSIGN_STATIC(StringProperty);
5917 ASSIGN_STATIC(EnumProperty);
5918 ASSIGN_STATIC(PointerProperty);
5919 ASSIGN_STATIC(CollectionProperty);
5920 ASSIGN_STATIC(RemoveProperty);
5921
5922 PyModule_AddType(submodule, &bpy_prop_deferred_Type);
5923
5924 /* Run this when properties are freed. */
5926
5927 return submodule;
5928}
5929
5931{
5932 /* Remove all user counts, so this isn't considered a leak from Python's perspective. */
5933 props_clear(nullptr);
5934
5935 /* Running is harmless, but redundant. */
5937
5938 /* Include as it's correct, in practice this should never be used again. */
5939 g_bpy_prop_store_list.clear_no_delete();
5940}
5941
5943
5944} // namespace blender
ID and Library types, which are fundamental for SDNA.
#define MAX_IDPROP_NAME
Definition DNA_ID.h:174
Read Blender memory allocation and freeing.
#define RNA_MAX_ARRAY_DIMENSION
Definition RNA_define.hh:29
#define RNA_ENUM_BITFLAG_SIZE
Definition RNA_types.hh:270
#define C
Definition RandGen.cpp:29
#define BLI_assert_unreachable()
#define STRINGIFY(x)
#define STREQ(a, b)
#define BPY_PROPDEF_SUBTYPE_STRING_DOC
Definition bpy_props.cc:72
#define ASSIGN_PYOBJECT_INCREF(a, b)
Definition bpy_props.cc:181
#define BPY_PROPDEF_RETURN_DOC
#define BPY_PROPDEF_OPTIONS_OVERRIDE_COLLECTION_DOC
Definition bpy_props.cc:68
#define BPY_PROPDEF_NAME_DOC
#define BPY_PROPDEF_FLOAT_STEP_DOC
#define BPY_PROPDEF_UPDATE_DOC
#define BPY_PROPDEF_NUM_SOFT_MINMAX_DOC(ty)
#define BPY_PROPDEF_DEFAULT_DOC(ty)
#define BPY_PROPDEF_FLOAT_PREC_DOC
#define BPY_PROPDEF_POLL_DOC
#define BPY_PROPDEF_NUM_MINMAX_DOC(ty)
#define BPY_PROPDEF_SET_DOC(ty)
#define BPY_PROPDEF_POINTER_TYPE_DOC
#define BPY_PROPDEF_GET_TRANSFORM_DOC(ty)
#define BPY_PROPDEF_CTXT_DOC
#define BPY_PROPDEF_COLLECTION_TYPE_DOC
#define BPY_PROPDEF_TAGS_DOC
#define BPY_PROP_STORE_PY_DATA_SIZE
Definition bpy_props.cc:179
#define BPY_PROPDEF_OPTIONS_DOC
Definition bpy_props.cc:56
#define BPY_PROPDEF_GET_DOC(ty)
#define BPY_PROPDEF_SET_TRANSFORM_DOC(ty)
#define BPY_PROPDEF_SEARCH_DOC
#define BPY_PROPDEF_OPTIONS_ENUM_DOC
Definition bpy_props.cc:60
#define BPY_PROPDEF_UNIT_DOC
#define BPY_PROPDEF_SUBTYPE_NUMBER_DOC
Definition bpy_props.cc:76
#define ASSIGN_STATIC(_name)
#define BPY_PROPDEF_SUBTYPE_NUMBER_ARRAY_DOC
Definition bpy_props.cc:80
#define BPY_PROPDEF_VECSIZE_DOC
#define BPY_PROPDEF_INT_STEP_DOC
#define BPY_PROPDEF_DESC_DOC
#define BPY_PROPDEF_OPTIONS_OVERRIDE_DOC
Definition bpy_props.cc:64
#define PYRNA_STACK_ARRAY
Definition bpy_props.hh:41
btScalar max
const T * data() const
Definition BLI_array.hh:323
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
#define FLT_MAX
#define INT_MAX
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float length(VecOp< float, D >) RET
BMesh Iterators.
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static int props_visit(PyObject *, visitproc visit, void *arg)
bool(*)(PointerRNA *ptr, PropertyRNA *prop, bool value, bool is_set) BooleanPropertyGetTransformFunc
Definition RNA_types.hh:776
static PyObject * pymeth_RemoveProperty
Definition bpy_props.cc:419
static void bpy_prop_boolean_array_get_transform_fn(PointerRNA *ptr, PropertyRNA *prop, const bool *curr_values, bool is_set, bool *r_values)
static int bpy_prop_int_get_transform_fn(PointerRNA *ptr, PropertyRNA *prop, int curr_value, bool is_set)
void RNA_def_property_tags(PropertyRNA *prop, int tags)
static std::string bpy_prop_string_set_transform_fn(PointerRNA *ptr, PropertyRNA *prop, const std::string &new_value, const std::string &curr_value, bool is_set)
void ** RNA_struct_instance(PointerRNA *ptr)
void RNA_def_property_boolean_funcs_runtime(PropertyRNA *prop, BooleanPropertyGetFunc getfunc, BooleanPropertySetFunc setfunc, BooleanPropertyGetTransformFunc get_transform_fn, BooleanPropertySetTransformFunc set_transform_fn)
static int bpy_prop_arg_parse_tag_defines(PyObject *o, void *p)
static void bpy_prop_float_array_set_fn(PointerRNA *ptr, PropertyRNA *prop, const float *values)
const EnumPropertyItem rna_enum_property_flag_items[]
Definition rna_rna.cc:189
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_float_funcs_runtime(PropertyRNA *prop, FloatPropertyGetFunc getfunc, FloatPropertySetFunc setfunc, FloatPropertyRangeFunc rangefunc, FloatPropertyGetTransformFunc get_transform_fn, FloatPropertySetTransformFunc set_transform_fn)
void(*)(PointerRNA *ptr, PropertyRNA *prop, const int *new_values, const int *curr_values, bool is_set, int *r_values) IntArrayPropertySetTransformFunc
Definition RNA_types.hh:808
static void bpy_prop_enum_set_fn(PointerRNA *ptr, PropertyRNA *prop, int value)
static void bpy_prop_float_array_from_callback_or_error(PropertyRNA *prop, PyObject *float_array_obj, const BPyPropArrayLength &array_len_info, PyObject *py_func, const bool do_matrix_row_col_swap, float *r_values)
static void bpy_prop_boolean_array_set_transform_fn(PointerRNA *ptr, PropertyRNA *prop, const bool *new_values, const bool *curr_values, bool is_set, bool *r_final_values)
int PyC_ParseBool(PyObject *o, void *p)
static bool py_long_as_int(PyObject *py_long, int *r_int)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_def_property_free_pointers_set_py_data_callback(void(*py_data_clear_fn)(PropertyRNA *prop))
void RNA_def_property_free_identifier_deferred_finish(StructOrFunctionRNA *cont_, void *handle)
@ STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES
static void bpy_prop_int_array_set_transform_fn(PointerRNA *ptr, PropertyRNA *prop, const int *new_values, const int *curr_values, bool is_set, int *r_final_values)
void RNA_def_property_boolean_array_default(PropertyRNA *prop, const bool *array)
int(*)(PointerRNA *ptr, PropertyRNA *prop, int value, bool is_set) EnumPropertyGetTransformFunc
Definition RNA_types.hh:914
void(*)(PointerRNA *ptr, PropertyRNA *prop, bool *r_values) BooleanArrayPropertyGetFunc
Definition RNA_types.hh:783
static BPyPropStore * bpy_prop_py_data_ensure(PropertyRNA *prop)
Definition bpy_props.cc:195
static PyObject * BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
static void bpy_prop_float_array_get_fn(PointerRNA *ptr, PropertyRNA *prop, float *values)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
unsigned int uint
Definition BKE_text.h:55
static ListBaseT< BPyPropStore > g_bpy_prop_store_list
Definition bpy_props.cc:193
std::string(*)(PointerRNA *ptr, PropertyRNA *prop) StringPropertyGetFunc
Definition RNA_types.hh:840
const EnumPropertyItem rna_enum_property_string_search_flag_items[]
Definition rna_rna.cc:284
static StructRNA * bpy_prop_deferred_data_or_srna(PyObject *self, PyObject *args, PyObject *kw, PyObject *method_object, PyObject **r_deferred_result)
static bool bpy_prop_string_visit_fn_call(PyObject *py_func, PyObject *item, FunctionRef< void(StringPropertySearchVisitParams)> visit_fn)
BPy_StructRNA * bpy_context_module
Definition bpy_rna.cc:100
static bool bpy_prop_array_is_matrix_compatible_ex(int subtype, const BPyPropArrayLength *array_len_info)
Definition bpy_props.cc:661
void(*)(PointerRNA *ptr, PropertyRNA *prop, const float *values) FloatArrayPropertySetFunc
Definition RNA_types.hh:826
static PyObject * bpy_prop_deferred_function_get(BPy_PropDeferred *self, void *)
Definition bpy_props.cc:283
static bool bpy_prop_boolean_set_transform_fn(PointerRNA *ptr, PropertyRNA *prop, bool new_value, bool curr_value, bool is_set)
Definition bpy_props.cc:895
static float bpy_prop_float_get_fn(PointerRNA *ptr, PropertyRNA *prop)
static int bpy_prop_string_length_fn(PointerRNA *ptr, PropertyRNA *prop)
static void bpy_prop_int_array_get_transform_fn(PointerRNA *ptr, PropertyRNA *prop, const int *curr_values, bool is_set, int *r_values)
void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
static bool bpy_prop_pointer_poll_fn(PointerRNA *self, PointerRNA candidate, PropertyRNA *prop)
void(*)(PointerRNA *ptr, PropertyRNA *prop, const bool *r_values) BooleanArrayPropertySetFunc
Definition RNA_types.hh:784
static PyObject * BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
static void bpy_prop_array_matrix_swap_row_column_vn(float *values, const BPyPropArrayLength *array_len_info)
Definition bpy_props.cc:693
void(*)(PointerRNA *ptr, PropertyRNA *prop, float *values) FloatArrayPropertyGetFunc
Definition RNA_types.hh:825
static void bpy_prop_deferred_dealloc(BPy_PropDeferred *self)
Definition bpy_props.cc:233
const EnumPropertyItem rna_enum_property_unit_items[]
Definition rna_rna.cc:144
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static int bpy_prop_deferred_clear(BPy_PropDeferred *self)
Definition bpy_props.cc:246
void RNA_def_property_string_funcs_runtime(PropertyRNA *prop, StringPropertyGetFunc getfunc, StringPropertyLengthFunc lengthfunc, StringPropertySetFunc setfunc, StringPropertyGetTransformFunc get_transform_fn, StringPropertySetTransformFunc set_transform_fn)
@ PROP_UNIT_NONE
Definition RNA_types.hh:221
static PyObject * BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
static void bpy_prop_int_array_from_callback_or_error(PyObject *int_array_obj, const BPyPropArrayLength &array_len_info, PyObject *py_func, int *r_values)
static void bpy_prop_assign_flag_override(PropertyRNA *prop, const int flag_override)
Definition bpy_props.cc:463
int PyC_AsArray(void *array, const size_t array_item_size, PyObject *value, const Py_ssize_t length, const PyTypeObject *type, const char *error_prefix)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static void bpy_prop_int_set_fn(PointerRNA *ptr, PropertyRNA *prop, int value)
StructRNA * pointer_type_from_py(PyObject *value, const char *error_prefix)
bool RNA_struct_idprops_contains_datablock(const StructRNA *type)
int(*)(PointerRNA *ptr, PropertyRNA *prop) IntPropertyGetFunc
Definition RNA_types.hh:796
void(*)(PointerRNA *ptr, PropertyRNA *prop, const int *values) IntArrayPropertySetFunc
Definition RNA_types.hh:805
bool(*)(PointerRNA *ptr, PropertyRNA *prop, bool new_value, bool curr_value, bool is_set) BooleanPropertySetTransformFunc
Definition RNA_types.hh:780
PropertyRNA * RNA_def_collection_runtime(StructOrFunctionRNA *cont, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
static bool bpy_prop_array_is_matrix_compatible(PropertyRNA *prop, const BPyPropArrayLength *array_len_info)
Definition bpy_props.cc:669
static std::string bpy_prop_string_get_transform_fn(PointerRNA *ptr, PropertyRNA *prop, const std::string &curr_value, bool is_set)
const char * RNA_struct_ui_name(const StructRNA *type)
static void bpy_prop_string_set_fn(PointerRNA *ptr, PropertyRNA *prop, const std::string &value)
void(*)(PointerRNA *ptr, PropertyRNA *prop, int value) EnumPropertySetFunc
Definition RNA_types.hh:913
static PyObject * pymeth_BoolProperty
Definition bpy_props.cc:409
static void bpy_prop_py_data_remove(PropertyRNA *prop)
Definition bpy_props.cc:209
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
Definition bpy_rna.cc:8874
static int bpy_prop_int_set_transform_fn(PointerRNA *ptr, PropertyRNA *prop, int new_value, int curr_value, bool is_set)
const EnumPropertyItem rna_enum_property_subtype_string_items[]
Definition rna_rna.cc:108
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
PropertyRNA * RNA_def_pointer_runtime(StructOrFunctionRNA *cont, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
static bool bpy_prop_callback_assign_float(PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn, PyObject *get_transform_fn, PyObject *set_transform_fn)
PyObject * BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA RNA_PropertyGroup
void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA *prop)
void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
static void bpy_prop_boolean_set_fn(PointerRNA *ptr, PropertyRNA *prop, bool value)
Definition bpy_props.cc:858
PropertyOverrideFlag
Definition RNA_types.hh:586
static PyObject * bpy_py_object_from_prop_array_with_dims(const void *values, const BPyPropArrayLength &array_len_info, const PyTypeObject &type)
Definition bpy_props.cc:617
static void bpy_prop_int_array_set_fn(PointerRNA *ptr, PropertyRNA *prop, const int *values)
void RNA_def_property_float_default(PropertyRNA *prop, float value)
void(*)(PointerRNA *ptr, PropertyRNA *prop, int *values) IntArrayPropertyGetFunc
Definition RNA_types.hh:804
static int bpy_prop_array_from_py_with_dims(void *values, size_t values_elem_size, PyObject *py_values, const BPyPropArrayLength *array_len_info, const PyTypeObject *type, const char *error_str)
Definition bpy_props.cc:600
PyObject * BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
int(*)(PointerRNA *ptr, PropertyRNA *prop, int value, bool is_set) IntPropertyGetTransformFunc
Definition RNA_types.hh:798
static void bpy_prop_int_array_get_fn(PointerRNA *ptr, PropertyRNA *prop, int *values)
static PyObject * BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
float(*)(PointerRNA *ptr, PropertyRNA *prop, float value, bool is_set) FloatPropertyGetTransformFunc
Definition RNA_types.hh:819
PyObject * PyC_Tuple_PackArray_Multi_Bool(const bool *array, const int dims[], const int dims_len)
const EnumPropertyItem * RNA_struct_property_tag_defines(const StructRNA *type)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
PropertyType RNA_property_type(PropertyRNA *prop)
const EnumPropertyItem rna_enum_property_override_flag_collection_items[]
Definition rna_rna.cc:269
void RNA_def_property_float_array_funcs_runtime(PropertyRNA *prop, FloatArrayPropertyGetFunc getfunc, FloatArrayPropertySetFunc setfunc, FloatPropertyRangeFunc rangefunc, FloatArrayPropertyGetTransformFunc get_transform_fn, FloatArrayPropertySetTransformFunc set_transform_fn)
static bool bpy_prop_callback_assign_enum(PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn, PyObject *itemf_fn, PyObject *get_transform_fn, PyObject *set_transform_fn)
static PyObject * pymeth_FloatProperty
Definition bpy_props.cc:413
int(*)(PointerRNA *ptr, PropertyRNA *prop) EnumPropertyGetFunc
Definition RNA_types.hh:912
static PyObject * pymeth_PointerProperty
Definition bpy_props.cc:417
void RNA_def_property_update_runtime_with_context_and_property(PropertyRNA *prop, RNAPropertyUpdateFuncWithContextAndProperty func)
static int bpy_prop_int_get_fn(PointerRNA *ptr, PropertyRNA *prop)
void(*)(PointerRNA *ptr, PropertyRNA *prop, bool value) BooleanPropertySetFunc
Definition RNA_types.hh:775
int RNA_property_enum_get_default(PointerRNA *ptr, PropertyRNA *prop)
void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
std::string(*)(PointerRNA *ptr, PropertyRNA *prop, const std::string &new_value, const std::string &curr_value, bool is_set) StringPropertySetTransformFunc
Definition RNA_types.hh:849
static PyObject * bpy_prop_deferred_repr(BPy_PropDeferred *self)
Definition bpy_props.cc:252
const EnumPropertyItem rna_enum_property_subtype_number_array_items[]
Definition rna_rna.cc:122
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static void bpy_prop_boolean_array_get_fn(PointerRNA *ptr, PropertyRNA *prop, bool *values)
Definition bpy_props.cc:976
eStringPropertySearchFlag
Definition RNA_types.hh:869
@ PROP_STRING_SEARCH_SUGGESTION
Definition RNA_types.hh:883
static float bpy_prop_float_set_transform_fn(PointerRNA *ptr, PropertyRNA *prop, float new_value, float curr_value, bool is_set)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_STRING
Definition RNA_types.hh:213
static void bpy_prop_assign_flag(PropertyRNA *prop, int flag)
Definition bpy_props.cc:445
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
void RNA_def_property_string_search_func_runtime(PropertyRNA *prop, StringPropertySearchFunc search_fn, const eStringPropertySearchFlag search_flag)
void RNA_def_property_int_funcs_runtime(PropertyRNA *prop, IntPropertyGetFunc getfunc, IntPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc, IntPropertyGetTransformFunc get_transform_fn, IntPropertySetTransformFunc set_transform_fn)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
static std::optional< std::string > bpy_prop_string_from_callback_or_error(PyObject *str_obj, const size_t max_length, PyObject *py_func)
static PyObject * pymeth_IntVectorProperty
Definition bpy_props.cc:412
static PyObject * pymeth_BoolVectorProperty
Definition bpy_props.cc:410
static PyObject * pyrna_struct_as_instance(PointerRNA *ptr)
Definition bpy_props.cc:421
static BPyPropGIL_RNAWritable_State bpy_prop_gil_rna_writable_begin()
Definition bpy_props.cc:476
static bool bpy_prop_callback_assign_boolean(PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn, PyObject *get_transform_fn, PyObject *set_transform_fn)
static PyModuleDef props_module
static bool bpy_prop_callback_assign_boolean_array(PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn, PyObject *get_transform_fn, PyObject *set_transform_fn)
static void bpy_prop_boolean_array_set_fn(PointerRNA *ptr, PropertyRNA *prop, const bool *values)
int RNA_property_flag(PropertyRNA *prop)
static int bpy_prop_enum_set_transform_fn(PointerRNA *ptr, PropertyRNA *prop, int new_value, int curr_value, bool is_set)
static const EnumPropertyItem * enum_items_from_py(PyObject *seq_fast, const bool is_enum_flag, PyObject *default_py, int *r_default_value)
int(*)(PointerRNA *ptr, PropertyRNA *prop) StringPropertyLengthFunc
Definition RNA_types.hh:841
PyObject * PyC_Tuple_PackArray_Multi_F32(const float *array, const int dims[], const int dims_len)
static void bpy_prop_float_array_set_transform_fn(PointerRNA *ptr, PropertyRNA *prop, const float *new_values, const float *curr_values, bool is_set, float *r_final_values)
static PyObject * pymeth_CollectionProperty
Definition bpy_props.cc:418
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
int pyrna_enum_bitfield_parse_set(PyObject *o, void *p)
const EnumPropertyItem rna_enum_property_flag_enum_items[]
Definition rna_rna.cc:233
void(*)(PointerRNA *ptr, PropertyRNA *prop, const float *new_values, const float *curr_values, bool is_set, float *r_values) FloatArrayPropertySetTransformFunc
Definition RNA_types.hh:831
void BPY_rna_props_clear_all()
static int bpy_prop_enum_get_transform_fn(PointerRNA *ptr, PropertyRNA *prop, int curr_value, bool is_set)
PyObject * PyC_Tuple_PackArray_I32(const int *array, uint len)
int(*)(PointerRNA *ptr, PropertyRNA *prop, int new_value, int curr_value, bool is_set) IntPropertySetTransformFunc
Definition RNA_types.hh:802
void RNA_def_property_enum_funcs_runtime(PropertyRNA *prop, EnumPropertyGetFunc getfunc, EnumPropertySetFunc setfunc, EnumPropertyItemFunc itemfunc, EnumPropertyGetTransformFunc get_transform_fn, EnumPropertySetTransformFunc set_transform_fn)
static PyMethodDef props_methods[]
static PyObject * BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
PyTypeObject bpy_prop_deferred_Type
Definition bpy_props.cc:334
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
static bool bpy_prop_callback_assign_int(PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn, PyObject *get_transform_fn, PyObject *set_transform_fn)
static int bpy_prop_deferred_traverse(BPy_PropDeferred *self, visitproc visit, void *arg)
Definition bpy_props.cc:240
int RNA_property_array_dimension(const PointerRNA *ptr, PropertyRNA *prop, int length[])
static int icon_id_from_name(const char *name)
static bool bpy_prop_boolean_get_fn(PointerRNA *ptr, PropertyRNA *prop)
Definition bpy_props.cc:765
void RNA_def_property_boolean_default(PropertyRNA *prop, bool value)
bool RNA_struct_is_ID(const StructRNA *type)
void(*)(PointerRNA *ptr, PropertyRNA *prop, const bool *new_values, const bool *curr_values, bool is_set, bool *r_values) BooleanArrayPropertySetTransformFunc
Definition RNA_types.hh:789
void PyC_Err_PrintWithFunc(PyObject *py_func)
void(*)(PointerRNA *ptr, PropertyRNA *prop, float value) FloatPropertySetFunc
Definition RNA_types.hh:818
const EnumPropertyItem rna_enum_property_override_flag_items[]
Definition rna_rna.cc:264
static PyObject * pymeth_StringProperty
Definition bpy_props.cc:415
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
const char * RNA_struct_identifier(const StructRNA *type)
int PyC_Long_AsBool(PyObject *value)
static void bpy_prop_float_set_fn(PointerRNA *ptr, PropertyRNA *prop, float value)
static void bpy_prop_float_array_get_transform_fn(PointerRNA *ptr, PropertyRNA *prop, const float *curr_values, bool is_set, float *r_values)
static float bpy_prop_float_get_transform_fn(PointerRNA *ptr, PropertyRNA *prop, float curr_value, bool is_set)
void(*)( PointerRNA *ptr, PropertyRNA *prop, const float *curr_values, bool is_set, float *r_values) FloatArrayPropertyGetTransformFunc
Definition RNA_types.hh:829
PropertySubType RNA_property_subtype(PropertyRNA *prop)
static bool bpy_prop_boolean_get_transform_fn(PointerRNA *ptr, PropertyRNA *prop, bool curr_value, bool is_set)
Definition bpy_props.cc:811
void pyrna_write_set(bool val)
Definition bpy_rna.cc:522
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_struct_flag(StructRNA *srna, StructFlag flag)
static int bpy_prop_arg_parse_id(PyObject *o, void *p)
PyObject * PyC_Tuple_PackArray_Multi_I32(const int *array, const int dims[], const int dims_len)
const EnumPropertyItem rna_enum_property_subtype_number_items[]
Definition rna_rna.cc:115
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
bool(*)(PointerRNA *ptr, PropertyRNA *prop) BooleanPropertyGetFunc
Definition RNA_types.hh:774
static PyObject * pymeth_FloatVectorProperty
Definition bpy_props.cc:414
float(*)(PointerRNA *ptr, PropertyRNA *prop, float new_value, float curr_value, bool is_set) FloatPropertySetTransformFunc
Definition RNA_types.hh:823
void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
bool bpy_context_set(struct bContext *C, PyGILState_STATE *gilstate) ATTR_NONNULL(1)
static void bpy_prop_callback_assign_update(PropertyRNA *prop, PyObject *update_fn)
void(*)(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *edit_text, FunctionRef< void(StringPropertySearchVisitParams)> visit_fn) StringPropertySearchFunc
Definition RNA_types.hh:897
static void bpy_prop_array_matrix_swap_row_column_vn_vn(float *values_dst, const float *values_src, const BPyPropArrayLength *array_len_info)
Definition bpy_props.cc:679
static PyObject * bpy_prop_deferred_data_CreatePyObject(PyObject *fn, PyObject *kw)
Definition bpy_props.cc:386
static PyObject * pymeth_EnumProperty
Definition bpy_props.cc:416
void RNA_def_property_poll_runtime(PropertyRNA *prop, const void *func)
PyObject * PyC_Tuple_PackArray_F32(const float *array, uint len)
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_ENUM_FLAG
Definition RNA_types.hh:474
@ PROP_ANIMATABLE
Definition RNA_types.hh:389
static PyObject * BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
static PyGetSetDef bpy_prop_deferred_getset[]
Definition bpy_props.cc:312
static PyObject * BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA * srna_from_self(PyObject *self, const char *error_prefix)
Definition bpy_rna.cc:9438
const EnumPropertyItem *(*)(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free) EnumPropertyItemFunc
Definition RNA_types.hh:921
bool pyrna_write_check()
Definition bpy_rna.cc:515
void RNA_def_property_int_array_funcs_runtime(PropertyRNA *prop, IntArrayPropertyGetFunc getfunc, IntArrayPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc, IntArrayPropertyGetTransformFunc get_transform_fn, IntArrayPropertySetTransformFunc set_transform_fn)
static std::string bpy_prop_string_get_transform_locked_fn(PointerRNA *ptr, PropertyRNA *prop, const std::string &curr_value, bool is_set)
PropertyRNA * RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static void bpy_prop_boolean_array_from_callback_or_error(PyObject *bool_array_obj, const BPyPropArrayLength &array_len_info, PyObject *py_func, bool *r_values)
Definition bpy_props.cc:944
void(*)(PointerRNA *ptr, PropertyRNA *prop, const std::string &value) StringPropertySetFunc
Definition RNA_types.hh:842
void(*)( PointerRNA *ptr, PropertyRNA *prop, const bool *curr_values, bool is_set, bool *r_values) BooleanArrayPropertyGetTransformFunc
Definition RNA_types.hh:787
float(*)(PointerRNA *ptr, PropertyRNA *prop) FloatPropertyGetFunc
Definition RNA_types.hh:817
void(*)(PointerRNA *ptr, PropertyRNA *prop, int value) IntPropertySetFunc
Definition RNA_types.hh:797
int RNA_def_property_free_identifier(StructOrFunctionRNA *cont_, const char *identifier)
static std::string bpy_prop_string_get_fn(PointerRNA *ptr, PropertyRNA *prop)
static PyObject * bpy_prop_deferred_call(BPy_PropDeferred *, PyObject *, PyObject *)
Definition bpy_props.cc:263
int(*)(PointerRNA *ptr, PropertyRNA *prop, int new_value, int curr_value, bool is_set) EnumPropertySetTransformFunc
Definition RNA_types.hh:918
PyObject * PyC_ExceptionBuffer()
int RNA_def_property_free_identifier_deferred_prepare(StructOrFunctionRNA *cont_, const char *identifier, void **handle)
static void bpy_prop_callback_assign_float_array(PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn, PyObject *get_transform_fn, PyObject *set_transform_fn)
static void bpy_prop_callback_assign_pointer(PropertyRNA *prop, PyObject *poll_fn)
static PyObject * BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
static int bpy_prop_callback_check(PyObject *py_func, const char *keyword, int argcount)
static bool bpy_prop_callback_assign_string(PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn, PyObject *get_transform_fn, PyObject *set_transform_fn, PyObject *search_fn, const eStringPropertySearchFlag search_flag)
std::string(*)(PointerRNA *ptr, PropertyRNA *prop, const std::string &value, bool is_set) StringPropertyGetTransformFunc
Definition RNA_types.hh:845
static PyObject * bpy_prop_deferred_keywords_get(BPy_PropDeferred *self, void *)
Definition bpy_props.cc:301
@ PROP_MATRIX
Definition RNA_types.hh:322
static void bpy_prop_callback_assign_int_array(PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn, PyObject *get_transform_fn, PyObject *set_transform_fn)
static int props_clear(PyObject *)
const EnumPropertyItem rna_enum_icon_items[]
Definition rna_ui_api.cc:30
int RNA_property_string_maxlength(PropertyRNA *prop)
void RNA_def_property_int_default(PropertyRNA *prop, int value)
static int bpy_prop_enum_get_fn(PointerRNA *ptr, PropertyRNA *prop)
void bpy_context_clear(struct bContext *C, const PyGILState_STATE *gilstate)
PyObject * PyC_Tuple_PackArray_Bool(const bool *array, uint len)
static void bpy_prop_string_visit_for_search_fn(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *edit_text, FunctionRef< void(StringPropertySearchVisitParams)> visit_fn)
void RNA_def_property_array(PropertyRNA *prop, int length)
int PyC_AsArray_Multi(void *array, const size_t array_item_size, PyObject *value, const int *dims, const int dims_len, const PyTypeObject *type, const char *error_prefix)
void RNA_def_property_boolean_array_funcs_runtime(PropertyRNA *prop, BooleanArrayPropertyGetFunc getfunc, BooleanArrayPropertySetFunc setfunc, BooleanArrayPropertyGetTransformFunc get_transform_fn, BooleanArrayPropertySetTransformFunc set_transform_fn)
void RNA_def_py_data(PropertyRNA *prop, void *py_data)
static int bpy_prop_array_length_parse(PyObject *o, void *p)
Definition bpy_props.cc:531
static PyObject * pymeth_IntProperty
Definition bpy_props.cc:411
int pyrna_enum_value_parse_string(PyObject *o, void *p)
static void bpy_prop_gil_rna_writable_end(const BPyPropGIL_RNAWritable_State &prop_state)
Definition bpy_props.cc:487
static std::string bpy_prop_string_get_locked_fn(PointerRNA *ptr, PropertyRNA *prop)
PyObject * BPY_rna_props()
static PyObject * BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static const EnumPropertyItem * bpy_prop_enum_itemf_fn(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
static void bpy_prop_update_fn(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
Definition bpy_props.cc:712
void(*)( PointerRNA *ptr, PropertyRNA *prop, const int *curr_values, bool is_set, int *r_values) IntArrayPropertyGetTransformFunc
Definition RNA_types.hh:806
_W64 int intptr_t
Definition BKE_text.h:119
void * RNA_property_py_data_get(PropertyRNA *prop)
header-only compatibility defines.
header-only utilities
#define PyTuple_SET_ITEMS(op_arg,...)
#define min(a, b)
Definition sort.cc:38
int dims[RNA_MAX_ARRAY_DIMENSION]
Definition bpy_props.cc:504
BPyPropArrayLength(PointerRNA *ptr, PropertyRNA *prop)
Definition bpy_props.cc:508
bool operator==(const BPyPropArrayLength &other) const
Definition bpy_props.cc:514
BPyPropStore * prev
Definition bpy_props.cc:125
BPyPropStore * next
Definition bpy_props.cc:125
struct blender::BPyPropStore::@272015242115301076255227137215124016151276252032 py_data
const EnumPropertyItem * items
PyObject_HEAD void * fn
Definition bpy_props.hh:34
std::optional< std::string > info
Definition RNA_types.hh:864
bool is_set(uint i)
struct blender::BPyPropStore::@272015242115301076255227137215124016151276252032::@260011254212300313036057375375011100041332121006::@171370051204113124243340350112163314233056313365 string_data
struct blender::BPyPropStore::@272015242115301076255227137215124016151276252032::@260011254212300313036057375375011100041332121006::@151171146354075051034366254366370305152246343176 enum_data
struct blender::BPyPropStore::@272015242115301076255227137215124016151276252032::@260011254212300313036057375375011100041332121006::@324322353102055344123176142377205371364333313227 pointer_data