30 double value = PyFloat_AsDouble(
ret);
31 if (value == -1.0f && PyErr_Occurred()) {
33 printf(
"Error: 'bpy.app.timers' callback ");
34 PyObject_Print(function, stdout, Py_PRINT_RAW);
35 printf(
" did not return None or float.\n");
39 value = std::max(value, 0.0);
46 PyGILState_STATE gilstate = PyGILState_Ensure();
48 PyObject *function =
static_cast<PyObject *
>(user_data);
50 PyObject *py_ret = PyObject_CallObject(function,
nullptr);
53 PyGILState_Release(gilstate);
60 PyGILState_STATE gilstate = PyGILState_Ensure();
62 PyObject *function =
static_cast<PyObject *
>(user_data);
65 PyGILState_Release(gilstate);
70 bpy_app_timers_register_doc,
71 ".. function:: register(function, *, first_interval=0, persistent=False)\n"
73 " Add a new function that will be called after the specified amount of seconds.\n"
74 " The function gets no arguments and is expected to return either None or a float.\n"
75 " If ``None`` is returned, the timer will be unregistered.\n"
76 " A returned number specifies the delay until the function is called again.\n"
77 " ``functools.partial`` can be used to assign some parameters.\n"
79 " :arg function: The function that should called.\n"
80 " :type function: Callable[[], float | None]\n"
81 " :arg first_interval: Seconds until the callback should be called the first time.\n"
82 " :type first_interval: float\n"
83 " :arg persistent: Don't remove timer when a new file is loaded.\n"
84 " :type persistent: bool\n");
88 double first_interval = 0;
89 int persistent =
false;
91 static const char *_keywords[] = {
"function",
"first_interval",
"persistent",
nullptr};
92 static _PyArg_Parser _parser = {
102 if (!_PyArg_ParseTupleAndKeywordsFast(
103 args, kw, &_parser, &function, &first_interval, &persistent))
108 if (!PyCallable_Check(function)) {
109 PyErr_SetString(PyExc_TypeError,
"function is not callable");
121 bpy_app_timers_unregister_doc,
122 ".. function:: unregister(function)\n"
124 " Unregister timer.\n"
126 " :arg function: Function to unregister.\n"
127 " :type function: Callable[[], float | None]\n");
131 PyErr_SetString(PyExc_ValueError,
"function is not registered");
139 bpy_app_timers_is_registered_doc,
140 ".. function:: is_registered(function)\n"
142 " Check if this function is registered as a timer.\n"
144 " :arg function: Function to check.\n"
145 " :type function: Callable[[], float | None]\n"
146 " :return: True when this function is registered, otherwise False.\n"
151 return PyBool_FromLong(
ret);
156# pragma clang diagnostic push
157# pragma clang diagnostic ignored "-Wcast-function-type"
159# pragma GCC diagnostic push
160# pragma GCC diagnostic ignored "-Wcast-function-type"
167 METH_VARARGS | METH_KEYWORDS,
168 bpy_app_timers_register_doc},
173 bpy_app_timers_is_registered_doc},
174 {
nullptr,
nullptr, 0,
nullptr},
179# pragma clang diagnostic pop
181# pragma GCC diagnostic pop
199 PyObject *sys_modules = PyImport_GetModuleDict();
201 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)
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[]
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")
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
header-only compatibility defines.
#define PY_ARG_PARSER_HEAD_COMPAT()