]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/DrawXXXList.py
2 from wxPython
.wx
import *
5 #----------------------------------------------------------------------
27 #----------------------------------------------------------------------
29 def makeRandomPoints(num
, w
, h
):
32 x
= whrandom
.randint(0, w
)
33 y
= whrandom
.randint(0, h
)
38 def makeRandomLines(num
, w
, h
):
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
) )
49 def makeRandomPens(num
, cache
):
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
)] )
60 class TestPanel(wxPanel
):
61 def __init__(self
, parent
, size
, log
):
62 wxPanel
.__init
__(self
, parent
, -1, size
=size
)
64 self
.SetBackgroundColour(wxWHITE
)
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
)
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
)
82 EVT_PAINT(self
, self
.OnPaint
)
85 def OnPaint(self
, evt
):
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
)
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
)
101 self
.log
.write("DrawTime: %s seconds\n" % (time
.time() - start
))
102 self
.log
.write("GetBoundingBox: %s\n" % (dc
.GetBoundingBox(), ))
104 #----------------------------------------------------------------------
106 def runTest(frame
, nb
, log
):
107 w
= nb
.GetClientSize().width
108 h
= nb
.GetClientSize().height
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
)
118 #----------------------------------------------------------------------
123 Some methods have been added to wxDC to help with optimization of
124 drawing routines. Currently they are:
127 DrawPointList(sequence, pens=None)
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.
133 DrawLineList(sequence, pens=None)
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