36#define BPY_MSGBUS_RNA_MSGKEY_DOC \
37 " :param key: Represents the type of data being subscribed to\n" \
39 " Arguments include\n" \
40 " - A property instance.\n" \
41 " - A struct type.\n" \
42 " - A tuple representing a (struct, property name) pair.\n" \
43 " :type key: :class:`bpy.types.Property` | " \
44 ":class:`bpy.types.Struct` | " \
45 "tuple[:class:`bpy.types.Struct`, str]\n"
59 const char *error_prefix)
65 if (py_sub_math->cb_user ==
nullptr) {
66 PyErr_Format(PyExc_TypeError,
"%s: math argument has no owner", error_prefix);
69 py_sub = py_sub_math->cb_user;
76 msg_key_params->
ptr = *data_prop->
ptr;
77 msg_key_params->
prop = data_prop->
prop;
83 msg_key_params->
ptr = *data_srna->
ptr;
86 else if (PyType_Check(py_sub)) {
88 if (data_type ==
nullptr) {
91 msg_key_params->
ptr.
type = data_type;
93 else if (PyTuple_CheckExact(py_sub)) {
94 if (PyTuple_GET_SIZE(py_sub) == 2) {
95 PyObject *data_type_py = PyTuple_GET_ITEM(py_sub, 0);
96 PyObject *data_prop_py = PyTuple_GET_ITEM(py_sub, 1);
98 if (data_type ==
nullptr) {
101 if (!PyUnicode_CheckExact(data_prop_py)) {
102 PyErr_Format(PyExc_TypeError,
"%s: expected property to be a string", error_prefix);
106 data_type_ptr.
type = data_type;
108 const char *data_prop_str = PyUnicode_AsUTF8(data_prop_py);
111 if (data_prop ==
nullptr) {
112 PyErr_Format(PyExc_TypeError,
113 "%s: struct %.200s does not contain property %.200s",
120 msg_key_params->
ptr.
type = data_type;
121 msg_key_params->
prop = data_prop;
124 PyErr_Format(PyExc_ValueError,
"%s: Expected a pair (type, property_id)", error_prefix);
137#define BPY_MSGBUS_USER_DATA_LEN 2
144 PyGILState_STATE gilstate;
151 PyObject *user_data =
static_cast<PyObject *
>(msg_val->
user_data);
154 PyObject *callback_args = PyTuple_GET_ITEM(user_data, 0);
155 PyObject *callback_notify = PyTuple_GET_ITEM(user_data, 1);
157 PyObject *
ret = PyObject_CallObject(callback_notify, callback_args);
159 if (
ret ==
nullptr) {
163 if (
ret != Py_None) {
164 PyErr_SetString(PyExc_ValueError,
"the return value must be None");
180 const PyGILState_STATE gilstate = PyGILState_Ensure();
181 Py_DECREF(msg_val->
owner);
183 PyGILState_Release(gilstate);
194 bpy_msgbus_subscribe_rna_doc,
195 ".. function:: subscribe_rna(*, key, owner, args, notify, options=set())\n"
197 " Register a message bus subscription. It will be cleared when another blend file is\n"
198 " loaded, or can be cleared explicitly via :func:`bpy.msgbus.clear_by_owner`.\n"
200 " :param owner: Handle for this subscription (compared by identity).\n"
201 " :type owner: Any\n"
202 " :param args: Arguments passed to the callback.\n"
203 " :type args: tuple\n"
204 " :param notify: The callback function.\n"
205 " :type notify: Callable[..., None]\n"
206 " :param options: Change the behavior of the subscriber.\n"
208 " - ``PERSISTENT`` when set, the subscriber will be kept when remapping ID data.\n"
210 " :type options: set[Literal['PERSISTENT']]\n"
214 " All subscribers will be cleared on file-load. Subscribers can be re-registered on load,\n"
215 " see :mod:`bpy.app.handlers.load_post`.\n");
218 const char *error_prefix =
"subscribe_rna";
219 PyObject *py_sub =
nullptr;
220 PyObject *py_owner =
nullptr;
221 PyObject *callback_args =
nullptr;
222 PyObject *callback_notify =
nullptr;
225 IS_PERSISTENT = (1 << 0),
227 PyObject *py_options =
nullptr;
229 {IS_PERSISTENT,
"PERSISTENT", 0,
""},
230 {0,
nullptr, 0,
nullptr,
nullptr},
234 if (PyTuple_GET_SIZE(args) != 0) {
235 PyErr_Format(PyExc_TypeError,
"%s: only keyword arguments are supported", error_prefix);
238 static const char *_keywords[] = {
246 static _PyArg_Parser _parser = {
257 if (!_PyArg_ParseTupleAndKeywordsFast(args,
288 if (!PyFunction_Check(callback_notify)) {
289 PyErr_Format(PyExc_TypeError,
290 "notify expects a function, found %.200s",
291 Py_TYPE(callback_notify)->tp_name);
303 msg_val_params.
owner = py_owner;
308 PyObject *user_data = PyTuple_New(2);
309 PyTuple_SET_ITEMS(user_data, Py_NewRef(callback_args), Py_NewRef(callback_notify));
327 bpy_msgbus_publish_rna_doc,
328 ".. function:: publish_rna(*, key)\n"
331 " Notify subscribers of changes to this property\n"
332 " (this typically doesn't need to be called explicitly since changes will automatically "
333 "publish updates).\n"
334 " In some cases it may be useful to publish changes explicitly using more general keys.\n");
337 const char *error_prefix =
"publish_rna";
338 PyObject *py_sub =
nullptr;
340 if (PyTuple_GET_SIZE(args) != 0) {
341 PyErr_Format(PyExc_TypeError,
"%s: only keyword arguments are supported", error_prefix);
344 static const char *_keywords[] = {
348 static _PyArg_Parser _parser = {
354 if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &py_sub)) {
374 bpy_msgbus_clear_by_owner_doc,
375 ".. function:: clear_by_owner(owner)\n"
377 " Clear all subscribers using this owner.\n"
379 " :param owner: The owner handle passed to :func:`subscribe_rna`.\n"
380 " :type owner: Any\n");
391# pragma clang diagnostic push
392# pragma clang diagnostic ignored "-Wcast-function-type"
394# pragma GCC diagnostic push
395# pragma GCC diagnostic ignored "-Wcast-function-type"
402 METH_VARARGS | METH_KEYWORDS,
403 bpy_msgbus_subscribe_rna_doc},
406 METH_VARARGS | METH_KEYWORDS,
407 bpy_msgbus_publish_rna_doc},
411 bpy_msgbus_clear_by_owner_doc},
412 {
nullptr,
nullptr, 0,
nullptr},
417# pragma clang diagnostic pop
419# pragma GCC diagnostic pop
#define BPY_MSGBUS_USER_DATA_LEN
#define BPY_MSGBUS_RNA_MSGKEY_DOC
#define PYRNA_STRUCT_CHECK_INT(obj)
#define PYRNA_PROP_CHECK_INT(obj)
#define BPy_StructRNA_Check(v)
#define BPy_PropertyRNA_Check(v)
CCL_NAMESPACE_BEGIN struct Options options
#define BaseMathObject_CheckExact(v)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static PyObject * bpy_msgbus_clear_by_owner(PyObject *, PyObject *py_owner)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
int pyrna_enum_bitfield_from_set(const EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix)
void WM_msg_dump(wmMsgBus *mbus, const char *info_str)
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static PyModuleDef _bpy_msgbus_def
static PyMethodDef BPy_msgbus_methods[]
void WM_msg_subscribe_rna_params(wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
static void bpy_msgbus_notify(bContext *C, wmMsgSubscribeKey *, wmMsgSubscribeValue *msg_val)
static PyObject * bpy_msgbus_publish_rna(PyObject *, PyObject *args, PyObject *kw)
struct bContext * BPY_context_get()
PyObject * BPY_msgbus_module()
static int py_msgbus_rna_key_from_py(PyObject *py_sub, wmMsgParams_RNA *msg_key_params, const char *error_prefix)
void WM_msgbus_clear_by_owner(wmMsgBus *mbus, void *owner)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
void PyC_Err_PrintWithFunc(PyObject *py_func)
const char * RNA_struct_identifier(const StructRNA *type)
void pyrna_write_set(bool val)
StructRNA * pyrna_struct_as_srna(PyObject *self, const bool parent, const char *error_prefix)
bool bpy_context_set(struct bContext *C, PyGILState_STATE *gilstate) ATTR_NONNULL(1)
static PyObject * bpy_msgbus_subscribe_rna(PyObject *, PyObject *args, PyObject *kw)
void bpy_context_clear(struct bContext *C, const PyGILState_STATE *gilstate)
static void bpy_msgbus_subscribe_value_free_data(wmMsgSubscribeKey *, wmMsgSubscribeValue *msg_val)
void WM_msg_publish_rna_params(wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params)
header-only compatibility defines.
#define PyTuple_SET_ITEMS(op_arg,...)
PyObject_HEAD std::optional< PointerRNA > ptr
PyObject_HEAD std::optional< PointerRNA > ptr
wmMsgSubscribeValueFreeDataFn free_data