-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtimer.py
59 lines (43 loc) · 1.61 KB
/
timer.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
"Timer support "
__author__ = "Mariano Reingart (reingart@gmail.com)"
__copyright__ = "Copyright (C) 2016- Mariano Reingart"
__license__ = "LGPL 3.0"
import wx
from .component import SubComponent, Spec
from . import images
from . import registry
class Timer(SubComponent):
"A simple timer to execute code at specified intervals"
_wx_class = wx.Timer
#_image = images.statusbar
_registry = registry.MISC
def __init__(self, parent=None, **kwargs):
"Custom constructor that just creates the wx.Timer instance"
self.wx_obj = self._wx_class(None)
self.set_parent(parent, init=True)
def set_parent(self, new_parent, init=False):
"Re-parent a child control with the new wx_obj parent (owner)"
##SubComponent.set_parent(self, new_parent, init)
self.wx_obj.SetOwner(new_parent.wx_obj.GetEventHandler())
def stop(self):
self.wx_obj.Stop()
def start(self, interval=-1):
self.wx_obj.Start(interval)
interval = Spec(lambda self: self.wx_obj.GetInterval(),
lambda self, value: self.wx_obj.Start(value),
default=1000, type="integer",
doc="current interval for the timer (in milliseconds)")
if __name__ == "__main__":
from gui.windows import Window
app = wx.App(redirect=False)
w = Window(title="hello world", name="frmTest", tool_window=False,
resizable=True, visible=False, pos=(180, 0))
t = Timer(w)
def timer(evt):
print("timer!")
w.ontimer = timer
t.interval = 100
w.show()
app.MainLoop()