]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/DrawXXXList.py
SetPath() is now implemented in dirdlg.cpp
[wxWidgets.git] / wxPython / demo / DrawXXXList.py
1
2 from wxPython.wx import *
3 import whrandom, time
4
5 #----------------------------------------------------------------------
6
7 colours = [
8 "BLACK",
9 "BLUE",
10 "BLUE VIOLET",
11 "BROWN",
12 "CYAN",
13 "DARK GREY",
14 "DARK GREEN",
15 "GOLD",
16 "GREY",
17 "GREEN",
18 "MAGENTA",
19 "NAVY",
20 "PINK",
21 "RED",
22 "SKY BLUE",
23 "VIOLET",
24 "YELLOW",
25 ]
26
27 #----------------------------------------------------------------------
28
29 def makeRandomPoints(num, w, h):
30 pnts = []
31 for i in range(num):
32 x = whrandom.randint(0, w)
33 y = whrandom.randint(0, h)
34 pnts.append( (x,y) )
35 return pnts
36
37
38 def makeRandomLines(num, w, h):
39 pnts = []
40 for i in range(num):
41 x1 = whrandom.randint(0, w)
42 y1 = whrandom.randint(0, h)
43 x2 = whrandom.randint(0, w)
44 y2 = whrandom.randint(0, h)
45 pnts.append( (x1,y1, x2,y2) )
46 return pnts
47
48
49 def makeRandomPens(num, cache):
50 pens = []
51 for i in range(num):
52 c = whrandom.choice(colours)
53 t = whrandom.randint(1, 4)
54 if not cache.has_key( (c, t) ):
55 cache[(c, t)] = wxPen(c, t)
56 pens.append( cache[(c, t)] )
57 return pens
58
59
60 class TestPanel(wxPanel):
61 def __init__(self, parent, size, log):
62 wxPanel.__init__(self, parent, -1, size=size)
63 self.log = log
64 self.SetBackgroundColour(wxWHITE)
65
66 w = size.width
67 h = size.height
68 pencache = {}
69
70 # make some lists of random points
71 self.pnts1 = makeRandomPoints(1000, w, h)
72 self.pnts2 = makeRandomPoints(1000, w, h)
73 self.pnts3 = makeRandomPoints(1000, w, h)
74 self.pens1 = makeRandomPens(1000, pencache)
75
76 # and now some lines
77 self.lines1 = makeRandomLines(500, w, h)
78 self.lines2 = makeRandomLines(500, w, h)
79 self.lines3 = makeRandomLines(500, w, h)
80 self.pens2 = makeRandomPens(500, pencache)
81
82 EVT_PAINT(self, self.OnPaint)
83
84
85 def OnPaint(self, evt):
86 dc = wxPaintDC(self)
87 dc.BeginDrawing()
88 start = time.time()
89
90 dc.SetPen(wxPen("BLACK", 1))
91 dc.DrawPointList(self.pnts1)
92 dc.DrawPointList(self.pnts2, wxPen("RED", 2))
93 dc.DrawPointList(self.pnts3, self.pens1)
94
95 dc.SetPen(wxPen("BLACK", 1))
96 dc.DrawLineList(self.lines1)
97 dc.DrawLineList(self.lines2, wxPen("RED", 2))
98 dc.DrawLineList(self.lines3, self.pens2)
99
100 dc.EndDrawing()
101 self.log.write("DrawTime: %s seconds\n" % (time.time() - start))
102 self.log.write("GetBoundingBox: %s\n" % (dc.GetBoundingBox(), ))
103
104 #----------------------------------------------------------------------
105
106 def runTest(frame, nb, log):
107 w = nb.GetClientSize().width
108 h = nb.GetClientSize().height
109 if w < 300: w = 300
110 if h < 300: h = 300
111 win = wxPanel(nb, -1)
112 tp = TestPanel(win, wxSize(w, h), log)
113 def OnPanelSize(evt, tp=tp):
114 tp.SetSize(evt.GetSize())
115 EVT_SIZE(win, OnPanelSize)
116 return win
117
118 #----------------------------------------------------------------------
119
120
121 overview = """\
122
123 Some methods have been added to wxDC to help with optimization of
124 drawing routines. Currently they are:
125
126 <pre>
127 DrawPointList(sequence, pens=None)
128 </pre>
129 Where sequence is a tuple, list, whatever of 2 element tuples
130 (x, y) and pens is either None, a single pen or a list of pens.
131
132 <pre>
133 DrawLineList(sequence, pens=None)
134 </pre>
135 Where sequence is a tuple, list, whatever of 4 element tuples
136 (x1,y1, x2,y2) andd pens is either None, a single pen or a list
137 of pens.
138
139 """