]>
Commit | Line | Data |
---|---|---|
8fa876ca | 1 | # |
95bfd958 RD |
2 | # 1/11/2004 - Jeff Grimmett (grimmtooth@softhome.net) |
3 | # | |
4 | # o It appears that wx.Timer has an issue where if you use | |
5 | # | |
6 | # self.timer = wx.Timer(self, -1) | |
7 | # | |
8 | # to create it, then | |
9 | # | |
10 | # self.timer.GetId() | |
11 | # | |
12 | # doesn't seem to return anything meaningful. In the demo, doing this | |
13 | # results in only one of the two handlers being called for both timers. | |
14 | # This means that | |
15 | # | |
16 | # self.Bind(wx.EVT_TIMER, self.onTimer, self.timer) | |
17 | # | |
18 | # doesn't work right. However, using | |
19 | # | |
20 | # self.timer = wx.Timer(self, wx.NewId()) | |
21 | # | |
22 | # makes it work OK. I believe this is a bug, but wiser heads than mine | |
23 | # should determine this. | |
24 | # | |
cf694132 | 25 | |
8fa876ca RD |
26 | import time |
27 | import wx | |
cf694132 RD |
28 | |
29 | #--------------------------------------------------------------------------- | |
30 | ||
8fa876ca RD |
31 | ## For your convenience; an example of creating your own timer class. |
32 | ## | |
95bfd958 | 33 | ## class TestTimer(wx.Timer): |
e6157a69 | 34 | ## def __init__(self, log = None): |
95bfd958 | 35 | ## wx.Timer.__init__(self) |
e6157a69 RD |
36 | ## self.log = log |
37 | ## def Notify(self): | |
95bfd958 | 38 | ## wx.Bell() |
e6157a69 RD |
39 | ## if self.log: |
40 | ## self.log.WriteText('beep!\n') | |
cf694132 RD |
41 | |
42 | #--------------------------------------------------------------------------- | |
43 | ||
8fa876ca | 44 | class TestTimerWin(wx.Panel): |
cf694132 | 45 | def __init__(self, parent, log): |
8fa876ca | 46 | wx.Panel.__init__(self, parent, -1) |
e6157a69 | 47 | self.log = log |
cf694132 | 48 | |
8fa876ca | 49 | wx.StaticText(self, -1, "This is a timer example", (15, 30)) |
95bfd958 RD |
50 | startBtn = wx.Button(self, -1, ' Start ', (15, 75), wx.DefaultSize) |
51 | stopBtn = wx.Button(self, -1, ' Stop ', (115, 75), wx.DefaultSize) | |
e6157a69 | 52 | |
95bfd958 RD |
53 | self.timer = wx.Timer(self, wx.NewId()) |
54 | self.timer2 = wx.Timer(self, wx.NewId()) | |
b96c7a38 | 55 | |
95bfd958 RD |
56 | self.Bind(wx.EVT_BUTTON, self.OnStart, startBtn) |
57 | self.Bind(wx.EVT_BUTTON, self.OnStop, stopBtn) | |
58 | self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) | |
59 | self.Bind(wx.EVT_TIMER, self.OnTimer2, self.timer2) | |
cf694132 RD |
60 | |
61 | def OnStart(self, event): | |
e6157a69 | 62 | self.timer.Start(1000) |
b96c7a38 | 63 | self.timer2.Start(1500) |
cf694132 RD |
64 | |
65 | def OnStop(self, event): | |
e6157a69 | 66 | self.timer.Stop() |
b96c7a38 | 67 | self.timer2.Stop() |
e6157a69 RD |
68 | |
69 | def OnTimer(self, event): | |
8fa876ca | 70 | wx.Bell() |
e6157a69 RD |
71 | if self.log: |
72 | self.log.WriteText('beep!\n') | |
cf694132 | 73 | |
b96c7a38 | 74 | def OnTimer2(self, event): |
8fa876ca | 75 | wx.Bell() |
b96c7a38 RD |
76 | if self.log: |
77 | self.log.WriteText('beep 2!\n') | |
78 | ||
cf694132 RD |
79 | #--------------------------------------------------------------------------- |
80 | ||
81 | def runTest(frame, nb, log): | |
82 | win = TestTimerWin(nb, log) | |
83 | return win | |
84 | ||
85 | #--------------------------------------------------------------------------- | |
86 | ||
87 | ||
88 | ||
cf694132 | 89 | overview = """\ |
95bfd958 | 90 | The wx.Timer class allows you to execute code at specified intervals from |
8fa876ca | 91 | within the wxPython event loop. Timers can be one-shot or repeating. |
cf694132 | 92 | |
cf694132 | 93 | """ |
68d92db3 RD |
94 | |
95 | ||
96 | ||
97 | ||
1fded56b RD |
98 | if __name__ == '__main__': |
99 | import sys,os | |
100 | import run | |
101 | run.main(['', os.path.basename(sys.argv[0])]) |