summaryrefslogtreecommitdiff
path: root/efl/ecore/efl.ecore_timer.pxi
blob: e87e58682fcfcadda77c497489c1408ca0ad1e51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright (C) 2007-2013 various contributors (see AUTHORS)
#
# This file is part of Python-EFL.
#
# Python-EFL is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# Python-EFL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this Python-EFL.  If not, see <http://www.gnu.org/licenses/>.


cdef class Timer(Eo):
    def __init__(self, double interval, func, *args, **kargs):
        if not callable(func):
            raise TypeError("Parameter 'func' must be callable")
        self.func = func
        self.args = args
        self.kargs = kargs
        self._set_obj(ecore_timer_add(interval, _ecore_task_cb, <void *>self))

    def __str__(self):
        return "%s Timer(func=%s, args=%s, kargs=%s)" % (Eo.__str__(self),
               self.func, self.args, self.kargs)

    def __repr__(self):
        return "%s Timer(interval=%f, func=%s, args=%s, kargs=%s)" % (Eo.__repr__(self),
                self.interval if self.obj else -1.0,
                self.func, self.args, self.kargs)

    cpdef object _task_exec(self):
        return self.func(*self.args, **self.kargs)

    def delete(self):
        ecore_timer_del(self.obj)
    
    def stop(self):
        self.delete()

    def freeze(self):
        ecore_timer_freeze(self.obj)

    def thaw(self):
        ecore_timer_thaw(self.obj)

    def interval_set(self, double t):
        ecore_timer_interval_set(self.obj, t)

    def interval_get(self):
        return ecore_timer_interval_get(self.obj)

    property interval:
        def __get__(self):
            return ecore_timer_interval_get(self.obj)

        def __set__(self, double t):
            ecore_timer_interval_set(self.obj, t)

    def delay(self, double add):
        ecore_timer_delay(self.obj, add)

    def reset(self):
        ecore_timer_reset(self.obj)

    def ecore_timer_pending_get(self):
        ecore_timer_pending_get(self.obj)

    property pending:
        def __get__(self):
            return ecore_timer_pending_get(self.obj)


def timer_add(double t, func, *args, **kargs):
    return Timer(t, func, *args, **kargs)


def timer_precision_get():
    return ecore_timer_precision_get()


def timer_precision_set(double value):
    ecore_timer_precision_set(value)