]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxTimer.py
Added PyPlot
[wxWidgets.git] / wxPython / demo / wxTimer.py
1 # 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2 #
3 # o Updated for wx namespace
4 #
5
6 import time
7 import wx
8
9 #---------------------------------------------------------------------------
10
11 ## For your convenience; an example of creating your own timer class.
12 ##
13 ## class TestTimer(wxTimer):
14 ## def __init__(self, log = None):
15 ## wxTimer.__init__(self)
16 ## self.log = log
17 ## def Notify(self):
18 ## wxBell()
19 ## if self.log:
20 ## self.log.WriteText('beep!\n')
21
22 #---------------------------------------------------------------------------
23
24 ID_Start = wx.NewId()
25 ID_Stop = wx.NewId()
26 ID_Timer = wx.NewId()
27 ID_Timer2 = wx.NewId()
28
29 class TestTimerWin(wx.Panel):
30 def __init__(self, parent, log):
31 wx.Panel.__init__(self, parent, -1)
32 self.log = log
33
34 wx.StaticText(self, -1, "This is a timer example", (15, 30))
35 wx.Button(self, ID_Start, ' Start ', (15, 75), wx.DefaultSize)
36 wx.Button(self, ID_Stop, ' Stop ', (115, 75), wx.DefaultSize)
37
38 self.timer = wx.Timer(self, # object to send the event to
39 ID_Timer) # event id to use
40
41 self.timer2 = wx.Timer(self, # object to send the event to
42 ID_Timer2) # event id to use
43
44 self.Bind(wx.EVT_BUTTON, self.OnStart, id=ID_Start)
45 self.Bind(wx.EVT_BUTTON, self.OnStop, id=ID_Stop)
46 self.Bind(wx.EVT_TIMER, self.OnTimer, id=ID_Timer)
47 self.Bind(wx.EVT_TIMER, self.OnTimer2, id=ID_Timer2)
48
49 def OnStart(self, event):
50 self.timer.Start(1000)
51 self.timer2.Start(1500)
52
53 def OnStop(self, event):
54 self.timer.Stop()
55 self.timer2.Stop()
56
57 def OnTimer(self, event):
58 wx.Bell()
59 if self.log:
60 self.log.WriteText('beep!\n')
61
62 def OnTimer2(self, event):
63 wx.Bell()
64 if self.log:
65 self.log.WriteText('beep 2!\n')
66
67 #---------------------------------------------------------------------------
68
69 def runTest(frame, nb, log):
70 win = TestTimerWin(nb, log)
71 return win
72
73 #---------------------------------------------------------------------------
74
75
76
77 overview = """\
78 The wxTimer class allows you to execute code at specified intervals from
79 within the wxPython event loop. Timers can be one-shot or repeating.
80
81 """
82
83
84
85
86 if __name__ == '__main__':
87 import sys,os
88 import run
89 run.main(['', os.path.basename(sys.argv[0])])