23 #define USE_STRING_COERCE
25 #ifdef USE_STRING_COERCE
44 PyObject *py_key = PyUnicode_FromString(name);
45 const bool result = PyDict_Contains(kwargs, py_key) == 1;
54 const char *rna_subtype,
55 const char *description)
57 if (rna_subtype !=
NULL) {
61 "IDPropertyUIManager.update") == -1) {
66 if (description !=
NULL) {
79 PyObject *default_value)
81 if (PySequence_Check(default_value)) {
83 PyErr_SetString(PyExc_TypeError,
"Only array properties can have array default values");
87 Py_ssize_t
len = PySequence_Size(default_value);
90 new_default_array,
sizeof(
int), default_value,
len, &PyLong_Type,
"ui_data_update") ==
100 const int value = PyC_Long_AsI32(default_value);
101 if ((value == -1) && PyErr_Occurred()) {
102 PyErr_SetString(PyExc_ValueError,
"Error converting \"default\" argument to integer");
116 const char *rna_subtype =
NULL;
117 const char *description =
NULL;
118 int min,
max, soft_min, soft_max, step;
119 PyObject *default_value =
NULL;
120 const char *kwlist[] = {
121 "min",
"max",
"soft_min",
"soft_max",
"step",
"default",
"subtype",
"description",
NULL};
122 if (!PyArg_ParseTupleAndKeywords(args,
148 ui_data.soft_min =
MAX2(ui_data.soft_min, ui_data.min);
149 ui_data.max =
MAX2(ui_data.min, ui_data.max);
153 ui_data.soft_max =
MIN2(ui_data.soft_max, ui_data.max);
154 ui_data.min =
MIN2(ui_data.min, ui_data.max);
157 ui_data.soft_min = soft_min;
158 ui_data.soft_min =
MAX2(ui_data.soft_min, ui_data.min);
159 ui_data.soft_max =
MAX2(ui_data.soft_min, ui_data.soft_max);
162 ui_data.soft_max = soft_max;
163 ui_data.soft_max =
MIN2(ui_data.soft_max, ui_data.max);
164 ui_data.soft_min =
MIN2(ui_data.soft_min, ui_data.soft_max);
170 if (!
ELEM(default_value,
NULL, Py_None)) {
180 *ui_data_orig = ui_data;
190 PyObject *default_value)
192 if (PySequence_Check(default_value)) {
194 PyErr_SetString(PyExc_TypeError,
"Only array properties can have array default values");
198 Py_ssize_t
len = PySequence_Size(default_value);
205 "ui_data_update") == -1) {
214 const double value = PyFloat_AsDouble(default_value);
215 if ((value == -1.0) && PyErr_Occurred()) {
216 PyErr_SetString(PyExc_ValueError,
"Error converting \"default\" argument to double");
230 const char *rna_subtype =
NULL;
231 const char *description =
NULL;
233 double min,
max, soft_min, soft_max, step;
234 PyObject *default_value =
NULL;
235 const char *kwlist[] = {
"min",
245 if (!PyArg_ParseTupleAndKeywords(args,
247 "|$dddddiOzz:update",
272 ui_data.soft_min =
MAX2(ui_data.soft_min, ui_data.min);
273 ui_data.max =
MAX2(ui_data.min, ui_data.max);
277 ui_data.soft_max =
MIN2(ui_data.soft_max, ui_data.max);
278 ui_data.min =
MIN2(ui_data.min, ui_data.max);
281 ui_data.soft_min = soft_min;
282 ui_data.soft_min =
MAX2(ui_data.soft_min, ui_data.min);
283 ui_data.soft_max =
MAX2(ui_data.soft_min, ui_data.soft_max);
286 ui_data.soft_max = soft_max;
287 ui_data.soft_max =
MIN2(ui_data.soft_max, ui_data.max);
288 ui_data.soft_min =
MIN2(ui_data.soft_min, ui_data.soft_max);
291 ui_data.step = (
float)step;
294 ui_data.precision = precision;
297 if (!
ELEM(default_value,
NULL, Py_None)) {
307 *ui_data_orig = ui_data;
316 const char *rna_subtype =
NULL;
317 const char *description =
NULL;
318 const char *default_value;
319 const char *kwlist[] = {
"default",
"subtype",
"description",
NULL};
320 if (!PyArg_ParseTupleAndKeywords(args,
339 if (default_value !=
NULL) {
340 ui_data.default_value =
BLI_strdup(default_value);
345 *ui_data_orig = ui_data;
354 const char *rna_subtype =
NULL;
355 const char *description =
NULL;
356 const char *kwlist[] = {
"subtype",
"description",
NULL};
357 if (!PyArg_ParseTupleAndKeywords(
358 args, kwargs,
"|$zz:update", (
char **)kwlist, &rna_subtype, &description)) {
373 *ui_data_orig = ui_data;
378 ".. method:: update( "
387 "description=None)\n"
389 " Update the RNA information of the IDProperty used for interaction and\n"
390 " display in the user interface. The required types for many of the keyword\n"
391 " arguments depend on the type of the property.\n ");
425 PyErr_Format(PyExc_TypeError,
"IDProperty \"%s\" does not support RNA data", property->name);
444 PyDict_SetItemString(dict,
"min", item = PyLong_FromLong(ui_data->
min));
446 PyDict_SetItemString(dict,
"max", item = PyLong_FromLong(ui_data->
max));
448 PyDict_SetItemString(dict,
"soft_min", item = PyLong_FromLong(ui_data->
soft_min));
450 PyDict_SetItemString(dict,
"soft_max", item = PyLong_FromLong(ui_data->
soft_max));
452 PyDict_SetItemString(dict,
"step", item = PyLong_FromLong(ui_data->
step));
457 PyList_SET_ITEM(list, i, PyLong_FromLong(ui_data->
default_array[i]));
459 PyDict_SetItemString(dict,
"default", list);
463 PyDict_SetItemString(dict,
"default", item = PyLong_FromLong(ui_data->
default_value));
473 PyDict_SetItemString(dict,
"min", item = PyFloat_FromDouble(ui_data->
min));
475 PyDict_SetItemString(dict,
"max", item = PyFloat_FromDouble(ui_data->
max));
477 PyDict_SetItemString(dict,
"soft_min", item = PyFloat_FromDouble(ui_data->
soft_min));
479 PyDict_SetItemString(dict,
"soft_max", item = PyFloat_FromDouble(ui_data->
soft_max));
481 PyDict_SetItemString(dict,
"step", item = PyFloat_FromDouble((
double)ui_data->
step));
483 PyDict_SetItemString(dict,
"precision", item = PyLong_FromDouble((
double)ui_data->
precision));
488 PyList_SET_ITEM(list, i, PyFloat_FromDouble(ui_data->
default_array[i]));
490 PyDict_SetItemString(dict,
"default", list);
494 PyDict_SetItemString(dict,
"default", item = PyFloat_FromDouble(ui_data->
default_value));
506 PyDict_SetItemString(dict,
"default", item = PyUnicode_FromString(default_value));
511 ".. method:: as_dict()\n"
513 " Return a dictionary of the property's RNA UI data. The fields in the\n"
514 " returned dictionary and their types will depend on the property's type.\n");
522 PyObject *dict = PyDict_New();
526 const char *subtype_id =
NULL;
528 PyObject *item = PyUnicode_FromString(subtype_id);
529 PyDict_SetItemString(dict,
"subtype", item);
535 PyObject *item = PyUnicode_FromString(ui_data->
description);
536 PyDict_SetItemString(dict,
"description", item);
568 ".. method:: clear()\n"
570 " Remove the RNA UI data from this IDProperty.\n");
576 if (property ==
NULL) {
577 PyErr_SetString(PyExc_RuntimeError,
"IDPropertyUIManager missing property");
582 if (property->ui_data !=
NULL) {
596 BPy_IDPropertyUIManager_update_from_doc,
597 ".. method:: update_from(ui_manager_source)\n"
599 " Copy UI data from an IDProperty in the source group to a property in this group.\n "
600 " If the source property has no UI data, the target UI data will be reset if it exists.\n"
602 " :raises TypeError: If the types of the two properties don't match.\n");
613 if (property->ui_data !=
NULL) {
633 METH_VARARGS | METH_KEYWORDS,
634 BPy_IDPropertyUIManager_update_doc},
638 BPy_IDPropertyUIManager_as_dict_doc},
642 BPy_IDPropertyUIManager_clear_doc},
646 BPy_IDPropertyUIManager_update_from_doc},
652 return PyUnicode_FromFormat(
653 "<bpy id prop ui manager: name=\"%s\", address=%p>",
self->property->name,
self->property);
658 return _Py_HashPointer(
self->property);
662 PyVarObject_HEAD_INIT(
NULL, 0)
664 "IDPropertyUIManager",
typedef float(TangentPoint)[2]
eIDPropertyUIDataType IDP_ui_data_type(const struct IDProperty *prop)
struct IDPropertyUIData * IDP_ui_data_ensure(struct IDProperty *prop)
bool IDP_ui_data_supported(const struct IDProperty *prop)
void IDP_ui_data_free_unique_contents(struct IDPropertyUIData *ui_data, eIDPropertyUIDataType type, const struct IDPropertyUIData *other)
@ IDP_UI_DATA_TYPE_UNSUPPORTED
@ IDP_UI_DATA_TYPE_STRING
struct IDPropertyUIData * IDP_ui_data_copy(const struct IDProperty *prop)
void IDP_ui_data_free(struct IDProperty *prop)
#define BLI_assert_unreachable()
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
ID and Library types, which are fundamental for sdna.
Read Guarded memory(de)allocation.
PyDoc_STRVAR(BPy_IDPropertyUIManager_update_doc, ".. method:: update( " "subtype=None, " "min=None, " "max=None, " "soft_min=None, " "soft_max=None, " "precision=None, " "step=None, " "default=None, " "description=None)\n" "\n" " Update the RNA information of the IDProperty used for interaction and\n" " display in the user interface. The required types for many of the keyword\n" " arguments depend on the type of the property.\n ")
void IDPropertyUIData_Init_Types()
static bool idprop_ui_data_update_float(IDProperty *idprop, PyObject *args, PyObject *kwargs)
static PyObject * BPy_IDIDPropertyUIManager_as_dict(BPy_IDPropertyUIManager *self)
static bool idprop_ui_data_update_int(IDProperty *idprop, PyObject *args, PyObject *kwargs)
static struct PyMethodDef BPy_IDPropertyUIManager_methods[]
static PyObject * BPy_IDPropertyUIManager_update_from(BPy_IDPropertyUIManager *self, PyObject *args)
static bool idprop_ui_data_update_id(IDProperty *idprop, PyObject *args, PyObject *kwargs)
static void idprop_ui_data_to_dict_string(IDProperty *property, PyObject *dict)
static PyObject * BPy_IDPropertyUIManager_clear(BPy_IDPropertyUIManager *self)
static bool idprop_ui_data_update_base(IDPropertyUIData *ui_data, const char *rna_subtype, const char *description)
static void idprop_ui_data_to_dict_float(IDProperty *property, PyObject *dict)
static bool args_contain_key(PyObject *kwargs, const char *name)
static bool idprop_ui_data_update_float_default(IDProperty *idprop, IDPropertyUIDataFloat *ui_data, PyObject *default_value)
static void idprop_ui_data_to_dict_int(IDProperty *property, PyObject *dict)
static Py_hash_t BPy_IDPropertyUIManager_hash(BPy_IDPropertyUIManager *self)
static bool idprop_ui_data_update_string(IDProperty *idprop, PyObject *args, PyObject *kwargs)
static PyObject * BPy_IDPropertyUIManager_update(BPy_IDPropertyUIManager *self, PyObject *args, PyObject *kwargs)
PyTypeObject BPy_IDPropertyUIManager_Type
static PyObject * BPy_IDPropertyUIManager_repr(BPy_IDPropertyUIManager *self)
static bool idprop_ui_data_update_int_default(IDProperty *idprop, IDPropertyUIDataInt *ui_data, PyObject *default_value)
struct BPy_IDPropertyUIManager BPy_IDPropertyUIManager
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
void(* MEM_freeN)(void *vmemh)
int pyrna_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value, const char *error_prefix)
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)
bool RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **r_identifier)
const EnumPropertyItem rna_enum_property_subtype_items[]
PyObject_VAR_HEAD struct IDProperty * property
IDPropertyUIData * ui_data