28 PyGILState_STATE gilstate = PyGILState_Ensure();
30 PyObject *py_args =
static_cast<PyObject *
>(user_data);
31 PyObject *py_func_or_msg = PyTuple_GET_ITEM(py_args, 0);
35 if (PyUnicode_Check(py_func_or_msg)) {
37 const char *msg_src = PyUnicode_AsUTF8AndSize(py_func_or_msg, &msg_len);
41 PyObject *py_args_after_first = PyTuple_GetSlice(py_args, 1, PY_SSIZE_T_MAX);
42 PyObject *py_msg = PyObject_CallObject(py_func_or_msg, py_args_after_first);
43 Py_DECREF(py_args_after_first);
48 if (py_msg ==
nullptr) {
52 if (py_msg == Py_None) {
55 else if (PyUnicode_Check(py_msg)) {
56 Py_ssize_t msg_src_len;
57 const char *msg_src = PyUnicode_AsUTF8AndSize(py_msg, &msg_src_len);
61 PyErr_Format(PyExc_TypeError,
62 "poll_message_set(function, ...): expected string or None, got %.200s",
63 Py_TYPE(py_msg)->tp_name);
75 PyGILState_Release(gilstate);
87 BPY_rna_operator_poll_message_set_doc,
88 ".. classmethod:: poll_message_set(message, *args)\n"
90 " Set the message to show in the tool-tip when poll fails.\n"
92 " When message is callable, "
93 "additional user defined positional arguments are passed to the message function.\n"
95 " :arg message: The message or a function that returns the message.\n"
96 " :type message: str | Callable[..., str | None]\n"
97 " :arg args: A sequence of arguments to pass to ``message``, if it's a callable, "
98 "otherwise argument is not available.\n"
99 " :type args: Any\n");
103 const Py_ssize_t args_len = PyTuple_GET_SIZE(args);
105 PyErr_SetString(PyExc_ValueError,
106 "poll_message_set(message, ...): requires a message argument");
110 PyObject *py_func_or_msg = PyTuple_GET_ITEM(args, 0);
112 if (PyUnicode_Check(py_func_or_msg)) {
114 PyErr_SetString(PyExc_ValueError,
115 "poll_message_set(message): does not support additional arguments");
119 else if (PyCallable_Check(py_func_or_msg)) {
123 PyErr_Format(PyExc_TypeError,
124 "poll_message_set(message, ...): "
125 "expected at least 1 string or callable argument, got %.200s",
126 Py_TYPE(py_func_or_msg)->tp_name);
134 params.user_data = Py_NewRef(args);
144 METH_VARARGS | METH_STATIC,
145 BPY_rna_operator_poll_message_set_doc,
void CTX_wm_operator_poll_msg_set_dynamic(bContext *C, const bContextPollMsgDyn_Params *params)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BPY_DECREF(void *pyob_ptr)
struct bContext * BPY_context_get()
static char * pyop_poll_message_get_fn(bContext *, void *user_data)
static PyObject * BPY_rna_operator_poll_message_set(PyObject *, PyObject *args)
static void pyop_poll_message_free_fn(bContext *, void *user_data)
PyDoc_STRVAR(BPY_rna_operator_poll_message_set_doc, ".. classmethod:: 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" " :arg message: The message or a function that returns the message.\n" " :type message: str | Callable[..., str | None]\n" " :arg args: A sequence of arguments to pass to ``message``, if it's a callable, " "otherwise argument is not available.\n" " :type args: Any\n")
PyMethodDef BPY_rna_operator_poll_message_set_method_def
static void error(const char *str)