28#include "RNA_prototypes.hh"
66 if (!PyUnicode_Check(o)) {
67 PyErr_Format(PyExc_TypeError,
"expected a string (got %.200s)", Py_TYPE(o)->tp_name);
70 const char *gz_prop_id = PyUnicode_AsUTF8(o);
72 if (gz_prop ==
nullptr) {
73 PyErr_Format(PyExc_ValueError,
74 "Gizmo target property '%s.%s' not found!",
79 gizmo_with_target->
gz_prop = gz_prop;
92 const char *gz_prop_id = PyUnicode_AsUTF8(o);
93 PyErr_Format(PyExc_ValueError,
94 "Gizmo target property '%s.%s' has not been initialized, "
95 "Call \"target_set_prop\" first!",
110 if (!PyUnicode_Check(o)) {
111 PyErr_Format(PyExc_TypeError,
"expected a string (got %.200s)", Py_TYPE(o)->tp_name);
114 const char *gz_prop_id = PyUnicode_AsUTF8(o);
117 if (gz_prop_type ==
nullptr) {
118 PyErr_Format(PyExc_ValueError,
119 "Gizmo target property '%s.%s' not found!",
139#define BPY_GIZMO_FN_SLOT_LEN (BPY_GIZMO_FN_SLOT_RANGE_GET + 1)
150 const PyGILState_STATE gilstate = PyGILState_Ensure();
155 if (
ret ==
nullptr) {
160 float *value =
static_cast<float *
>(value_p);
162 if ((*value = PyFloat_AsDouble(
ret)) == -1.0f && PyErr_Occurred()) {
172 "Gizmo get callback: ") == -1)
179 PyErr_SetString(PyExc_AttributeError,
"internal error, unsupported type");
185 PyGILState_Release(gilstate);
194 PyGILState_Release(gilstate);
201 const PyGILState_STATE gilstate = PyGILState_Ensure();
206 PyObject *args = PyTuple_New(1);
210 const float *value =
static_cast<const float *
>(value_p);
213 py_value = PyFloat_FromDouble(*value);
218 if (py_value ==
nullptr) {
221 PyTuple_SET_ITEM(args, 0, py_value);
224 PyErr_SetString(PyExc_AttributeError,
"internal error, unsupported type");
229 if (
ret ==
nullptr) {
235 PyGILState_Release(gilstate);
244 PyGILState_Release(gilstate);
254 const PyGILState_STATE gilstate = PyGILState_Ensure();
257 if (
ret ==
nullptr) {
261 if (!PyTuple_Check(
ret)) {
262 PyErr_Format(PyExc_TypeError,
"Expected a tuple, not %.200s", Py_TYPE(
ret)->tp_name);
266 if (PyTuple_GET_SIZE(
ret) != 2) {
267 PyErr_Format(PyExc_TypeError,
"Expected a tuple of size 2, not %d", PyTuple_GET_SIZE(
ret));
273 for (
int i = 0; i < 2; i++) {
274 if (((range[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(
ret, i))) == -1.0f && PyErr_Occurred()) ==
283 memcpy(value_p, range,
sizeof(range));
286 PyErr_SetString(PyExc_AttributeError,
"internal error, unsupported type");
291 PyGILState_Release(gilstate);
300 PyGILState_Release(gilstate);
308 const PyGILState_STATE gilstate = PyGILState_Ensure();
310 Py_XDECREF(data->fn_slots[i]);
312 PyGILState_Release(gilstate);
319 bpy_gizmo_target_set_handler_doc,
320 ".. method:: target_set_handler(target, get, set, range=None):\n"
322 " Assigns callbacks to a gizmos property.\n"
324 " :arg target: Target property name.\n"
325 " :type target: str\n"
326 " :arg get: Function that returns the value for this property (single value or sequence).\n"
327 " :type get: Callable[[], float | Sequence[float]]\n"
328 " :arg set: Function that takes a single value argument and applies it.\n"
329 " :type set: Callable[[tuple[float, ...]], Any]\n"
330 " :arg range: Function that returns a (min, max) tuple for gizmos that use a range. "
331 "The returned value is not used.\n"
332 " :type range: callable\n");
335 const PyGILState_STATE gilstate = PyGILState_Ensure();
348 static const char *
const _keywords[] = {
"self",
"target",
"get",
"set",
"range",
nullptr};
349 static _PyArg_Parser _parser = {
357 ":target_set_handler",
366 if (!_PyArg_ParseTupleAndKeywordsFast(args,
371 &
params.gz_with_target_type.gz,
374 &
params.gz_with_target_type,
383 gz =
params.gz_with_target_type.gz;
384 gz_prop_type =
params.gz_with_target_type.gz_prop_type;
387 const int slots_required = 2;
388 const int slots_start = 2;
390 if (
params.py_fn_slots[i] ==
nullptr) {
391 if (i < slots_required) {
392 PyErr_Format(PyExc_ValueError,
"Argument '%s' not given", _keywords[slots_start + i]);
396 else if (!PyCallable_Check(
params.py_fn_slots[i])) {
397 PyErr_Format(PyExc_ValueError,
"Argument '%s' not callable", _keywords[slots_start + i]);
407 Py_XINCREF(
params.py_fn_slots[i]);
416 fn_params.user_data =
data;
420 PyGILState_Release(gilstate);
425 PyGILState_Release(gilstate);
437 bpy_gizmo_target_get_value_doc,
438 ".. method:: target_get_value(target):\n"
440 " Get the value of this target property.\n"
442 " :arg target: Target property name.\n"
443 " :type target: str\n"
444 " :return: The value of the target property as a value or array based on the target type.\n"
445 " :rtype: float | tuple[float, ...]\n");
454 static const char *
const _keywords[] = {
"self",
"target",
nullptr};
455 static _PyArg_Parser _parser = {
468 if (!_PyArg_ParseTupleAndKeywordsFast(args,
473 &
params.gz_with_target.gz,
481 gz =
params.gz_with_target.gz;
482 gz_prop =
params.gz_with_target.gz_prop;
487 if (array_len != 0) {
494 return PyFloat_FromDouble(value);
497 PyErr_SetString(PyExc_RuntimeError,
"Not yet supported type");
508 bpy_gizmo_target_set_value_doc,
509 ".. method:: target_set_value(target):\n"
511 " Set the value of this target property.\n"
513 " :arg target: Target property name.\n"
514 " :type target: str\n");
525 static const char *
const _keywords[] = {
"self",
"target",
"value",
nullptr};
526 static _PyArg_Parser _parser = {
540 if (!_PyArg_ParseTupleAndKeywordsFast(args,
545 &
params.gz_with_target.gz,
555 gz =
params.gz_with_target.gz;
556 gz_prop =
params.gz_with_target.gz_prop;
561 if (array_len != 0) {
568 "Gizmo target property array: ") == -1)
576 if ((value = PyFloat_AsDouble(
params.value)) == -1.0f && PyErr_Occurred()) {
584 PyErr_SetString(PyExc_RuntimeError,
"Not yet supported type");
595 bpy_gizmo_target_get_range_doc,
596 ".. method:: target_get_range(target):\n"
598 " Get the range for this target property.\n"
600 " :arg target: Target property name.\n"
601 " :return: The range of this property (min, max).\n"
602 " :rtype: tuple[float, float]\n");
611 static const char *
const _keywords[] = {
"self",
"target",
nullptr};
612 static _PyArg_Parser _parser = {
624 if (!_PyArg_ParseTupleAndKeywordsFast(args,
629 &
params.gz_with_target.gz,
637 gz =
params.gz_with_target.gz;
638 gz_prop =
params.gz_with_target.gz_prop;
647 PyErr_SetString(PyExc_RuntimeError,
"Not yet supported type");
665#if (defined(__GNUC__) && !defined(__clang__))
666# pragma GCC diagnostic push
667# pragma GCC diagnostic ignored "-Wcast-function-type"
670 static PyMethodDef method_def_array[] = {
672 {
"target_set_handler",
674 METH_VARARGS | METH_KEYWORDS,
675 bpy_gizmo_target_set_handler_doc},
679 METH_VARARGS | METH_KEYWORDS,
680 bpy_gizmo_target_get_value_doc},
683 METH_VARARGS | METH_KEYWORDS,
684 bpy_gizmo_target_set_value_doc},
687 METH_VARARGS | METH_KEYWORDS,
688 bpy_gizmo_target_get_range_doc},
692#if (defined(__GNUC__) && !defined(__clang__))
693# pragma GCC diagnostic pop
696 for (
int i = 0; i <
ARRAY_SIZE(method_def_array); i++) {
697 PyMethodDef *m = &method_def_array[i];
698 PyObject *func = PyCFunction_New(m,
nullptr);
699 PyObject *func_inst = PyInstanceMethod_New(func);
700 char name_prefix[128];
701 PyOS_snprintf(name_prefix,
sizeof(name_prefix),
"_rna_gizmo_%s", m->ml_name);
703 PyModule_AddObject(mod_par, name_prefix, func_inst);
#define BLI_array_alloca(arr, realsize)
Read Guarded memory(de)allocation.
struct bContext * BPY_context_get(void)
#define BPy_StructRNA_Check(v)
static void py_rna_gizmo_handler_range_get_cb(const wmGizmo *, wmGizmoProperty *gz_prop, void *value_p)
static void py_rna_gizmo_handler_free_cb(const wmGizmo *, wmGizmoProperty *gz_prop)
bool BPY_rna_gizmo_module(PyObject *mod_par)
static int py_rna_gizmo_target_id_parse(PyObject *o, void *p)
static int py_rna_gizmo_target_id_parse_and_ensure_is_valid(PyObject *o, void *p)
PyDoc_STRVAR(bpy_gizmo_target_set_handler_doc, ".. method:: target_set_handler(target, get, set, range=None):\n" "\n" " Assigns callbacks to a gizmos property.\n" "\n" " :arg target: Target property name.\n" " :type target: str\n" " :arg get: Function that returns the value for this property (single value or sequence).\n" " :type get: Callable[[], float | Sequence[float]]\n" " :arg set: Function that takes a single value argument and applies it.\n" " :type set: Callable[[tuple[float, ...]], Any]\n" " :arg range: Function that returns a (min, max) tuple for gizmos that use a range. " "The returned value is not used.\n" " :type range: callable\n")
static PyObject * bpy_gizmo_target_set_handler(PyObject *, PyObject *args, PyObject *kw)
static PyObject * bpy_gizmo_target_set_value(PyObject *, PyObject *args, PyObject *kw)
static PyObject * bpy_gizmo_target_get_value(PyObject *, PyObject *args, PyObject *kw)
#define BPY_GIZMO_FN_SLOT_LEN
static PyObject * bpy_gizmo_target_get_range(PyObject *, PyObject *args, PyObject *kw)
static int py_rna_gizmo_target_type_id_parse(PyObject *o, void *p)
static void py_rna_gizmo_handler_get_cb(const wmGizmo *, wmGizmoProperty *gz_prop, void *value_p)
static void py_rna_gizmo_handler_set_cb(const wmGizmo *, wmGizmoProperty *gz_prop, const void *value_p)
@ BPY_GIZMO_FN_SLOT_RANGE_GET
static int py_rna_gizmo_parse(PyObject *o, void *p)
void MEM_freeN(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
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)
PyObject * PyC_Tuple_PackArray_F32(const float *array, uint len)
header-only compatibility defines.
#define PY_ARG_PARSER_HEAD_COMPAT()
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
PyObject * fn_slots[BPY_GIZMO_FN_SLOT_LEN]
const wmGizmoPropertyType * gz_prop_type
wmGizmoProperty * gz_prop
wmGizmoPropertyFnGet value_get_fn
const wmGizmoPropertyType * type
struct wmGizmoProperty::@1373 custom_func
void WM_gizmo_target_property_float_set(bContext *C, const wmGizmo *gz, wmGizmoProperty *gz_prop, const float value)
const wmGizmoPropertyType * WM_gizmotype_target_property_find(const wmGizmoType *gzt, const char *idname)
bool WM_gizmo_target_property_is_valid(const wmGizmoProperty *gz_prop)
void WM_gizmo_target_property_float_get_array(const wmGizmo *gz, wmGizmoProperty *gz_prop, float *value)
int WM_gizmo_target_property_array_length(const wmGizmo *, wmGizmoProperty *gz_prop)
void WM_gizmo_target_property_def_func_ptr(wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type, const wmGizmoPropertyFnParams *params)
float WM_gizmo_target_property_float_get(const wmGizmo *gz, wmGizmoProperty *gz_prop)
void WM_gizmo_target_property_float_set_array(bContext *C, const wmGizmo *gz, wmGizmoProperty *gz_prop, const float *value)
wmGizmoProperty * WM_gizmo_target_property_find(wmGizmo *gz, const char *idname)
bool WM_gizmo_target_property_float_range_get(const wmGizmo *gz, wmGizmoProperty *gz_prop, float range[2])