21 #include "../generic/python_utildefines.h"
27 const int pointers_num,
37 "Called after frame change for playback and rendering, before any data is evaluated for the "
38 "new frame. This makes it possible to change data and relations (for example swap an object "
39 "to another mesh) for the new frame. Note that this handler is **not** to be used as 'before "
40 "the frame changes' event. The dependency graph is not available in this handler, as data "
41 "and relations may have been altered and the dependency graph has not yet been updated for "
44 "Called after frame change for playback and rendering, after the data has been evaluated "
45 "for the new frame."},
46 {
"render_pre",
"on render (before)"},
47 {
"render_post",
"on render (after)"},
48 {
"render_write",
"on writing a render frame (directly after the frame is written)"},
49 {
"render_stats",
"on printing render statistics"},
50 {
"render_init",
"on initialization of a render job"},
51 {
"render_complete",
"on completion of render job"},
52 {
"render_cancel",
"on canceling a render job"},
53 {
"load_pre",
"on loading a new blend file (before)"},
54 {
"load_post",
"on loading a new blend file (after)"},
55 {
"save_pre",
"on saving a blend file (before)"},
56 {
"save_post",
"on saving a blend file (after)"},
57 {
"undo_pre",
"on loading an undo step (before)"},
58 {
"undo_post",
"on loading an undo step (after)"},
59 {
"redo_pre",
"on loading a redo step (before)"},
60 {
"redo_post",
"on loading a redo step (after)"},
61 {
"depsgraph_update_pre",
"on depsgraph update (pre)"},
62 {
"depsgraph_update_post",
"on depsgraph update (post)"},
63 {
"version_update",
"on ending the versioning code"},
64 {
"load_factory_preferences_post",
"on loading factory preferences (after)"},
65 {
"load_factory_startup_post",
"on loading factory startup (after)"},
66 {
"xr_session_start_pre",
"on starting an xr session (before)"},
67 {
"annotation_pre",
"on drawing an annotation (before)"},
68 {
"annotation_post",
"on drawing an annotation (after)"},
69 {
"object_bake_pre",
"before starting a bake job"},
70 {
"object_bake_complete",
"on completing a bake job; will be called in the main thread"},
71 {
"object_bake_cancel",
"on canceling a bake job; will be called in the main thread"},
72 {
"composite_pre",
"on a compositing background job (before)"},
73 {
"composite_post",
"on a compositing background job (after)"},
74 {
"composite_cancel",
"on a compositing background job (cancel)"},
77 #define APP_CB_OTHER_FIELDS 1
79 "Function decorator for callback functions not to be removed when loading new files"},
86 "This module contains callback lists",
92 # if (BKE_CB_EVT_TOT != ARRAY_SIZE(app_cb_info_fields))
93 # error "Callbacks are out of sync"
99 #define PERMINENT_CB_ID "_bpy_persistent"
107 if (!PyArg_ParseTuple(args,
"O:bpy.app.handlers.persistent", &value)) {
111 if (PyFunction_Check(value)) {
112 PyObject **dict_ptr = _PyObject_GetDictPtr(value);
113 if (dict_ptr ==
NULL) {
114 PyErr_SetString(PyExc_ValueError,
115 "bpy.app.handlers.persistent wasn't able to "
116 "get the dictionary from the function passed");
121 if (*dict_ptr ==
NULL) {
122 *dict_ptr = PyDict_New();
131 PyErr_SetString(PyExc_ValueError,
"bpy.app.handlers.persistent expected a function");
138 #if defined(_MSC_VER)
139 PyVarObject_HEAD_INIT(
NULL, 0)
141 PyVarObject_HEAD_INIT(&PyType_Type, 0)
163 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
189 PyObject *app_cb_info;
193 if (app_cb_info ==
NULL) {
199 Py_FatalError(
"invalid callback slots 1");
204 Py_FatalError(
"invalid callback slots 2");
217 #if defined(_MSC_VER)
222 BLI_assert_msg(0,
"error initializing 'bpy.app.handlers.persistent'");
242 funcstore = &funcstore_array[
pos];
244 funcstore->
alloc = 0;
255 PyGILState_STATE gilstate;
258 gilstate = PyGILState_Ensure();
275 for (i = PyList_GET_SIZE(ls) - 1; i >= 0; i--) {
276 PyObject *item = PyList_GET_ITEM(ls, i);
278 if (PyMethod_Check(item)) {
279 PyObject *item_test = PyMethod_GET_FUNCTION(item);
286 if (PyFunction_Check(item) && (dict_ptr = _PyObject_GetDictPtr(item)) && (*dict_ptr) &&
287 (PyDict_GetItem(*dict_ptr, perm_id_str) !=
NULL)) {
293 PyList_SetSlice(ls, i, i + 1,
NULL);
298 Py_DECREF(perm_id_str);
301 PyGILState_Release(gilstate);
304 static PyObject *
choose_arguments(PyObject *func, PyObject *args_all, PyObject *args_single)
306 if (!PyFunction_Check(func)) {
309 PyCodeObject *code = (PyCodeObject *)PyFunction_GetCode(func);
310 if (code->co_argcount == 1) {
319 const int pointers_num,
323 if (PyList_GET_SIZE(cb_list) > 0) {
324 const PyGILState_STATE gilstate = PyGILState_Ensure();
326 const int num_arguments = 2;
327 PyObject *args_all = PyTuple_New(num_arguments);
328 PyObject *args_single = PyTuple_New(1);
334 for (
int i = 0; i < pointers_num; ++i) {
337 for (
int i = pointers_num; i < num_arguments; ++i) {
338 PyTuple_SET_ITEM(args_all, i, Py_INCREF_RET(Py_None));
341 if (pointers_num == 0) {
342 PyTuple_SET_ITEM(args_single, 0, Py_INCREF_RET(Py_None));
350 for (
pos = 0;
pos < PyList_GET_SIZE(cb_list);
pos++) {
351 func = PyList_GET_ITEM(cb_list,
pos);
353 ret = PyObject_Call(func, args,
NULL);
370 Py_DECREF(args_single);
372 PyGILState_Release(gilstate);
void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt)
#define BLI_assert_msg(a, msg)
#define POINTER_FROM_INT(i)
#define POINTER_AS_INT(i)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
int main(int argc, char *argv[])
static PyObject * bpy_app_handlers_persistent_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *UNUSED(kwds))
static PyStructSequence_Desc app_cb_info_desc
static PyObject * choose_arguments(PyObject *func, PyObject *args_all, PyObject *args_single)
static PyObject * make_app_cb_info(void)
#define APP_CB_OTHER_FIELDS
static PyTypeObject BPyPersistent_Type
PyObject * BPY_app_handlers_struct(void)
void bpy_app_generic_callback(struct Main *main, struct PointerRNA **pointers, const int pointers_num, void *arg)
void BPY_app_handlers_reset(const bool do_all)
static PyStructSequence_Field app_cb_info_fields[]
static PyObject * py_cb_array[BKE_CB_EVT_TOT]
static PyTypeObject BlenderAppCbType
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
void(* func)(struct Main *, struct PointerRNA **, int num_pointers, void *arg)