[Bf-blender-cvs] [5b555dc28aa] custom-manipulators: Docs: Manipulator.target_set_handler docstring
Campbell Barton
noreply at git.blender.org
Mon Jun 26 06:13:10 CEST 2017
Commit: 5b555dc28aa819e7c5d3ef03e29bf8f99649dcf6
Author: Campbell Barton
Date: Mon Jun 26 14:17:38 2017 +1000
Branches: custom-manipulators
https://developer.blender.org/rB5b555dc28aa819e7c5d3ef03e29bf8f99649dcf6
Docs: Manipulator.target_set_handler docstring
Also generalize checks for callable args
===================================================================
M source/blender/python/intern/bpy_rna_manipulator.c
===================================================================
diff --git a/source/blender/python/intern/bpy_rna_manipulator.c b/source/blender/python/intern/bpy_rna_manipulator.c
index 2ea29f4ec41..d7bf929ff4b 100644
--- a/source/blender/python/intern/bpy_rna_manipulator.c
+++ b/source/blender/python/intern/bpy_rna_manipulator.c
@@ -166,14 +166,22 @@ static void py_rna_manipulator_handler_free_cb(
}
PyDoc_STRVAR(bpy_manipulator_target_set_handler_doc,
-".. method:: target_set_handler():\n"
+".. method:: target_set_handler(target, get, set, range=None):\n"
"\n"
-" TODO.\n"
+" Assigns callbacks to a manipulators 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 manipulators that use a range.\n"
+" :type range: callable\n"
);
static PyObject *bpy_manipulator_target_set_handler(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
{
- /* Note: this is a counter-part to RNA function:
- * 'Manipulator.target_set_prop' (see: rna_wm_manipulator_api.c). conventions should match. */
+ /* Note: this is a counter-part to functions:
+ * 'Manipulator.target_set_prop & target_set_operator'
+ * (see: rna_wm_manipulator_api.c). conventions should match. */
static const char * const _keywords[] = {"self", "target", "get", "set", "range", NULL};
static _PyArg_Parser _parser = {"Os|$OOO:target_set_handler", _keywords, 0};
@@ -212,13 +220,21 @@ static PyObject *bpy_manipulator_target_set_handler(PyObject *UNUSED(self), PyOb
goto fail;
}
- if ((!PyCallable_Check(params.py_fn_slots[BPY_MANIPULATOR_FN_SLOT_GET])) ||
- (!PyCallable_Check(params.py_fn_slots[BPY_MANIPULATOR_FN_SLOT_SET])) ||
- ((params.py_fn_slots[BPY_MANIPULATOR_FN_SLOT_RANGE] != NULL) &&
- !PyCallable_Check(params.py_fn_slots[BPY_MANIPULATOR_FN_SLOT_RANGE])))
{
- PyErr_SetString(PyExc_RuntimeError, "Non callable passed as handler");
- goto fail;
+ const int slots_required = 2;
+ const int slots_start = 2;
+ for (int i = 0; i < BPY_MANIPULATOR_FN_SLOT_LEN; i++) {
+ if (params.py_fn_slots[i] == NULL) {
+ if (i < slots_required) {
+ PyErr_Format(PyExc_ValueError, "Argument '%s' not given", _keywords[slots_start + i]);
+ goto fail;
+ }
+ }
+ else if (!PyCallable_Check(params.py_fn_slots[i])) {
+ PyErr_Format(PyExc_ValueError, "Argument '%s' not callable", _keywords[slots_start + i]);
+ goto fail;
+ }
+ }
}
struct BPyManipulatorHandlerUserData *data = MEM_callocN(sizeof(*data), __func__);
More information about the Bf-blender-cvs
mailing list