]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Timer.py
2 # 1/11/2004 - Jeff Grimmett (grimmtooth@softhome.net)
4 # o It appears that wx.Timer has an issue where if you use
6 # self.timer = wx.Timer(self, -1)
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.
16 # self.Bind(wx.EVT_TIMER, self.onTimer, self.timer)
18 # doesn't work right. However, using
20 # self.timer = wx.Timer(self, wx.NewId())
22 # makes it work OK. I believe this is a bug, but wiser heads than mine
23 # should determine this.
29 #---------------------------------------------------------------------------
31 ## For your convenience; an example of creating your own timer class.
33 ## class TestTimer(wx.Timer):
34 ## def __init__(self, log = None):
35 ## wx.Timer.__init__(self)
40 ## self.log.WriteText('beep!\n')
42 #---------------------------------------------------------------------------
44 class TestTimerWin(wx
.Panel
):
45 def __init__(self
, parent
, log
):
46 wx
.Panel
.__init
__(self
, parent
, -1)
49 wx
.StaticText(self
, -1, "This is a timer example", (15, 30))
50 startBtn
= wx
.Button(self
, -1, ' Start ', (15, 75), wx
.DefaultSize
)
51 stopBtn
= wx
.Button(self
, -1, ' Stop ', (115, 75), wx
.DefaultSize
)
53 self
.timer
= wx
.Timer(self
, wx
.NewId())
54 self
.timer2
= wx
.Timer(self
, wx
.NewId())
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
)
61 def OnStart(self
, event
):
62 self
.timer
.Start(1000)
63 self
.timer2
.Start(1500)
65 def OnStop(self
, event
):
69 def OnTimer(self
, event
):
72 self
.log
.WriteText('beep!\n')
74 def OnTimer2(self
, event
):
77 self
.log
.WriteText('beep 2!\n')
79 #---------------------------------------------------------------------------
81 def runTest(frame
, nb
, log
):
82 win
= TestTimerWin(nb
, log
)
85 #---------------------------------------------------------------------------
90 The wx.Timer class allows you to execute code at specified intervals from
91 within the wxPython event loop. Timers can be one-shot or repeating.
98 if __name__
== '__main__':
101 run
.main(['', os
.path
.basename(sys
.argv
[0])])