-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathTimerDemo.py
executable file
·76 lines (55 loc) · 2.11 KB
/
TimerDemo.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
#!/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 timer:
self.Timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer)
self.Counter = 0
def SetUpTheButtons(self):
StartButton = wx.Button(self, wx.NewId(), "Start")
StartButton.Bind(wx.EVT_BUTTON, self.OnStart)
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(StartButton, 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 OnTimer(self, event):
self.Counter += 1
self.TextCtrl.AddText("Sentence number: %i\n"%self.Counter)
def OnStart(self, event):
self.Timer.Start(500) # time between events (in milliseconds)
def OnStop(self, event=None):
self.Timer.Stop()
def OnMouseDown(self, event):
if self.Timer.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()