15 #include "../generic/py_capi_utils.h"
16 #include "../generic/python_utildefines.h"
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");
50 PyGILState_STATE gilstate;
51 gilstate = PyGILState_Ensure();
53 PyObject *py_ret = PyObject_CallObject(
function,
NULL);
56 PyGILState_Release(gilstate);
65 PyGILState_STATE gilstate;
66 gilstate = PyGILState_Ensure();
70 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[[], Union[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",
NULL};
96 static _PyArg_Parser _parser = {
105 if (!_PyArg_ParseTupleAndKeywordsFast(
106 args, kw, &_parser, &
function, &first_interval, &persistent)) {
110 if (!PyCallable_Check(
function)) {
111 PyErr_SetString(PyExc_TypeError,
"function is not callable");
122 ".. function:: unregister(function)\n"
124 " Unregister timer.\n"
126 " :arg function: Function to unregister.\n"
127 " :type function: function\n");
131 PyErr_SetString(PyExc_ValueError,
"Error: function is not registered");
138 ".. function:: is_registered(function)\n"
140 " Check if this function is registered as a timer.\n"
142 " :arg function: Function to check.\n"
143 " :type function: int\n"
144 " :return: True when this function is registered, otherwise False.\n"
149 return PyBool_FromLong(
ret);
155 METH_VARARGS | METH_KEYWORDS,
156 bpy_app_timers_register_doc},
161 bpy_app_timers_is_registered_doc},
166 PyModuleDef_HEAD_INIT,
179 PyObject *sys_modules = PyImport_GetModuleDict();
181 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)
Platform independent time functions.
static struct PyMethodDef M_AppTimers_methods[]
static struct PyModuleDef M_AppTimers_module_def
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[[], Union[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 double handle_returned_value(PyObject *function, PyObject *ret)
static PyObject * bpy_app_timers_is_registered(PyObject *UNUSED(self), PyObject *function)
static PyObject * bpy_app_timers_unregister(PyObject *UNUSED(self), PyObject *function)
PyObject * BPY_app_timers_module(void)
static PyObject * bpy_app_timers_register(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static void py_timer_free(uintptr_t UNUSED(uuid), void *user_data)
static double py_timer_execute(uintptr_t UNUSED(uuid), void *user_data)
_W64 unsigned int uintptr_t
ccl_device_inline int mod(int x, int m)