-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathTestUpdate3.py
executable file
·102 lines (77 loc) · 2.69 KB
/
TestUpdate3.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
98
99
100
101
102
#!/usr/bin/env python
"""
This way uses a wxClientDC
"""
import wx
import time
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "DrawLines Test",
wx.DefaultPosition,
size=(500,500),
style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
## Set up the MenuBar
MenuBar = wx.MenuBar()
file_menu = wx.Menu()
ID_CLEAR_MENU = wx.NewId()
file_menu.Append(ID_CLEAR_MENU, "&Clear", "Clear the Screen")
self.Bind(wx.EVT_MENU, self.Clear, id=ID_CLEAR_MENU)
ID_ANIMATE_MENU = wx.NewId()
file_menu.Append(ID_ANIMATE_MENU, "&Animate", "Animate the Screen")
self.Bind(wx.EVT_MENU, self.Animate, id=ID_ANIMATE_MENU)
file_menu.Append(wx.ID_EXIT, "E&xit", "Terminate the program")
self.Bind(wx.EVT_MENU, self.OnQuit, id=wx.ID_EXIT)
MenuBar.Append(file_menu, "&File")
self.SetMenuBar(MenuBar)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.LineData = []
def OnPaint(self,event):
print("OnPaint Called")
dc = wx.PaintDC(self)
dc.SetBackground( wx.Brush("Purple") )
dc.Clear()
dc.SetPen(wx.Pen("Red", 3))
for Line in self.LineData:
dc.DrawLines(Line)
def Clear(self, event=None):
self.LineData = []
self.Refresh()
def OnLeftDown(self,event):
xy = event.GetPosition()
self.LineData.append( [xy] )
def OnMouseMove(self, event):
if event.Dragging() and event.LeftIsDown():
xy = event.GetPosition()
self.LineData[-1].append(xy)
dc = wx.ClientDC(self)
dc.SetPen(wx.Pen("Red", 3))
x1, y1 = self.LineData[-1][-2]
x2, y2 =self.LineData[-1][-1]
dc.DrawLine(x1, y1, x2, y2)
def Animate(self, event):
self.Refresh()
self.Update()
self.LineData.append( [(0,0)] )
dc = wx.ClientDC(self)
dc.SetPen(wx.Pen("Red", 3))
for i in xrange(10,500,5):
self.LineData[-1].append((i,i))
x1, y1 = self.LineData[-1][-2]
x2, y2 =self.LineData[-1][-1]
dc.DrawLine(x1, y1, x2, y2)
#self.Update()
wx.GetApp().Yield(1)
time.sleep(0.01)
def OnQuit(self,event):
self.Close(True)
class DemoApp(wx.App):
def OnInit(self):
frame = TestFrame()
frame.Show(True)
self.SetTopWindow(frame)
return True
if __name__ == "__main__":
app = DemoApp(0)
app.MainLoop()