]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ImageAlpha.py
moved fatal exception handling code to msw/main.cpp from common code
[wxWidgets.git] / wxPython / demo / ImageAlpha.py
CommitLineData
8a88769e
RD
1
2import wx # This module uses the new wx namespace
3from Main import opj
4
5
6#----------------------------------------------------------------------
7
f1fabff5 8msg = "Some text will appear mixed in the image's shadow..."
8a88769e
RD
9
10class TestPanel(wx.Panel):
11 def __init__(self, parent, log):
12 self.log = log
13 wx.Panel.__init__(self, parent, -1)
14
15 self.Bind(wx.EVT_PAINT, self.OnPaint)
16
17
18 def OnPaint(self, evt):
19 dc = wx.PaintDC(self)
20 dc.SetBackground(wx.Brush("WHITE"))
21 dc.Clear()
22
23 dc.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD, True))
f1fabff5 24 dc.DrawText("Bitmap alpha blending (on all ports but gtk+ 1.2)",
d7403ad2
RD
25 25,25)
26
8a88769e 27 bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
f1fabff5
RD
28 if "gtk1" in wx.PlatformInfo:
29 # Try to make up for lack of alpha support in wxGTK (gtk+
30 # 1.2) by converting the alpha blending into a
31 # transparency mask.
32
33 # first convert to a wx.Image
c0d9c29d 34 img = bmp.ConvertToImage()
f1fabff5
RD
35
36 # Then convert the alpha channel to a mask, specifying the
37 # threshold below which alpha will be made fully
38 # transparent
39 img.ConvertAlphaToMask(220)
40
41 # convert back to a wx.Bitmap
c0d9c29d 42 bmp = img.ConvertToBitmap()
f1fabff5 43
803a0ba6 44
d7403ad2 45 dc.DrawBitmap(bmp, 25,100, True)
8a88769e
RD
46
47 dc.SetFont(self.GetFont())
48 y = 75
49 for line in range(10):
50 y += dc.GetCharHeight() + 5
d7403ad2
RD
51 dc.DrawText(msg, 200, y)
52 dc.DrawBitmap(bmp, 250,100, True)
8a88769e
RD
53
54
55
56#----------------------------------------------------------------------
57
58def runTest(frame, nb, log):
59 win = TestPanel(nb, log)
60 return win
61
62#----------------------------------------------------------------------
63
64
65
66overview = """<html><body>
67<h2><center>Images with Alpha</center></h2>
68
8e43747f 69wxMSW and wxMac now support alpha channels of supported image
6a8fa617 70types, and will properly blend that channel when drawing a
8a88769e
RD
71bitmap. It is not supported yet on wxGTK, (if you would like to
72change that please submit a patch!)
73
803a0ba6
RD
74<p>On wxGTK this demo turns the alpha channel into a 1-bit mask, so
75yes, it looks like crap. Please help us fix it!
76
8a88769e
RD
77</body></html>
78"""
79
80
81
82if __name__ == '__main__':
83 import sys,os
84 import run
85 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
86