X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..b881fc787d2823bdd8a415080b82feee90804a17:/wxPython/demo/wxTimer.py diff --git a/wxPython/demo/wxTimer.py b/wxPython/demo/wxTimer.py index 14ad594100..7f71b1f442 100644 --- a/wxPython/demo/wxTimer.py +++ b/wxPython/demo/wxTimer.py @@ -1,43 +1,68 @@ +# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Updated for wx namespace +# -from wxPython.wx import * - -import time +import time +import wx #--------------------------------------------------------------------------- -class TestTimer(wxTimer): - def __init__(self, log = None): - wxTimer.__init__(self) - self.log = log - - def Notify(self): - wxBell() - if self.log: - self.log.WriteText('beep!\n') +## For your convenience; an example of creating your own timer class. +## +## class TestTimer(wxTimer): +## def __init__(self, log = None): +## wxTimer.__init__(self) +## self.log = log +## def Notify(self): +## wxBell() +## if self.log: +## self.log.WriteText('beep!\n') #--------------------------------------------------------------------------- -_timer = TestTimer() - +ID_Start = wx.NewId() +ID_Stop = wx.NewId() +ID_Timer = wx.NewId() +ID_Timer2 = wx.NewId() -class TestTimerWin(wxPanel): +class TestTimerWin(wx.Panel): def __init__(self, parent, log): - _timer.log = log - wxPanel.__init__(self, parent, -1) + 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 - wxStaticText(self, -1, "This is a timer example", - wxPoint(15, 30)) + self.timer2 = wx.Timer(self, # object to send the event to + ID_Timer2) # event id to use - wxButton(self, 11101, ' Start ', wxPoint(15, 75), wxDefaultSize) - wxButton(self, 11102, ' Stop ', wxPoint(115, 75), wxDefaultSize) - EVT_BUTTON(self, 11101, self.OnStart) - EVT_BUTTON(self, 11102, self.OnStop) + 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) def OnStart(self, event): - _timer.Start(1000) + self.timer.Start(1000) + self.timer2.Start(1500) def OnStop(self, event): - _timer.Stop() + self.timer.Stop() + self.timer2.Stop() + + def OnTimer(self, event): + wx.Bell() + if self.log: + self.log.WriteText('beep!\n') + + def OnTimer2(self, event): + wx.Bell() + if self.log: + self.log.WriteText('beep 2!\n') #--------------------------------------------------------------------------- @@ -49,19 +74,16 @@ def runTest(frame, nb, log): +overview = """\ +The wxTimer class allows you to execute code at specified intervals from +within the wxPython event loop. Timers can be one-shot or repeating. +""" - - - -overview = """\ -The wxTimer class allows you to execute code at specified intervals. To use it, derive a new class and override the Notify member to perform the required action. Start with Start, stop with Stop, it's as simple as that. - -wxTimer() ------------------- - -Constructor. -""" +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])])