-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathDrawLinesTest.py
executable file
·102 lines (79 loc) · 2.55 KB
/
DrawLinesTest.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 pythonw
"""
Timing test of the DrawLineList DC methods
It is NOT fast!
"""
import time
import wx
from numpy import random
NumLinePoints = 500
NumPointPoints = 500
# Make some random data to draw things with.
MaxX = 500
LinesPoints = random.randint(1, MaxX, (NumLinePoints, 2))
PointsPoints = random.randint(1, MaxX, (NumPointPoints, 2))
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(
self,
None,
-1,
"DrawLines Test",
wx.DefaultPosition,
size=(MaxX, MaxX),
style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
# Set up the MenuBar.
MenuBar = wx.MenuBar()
file_menu = wx.Menu()
item = file_menu.Append(wx.ID_EXIT, "E&xit", "Terminate the program")
self.Bind(wx.EVT_MENU, self.OnQuit, item)
MenuBar.Append(file_menu, "&File")
draw_menu = wx.Menu()
item = draw_menu.Append(wx.ID_ANY, "&ReDraw", "DrawAgain")
self.Bind(wx.EVT_MENU, self.ReDraw, item)
MenuBar.Append(draw_menu, "&Draw")
self.SetMenuBar(MenuBar)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, event):
print("in OnPaint...")
dc = wx.PaintDC(self)
dc.SetBackground(wx.Brush("White"))
dc.Clear()
self.DrawLines(dc)
self.DrawPoints(dc)
def ReDraw(self, event=None):
dc = wx.ClientDC(self)
dc.SetBackground(wx.Brush("White"))
dc.Clear()
self.DrawLines(dc)
self.DrawPoints(dc)
def DrawLines(self, dc):
dc.SetPen(wx.Pen('Black', 2))
start = time.time()
dc.DrawLines(LinesPoints)
print("DrawLines Call took %f seconds" % (time.time() - start))
start = time.time()
for i in range(len(LinesPoints) - 1):
dc.DrawLine(
LinesPoints[i, 0],
LinesPoints[i, 1],
LinesPoints[i + 1, 0],
LinesPoints[i + 1, 1],
)
print("DrawLine loop took %f seconds" % (time.time() - start))
def DrawPoints(self, dc):
dc.SetPen(wx.Pen('Red', 2))
start = time.time()
dc.DrawPointList(PointsPoints)
print("DrawPointList Call took %f seconds" % (time.time() - start))
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(False)
app.MainLoop()