-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathTimerDemo3.py
executable file
·97 lines (74 loc) · 3.03 KB
/
TimerDemo3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
import wx
import wx.stc as stc
class DemoFrame(wx.Frame):
""" This window displays a button """
def __init__(self, title="Timer Demo"):
wx.Frame.__init__(self, None , -1, title)#, size = (800,600), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
self.TextCtrl = stc.StyledTextCtrl(self, wx.NewId())
self.TextCtrl.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.TextCtrl, 1, wx.GROW)
# set up the buttons
ButtonSizer = self.SetUpTheButtons()
sizer.Add(ButtonSizer, 0, wx.GROW)
self.SetSizer(sizer)
# now set up the timers:
self.Timer1 = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer1, self.Timer1)
#self.Bind(wx.EVT_TIMER, self.OnTimer1, id = self.Timer1.GetId())
#self.Timer1.Bind(wx.EVT_TIMER, self.OnTimer1)
self.Timer2 = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer2, self.Timer2)
#self.Bind(wx.EVT_TIMER, self.OnTimer2, id = self.Timer2.GetId())
#self.Timer2.Bind(wx.EVT_TIMER, self.OnTimer2)
self.Counter1 = 0
self.Counter2 = 0
def SetUpTheButtons(self):
StartButton1 = wx.Button(self, wx.NewId(), "Start1")
StartButton1.Bind(wx.EVT_BUTTON, self.OnStart1)
StartButton2 = wx.Button(self, wx.NewId(), "Start2")
StartButton2.Bind(wx.EVT_BUTTON, self.OnStart2)
StopButton = wx.Button(self, wx.NewId(), "Stop")
StopButton.Bind(wx.EVT_BUTTON, self.OnStop)
QuitButton = wx.Button(self, wx.NewId(), "Quit")
QuitButton.Bind(wx.EVT_BUTTON, self.OnQuit)
self.Bind(wx.EVT_CLOSE, self.OnQuit)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add((1, 1), 1)
sizer.Add(StartButton1, 0, wx.ALIGN_CENTER | wx.ALL, 4)
sizer.Add((1, 1), 1)
sizer.Add(StartButton2, 0, wx.ALIGN_CENTER | wx.ALL, 4)
sizer.Add((1, 1), 1)
sizer.Add(StopButton, 0, wx.ALIGN_CENTER | wx.ALL, 4)
sizer.Add((1, 1), 1)
sizer.Add(QuitButton, 0, wx.ALIGN_CENTER | wx.ALL, 4)
sizer.Add((1, 1), 1)
return sizer
def OnTimer1(self, event):
print("OnTimer1 called")
self.Counter1 += 1
self.TextCtrl.AddText("Timer1 Output: %i\n"%self.Counter1)
def OnStart1(self, event):
self.Timer1.Start(200) # time between events (in milliseconds)
def OnTimer2(self, event):
print("OnTimer2 called")
self.Counter2 += 1
self.TextCtrl.AddText("Timer2 Output: %i\n"%self.Counter2)
def OnStart2(self, event):
self.Timer2.Start(1000) # time between events (in milliseconds)
def OnStop(self, event=None):
self.Timer1.Stop()
self.Timer2.Stop()
def OnMouseDown(self, event):
if self.Timer1.IsRunning():
self.OnStop()
else:
event.Skip()
def OnQuit(self, event):
self.Destroy()
if __name__ == "__main__":
app = wx.App(0)
frame = DemoFrame()
frame.Show()
app.MainLoop()