35 #include "../generic/python_utildefines.h"
41 const int num_pointers,
48 "Called after frame change for playback and rendering, before any data is evaluated for the "
49 "new frame. This makes it possible to change data and relations (for example swap an object "
50 "to another mesh) for the new frame. Note that this handler is **not** to be used as 'before "
51 "the frame changes' event. The dependency graph is not available in this handler, as data "
52 "and relations may have been altered and the dependency graph has not yet been updated for "
55 "Called after frame change for playback and rendering, after the data has been evaluated "
56 "for the new frame."},
57 {
"render_pre",
"on render (before)"},
58 {
"render_post",
"on render (after)"},
59 {
"render_write",
"on writing a render frame (directly after the frame is written)"},
60 {
"render_stats",
"on printing render statistics"},
61 {
"render_init",
"on initialization of a render job"},
62 {
"render_complete",
"on completion of render job"},
63 {
"render_cancel",
"on canceling a render job"},
64 {
"load_pre",
"on loading a new blend file (before)"},
65 {
"load_post",
"on loading a new blend file (after)"},
66 {
"save_pre",
"on saving a blend file (before)"},
67 {
"save_post",
"on saving a blend file (after)"},
68 {
"undo_pre",
"on loading an undo step (before)"},
69 {
"undo_post",
"on loading an undo step (after)"},
70 {
"redo_pre",
"on loading a redo step (before)"},
71 {
"redo_post",
"on loading a redo step (after)"},
72 {
"depsgraph_update_pre",
"on depsgraph update (pre)"},
73 {
"depsgraph_update_post",
"on depsgraph update (post)"},
74 {
"version_update",
"on ending the versioning code"},
75 {
"load_factory_preferences_post",
"on loading factory preferences (after)"},
76 {
"load_factory_startup_post",
"on loading factory startup (after)"},
79 #define APP_CB_OTHER_FIELDS 1
81 "Function decorator for callback functions not to be removed when loading new files"},
88 "This module contains callback lists",
94 # if (BKE_CB_EVT_TOT != ARRAY_SIZE(app_cb_info_fields))
95 # error "Callbacks are out of sync"
101 #define PERMINENT_CB_ID "_bpy_persistent"
109 if (!PyArg_ParseTuple(args,
"O:bpy.app.handlers.persistent", &value)) {
113 if (PyFunction_Check(value)) {
114 PyObject **dict_ptr = _PyObject_GetDictPtr(value);
115 if (dict_ptr ==
NULL) {
116 PyErr_SetString(PyExc_ValueError,
117 "bpy.app.handlers.persistent wasn't able to "
118 "get the dictionary from the function passed");
123 if (*dict_ptr ==
NULL) {
124 *dict_ptr = PyDict_New();
133 PyErr_SetString(PyExc_ValueError,
"bpy.app.handlers.persistent expected a function");
140 #if defined(_MSC_VER)
141 PyVarObject_HEAD_INIT(
NULL, 0)
143 PyVarObject_HEAD_INIT(&PyType_Type, 0)
165 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
191 PyObject *app_cb_info;
195 if (app_cb_info ==
NULL) {
201 Py_FatalError(
"invalid callback slots 1");
206 Py_FatalError(
"invalid callback slots 2");
219 #if defined(_MSC_VER)
224 BLI_assert(!
"error initializing 'bpy.app.handlers.persistent'");
244 funcstore = &funcstore_array[
pos];
246 funcstore->
alloc = 0;
257 PyGILState_STATE gilstate;
260 gilstate = PyGILState_Ensure();
280 for (i = PyList_GET_SIZE(ls) - 1; i >= 0; i--) {
282 if ((PyFunction_Check((item = PyList_GET_ITEM(ls, i)))) &&
283 (dict_ptr = _PyObject_GetDictPtr(item)) && (*dict_ptr) &&
284 (PyDict_GetItem(*dict_ptr, perm_id_str) !=
NULL)) {
290 PyList_SetSlice(ls, i, i + 1,
NULL);
295 Py_DECREF(perm_id_str);
298 PyGILState_Release(gilstate);
301 static PyObject *
choose_arguments(PyObject *func, PyObject *args_all, PyObject *args_single)
303 if (!PyFunction_Check(func)) {
306 PyCodeObject *code = (PyCodeObject *)PyFunction_GetCode(func);
307 if (code->co_argcount == 1) {
316 const int num_pointers,
320 if (PyList_GET_SIZE(cb_list) > 0) {
321 const PyGILState_STATE gilstate = PyGILState_Ensure();
323 const int num_arguments = 2;
324 PyObject *args_all = PyTuple_New(num_arguments);
325 PyObject *args_single = PyTuple_New(1);
331 for (
int i = 0; i < num_pointers; ++i) {
334 for (
int i = num_pointers; i < num_arguments; ++i) {
335 PyTuple_SET_ITEM(args_all, i, Py_INCREF_RET(Py_None));
338 if (num_pointers == 0) {
339 PyTuple_SET_ITEM(args_single, 0, Py_INCREF_RET(Py_None));
347 for (
pos = 0;
pos < PyList_GET_SIZE(cb_list);
pos++) {
348 func = PyList_GET_ITEM(cb_list,
pos);
350 ret = PyObject_Call(func, args,
NULL);
367 Py_DECREF(args_single);
369 PyGILState_Release(gilstate);
void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt)
#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
static PyObject * bpy_app_handlers_persistent_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *UNUSED(kwds))
void bpy_app_generic_callback(struct Main *main, struct PointerRNA **pointers, const int num_pointers, void *arg)
void BPY_app_handlers_reset(const short do_all)
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)
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)
int main(int argc, char **argv)
void(* func)(struct Main *, struct PointerRNA **, const int num_pointers, void *arg)