]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | # 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # | |
cf694132 | 5 | |
8fa876ca RD |
6 | import time |
7 | import wx | |
cf694132 RD |
8 | |
9 | #--------------------------------------------------------------------------- | |
10 | ||
8fa876ca RD |
11 | ## For your convenience; an example of creating your own timer class. |
12 | ## | |
e6157a69 RD |
13 | ## class TestTimer(wxTimer): |
14 | ## def __init__(self, log = None): | |
15 | ## wxTimer.__init__(self) | |
16 | ## self.log = log | |
17 | ## def Notify(self): | |
18 | ## wxBell() | |
19 | ## if self.log: | |
20 | ## self.log.WriteText('beep!\n') | |
cf694132 RD |
21 | |
22 | #--------------------------------------------------------------------------- | |
23 | ||
8fa876ca RD |
24 | ID_Start = wx.NewId() |
25 | ID_Stop = wx.NewId() | |
26 | ID_Timer = wx.NewId() | |
27 | ID_Timer2 = wx.NewId() | |
cf694132 | 28 | |
8fa876ca | 29 | class TestTimerWin(wx.Panel): |
cf694132 | 30 | def __init__(self, parent, log): |
8fa876ca | 31 | wx.Panel.__init__(self, parent, -1) |
e6157a69 | 32 | self.log = log |
cf694132 | 33 | |
8fa876ca RD |
34 | wx.StaticText(self, -1, "This is a timer example", (15, 30)) |
35 | wx.Button(self, ID_Start, ' Start ', (15, 75), wx.DefaultSize) | |
36 | wx.Button(self, ID_Stop, ' Stop ', (115, 75), wx.DefaultSize) | |
e6157a69 | 37 | |
8fa876ca RD |
38 | self.timer = wx.Timer(self, # object to send the event to |
39 | ID_Timer) # event id to use | |
e6157a69 | 40 | |
8fa876ca RD |
41 | self.timer2 = wx.Timer(self, # object to send the event to |
42 | ID_Timer2) # event id to use | |
b96c7a38 | 43 | |
8fa876ca RD |
44 | self.Bind(wx.EVT_BUTTON, self.OnStart, id=ID_Start) |
45 | self.Bind(wx.EVT_BUTTON, self.OnStop, id=ID_Stop) | |
46 | self.Bind(wx.EVT_TIMER, self.OnTimer, id=ID_Timer) | |
47 | self.Bind(wx.EVT_TIMER, self.OnTimer2, id=ID_Timer2) | |
cf694132 RD |
48 | |
49 | def OnStart(self, event): | |
e6157a69 | 50 | self.timer.Start(1000) |
b96c7a38 | 51 | self.timer2.Start(1500) |
cf694132 RD |
52 | |
53 | def OnStop(self, event): | |
e6157a69 | 54 | self.timer.Stop() |
b96c7a38 | 55 | self.timer2.Stop() |
e6157a69 RD |
56 | |
57 | def OnTimer(self, event): | |
8fa876ca | 58 | wx.Bell() |
e6157a69 RD |
59 | if self.log: |
60 | self.log.WriteText('beep!\n') | |
cf694132 | 61 | |
b96c7a38 | 62 | def OnTimer2(self, event): |
8fa876ca | 63 | wx.Bell() |
b96c7a38 RD |
64 | if self.log: |
65 | self.log.WriteText('beep 2!\n') | |
66 | ||
cf694132 RD |
67 | #--------------------------------------------------------------------------- |
68 | ||
69 | def runTest(frame, nb, log): | |
70 | win = TestTimerWin(nb, log) | |
71 | return win | |
72 | ||
73 | #--------------------------------------------------------------------------- | |
74 | ||
75 | ||
76 | ||
cf694132 | 77 | overview = """\ |
8fa876ca RD |
78 | The wxTimer class allows you to execute code at specified intervals from |
79 | within the wxPython event loop. Timers can be one-shot or repeating. | |
cf694132 | 80 | |
cf694132 | 81 | """ |
68d92db3 RD |
82 | |
83 | ||
84 | ||
85 | ||
1fded56b RD |
86 | if __name__ == '__main__': |
87 | import sys,os | |
88 | import run | |
89 | run.main(['', os.path.basename(sys.argv[0])]) |