31 double value = PyFloat_AsDouble(
ret);
32 if (value == -1.0f && PyErr_Occurred()) {
34 printf(
"Error: 'bpy.app.timers' callback ");
35 PyObject_Print(function, stdout, Py_PRINT_RAW);
36 printf(
" did not return None or float.\n");
40 value = std::max(value, 0.0);
47 PyGILState_STATE gilstate = PyGILState_Ensure();
49 PyObject *function =
static_cast<PyObject *
>(user_data);
51 PyObject *py_ret = PyObject_CallObject(function,
nullptr);
54 PyGILState_Release(gilstate);
61 PyGILState_STATE gilstate = PyGILState_Ensure();
63 PyObject *function =
static_cast<PyObject *
>(user_data);
66 PyGILState_Release(gilstate);
71 bpy_app_timers_register_doc,
72 ".. function:: register(function, first_interval=0, persistent=False)\n"
74 " Add a new function that will be called after the specified amount of seconds.\n"
75 " The function gets no arguments and is expected to return either None or a float.\n"
76 " If ``None`` is returned, the timer will be unregistered.\n"
77 " A returned number specifies the delay until the function is called again.\n"
78 " ``functools.partial`` can be used to assign some parameters.\n"
80 " :arg function: The function that should called.\n"
81 " :type function: Callable[[], float | None]\n"
82 " :arg first_interval: Seconds until the callback should be called the first time.\n"
83 " :type first_interval: float\n"
84 " :arg persistent: Don't remove timer when a new file is loaded.\n"
85 " :type persistent: bool\n");
89 double first_interval = 0;
90 int persistent =
false;
92 static const char *_keywords[] = {
"function",
"first_interval",
"persistent",
nullptr};
93 static _PyArg_Parser _parser = {
103 if (!_PyArg_ParseTupleAndKeywordsFast(
104 args, kw, &_parser, &function, &first_interval, &persistent))
109 if (!PyCallable_Check(function)) {
110 PyErr_SetString(PyExc_TypeError,
"function is not callable");
122 bpy_app_timers_unregister_doc,
123 ".. function:: unregister(function)\n"
125 " Unregister timer.\n"
127 " :arg function: Function to unregister.\n"
128 " :type function: Callable[[], float | None]\n");
132 PyErr_SetString(PyExc_ValueError,
"Error: function is not registered");
140 bpy_app_timers_is_registered_doc,
141 ".. function:: is_registered(function)\n"
143 " Check if this function is registered as a timer.\n"
145 " :arg function: Function to check.\n"
146 " :type function: Callable[[], float | None]\n"
147 " :return: True when this function is registered, otherwise False.\n"
152 return PyBool_FromLong(
ret);
157# pragma clang diagnostic push
158# pragma clang diagnostic ignored "-Wcast-function-type"
160# pragma GCC diagnostic push
161# pragma GCC diagnostic ignored "-Wcast-function-type"
168 METH_VARARGS | METH_KEYWORDS,
169 bpy_app_timers_register_doc},
174 bpy_app_timers_is_registered_doc},
175 {
nullptr,
nullptr, 0,
nullptr},
180# pragma clang diagnostic pop
182# pragma GCC diagnostic pop
200 PyObject *sys_modules = PyImport_GetModuleDict();
202 PyDict_SetItem(sys_modules, PyModule_GetNameObject(
mod),
mod);
bool BLI_timer_is_registered(uintptr_t uuid)
void BLI_timer_register(uintptr_t uuid, BLI_timer_func func, void *user_data, BLI_timer_data_free user_data_free, double first_interval, bool persistent)
bool BLI_timer_unregister(uintptr_t uuid)
PyObject * BPY_app_timers_module()
static double handle_returned_value(PyObject *function, PyObject *ret)
static PyObject * bpy_app_timers_unregister(PyObject *, PyObject *function)
PyDoc_STRVAR(bpy_app_timers_register_doc, ".. function:: register(function, first_interval=0, persistent=False)\n" "\n" " Add a new function that will be called after the specified amount of seconds.\n" " The function gets no arguments and is expected to return either None or a float.\n" " If ``None`` is returned, the timer will be unregistered.\n" " A returned number specifies the delay until the function is called again.\n" " ``functools.partial`` can be used to assign some parameters.\n" "\n" " :arg function: The function that should called.\n" " :type function: Callable[[], float | None]\n" " :arg first_interval: Seconds until the callback should be called the first time.\n" " :type first_interval: float\n" " :arg persistent: Don't remove timer when a new file is loaded.\n" " :type persistent: bool\n")
static PyObject * bpy_app_timers_register(PyObject *, PyObject *args, PyObject *kw)
static double py_timer_execute(uintptr_t, void *user_data)
static PyModuleDef M_AppTimers_module_def
static PyObject * bpy_app_timers_is_registered(PyObject *, PyObject *function)
static void py_timer_free(uintptr_t, void *user_data)
static PyMethodDef M_AppTimers_methods[]
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
header-only compatibility defines.
#define PY_ARG_PARSER_HEAD_COMPAT()