]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/AlphaDrawing.py
Added sample showing Alpha drawing for Mac with CoreGraphics
[wxWidgets.git] / wxPython / demo / AlphaDrawing.py
CommitLineData
59780c72
RD
1
2import wx
3
4#----------------------------------------------------------------------
5
6class TestPanel(wx.Panel):
7 def __init__(self, parent, log):
8 self.log = log
9 wx.Panel.__init__(self, parent, -1)
10
11 wx.StaticText(self, -1,
12 "On the Mac these squares should be transparent,\n"
13 "if the CoreGrahics option is turned on.",
14 (20, 20))
15
16 self.Bind(wx.EVT_PAINT, self.OnPaint)
17
18 def OnPaint(self, evt):
19 dc = wx.PaintDC(self)
20 rect = wx.Rect(0,0, 100, 100)
21 for RGB, pos in [((178, 34, 34), ( 50, 70)),
22 (( 35, 142, 35), (110, 130)),
23 (( 0, 0, 139), (170, 70))
24 ]:
25 r, g, b = RGB
26 penclr = wx.Colour(r, g, b, wx.ALPHA_OPAQUE)
27 brushclr = wx.Colour(r, g, b, 128) # half transparent
28 dc.SetPen(wx.Pen(penclr))
29 dc.SetBrush(wx.Brush(brushclr))
30 rect.SetPosition(pos)
31 dc.DrawRectangleRect(rect)
32
33
34#----------------------------------------------------------------------
35
36def runTest(frame, nb, log):
37 win = TestPanel(nb, log)
38 return win
39
40#----------------------------------------------------------------------
41
42
43
44overview = """<html><body>
45<h2><center>Alpha Drawing</center></h2>
46
47The wx.DC on Mac now supports alpha transparent drawing using pens and
48brushes. This is accomplished by enabling the wx.Colour class to have
49a fourth component for the alpha value, where 0 is fully transparent,
50and 255 is fully opaque.
51
52</body></html>
53"""
54
55
56
57if __name__ == '__main__':
58 import sys,os
59 import run
60 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
61