]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ImageAlpha.py
   2 import wx                  
# This module uses the new wx namespace 
   6 #---------------------------------------------------------------------- 
   8 msg 
= "Some text will appear mixed in the image's shadow..." 
  10 class TestPanel(wx
.Panel
): 
  11     def __init__(self
, parent
, log
): 
  13         wx
.Panel
.__init
__(self
, parent
, -1) 
  15         self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
) 
  18     def OnPaint(self
, evt
): 
  20         dc
.SetBackground(wx
.Brush("WHITE")) 
  23         dc
.SetFont(wx
.Font(16, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
, True)) 
  24         dc
.DrawText("Bitmap alpha blending (on all ports but gtk+ 1.2)", 
  27         bmp 
= wx
.Bitmap(opj('bitmaps/toucan.png')) 
  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 
  33             # first convert to a wx.Image 
  34             img 
= bmp
.ConvertToImage() 
  36             # Then convert the alpha channel to a mask, specifying the 
  37             # threshold below which alpha will be made fully 
  39             img
.ConvertAlphaToMask(220) 
  41             # convert back to a wx.Bitmap 
  42             bmp 
= img
.ConvertToBitmap() 
  45         dc
.DrawBitmap(bmp
, 25,100, True) 
  47         dc
.SetFont(self
.GetFont()) 
  49         for line 
in range(10): 
  50             y 
+= dc
.GetCharHeight() + 5 
  51             dc
.DrawText(msg
, 200, y
) 
  52         dc
.DrawBitmap(bmp
, 250,100, True) 
  56 #---------------------------------------------------------------------- 
  58 def runTest(frame
, nb
, log
): 
  59     win 
= TestPanel(nb
, log
) 
  62 #---------------------------------------------------------------------- 
  66 overview 
= """<html><body> 
  67 <h2><center>Images with Alpha</center></h2> 
  69 wxMSW and wxMac now support alpha channels of supported image 
  70 types, and will properly blend that channel when drawing a 
  71 bitmap.  It is not supported yet on wxGTK, (if you would like to 
  72 change that please submit a patch!) 
  74 <p>On wxGTK this demo turns the alpha channel into a 1-bit mask, so 
  75 yes, it looks like crap.  Please help us fix it! 
  82 if __name__ 
== '__main__': 
  85     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])