Skip to content

Commit d95da8a

Browse files
committed
Implements wx.DC.DrawXXXList methods
1 parent 1d59a11 commit d95da8a

File tree

3 files changed

+103
-24
lines changed

3 files changed

+103
-24
lines changed

etg/cffi/dc.py

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,79 @@
11
def run(module):
2-
# TODO: replicate the methods from the sip/dc.py
3-
pass
2+
module.addPyCode('''\
3+
import itertools''')
4+
5+
c = module.find('wxDC')
6+
7+
c.addPyMethod(
8+
'_DrawRectangleList', '(self, coords, pens, brushes)',
9+
body="""\
10+
for (coord, pen, brush) in itertools.izip_longest(
11+
coords, pens, brushes):
12+
if pen is not None:
13+
self.SetPen(pen)
14+
if brush is not None:
15+
self.SetBrush(brush)
16+
self.DrawRectangle(*coord)
17+
""")
18+
19+
c.addPyMethod(
20+
'_DrawEllipseList', '(self, coords, pens, brushes)',
21+
body="""\
22+
for (coord, pen, brush) in itertools.izip_longest(
23+
coords, pens, brushes):
24+
if pen is not None:
25+
self.SetPen(pen)
26+
if brush is not None:
27+
self.SetBrush(brush)
28+
self.DrawEllipse(*coord)
29+
""")
30+
31+
c.addPyMethod(
32+
'_DrawPolygonList', '(self, coords, pens, brushes)',
33+
body="""\
34+
for (coord, pen, brush) in itertools.izip_longest(
35+
coords, pens, brushes):
36+
if pen is not None:
37+
self.SetPen(pen)
38+
if brush is not None:
39+
self.SetBrush(brush)
40+
self.DrawPolygon(coord)
41+
""")
42+
43+
c.addPyMethod(
44+
'_DrawPointList', '(self, coords, pens, brushes)',
45+
body="""\
46+
for (coord, pen, brush) in itertools.izip_longest(
47+
coords, pens, brushes):
48+
if pen is not None:
49+
self.SetPen(pen)
50+
if brush is not None:
51+
self.SetBrush(brush)
52+
self.DrawPoint(*coord)
53+
""")
54+
55+
c.addPyMethod(
56+
'_DrawLineList', '(self, coords, pens, brushes)',
57+
body="""\
58+
for (coord, pen, brush) in itertools.izip_longest(
59+
coords, pens, brushes):
60+
if pen is not None:
61+
self.SetPen(pen)
62+
if brush is not None:
63+
self.SetBrush(brush)
64+
self.DrawLine(*coord)
65+
""")
66+
67+
c.addPyMethod(
68+
'_DrawTextList', '(self, texts, points, foregrounds, backgrounds)',
69+
body="""\
70+
for (text, point, fg, bg) in itertools.izip_longest(
71+
texts, points, foregrounds, backgrounds):
72+
if text is not None:
73+
string = text
74+
if fg is not None:
75+
self.SetTextForeground(fg)
76+
if bg is not None:
77+
self.SetTextBackground(bg)
78+
self.DrawText(string, point[0], point[1])
79+
""")

etg/dc.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
'wxDCFontChanger',
2828
]
2929

30-
OTHERDEPS = [ 'src/dc_ex.cpp', ]
30+
OTHERDEPS = [ 'src/dc_ex.cpp',
31+
'etg/sip/dc.py',
32+
'etg/cffi/dc.py',]
3133

3234
#---------------------------------------------------------------------------
3335

@@ -174,6 +176,28 @@ def run():
174176
c.addPyCode('DC.GetGdkDrawable = wx.deprecated(DC.GetGdkDrawable, "Use GetHandle instead.")')
175177

176178

179+
180+
181+
c.addPyMethod('DrawPointList', '(self, points, pens=None)',
182+
doc="""\
183+
Draw a list of points as quickly as possible.
184+
185+
:param points: A sequence of 2-element sequences representing
186+
each point to draw, (x,y).
187+
:param pens: If None, then the current pen is used. If a single
188+
pen then it will be used for all points. If a list of
189+
pens then there should be one for each point in points.
190+
""",
191+
body="""\
192+
if pens is None:
193+
pens = []
194+
elif isinstance(pens, wx.Pen):
195+
pens = [pens]
196+
elif len(pens) != len(points):
197+
raise ValueError('points and pens must have same length')
198+
return self._DrawPointList(points, pens, [])
199+
""")
200+
177201
c.addPyMethod('DrawLineList', '(self, lines, pens=None)',
178202
doc="""\
179203
Draw a list of lines as quickly as possible.

etg/sip/dc.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,3 @@ def run(module):
2424
c.addCppMethod('PyObject*', '_DrawTextList',
2525
'(PyObject* textList, PyObject* pyPoints, PyObject* foregroundList, PyObject* backgroundList)',
2626
body="return wxPyDrawTextList(*self, textList, pyPoints, foregroundList, backgroundList);")
27-
28-
29-
c.addPyMethod('DrawPointList', '(self, points, pens=None)',
30-
doc="""\
31-
Draw a list of points as quickly as possible.
32-
33-
:param points: A sequence of 2-element sequences representing
34-
each point to draw, (x,y).
35-
:param pens: If None, then the current pen is used. If a single
36-
pen then it will be used for all points. If a list of
37-
pens then there should be one for each point in points.
38-
""",
39-
body="""\
40-
if pens is None:
41-
pens = []
42-
elif isinstance(pens, wx.Pen):
43-
pens = [pens]
44-
elif len(pens) != len(points):
45-
raise ValueError('points and pens must have same length')
46-
return self._DrawPointList(points, pens, [])
47-
""")

0 commit comments

Comments
 (0)