Hi folks,
As promised, I wrote up a little prototype of the proposed Draw-List-of
stuff code.
Tim Hochberg wrote:
OK. Well like I said Draw<Thing>List seems fine to me at the moment.
I decided to go with Draw<Thing>Set instead of "List", as I'm hoping any
sequence will do, not just a list (NumPy arrays come to mind, in
particular). I'm not wedded to the name, LIst would be fine too.
That's pretty much my position. I have no need for DrawPolygonList right
now,
I do have a need, so I'd really like to see it, while we are at it, even
if the performance improvement is small.
Actually I take it back I
think it should actually be DrawLineList and DrawPointList (no plurals).
I agree, no plurals
wxPython has both DrawLine and DrawLines,
Unfortunately, "DrawLines" really should be DrawPolyline, since that's
what it does. It's too bad, also, because if DrawLines didn't exist
already, I'd be tempted to go with the plural form, rather than all this
Set or List business.
I've named my function DrawPolylineSet, as DrawLinesSet and DrawLineSet
are just too close.
Agreed. But that doesn't mean we would have to include it for the interface
for DrawLineList, does it? (I don't think that's what you mean, but I'm just
checking).
Nope, we jsut need to keep it in mind.
That was actually my first thought, but since DrawPoint doesn't take a pen
argument, I thought it would be more consistent to not allow a singleton pen
argument. I don't feel strongly about it either way though.
I wasn't sure if I wanted symetry with DrawPoint, or with the passing of
a list, so I went with either. If you pass None (or nothing) you get
the current pwn. If you pass a single pen, it is used, if you pass a
sequence of pens, those get used. It's easy to do all that in Python, I
don't know about C++ !
From what Robin says
in a subsequent message, he doesn't seem to think this is a problem,
It sounds like he has a good idea of the best way to handle it, and he
should know!
So, here is my prototype: I've done:
DrawPointSet(points,Pens = None):
DrawLineSet(Lines,Pens = None):
DrawPolylineSet(Lines,Pens = None):
DrawPolygonSet(Polygons, Pens = None, Brushes = None):
I'd like to see the whole bunch done (DrawElipse, DrawRectangle,
DrawSpline, are there more?). I don't know if it's worth it for text or
icons.
Here is the code: (I've enclosed a little app that tests it). It is
intended to prototype the API, nothing more, let me know what you all
think.
class SetDC(wxPaintDC):
def __init__(self,Panel):
wxPaintDC.__init__(self,Panel)
self.pentype = type(wxRED_PEN)
self.brushtype = type(wxBLUE_BRUSH)
def DrawPointSet(self,points,Pens = None):
N = len(points)
if Pens is None:
Pens = self.GetPen()
assert (type(Pens) is self.pentype or len(Pens) == len(points),
'lengths of Pens and points must match')
if type(Pens) == self.pentype:
self.SetPen(Pens)
for point in points:
self.DrawPoint(point[0],point[1])
else:
for (point,pen) in zip(points,Pens):
self.SetPen(pen)
self.DrawPoint(point[0],point[1])
def DrawLineSet(self,Lines,Pens = None):
N = len(Lines)
if Pens is None:
Pens = self.GetPen()
assert (type(Pens) is self.pentype or len(Pens) == len(Lines),
'lengths of Pens and Lines must match')
if type(Pens) == self.pentype:
self.SetPen(Pens)
for line in Lines:
self.DrawLine(line[0],line[1],line[2],line[3])
else:
for (line,pen) in zip(Lines,Pens):
self.SetPen(pen)
self.DrawLine(line[0],line[1],line[2],line[3])
def DrawPolylineSet(self,Lines,Pens = None):
# I used "PolylineSet" here because it seemed that LinesSet
would be too close to LineSet, and
# DC.DrawLines really draws a polyline anyway.
N = len(Lines)
if Pens is None:
Pens = self.GetPen()
assert (type(Pens) is self.pentype or len(Pens) == len(Lines),
'lengths of Pens and Lines must match')
if type(Pens) == self.pentype:
self.SetPen(Pens)
for line in Lines:
self.DrawLines(line)
else:
for (line,pen) in zip(Lines,Pens):
self.SetPen(pen)
self.DrawLines(line)
def DrawPolygonSet(self,Polygons, Pens = None, Brushes = None):
N = len(Polygons)
if Pens is None:
Pens = self.GetPen()
if Brushes is None:
Brushes = self.GetBrush()
assert (type(Pens) is self.pentype or len(Pens) ==
len(Polygons),
'lengths of Pens and Polygons must match')
assert (type(Brushes) is self.brushtype or len(Brushes) ==
len(Polygons),
'lengths of Brushes and Polygons must match')
# too many to special case
for polygon, i in zip(Polygons,range(len(Polygons))):
if not (type(Pens) == self.pentype):
self.SetPen(Pens[i])
if not (type(Brushes) == self.brushtype):
self.SetBrush(Brushes[i])
self.DrawPolygon(polygon)
draw_win.py (7.88 KB)
···
--
Christopher Barker,
Ph.D.
ChrisHBarker@home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------