-
Notifications
You must be signed in to change notification settings - Fork 21
/
DrawOnControl.py
executable file
·91 lines (68 loc) · 2.39 KB
/
DrawOnControl.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
#!/usr/bin/env python
"""
Note that this doesn't work right!
I don't remember if it ever did
"""
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=wx.Size(360, 240))
self.panel = MyPanel(self)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.Destroy()
class MyPanel(wx.Panel):
def __init__(self, window):
wx.Panel.__init__(self, window, wx.NewId(), style=wx.CLIP_CHILDREN)
self.b = wx.Button(self, -1, "Start Flashing", (50, 50))
self.st = wx.StaticText(self, -1, "A Static Text", (50, 100), style=wx.BORDER_SUNKEN)
wx.EVT_BUTTON(self,self.b.GetId(), self.OnButton)
wx.EVT_PAINT(self, self.OnPaint)
self.BorderColor = wx.RED
self.timer = wx.Timer(self, 999)
#self.timer.Start(300)
self.Bind(wx.EVT_TIMER, self.OnTimer)
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, event):
self.Refresh()
def OnTimer(self, event):
if self.BorderColor == wx.RED:
self.BorderColor = wx.BLUE
else:
self.BorderColor = wx.RED
self.ResetBorder()
def OnPaint(self, event):
dc = wx.PaintDC(self)
self.DrawBorder(dc)
event.Skip()
def OnSize(self, event):
dc = wx.ClientDC(self)
self.DrawBorder(dc)
def DrawBorder(self, dc):
size = self.GetSize()
dc.SetPen(wx.Pen(self.BorderColor, 4))
dc.DrawRectangle(2, 2, size[0] - 3, size[1] - 3)
def ResetBorder(self, Color=wx.RED):
dc = wx.ClientDC(self)
self.DrawBorder(dc)
for c in self.GetChildren():
c.Refresh()
def OnButton(self,Event):
print("Button Clicked")
if self.timer.IsRunning():
self.st.SetLabel("Stopping Timer")
self.timer.Stop()
self.b.SetLabel("Start Flashing")
else:
self.st.SetLabel("Starting timer")
self.timer.Start(200)
self.b.SetLabel("Stop Flashing")
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, "This is a test")
frame.Show(True)
self.SetTopWindow(frame)
return True
if __name__ == "__main__":
app = MyApp(0) # Create an instance of the application class
app.MainLoop() # Tell it to start processing events