37 #include "../generic/py_capi_utils.h"
38 #include "../generic/python_utildefines.h"
55 #define BPY_GIZMO_FN_SLOT_LEN (BPY_GIZMO_FN_SLOT_RANGE_GET + 1)
66 const PyGILState_STATE gilstate = PyGILState_Ensure();
75 float *value = value_p;
77 if ((*value = PyFloat_AsDouble(
ret)) == -1.0f && PyErr_Occurred()) {
87 "Gizmo get callback: ") == -1) {
93 PyErr_SetString(PyExc_AttributeError,
"internal error, unsupported type");
99 PyGILState_Release(gilstate);
108 PyGILState_Release(gilstate);
115 const PyGILState_STATE gilstate = PyGILState_Ensure();
119 PyObject *args = PyTuple_New(1);
122 const float *value = value_p;
125 py_value = PyFloat_FromDouble(*value);
130 if (py_value ==
NULL) {
133 PyTuple_SET_ITEM(args, 0, py_value);
136 PyErr_SetString(PyExc_AttributeError,
"internal error, unsupported type");
147 PyGILState_Release(gilstate);
156 PyGILState_Release(gilstate);
165 const PyGILState_STATE gilstate = PyGILState_Ensure();
172 if (!PyTuple_Check(
ret)) {
173 PyErr_Format(PyExc_TypeError,
"Expected a tuple, not %.200s", Py_TYPE(
ret)->tp_name);
177 if (PyTuple_GET_SIZE(
ret) != 2) {
178 PyErr_Format(PyExc_TypeError,
"Expected a tuple of size 2, not %d", PyTuple_GET_SIZE(
ret));
184 for (
int i = 0; i < 2; i++) {
185 if (((range[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(
ret, i))) == -1.0f && PyErr_Occurred()) ==
193 memcpy(value_p, range,
sizeof(range));
196 PyErr_SetString(PyExc_AttributeError,
"internal error, unsupported type");
201 PyGILState_Release(gilstate);
210 PyGILState_Release(gilstate);
217 const PyGILState_STATE gilstate = PyGILState_Ensure();
219 Py_XDECREF(
data->fn_slots[i]);
221 PyGILState_Release(gilstate);
227 bpy_gizmo_target_set_handler_doc,
228 ".. method:: target_set_handler(target, get, set, range=None):\n"
230 " Assigns callbacks to a gizmos property.\n"
232 " :arg get: Function that returns the value for this property (single value or sequence).\n"
233 " :type get: callable\n"
234 " :arg set: Function that takes a single value argument and applies it.\n"
235 " :type set: callable\n"
236 " :arg range: Function that returns a (min, max) tuple for gizmos that use a range.\n"
237 " :type range: callable\n");
240 const PyGILState_STATE gilstate = PyGILState_Ensure();
249 .py_fn_slots = {
NULL},
255 static const char *
const _keywords[] = {
"self",
"target",
"get",
"set",
"range",
NULL};
256 static _PyArg_Parser _parser = {
"Os|$OOO:target_set_handler", _keywords, 0};
257 if (!_PyArg_ParseTupleAndKeywordsFast(args,
272 if (gz_prop_type ==
NULL) {
273 PyErr_Format(PyExc_ValueError,
274 "Gizmo target property '%s.%s' not found",
281 const int slots_required = 2;
282 const int slots_start = 2;
285 if (i < slots_required) {
286 PyErr_Format(PyExc_ValueError,
"Argument '%s' not given", _keywords[slots_start + i]);
290 else if (!PyCallable_Check(
params.py_fn_slots[i])) {
291 PyErr_Format(PyExc_ValueError,
"Argument '%s' not callable", _keywords[slots_start + i]);
301 Py_XINCREF(
params.py_fn_slots[i]);
314 PyGILState_Release(gilstate);
319 PyGILState_Release(gilstate);
330 ".. method:: target_get_value(target):\n"
332 " Get the value of this target property.\n"
334 " :arg target: Target property name.\n"
335 " :type target: string\n"
336 " :return: The value of the target property.\n"
337 " :rtype: Single value or array based on the target type\n");
348 static const char *
const _keywords[] = {
"self",
"target",
NULL};
349 static _PyArg_Parser _parser = {
"Os:target_get_value", _keywords, 0};
350 if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &
params.self, &
params.target)) {
357 if (gz_prop ==
NULL) {
358 PyErr_Format(PyExc_ValueError,
359 "Gizmo target property '%s.%s' not found",
368 if (array_len != 0) {
375 return PyFloat_FromDouble(value);
380 PyErr_SetString(PyExc_RuntimeError,
"Not yet supported type");
390 ".. method:: target_set_value(target):\n"
392 " Set the value of this target property.\n"
394 " :arg target: Target property name.\n"
395 " :type target: string\n");
408 static const char *
const _keywords[] = {
"self",
"target",
"value",
NULL};
409 static _PyArg_Parser _parser = {
"OsO:target_set_value", _keywords, 0};
410 if (!_PyArg_ParseTupleAndKeywordsFast(
418 if (gz_prop ==
NULL) {
419 PyErr_Format(PyExc_ValueError,
420 "Gizmo target property '%s.%s' not found",
429 if (array_len != 0) {
436 "Gizmo target property array") == -1) {
443 if ((value = PyFloat_AsDouble(
params.value)) == -1.0f && PyErr_Occurred()) {
451 PyErr_SetString(PyExc_RuntimeError,
"Not yet supported type");
461 ".. method:: target_get_range(target):\n"
463 " Get the range for this target property.\n"
465 " :arg target: Target property name.\n"
466 " :return: The range of this property (min, max).\n"
467 " :rtype: tuple pair.\n");
478 static const char *
const _keywords[] = {
"self",
"target",
NULL};
479 static _PyArg_Parser _parser = {
"Os:target_get_range", _keywords, 0};
480 if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &
params.self, &
params.target)) {
487 if (gz_prop ==
NULL) {
488 PyErr_Format(PyExc_ValueError,
489 "Gizmo target property '%s.%s' not found",
502 PyErr_SetString(PyExc_RuntimeError,
"Not yet supported type");
515 static PyMethodDef method_def_array[] = {
517 {
"target_set_handler",
519 METH_VARARGS | METH_KEYWORDS,
520 bpy_gizmo_target_set_handler_doc},
524 METH_VARARGS | METH_KEYWORDS,
525 bpy_gizmo_target_get_value_doc},
528 METH_VARARGS | METH_KEYWORDS,
529 bpy_gizmo_target_set_value_doc},
532 METH_VARARGS | METH_KEYWORDS,
533 bpy_gizmo_target_get_range_doc},
537 for (
int i = 0; i <
ARRAY_SIZE(method_def_array); i++) {
538 PyMethodDef *m = &method_def_array[i];
539 PyObject *func = PyCFunction_New(m,
NULL);
540 PyObject *func_inst = PyInstanceMethod_New(func);
541 char name_prefix[128];
542 PyOS_snprintf(name_prefix,
sizeof(name_prefix),
"_rna_gizmo_%s", m->ml_name);
544 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)
@ BPY_GIZMO_FN_SLOT_RANGE_GET
static PyObject * bpy_gizmo_target_get_value(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static void py_rna_gizmo_handler_range_get_cb(const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, void *value_p)
bool BPY_rna_gizmo_module(PyObject *mod_par)
static void py_rna_gizmo_handler_set_cb(const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, const void *value_p)
static PyObject * bpy_gizmo_target_get_range(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static PyObject * bpy_gizmo_target_set_value(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
#define BPY_GIZMO_FN_SLOT_LEN
static PyObject * bpy_gizmo_target_set_handler(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static void py_rna_gizmo_handler_get_cb(const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, void *value_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 get: Function that returns the value for this property (single value or sequence).\n" " :type get: callable\n" " :arg set: Function that takes a single value argument and applies it.\n" " :type set: callable\n" " :arg range: Function that returns a (min, max) tuple for gizmos that use a range.\n" " :type range: callable\n")
static void py_rna_gizmo_handler_free_cb(const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
PyObject * PyC_Tuple_PackArray_F32(const float *array, uint len)
int PyC_AsArray(void *array, PyObject *value, const Py_ssize_t length, const PyTypeObject *type, const bool is_double, const char *error_prefix)
PyObject * fn_slots[BPY_GIZMO_FN_SLOT_LEN]
struct wmGizmoProperty::@1149 custom_func
const struct wmGizmoPropertyType * type
const struct wmGizmoType * type
void WM_gizmo_target_property_float_set(bContext *C, const wmGizmo *gz, wmGizmoProperty *gz_prop, const float value)
wmGizmoProperty * WM_gizmo_target_property_find(wmGizmo *gz, const char *idname)
void WM_gizmo_target_property_float_get_array(const wmGizmo *gz, wmGizmoProperty *gz_prop, float *value)
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)
const wmGizmoPropertyType * WM_gizmotype_target_property_find(const wmGizmoType *gzt, const char *idname)
int WM_gizmo_target_property_array_length(const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop)
bool WM_gizmo_target_property_float_range_get(const wmGizmo *gz, wmGizmoProperty *gz_prop, float range[2])