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);
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);
74 PyGILState_Release(gilstate);
86 BPY_rna_operator_poll_message_set_doc,
87 ".. classmethod:: poll_message_set(message, *args)\n"
89 " Set the message to show in the tool-tip when poll fails.\n"
91 " When message is callable, "
92 "additional user defined positional arguments are passed to the message function.\n"
94 " :arg message: The message or a function that returns the message.\n"
95 " :type message: str | Callable[..., str | None]\n"
96 " :arg args: A sequence of arguments to pass to ``message``, if it's a callable, "
97 "otherwise argument is not available.\n"
98 " :type args: Any\n");
101 const Py_ssize_t args_len = PyTuple_GET_SIZE(args);
103 PyErr_SetString(PyExc_ValueError,
104 "poll_message_set(message, ...): requires a message argument");
108 PyObject *py_func_or_msg = PyTuple_GET_ITEM(args, 0);
110 if (PyUnicode_Check(py_func_or_msg)) {
112 PyErr_SetString(PyExc_ValueError,
113 "poll_message_set(message): does not support additional arguments");
117 else if (PyCallable_Check(py_func_or_msg)) {
121 PyErr_Format(PyExc_TypeError,
122 "poll_message_set(message, ...): "
123 "expected at least 1 string or callable argument, got %.200s",
124 Py_TYPE(py_func_or_msg)->tp_name);
132 params.user_data = Py_NewRef(args);
142 METH_VARARGS | METH_STATIC,
143 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)