29 double value = PyFloat_AsDouble(
ret);
30 if (value == -1.0f && PyErr_Occurred()) {
32 printf(
"Error: 'bpy.app.timers' callback ");
33 PyObject_Print(function, stdout, Py_PRINT_RAW);
34 printf(
" did not return None or float.\n");
47 PyObject *function =
static_cast<PyObject *
>(user_data);
49 PyGILState_STATE gilstate;
50 gilstate = PyGILState_Ensure();
52 PyObject *py_ret = PyObject_CallObject(function,
nullptr);
55 PyGILState_Release(gilstate);
62 PyObject *function =
static_cast<PyObject *
>(user_data);
64 PyGILState_STATE gilstate;
65 gilstate = PyGILState_Ensure();
69 PyGILState_Release(gilstate);
74 bpy_app_timers_register_doc,
75 ".. function:: register(function, first_interval=0, persistent=False)\n"
77 " Add a new function that will be called after the specified amount of seconds.\n"
78 " The function gets no arguments and is expected to return either None or a float.\n"
79 " If ``None`` is returned, the timer will be unregistered.\n"
80 " A returned number specifies the delay until the function is called again.\n"
81 " ``functools.partial`` can be used to assign some parameters.\n"
83 " :arg function: The function that should called.\n"
84 " :type function: Callable[[], float | None]\n"
85 " :arg first_interval: Seconds until the callback should be called the first time.\n"
86 " :type first_interval: float\n"
87 " :arg persistent: Don't remove timer when a new file is loaded.\n"
88 " :type persistent: bool\n");
92 double first_interval = 0;
93 int persistent =
false;
95 static const char *_keywords[] = {
"function",
"first_interval",
"persistent",
nullptr};
96 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 " :arg function: Function to unregister.\n"
131 " :type function: Callable[[], float | None]\n");
135 PyErr_SetString(PyExc_ValueError,
"Error: 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 " :arg 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);
158#if (defined(__GNUC__) && !defined(__clang__))
159# pragma GCC diagnostic push
160# pragma GCC diagnostic ignored "-Wcast-function-type"
166 METH_VARARGS | METH_KEYWORDS,
167 bpy_app_timers_register_doc},
172 bpy_app_timers_is_registered_doc},
173 {
nullptr,
nullptr, 0,
nullptr},
176#if (defined(__GNUC__) && !defined(__clang__))
177# pragma GCC diagnostic pop
181 PyModuleDef_HEAD_INIT,
194 PyObject *sys_modules = PyImport_GetModuleDict();
196 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[]
header-only compatibility defines.
#define PY_ARG_PARSER_HEAD_COMPAT()
_W64 unsigned int uintptr_t
ccl_device_inline int mod(int x, int m)