2003-12-09 01:23:28 +00:00
|
|
|
#
|
2004-01-13 03:17:17 +00:00
|
|
|
# 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.
|
|
|
|
#
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
import time
|
|
|
|
import wx
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
## For your convenience; an example of creating your own timer class.
|
|
|
|
##
|
2004-01-13 03:17:17 +00:00
|
|
|
## class TestTimer(wx.Timer):
|
2001-10-30 18:15:13 +00:00
|
|
|
## def __init__(self, log = None):
|
2004-01-13 03:17:17 +00:00
|
|
|
## wx.Timer.__init__(self)
|
2001-10-30 18:15:13 +00:00
|
|
|
## self.log = log
|
|
|
|
## def Notify(self):
|
2004-01-13 03:17:17 +00:00
|
|
|
## wx.Bell()
|
2001-10-30 18:15:13 +00:00
|
|
|
## if self.log:
|
|
|
|
## self.log.WriteText('beep!\n')
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
class TestTimerWin(wx.Panel):
|
1999-04-30 03:29:54 +00:00
|
|
|
def __init__(self, parent, log):
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2001-10-30 18:15:13 +00:00
|
|
|
self.log = log
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.StaticText(self, -1, "This is a timer example", (15, 30))
|
2004-01-13 03:17:17 +00:00
|
|
|
startBtn = wx.Button(self, -1, ' Start ', (15, 75), wx.DefaultSize)
|
|
|
|
stopBtn = wx.Button(self, -1, ' Stop ', (115, 75), wx.DefaultSize)
|
2001-10-30 18:15:13 +00:00
|
|
|
|
2004-01-13 03:17:17 +00:00
|
|
|
self.timer = wx.Timer(self, wx.NewId())
|
|
|
|
self.timer2 = wx.Timer(self, wx.NewId())
|
2002-03-26 21:55:33 +00:00
|
|
|
|
2004-01-13 03:17:17 +00:00
|
|
|
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)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
def OnStart(self, event):
|
2001-10-30 18:15:13 +00:00
|
|
|
self.timer.Start(1000)
|
2002-03-26 21:55:33 +00:00
|
|
|
self.timer2.Start(1500)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
def OnStop(self, event):
|
2001-10-30 18:15:13 +00:00
|
|
|
self.timer.Stop()
|
2002-03-26 21:55:33 +00:00
|
|
|
self.timer2.Stop()
|
2001-10-30 18:15:13 +00:00
|
|
|
|
|
|
|
def OnTimer(self, event):
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Bell()
|
2001-10-30 18:15:13 +00:00
|
|
|
if self.log:
|
|
|
|
self.log.WriteText('beep!\n')
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2002-03-26 21:55:33 +00:00
|
|
|
def OnTimer2(self, event):
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Bell()
|
2002-03-26 21:55:33 +00:00
|
|
|
if self.log:
|
|
|
|
self.log.WriteText('beep 2!\n')
|
|
|
|
|
1999-04-30 03:29:54 +00:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestTimerWin(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """\
|
2004-01-13 03:17:17 +00:00
|
|
|
The wx.Timer class allows you to execute code at specified intervals from
|
2003-12-09 01:23:28 +00:00
|
|
|
within the wxPython event loop. Timers can be one-shot or repeating.
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
"""
|
2001-10-30 18:16:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-07-02 23:13:10 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])])
|