]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Timer.py
resolving conflicts in files I had forgot to commit (sorry)
[wxWidgets.git] / wxPython / demo / Timer.py
1 #
2 # 1/11/2004 - Jeff Grimmett (grimmtooth@softhome.net)
3 #
4 # o It appears that wx.Timer has an issue where if you use
5 #
6 # self.timer = wx.Timer(self, -1)
7 #
8 # to create it, then
9 #
10 # self.timer.GetId()
11 #
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.
14 # This means that
15 #
16 # self.Bind(wx.EVT_TIMER, self.onTimer, self.timer)
17 #
18 # doesn't work right. However, using
19 #
20 # self.timer = wx.Timer(self, wx.NewId())
21 #
22 # makes it work OK. I believe this is a bug, but wiser heads than mine
23 # should determine this.
24 #
25
26 import time
27 import wx
28
29 #---------------------------------------------------------------------------
30
31 ## For your convenience; an example of creating your own timer class.
32 ##
33 ## class TestTimer(wx.Timer):
34 ## def __init__(self, log = None):
35 ## wx.Timer.__init__(self)
36 ## self.log = log
37 ## def Notify(self):
38 ## wx.Bell()
39 ## if self.log:
40 ## self.log.WriteText('beep!\n')
41
42 #---------------------------------------------------------------------------
43
44 class TestTimerWin(wx.Panel):
45 def __init__(self, parent, log):
46 wx.Panel.__init__(self, parent, -1)
47 self.log = log
48
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)
52
53 self.timer = wx.Timer(self, wx.NewId())
54 self.timer2 = wx.Timer(self, wx.NewId())
55
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)
60
61 def OnStart(self, event):
62 self.timer.Start(1000)
63 self.timer2.Start(1500)
64
65 def OnStop(self, event):
66 self.timer.Stop()
67 self.timer2.Stop()
68
69 def OnTimer(self, event):
70 wx.Bell()
71 if self.log:
72 self.log.WriteText('beep!\n')
73
74 def OnTimer2(self, event):
75 wx.Bell()
76 if self.log:
77 self.log.WriteText('beep 2!\n')
78
79 #---------------------------------------------------------------------------
80
81 def runTest(frame, nb, log):
82 win = TestTimerWin(nb, log)
83 return win
84
85 #---------------------------------------------------------------------------
86
87
88
89 overview = """\
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.
92
93 """
94
95
96
97
98 if __name__ == '__main__':
99 import sys,os
100 import run
101 run.main(['', os.path.basename(sys.argv[0])])