X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/299647acac7960652aadb008775429c1f8ea9b8d..35095c028d472a2d0b9607a9430a468765a16e3f:/wxPython/demo/Timer.py diff --git a/wxPython/demo/Timer.py b/wxPython/demo/Timer.py index 7f71b1f442..86892c7f88 100644 --- a/wxPython/demo/Timer.py +++ b/wxPython/demo/Timer.py @@ -1,7 +1,27 @@ -# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net) -# -# o Updated for wx namespace # +# 1/11/2004 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o It appears that wx.Timer has an issue where if you use +# +# self.timer = wx.Timer(self, -1) +# +# to create it, then +# +# self.timer.GetId() +# +# doesn't seem to return anything meaningful. In the demo, doing this +# results in only one of the two handlers being called for both timers. +# This means that +# +# self.Bind(wx.EVT_TIMER, self.onTimer, self.timer) +# +# doesn't work right. However, using +# +# self.timer = wx.Timer(self, wx.NewId()) +# +# makes it work OK. I believe this is a bug, but wiser heads than mine +# should determine this. +# import time import wx @@ -10,41 +30,33 @@ import wx ## For your convenience; an example of creating your own timer class. ## -## class TestTimer(wxTimer): +## class TestTimer(wx.Timer): ## def __init__(self, log = None): -## wxTimer.__init__(self) +## wx.Timer.__init__(self) ## self.log = log ## def Notify(self): -## wxBell() +## wx.Bell() ## if self.log: ## self.log.WriteText('beep!\n') #--------------------------------------------------------------------------- -ID_Start = wx.NewId() -ID_Stop = wx.NewId() -ID_Timer = wx.NewId() -ID_Timer2 = wx.NewId() - class TestTimerWin(wx.Panel): def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1) self.log = log wx.StaticText(self, -1, "This is a timer example", (15, 30)) - wx.Button(self, ID_Start, ' Start ', (15, 75), wx.DefaultSize) - wx.Button(self, ID_Stop, ' Stop ', (115, 75), wx.DefaultSize) - - self.timer = wx.Timer(self, # object to send the event to - ID_Timer) # event id to use + startBtn = wx.Button(self, -1, ' Start ', (15, 75), wx.DefaultSize) + stopBtn = wx.Button(self, -1, ' Stop ', (115, 75), wx.DefaultSize) - self.timer2 = wx.Timer(self, # object to send the event to - ID_Timer2) # event id to use + self.timer = wx.Timer(self, wx.NewId()) + self.timer2 = wx.Timer(self, wx.NewId()) - self.Bind(wx.EVT_BUTTON, self.OnStart, id=ID_Start) - self.Bind(wx.EVT_BUTTON, self.OnStop, id=ID_Stop) - self.Bind(wx.EVT_TIMER, self.OnTimer, id=ID_Timer) - self.Bind(wx.EVT_TIMER, self.OnTimer2, id=ID_Timer2) + self.Bind(wx.EVT_BUTTON, self.OnStart, startBtn) + self.Bind(wx.EVT_BUTTON, self.OnStop, stopBtn) + self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) + self.Bind(wx.EVT_TIMER, self.OnTimer2, self.timer2) def OnStart(self, event): self.timer.Start(1000) @@ -75,7 +87,7 @@ def runTest(frame, nb, log): overview = """\ -The wxTimer class allows you to execute code at specified intervals from +The wx.Timer class allows you to execute code at specified intervals from within the wxPython event loop. Timers can be one-shot or repeating. """