]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Timer.py
1 # 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
9 #---------------------------------------------------------------------------
11 ## For your convenience; an example of creating your own timer class.
13 ## class TestTimer(wxTimer):
14 ## def __init__(self, log = None):
15 ## wxTimer.__init__(self)
20 ## self.log.WriteText('beep!\n')
22 #---------------------------------------------------------------------------
27 ID_Timer2
= wx
.NewId()
29 class TestTimerWin(wx
.Panel
):
30 def __init__(self
, parent
, log
):
31 wx
.Panel
.__init
__(self
, parent
, -1)
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
)
38 self
.timer
= wx
.Timer(self
, # object to send the event to
39 ID_Timer
) # event id to use
41 self
.timer2
= wx
.Timer(self
, # object to send the event to
42 ID_Timer2
) # event id to use
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
)
49 def OnStart(self
, event
):
50 self
.timer
.Start(1000)
51 self
.timer2
.Start(1500)
53 def OnStop(self
, event
):
57 def OnTimer(self
, event
):
60 self
.log
.WriteText('beep!\n')
62 def OnTimer2(self
, event
):
65 self
.log
.WriteText('beep 2!\n')
67 #---------------------------------------------------------------------------
69 def runTest(frame
, nb
, log
):
70 win
= TestTimerWin(nb
, log
)
73 #---------------------------------------------------------------------------
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.
86 if __name__
== '__main__':
89 run
.main(['', os
.path
.basename(sys
.argv
[0])])