- Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDrawOnControl.py
More file actions
Latest commit
executable file
·91 lines (68 loc) · 2.39 KB
/
Copy pathDrawOnControl.py
File metadata and controls
executable file
·91 lines (68 loc) · 2.39 KB
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
"""
importwx
classMyFrame(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)
defOnCloseWindow(self, event):
self.Destroy()
classMyPanel(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)
defOnSize(self, event):
self.Refresh()
defOnTimer(self, event):
ifself.BorderColor==wx.RED:
self.BorderColor=wx.BLUE
else:
self.BorderColor=wx.RED
self.ResetBorder()
defOnPaint(self, event):
dc=wx.PaintDC(self)
self.DrawBorder(dc)
event.Skip()
defOnSize(self, event):
dc=wx.ClientDC(self)
self.DrawBorder(dc)
defDrawBorder(self, dc):
size=self.GetSize()
dc.SetPen(wx.Pen(self.BorderColor, 4))
dc.DrawRectangle(2, 2, size[0] -3, size[1] -3)
defResetBorder(self, Color=wx.RED):
dc=wx.ClientDC(self)
self.DrawBorder(dc)
forcinself.GetChildren():
c.Refresh()
defOnButton(self,Event):
print("Button Clicked")
ifself.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")
classMyApp(wx.App):
defOnInit(self):
frame=MyFrame(None, -1, "This is a test")
frame.Show(True)
self.SetTopWindow(frame)
returnTrue
if__name__=="__main__":
app=MyApp(0) # Create an instance of the application class
app.MainLoop() # Tell it to start processing events