28 double value = PyFloat_AsDouble(
ret);
29 if (value == -1.0f && PyErr_Occurred()) {
31 printf(
"Error: 'bpy.app.timers' callback ");
32 PyObject_Print(function, stdout, Py_PRINT_RAW);
33 printf(
" did not return None or float.\n");
37 value = std::max(value, 0.0);
44 PyGILState_STATE gilstate = PyGILState_Ensure();
46 PyObject *function =
static_cast<PyObject *
>(user_data);
49 if (PyObject *py_ret = PyObject_CallObject(function,
nullptr)) {
58 PyGILState_Release(gilstate);
65 PyGILState_STATE gilstate = PyGILState_Ensure();
67 PyObject *function =
static_cast<PyObject *
>(user_data);
70 PyGILState_Release(gilstate);
75 bpy_app_timers_register_doc,
76 ".. function:: register(function, *, first_interval=0, persistent=False)\n"
78 " Add a new function that will be called after the specified amount of seconds.\n"
79 " The function gets no arguments and is expected to return either None or a float.\n"
80 " If ``None`` is returned, the timer will be unregistered.\n"
81 " A returned number specifies the delay until the function is called again.\n"
82 " ``functools.partial`` can be used to assign some parameters.\n"
84 " :param function: The function that should called.\n"
85 " :type function: Callable[[], float | None]\n"
86 " :param first_interval: Seconds until the callback should be called the first time.\n"
87 " :type first_interval: float\n"
88 " :param persistent: Don't remove timer when a new file is loaded.\n"
89 " :type persistent: bool\n");
93 double first_interval = 0;
94 int persistent =
false;
96 static const char *_keywords[] = {
"function",
"first_interval",
"persistent",
nullptr};
97 static _PyArg_Parser _parser = {
106 if (!_PyArg_ParseTupleAndKeywordsFast(
107 args, kw, &_parser, &function, &first_interval, &persistent))
112 if (!PyCallable_Check(function)) {
113 PyErr_SetString(PyExc_TypeError,
"function is not callable");
125 bpy_app_timers_unregister_doc,
126 ".. function:: unregister(function)\n"
128 " Unregister timer.\n"
130 " :param function: Function to unregister.\n"
131 " :type function: Callable[[], float | None]\n");
135 PyErr_SetString(PyExc_ValueError,
"function is not registered");
143 bpy_app_timers_is_registered_doc,
144 ".. function:: is_registered(function)\n"
146 " Check if this function is registered as a timer.\n"
148 " :param function: Function to check.\n"
149 " :type function: Callable[[], float | None]\n"
150 " :return: True when this function is registered, otherwise False.\n"
155 return PyBool_FromLong(
ret);
160# pragma clang diagnostic push
161# pragma clang diagnostic ignored "-Wcast-function-type"
163# pragma GCC diagnostic push
164# pragma GCC diagnostic ignored "-Wcast-function-type"
171 METH_VARARGS | METH_KEYWORDS,
172 bpy_app_timers_register_doc},
176 bpy_app_timers_unregister_doc},
180 bpy_app_timers_is_registered_doc},
181 {
nullptr,
nullptr, 0,
nullptr},
186# pragma clang diagnostic pop
188# pragma GCC diagnostic pop
206 PyObject *sys_modules = PyImport_GetModuleDict();
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
static void py_timer_free(uintptr_t, void *user_data)
PyObject * BPY_app_timers_module()
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 M_AppTimers_module_def
bool BLI_timer_is_registered(uintptr_t uuid)
static double handle_returned_value(PyObject *function, PyObject *ret)
static double py_timer_execute(uintptr_t, void *user_data)
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)
_W64 unsigned int uintptr_t
bool BLI_timer_unregister(uintptr_t uuid)
int PyC_Module_AddToSysModules(PyObject *sys_modules, PyObject *module)
static PyObject * bpy_app_timers_unregister(PyObject *, PyObject *function)
static PyObject * bpy_app_timers_register(PyObject *, PyObject *args, PyObject *kw)
static PyMethodDef M_AppTimers_methods[]
static PyObject * bpy_app_timers_is_registered(PyObject *, PyObject *function)
header-only compatibility defines.