27#define USE_STRING_COERCE
42 const char *rna_subtype,
43 const char *description)
45 if (rna_subtype !=
nullptr) {
49 "IDPropertyUIManager.update") == -1)
55 if (description !=
nullptr) {
65 if (PyLong_CheckExact(py_long)) {
66 *r_int = int(PyLong_AS_LONG(py_long));
79 if (!PyTuple_CheckExact(py_item)) {
82 Py_ssize_t item_size = PyTuple_GET_SIZE(py_item);
83 if (item_size < 3 || item_size > 5) {
87 Py_ssize_t identifier_len;
89 Py_ssize_t description_len;
90 const char *identifier = PyUnicode_AsUTF8AndSize(PyTuple_GET_ITEM(py_item, 0), &identifier_len);
91 const char *name = PyUnicode_AsUTF8AndSize(PyTuple_GET_ITEM(py_item, 1), &name_len);
92 const char *description = PyUnicode_AsUTF8AndSize(PyTuple_GET_ITEM(py_item, 2),
94 if (!identifier || !name || !description) {
98 const char *icon_name =
nullptr;
102 else if (item_size == 4) {
107 else if (item_size == 5) {
110 !(icon_name = PyUnicode_AsUTF8(PyTuple_GET_ITEM(py_item, 3))))
132 const Py_ssize_t seq_len = PySequence_Fast_GET_SIZE(seq_fast);
133 PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
136 items = MEM_new_array<IDPropertyUIDataEnumItem>(seq_len, __func__);
137 r_items_num = seq_len;
139 for (i = 0; i < seq_len; i++) {
141 PyObject *py_item = seq_fast_items[i];
145 else if (py_item == Py_None) {
150 PyErr_SetString(PyExc_TypeError,
151 "expected a tuple containing "
152 "(identifier, name, description) and optionally an "
153 "icon name and unique number");
167 PyObject *default_value)
169 if (PySequence_Check(default_value)) {
171 PyErr_SetString(PyExc_TypeError,
"Only array properties can have array default values");
175 Py_ssize_t
len = PySequence_Size(default_value);
178 new_default_array,
sizeof(
int), default_value,
len, &PyLong_Type,
"ui_data_update") ==
181 MEM_delete(new_default_array);
189 const int value = PyC_Long_AsI32(default_value);
190 if ((value == -1) && PyErr_Occurred()) {
191 PyErr_SetString(PyExc_ValueError,
"Cannot convert \"default\" argument to integer");
210 const char *rna_subtype =
nullptr;
211 const char *description =
nullptr;
212 std::optional<int>
min,
max, soft_min, soft_max,
step;
213 PyObject *default_value =
nullptr;
214 PyObject *items =
nullptr;
216 static const char *_keywords[] = {
228 static _PyArg_Parser _parser = {
243 if (!_PyArg_ParseTupleAndKeywordsFast(args,
276 ui_data.
max = std::max(ui_data.
min, ui_data.
max);
281 ui_data.
min = std::min(ui_data.
min, ui_data.
max);
297 if (!
ELEM(default_value,
nullptr, Py_None)) {
305 if (!
ELEM(items,
nullptr, Py_None)) {
306 PyObject *items_fast;
307 if (!(items_fast = PySequence_Fast(items,
"expected a sequence of tuples for the enum items")))
314 int idprop_items_num = 0;
319 const bool has_error = (idprop_items ==
nullptr) ||
321 idprop_items, idprop_items_num, [](
const char *msg) {
322 PyErr_SetString(PyExc_ValueError, msg);
324 Py_DECREF(items_fast);
325 if (idprop_items !=
nullptr) {
345 *ui_data_orig = ui_data;
355 PyObject *default_value)
357 if (PySequence_Check(default_value)) {
359 PyErr_SetString(PyExc_TypeError,
"Only array properties can have array default values");
363 Py_ssize_t
len = PySequence_Size(default_value);
370 "ui_data_update") == -1)
372 MEM_delete(new_default_array);
381 if ((value == -1) && PyErr_Occurred()) {
382 PyErr_SetString(PyExc_ValueError,
"Cannot convert \"default\" argument to integer");
401 const char *rna_subtype =
nullptr;
402 const char *description =
nullptr;
403 PyObject *default_value =
nullptr;
404 const char *kwlist[] = {
"default",
"subtype",
"description",
nullptr};
405 if (!PyArg_ParseTupleAndKeywords(args,
412 const_cast<char **
>(kwlist),
429 if (!
ELEM(default_value,
nullptr, Py_None)) {
439 *ui_data_orig = ui_data;
449 PyObject *default_value)
451 if (PySequence_Check(default_value)) {
453 PyErr_SetString(PyExc_TypeError,
"Only array properties can have array default values");
457 Py_ssize_t
len = PySequence_Size(default_value);
464 "ui_data_update") == -1)
466 MEM_delete(new_default_array);
474 const double value = PyFloat_AsDouble(default_value);
475 if ((value == -1.0) && PyErr_Occurred()) {
476 PyErr_SetString(PyExc_ValueError,
"Cannot convert \"default\" argument to double");
495 const char *rna_subtype =
nullptr;
496 const char *description =
nullptr;
497 std::optional<int> precision;
498 std::optional<double>
min,
max, soft_min, soft_max,
step;
499 PyObject *default_value =
nullptr;
501 static const char *_keywords[] = {
513 static _PyArg_Parser _parser = {
528 if (!_PyArg_ParseTupleAndKeywordsFast(args,
562 ui_data.
max = std::max(ui_data.
min, ui_data.
max);
567 ui_data.
min = std::min(ui_data.
min, ui_data.
max);
586 if (!
ELEM(default_value,
nullptr, Py_None)) {
596 *ui_data_orig = ui_data;
605 const char *rna_subtype =
nullptr;
606 const char *description =
nullptr;
607 const char *default_value =
nullptr;
608 const char *kwlist[] = {
"default",
"subtype",
"description",
nullptr};
609 if (!PyArg_ParseTupleAndKeywords(args,
616 const_cast<char **
>(kwlist),
634 if (default_value !=
nullptr) {
640 *ui_data_orig = ui_data;
649 const char *rna_subtype =
nullptr;
650 const char *description =
nullptr;
651 const char *id_type =
nullptr;
652 const char *kwlist[] = {
"subtype",
"description",
"id_type",
nullptr};
653 if (!PyArg_ParseTupleAndKeywords(args,
660 const_cast<char **
>(kwlist),
677 if (id_type !=
nullptr) {
685 ui_data.
id_type = short(id_type_tmp);
690 *ui_data_orig = ui_data;
696 BPy_IDPropertyUIManager_update_doc,
697 ".. method:: update(*, "
708 "description=None)\n"
710 " Update the RNA information of the IDProperty used for interaction and\n"
711 " display in the user interface. The required types for many of the keyword\n"
712 " arguments depend on the type of the property.\n"
714 " :param subtype: Enumerator in :ref:`rna_enum_property_subtype_items`.\n"
715 " :type subtype: str | None\n"
716 " :param min: Minimum value (int & float properties).\n"
717 " :type min: int | float | None\n"
718 " :param max: Maximum value (int & float properties).\n"
719 " :type max: int | float | None\n"
720 " :param soft_min: Soft minimum value (int & float properties).\n"
721 " :type soft_min: int | float | None\n"
722 " :param soft_max: Soft maximum value (int & float properties).\n"
723 " :type soft_max: int | float | None\n"
724 " :param precision: Number of digits to display after the decimal point\n"
725 " (float properties).\n"
726 " :type precision: int | None\n"
727 " :param step: Step used when dragging the value (int & float properties).\n"
728 " :type step: int | float | None\n"
729 " :param default: Default value, may be a sequence for array properties.\n"
730 " :type default: Any\n"
731 " :param id_type: Enumerator in :ref:`rna_enum_id_type_items` (ID properties).\n"
732 " :type id_type: str | None\n"
733 " :param items: Enum items (int properties),\n"
734 " see :func:`bpy.props.EnumProperty` for the item format.\n"
735 " :type items: Iterable["
736 "tuple[str, str, str] | "
737 "tuple[str, str, str, int] | "
738 "tuple[str, str, str, str | int, int] | "
740 " :param description: Tooltip text.\n"
741 " :type description: str | None\n");
781 PyErr_Format(PyExc_TypeError,
"IDProperty \"%s\" does not support RNA data", property->name);
800 PyDict_SetItemString(dict,
"min", item = PyLong_FromLong(ui_data->
min));
802 PyDict_SetItemString(dict,
"max", item = PyLong_FromLong(ui_data->
max));
804 PyDict_SetItemString(dict,
"soft_min", item = PyLong_FromLong(ui_data->
soft_min));
806 PyDict_SetItemString(dict,
"soft_max", item = PyLong_FromLong(ui_data->
soft_max));
808 PyDict_SetItemString(dict,
"step", item = PyLong_FromLong(ui_data->
step));
815 PyDict_SetItemString(dict,
"default",
list);
819 PyDict_SetItemString(dict,
"default", item = PyLong_FromLong(ui_data->
default_value));
830 PyObject *item_tuple = PyTuple_New(5);
831 PyTuple_SET_ITEM(item_tuple, 0, PyUnicode_FromString(item.
identifier));
832 PyTuple_SET_ITEM(item_tuple, 1, PyUnicode_FromString(item.
name));
835 PyTuple_SET_ITEM(item_tuple, 3, PyLong_FromLong(item.
icon));
836 PyTuple_SET_ITEM(item_tuple, 4, PyLong_FromLong(item.
value));
838 PyList_SET_ITEM(items_list, i, item_tuple);
840 PyDict_SetItemString(dict,
"items", items_list);
841 Py_DECREF(items_list);
855 PyDict_SetItemString(dict,
"default",
list);
859 PyDict_SetItemString(dict,
"default", item = PyBool_FromLong(ui_data->
default_value));
869 PyDict_SetItemString(dict,
"min", item = PyFloat_FromDouble(ui_data->
min));
871 PyDict_SetItemString(dict,
"max", item = PyFloat_FromDouble(ui_data->
max));
873 PyDict_SetItemString(dict,
"soft_min", item = PyFloat_FromDouble(ui_data->
soft_min));
875 PyDict_SetItemString(dict,
"soft_max", item = PyFloat_FromDouble(ui_data->
soft_max));
877 PyDict_SetItemString(dict,
"step", item = PyFloat_FromDouble(
double(ui_data->
step)));
879 PyDict_SetItemString(dict,
"precision", item = PyLong_FromDouble(
double(ui_data->
precision)));
886 PyDict_SetItemString(dict,
"default",
list);
890 PyDict_SetItemString(dict,
"default", item = PyFloat_FromDouble(ui_data->
default_value));
902 PyDict_SetItemString(dict,
"default", item = PyUnicode_FromString(default_value));
910 short id_type_value = ui_data->
id_type;
911 if (id_type_value == 0) {
916 id_type_value =
id ?
GS(
id->name) :
ID_OB;
919 const char *id_type =
nullptr;
925 PyObject *item = PyUnicode_FromString(id_type);
926 PyDict_SetItemString(dict,
"id_type", item);
932 BPy_IDPropertyUIManager_as_dict_doc,
933 ".. method:: as_dict()\n"
935 " Return a dictionary of the property's RNA UI data. The fields in the\n"
936 " returned dictionary and their types will depend on the property's type.\n"
938 " :return: The property's UI data.\n"
939 " :rtype: dict[str, Any]\n");
947 PyObject *dict = PyDict_New();
951 const char *subtype_id =
nullptr;
956 PyObject *item = PyUnicode_FromString(subtype_id);
957 PyDict_SetItemString(dict,
"subtype", item);
963 PyObject *item = PyUnicode_FromString(ui_data->
description);
964 PyDict_SetItemString(dict,
"description", item);
1001 BPy_IDPropertyUIManager_clear_doc,
1002 ".. method:: clear()\n"
1004 " Remove the RNA UI data from this IDProperty.\n");
1010 if (property ==
nullptr) {
1011 PyErr_SetString(PyExc_RuntimeError,
"IDPropertyUIManager missing property");
1016 if (property->ui_data !=
nullptr) {
1031 BPy_IDPropertyUIManager_update_from_doc,
1032 ".. method:: update_from(ui_manager_source, /)\n"
1034 " Copy UI data from an IDProperty in the source group to a property in this group.\n"
1035 " If the source property has no UI data, the target UI data will be reset if it exists.\n"
1037 " :param ui_manager_source: The UI manager to copy from.\n"
1038 " :type ui_manager_source: :class:`IDPropertyUIManager`\n"
1039 " :raises TypeError: If the types of the two properties don't match.\n");
1046 if (!PyArg_ParseTuple(args,
1056 if ((property->type != src_prop->
type) || property->subtype != src_prop->
subtype) {
1057 PyErr_SetString(PyExc_TypeError,
"Properties type does not match.");
1061 if (property->ui_data !=
nullptr) {
1080# pragma clang diagnostic push
1081# pragma clang diagnostic ignored "-Wcast-function-type"
1083# pragma GCC diagnostic push
1084# pragma GCC diagnostic ignored "-Wcast-function-type"
1091 METH_VARARGS | METH_KEYWORDS,
1092 BPy_IDPropertyUIManager_update_doc},
1096 BPy_IDPropertyUIManager_as_dict_doc},
1100 BPy_IDPropertyUIManager_clear_doc},
1104 BPy_IDPropertyUIManager_update_from_doc},
1105 {
nullptr,
nullptr, 0,
nullptr},
1110# pragma clang diagnostic pop
1112# pragma GCC diagnostic pop
1118 return PyUnicode_FromFormat(
1129 BPy_IDPropertyUIManager_Type_doc,
1130 "Manages the UI data of an ID property, "
1131 "see :meth:`bpy.types.bpy_struct.id_properties_ui`.");
1134 PyVarObject_HEAD_INIT(
nullptr, 0)
1136 "IDPropertyUIManager",
1155 BPy_IDPropertyUIManager_Type_doc,
ID and Library types, which are fundamental for SDNA.
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
bool IDP_EnumItemsValidate(const IDPropertyUIDataEnumItem *items, int items_num, void(*error_fn)(const char *))
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static PyMethodDef BPy_IDPropertyUIManager_methods[]
int PyC_ParseOptionalDouble(PyObject *o, void *p)
static Py_hash_t BPy_IDPropertyUIManager_hash(BPy_IDPropertyUIManager *self)
const EnumPropertyItem rna_enum_id_type_items[]
static bool idprop_ui_data_update_base(IDPropertyUIData *ui_data, const char *rna_subtype, const char *description)
static bool py_long_as_int(PyObject *py_long, int *r_int)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void idprop_ui_data_to_dict_int(IDProperty *property, PyObject *dict)
void IDPropertyUIData_Init_Types()
static PyObject * BPy_IDIDPropertyUIManager_as_dict(BPy_IDPropertyUIManager *self)
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")
const EnumPropertyItem rna_enum_property_subtype_items[]
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)
static bool idprop_ui_data_update_float_default(IDProperty *idprop, IDPropertyUIDataFloat *ui_data, PyObject *default_value)
eIDPropertyUIDataType IDP_ui_data_type(const IDProperty *prop)
static PyObject * BPy_IDPropertyUIManager_clear(BPy_IDPropertyUIManager *self)
void IDP_ui_data_free(IDProperty *prop)
static bool idprop_ui_data_update_float(IDProperty *idprop, PyObject *args, PyObject *kwargs)
static bool idprop_ui_data_update_bool_default(IDProperty *idprop, IDPropertyUIDataBool *ui_data, PyObject *default_value)
static bool idprop_ui_data_update_int_default(IDProperty *idprop, IDPropertyUIDataInt *ui_data, PyObject *default_value)
int PyC_ParseOptionalInt(PyObject *o, void *p)
static PyObject * BPy_IDPropertyUIManager_repr(BPy_IDPropertyUIManager *self)
static void idprop_ui_data_to_dict_string(IDProperty *property, PyObject *dict)
static bool idprop_ui_data_update_string(IDProperty *idprop, PyObject *args, PyObject *kwargs)
int PyC_Long_AsBool(PyObject *value)
bool RNA_enum_value_from_identifier(const EnumPropertyItem *item, const char *identifier, int *r_value)
PyTypeObject BPy_IDPropertyUIManager_Type
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
static PyObject * BPy_IDPropertyUIManager_update(BPy_IDPropertyUIManager *self, PyObject *args, PyObject *kwargs)
void IDP_ui_data_free_unique_contents(IDPropertyUIData *ui_data, eIDPropertyUIDataType type, const IDPropertyUIData *other)
static void idprop_ui_data_to_dict_float(IDProperty *property, PyObject *dict)
static bool idprop_ui_data_update_int(IDProperty *idprop, PyObject *args, PyObject *kwargs)
ID_Type GS(const char *name)
static bool idprop_ui_data_update_id(IDProperty *idprop, PyObject *args, PyObject *kwargs)
static void idprop_ui_data_to_dict_bool(IDProperty *property, PyObject *dict)
static IDPropertyUIDataEnumItem * idprop_enum_items_from_py(PyObject *seq_fast, int &r_items_num)
static void idprop_ui_data_to_dict_id(IDProperty *property, PyObject *dict)
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
void IDP_EnumItemsFree(IDPropertyUIDataEnumItem *items, int items_num)
bool RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **r_identifier)
static bool try_parse_enum_item(PyObject *py_item, const int index, IDPropertyUIDataEnumItem &item)
IDPropertyUIData * IDP_ui_data_copy(const IDProperty *prop)
int pyrna_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value, const char *error_prefix)
const EnumPropertyItem rna_enum_icon_items[]
IDPropertyUIData * IDP_ui_data_ensure(IDProperty *prop)
@ IDP_UI_DATA_TYPE_STRING
@ IDP_UI_DATA_TYPE_UNSUPPORTED
@ IDP_UI_DATA_TYPE_BOOLEAN
bool IDP_ui_data_supported(const IDProperty *prop)
static bool idprop_ui_data_update_bool(IDProperty *idprop, PyObject *args, PyObject *kwargs)
static PyObject * BPy_IDPropertyUIManager_update_from(BPy_IDPropertyUIManager *self, PyObject *args)
header-only compatibility defines.
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
PyObject_HEAD IDProperty * property
IDPropertyUIDataEnumItem * enum_items
IDPropertyUIData * ui_data