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