[Bf-blender-cvs] [4877b0f742f] refactor-idprop-ui-data: Refactor new IDProperty UI data API (the changes described above)
Hans Goudey
noreply at git.blender.org
Mon Aug 2 06:17:18 CEST 2021
Commit: 4877b0f742fd049caacb2b8b8207eabaa314f357
Author: Hans Goudey
Date: Sun Aug 1 23:24:09 2021 -0400
Branches: refactor-idprop-ui-data
https://developer.blender.org/rB4877b0f742fd049caacb2b8b8207eabaa314f357
Refactor new IDProperty UI data API (the changes described above)
===================================================================
M release/scripts/modules/rna_prop_ui.py
M release/scripts/startup/bl_operators/wm.py
M source/blender/python/generic/CMakeLists.txt
M source/blender/python/generic/idprop_py_api.c
A source/blender/python/generic/idprop_py_ui_api.cc
A source/blender/python/generic/idprop_py_ui_api.h
M source/blender/python/generic/py_capi_utils.h
M source/blender/python/intern/bpy.c
M source/blender/python/intern/bpy_rna.c
M tests/python/bl_pyapi_idprop.py
===================================================================
diff --git a/release/scripts/modules/rna_prop_ui.py b/release/scripts/modules/rna_prop_ui.py
index efbaa80a89a..4b72a00f590 100644
--- a/release/scripts/modules/rna_prop_ui.py
+++ b/release/scripts/modules/rna_prop_ui.py
@@ -42,8 +42,8 @@ def rna_idprop_ui_prop_update(item, prop):
def rna_idprop_ui_prop_clear(item, prop):
- props = item.id_properties_ensure()
- props.ui_data_clear(prop)
+ ui_data = item.id_properties_ui(prop)
+ ui_data.clear()
def rna_idprop_context_value(context, context_member, property_type):
@@ -84,7 +84,8 @@ def rna_idprop_value_item_type(value):
def rna_idprop_ui_prop_default_set(item, prop, value):
- item.ui_data_update(prop, default=value)
+ ui_data = item.id_properties_ui(prop)
+ ui_data.update(default=value)
def rna_idprop_ui_create(
@@ -114,10 +115,9 @@ def rna_idprop_ui_create(
rna_idprop_ui_prop_update(item, prop)
- # Update the UI settings
- props = item.id_properties_ensure()
- props.ui_data_update(
- prop,
+ # Update the UI settings
+ ui_data = item.id_properties_ui(prop)
+ ui_data.update(
subtype=subtype,
min=min,
max=max,
diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py
index acff62015e3..96e9421a917 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -1429,20 +1429,16 @@ class WM_OT_properties_edit(Operator):
prop_type_new = type(prop_value)
prop_type, is_array = rna_idprop_value_item_type(prop_value)
- props = item.id_properties_ensure()
- props.ui_data_update(
- prop,
- subtype=self.subtype,
- description=self.description,
- )
+ ui_data = item.id_properties_ui(prop)
+ ui_data.update(subtype=self.subtype, description=self.description)
+
if prop_type == int:
if type(default_eval) == str:
self.report({'WARNING'}, "Could not evaluate number from default")
default_eval = None
elif hasattr(default_eval, "__len__"):
default_eval = [int(round(value)) for value in default_eval]
- props.ui_data_update(
- prop,
+ ui_data.update(
min=int(round(self.min)),
max=int(round(self.max)),
soft_min=int(round(self.soft_min)),
@@ -1453,8 +1449,7 @@ class WM_OT_properties_edit(Operator):
if type(default_eval) == str:
self.report({'WARNING'}, "Could not evaluate number from default")
default_eval = None
- props.ui_data_update(
- prop,
+ ui_data.update(
min=self.min,
max=self.max,
soft_min=self.soft_min,
@@ -1462,8 +1457,7 @@ class WM_OT_properties_edit(Operator):
default=default_eval,
)
elif prop_type == str:
- props.ui_data_update(prop, default=self.default)
-
+ ui_data.update(default=self.default)
# If we have changed the type of the property, update its potential anim curves!
if prop_type_old != prop_type_new:
@@ -1537,8 +1531,8 @@ class WM_OT_properties_edit(Operator):
self.default = ""
# setup defaults
- props = item.id_properties_ensure()
- rna_data = props.ui_data(prop)
+ ui_data = item.id_properties_ui(prop)
+ rna_data = ui_data.as_dict()
self.subtype = rna_data["subtype"]
if prop_type in {int, float}:
self.min = rna_data["min"]
diff --git a/source/blender/python/generic/CMakeLists.txt b/source/blender/python/generic/CMakeLists.txt
index a487e5508d4..c2d8167baf9 100644
--- a/source/blender/python/generic/CMakeLists.txt
+++ b/source/blender/python/generic/CMakeLists.txt
@@ -37,6 +37,7 @@ set(SRC
blf_py_api.c
bpy_threads.c
idprop_py_api.c
+ idprop_py_ui_api.cc
imbuf_py_api.c
py_capi_utils.c
@@ -44,6 +45,7 @@ set(SRC
bl_math_py_api.h
blf_py_api.h
idprop_py_api.h
+ idprop_py_ui_api.h
imbuf_py_api.h
py_capi_utils.h
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index a73e6a38912..c93cbdb146a 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -26,6 +26,7 @@
#include "BLI_utildefines.h"
#include "idprop_py_api.h"
+#include "idprop_py_ui_api.h"
#include "BKE_idprop.h"
@@ -1528,588 +1529,6 @@ static PyObject *BPy_IDGroup_get(BPy_IDProperty *self, PyObject *args)
return def;
}
-static bool args_contain_key(PyObject *kwargs, const char *name)
-{
- PyObject *py_key = PyUnicode_FromString(name);
- const bool result = PyDict_Contains(kwargs, py_key) == 1;
- Py_DECREF(py_key);
- return result;
-}
-
-/**
- * \return False when parsing fails, in which case caller should return NULL.
- */
-static bool idprop_ui_data_update_base(IDProperty *idprop,
- const char *rna_subtype,
- const char *description)
-{
- if (rna_subtype != NULL) {
- int result = PROP_NONE;
- if (!RNA_enum_value_from_id(rna_enum_property_subtype_items, rna_subtype, &result)) {
- PyErr_SetString(PyExc_KeyError, "RNA subtype not found");
- return false;
- }
- idprop->ui_data->rna_subtype = result;
- }
-
- if (description != NULL) {
- idprop->ui_data->description = BLI_strdup(description);
- }
-
- return true;
-}
-
-/**
- * \return False when parsing fails, in which case caller should return NULL.
- */
-static bool idprop_ui_data_update_int(IDProperty *idprop, PyObject *args, PyObject *kwargs)
-{
- /* Base class data included here to allow parsing all arguments at once. */
- const char *dummy_key;
- const char *rna_subtype = NULL;
- const char *description = NULL;
-
- int min, max, soft_min, soft_max, step;
- PyObject *default_value = NULL;
- const char *kwlist[] = {
- "", "min", "max", "soft_min", "soft_max", "step", "default", "subtype", "description", NULL};
- if (!PyArg_ParseTupleAndKeywords(args,
- kwargs,
- "s|$iiiiiOzz:ui_data_update",
- (char **)kwlist,
- &dummy_key,
- &min,
- &max,
- &soft_min,
- &soft_max,
- &step,
- &default_value,
- &rna_subtype,
- &description)) {
- return false;
- }
-
- if (!idprop_ui_data_update_base(idprop, rna_subtype, description)) {
- return false;
- }
-
- IDPropertyUIDataInt *ui_data = (IDPropertyUIDataInt *)idprop->ui_data;
-
- if (args_contain_key(kwargs, "min")) {
- ui_data->min = min;
- ui_data->soft_min = MAX2(ui_data->soft_min, ui_data->min);
- ui_data->max = MAX2(ui_data->min, ui_data->max);
- }
- if (args_contain_key(kwargs, "max")) {
- ui_data->max = max;
- ui_data->soft_max = MIN2(ui_data->soft_max, ui_data->max);
- ui_data->min = MIN2(ui_data->min, ui_data->max);
- }
- if (args_contain_key(kwargs, "soft_min")) {
- ui_data->soft_min = soft_min;
- ui_data->soft_min = MAX2(ui_data->soft_min, ui_data->min);
- ui_data->soft_max = MAX2(ui_data->soft_min, ui_data->soft_max);
- }
- if (args_contain_key(kwargs, "soft_max")) {
- ui_data->soft_max = soft_max;
- ui_data->soft_max = MIN2(ui_data->soft_max, ui_data->max);
- ui_data->soft_min = MIN2(ui_data->soft_min, ui_data->soft_max);
- }
- if (args_contain_key(kwargs, "step")) {
- ui_data->step = step;
- }
-
- /* The default value needs special handling because for array IDProperties it can be a single
- * value or an array, but for non-array properties it can only be a value. */
- if (!ELEM(default_value, NULL, Py_None)) {
- if (PySequence_Check(default_value)) {
- if (idprop->type != IDP_ARRAY) {
- PyErr_SetString(PyExc_TypeError, "Only array properties can have array default values");
- return false;
- }
-
- Py_ssize_t len = PySequence_Size(default_value);
- int *new_default_array = MEM_malloc_arrayN(len, sizeof(int), __func__);
- if (PyC_AsArray(
- new_default_array, default_value, len, &PyLong_Type, false, "ui_data_update") ==
- -1) {
- MEM_freeN(new_default_array);
- return false;
- }
-
- ui_data->default_array_len = len;
- MEM_SAFE_FREE(ui_data->default_array);
- ui_data->default_array = new_default_array;
- }
- else {
- const int value = PyC_Long_AsI32(default_value);
- if ((value == -1) && PyErr_Occurred()) {
- PyErr_SetString(PyExc_ValueError, "Error converting \"default\" argument to integer");
- return false;
- }
- ui_data->default_value = value;
- }
- }
-
- return true;
-}
-
-/**
- * \return False when parsing fails, in which case caller should return NULL.
- */
-static bool idprop_ui_data_update_float(IDProperty *idprop, PyObject *args, PyObject *kwargs)
-{
- /* Base class data included here to allow parsing all arguments at once. */
- const char *dummy_key;
- const char *rna_subtype = NULL;
- const char *description = NULL;
-
- int precision;
- double min, max, soft_min, soft_max, step;
- PyObject *default_value = NULL;
- const char *kwlist[] = {"",
- "min",
- "max",
- "soft_min",
- "soft_max",
- "step",
- "precision",
- "default",
- "subtype",
- "description",
- NULL};
- if (!PyArg_ParseTupleAndKeywords(args,
- kwargs,
- "s|$dddddiOzz:ui_data_update",
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list