15 #include "../generic/python_utildefines.h"
28 PyGILState_STATE gilstate = PyGILState_Ensure();
31 PyObject *py_func_or_msg = PyTuple_GET_ITEM(py_args, 0);
33 if (PyUnicode_Check(py_func_or_msg)) {
34 return BLI_strdup(PyUnicode_AsUTF8(py_func_or_msg));
37 PyObject *py_args_after_first = PyTuple_GetSlice(py_args, 1, PY_SSIZE_T_MAX);
38 PyObject *py_msg = PyObject_CallObject(py_func_or_msg, py_args_after_first);
39 Py_DECREF(py_args_after_first);
49 if (py_msg == Py_None) {
52 else if (PyUnicode_Check(py_msg)) {
56 PyErr_Format(PyExc_TypeError,
57 "poll_message_set(function, ...): expected string or None, got %.200s",
58 Py_TYPE(py_msg)->tp_name);
69 PyGILState_Release(gilstate);
80 ".. method:: poll_message_set(message, *args)\n"
82 " Set the message to show in the tool-tip when poll fails.\n"
84 " When message is callable, "
85 "additional user defined positional arguments are passed to the message function.\n"
87 " :param message: The message or a function that returns the message.\n"
88 " :type message: string or a callable that returns a string or None.\n");
92 const Py_ssize_t args_len = PyTuple_GET_SIZE(args);
94 PyErr_SetString(PyExc_ValueError,
95 "poll_message_set(message, ...): requires a message argument");
99 PyObject *py_func_or_msg = PyTuple_GET_ITEM(args, 0);
101 if (PyUnicode_Check(py_func_or_msg)) {
103 PyErr_SetString(PyExc_ValueError,
104 "poll_message_set(message): does not support additional arguments");
108 else if (PyCallable_Check(py_func_or_msg)) {
112 PyErr_Format(PyExc_TypeError,
113 "poll_message_set(message, ...): "
114 "expected at least 1 string or callable argument, got %.200s",
115 Py_TYPE(py_func_or_msg)->tp_name);
123 .user_data = Py_INCREF_RET(args),
134 METH_VARARGS | METH_STATIC,
135 BPY_rna_operator_poll_message_set_doc,
void CTX_wm_operator_poll_msg_set_dynamic(bContext *C, const struct bContextPollMsgDyn_Params *params)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
void BPY_DECREF(void *pyob_ptr)
struct bContext * BPY_context_get(void)
static void pyop_poll_message_free_fn(bContext *UNUSED(C), void *user_data)
static PyObject * BPY_rna_operator_poll_message_set(PyObject *UNUSED(self), PyObject *args)
PyDoc_STRVAR(BPY_rna_operator_poll_message_set_doc, ".. method:: poll_message_set(message, *args)\n" "\n" " Set the message to show in the tool-tip when poll fails.\n" "\n" " When message is callable, " "additional user defined positional arguments are passed to the message function.\n" "\n" " :param message: The message or a function that returns the message.\n" " :type message: string or a callable that returns a string or None.\n")
PyMethodDef BPY_rna_operator_poll_message_set_method_def
static char * pyop_poll_message_get_fn(bContext *UNUSED(C), void *user_data)
static void error(const char *str)