- Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathTestUpdate.py
More file actions
Latest commit
executable file
·85 lines (64 loc) · 2.27 KB
/
Copy pathTestUpdate.py
File metadata and controls
executable file
·85 lines (64 loc) · 2.27 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
#!/usr/bin/env python
importwx
importtime
classTestFrame(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= []
defOnPaint(self,event):
dc=wx.PaintDC(self)
dc.SetBackground(wx.Brush("Purple"))
dc.Clear()
dc.SetPen(wx.Pen("Red", 3))
forLineinself.LineData:
dc.DrawLines(Line)
defClear(self, event=None):
self.LineData= []
self.Refresh()
defOnLeftDown(self,event):
xy=event.GetPosition()
self.LineData.append([xy])
defOnMouseMove(self, event):
ifevent.Dragging() andevent.LeftIsDown():
xy=event.GetPosition()
self.LineData[-1].append(xy)
# note: Update() doesn't work
self.Refresh()
defAnimate(self, event):
self.Refresh()
self.LineData.append( [] )
foriinxrange(0,500,5):
self.LineData[-1].append((i,i))
self.Refresh()
self.Update()
time.sleep(0.01)
defOnQuit(self,event):
self.Close(True)
classDemoApp(wx.App):
defOnInit(self):
frame=TestFrame()
frame.Show(True)
self.SetTopWindow(frame)
returnTrue
if__name__=="__main__":
app=DemoApp(0)
app.MainLoop()