29 #include "../generic/py_capi_utils.h"
30 #include "../generic/python_utildefines.h"
44 double value = PyFloat_AsDouble(
ret);
45 if (value == -1.0f && PyErr_Occurred()) {
47 printf(
"Error: 'bpy.app.timers' callback ");
48 PyObject_Print(
function, stdout, Py_PRINT_RAW);
49 printf(
" did not return None or float.\n");
64 PyGILState_STATE gilstate;
65 gilstate = PyGILState_Ensure();
67 PyObject *py_ret = PyObject_CallObject(
function,
NULL);
70 PyGILState_Release(gilstate);
79 PyGILState_STATE gilstate;
80 gilstate = PyGILState_Ensure();
84 PyGILState_Release(gilstate);
88 bpy_app_timers_register_doc,
89 ".. function:: register(function, first_interval=0, persistent=False)\n"
91 " Add a new function that will be called after the specified amount of seconds.\n"
92 " The function gets no arguments and is expected to return either None or a float.\n"
93 " If ``None`` is returned, the timer will be unregistered.\n"
94 " A returned number specifies the delay until the function is called again.\n"
95 " ``functools.partial`` can be used to assign some parameters.\n"
97 " :arg function: The function that should called.\n"
98 " :type function: Callable[[], Union[float, None]]\n"
99 " :arg first_interval: Seconds until the callback should be called the first time.\n"
100 " :type first_interval: float\n"
101 " :arg persistent: Don't remove timer when a new file is loaded.\n"
102 " :type persistent: bool\n");
106 double first_interval = 0;
107 int persistent =
false;
109 static const char *_keywords[] = {
"function",
"first_interval",
"persistent",
NULL};
110 static _PyArg_Parser _parser = {
"O|$dp:register", _keywords, 0};
111 if (!_PyArg_ParseTupleAndKeywordsFast(
112 args, kw, &_parser, &
function, &first_interval, &persistent)) {
116 if (!PyCallable_Check(
function)) {
117 PyErr_SetString(PyExc_TypeError,
"function is not callable");
128 ".. function:: unregister(function)\n"
130 " Unregister timer.\n"
132 " :arg function: Function to unregister.\n"
133 " :type function: function\n");
137 PyErr_SetString(PyExc_ValueError,
"Error: function is not registered");
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: int\n"
150 " :return: True when this function is registered, otherwise False.\n"
155 return PyBool_FromLong(
ret);
161 METH_VARARGS | METH_KEYWORDS,
162 bpy_app_timers_register_doc},
167 bpy_app_timers_is_registered_doc},
172 PyModuleDef_HEAD_INIT,
185 PyObject *sys_modules = PyImport_GetModuleDict();
187 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)