cbfc9df676
Make updates for recent changes on CVS HEAD. Remove or workaround deprecated items. Fix compile errors. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45088 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
201 lines
9.8 KiB
Python
201 lines
9.8 KiB
Python
import wx
|
|
import math
|
|
|
|
##import os; print "PID:", os.getpid(); raw_input("Press Enter...")
|
|
|
|
class TestPanel(wx.Panel):
|
|
def __init__(self, *args, **kw):
|
|
wx.Panel.__init__(self, *args, **kw)
|
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
|
|
|
self.SetBackgroundColour("white")
|
|
|
|
# maskless image
|
|
self.bmp1 = getTest2Bitmap()
|
|
|
|
# give this one a mask
|
|
self.bmp2 = getTest2Bitmap()
|
|
self.bmp2.SetMaskColour("blue")
|
|
|
|
# now make one in which the opaque pixels from #2 are made
|
|
# partially transparent
|
|
bmp = getTest2Bitmap()
|
|
bmp.SetMaskColour("blue")
|
|
img = bmp.ConvertToImage()
|
|
img.InitAlpha()
|
|
self.bmp3 = img.ConvertToBitmap()
|
|
pixelData = wx.AlphaPixelData(self.bmp3)
|
|
if not pixelData:
|
|
raise RuntimeError("Failed to gain raw access to bitmap data.")
|
|
for pixel in pixelData:
|
|
red, green, blue, alpha = pixel.Get()
|
|
if alpha == 255:
|
|
pixel.Set(red, green, blue, 128)
|
|
|
|
##self.bmp3 = wx.Bitmap("bitmaps/toucan.png")
|
|
|
|
|
|
def OnPaint(self, evt):
|
|
gc = wx.GraphicsContext.Create(wx.PaintDC(self))
|
|
|
|
# draw some lines to use as a background
|
|
gc.SetPen(wx.Pen("navy", 1))
|
|
x = y = 0
|
|
sz = self.GetSize()
|
|
while x < sz.width*2 or y < sz.height*2:
|
|
gc.StrokeLine(x,0, 0,y)
|
|
x += 20
|
|
y += 20
|
|
|
|
|
|
for bmp in [self.bmp1, self.bmp2, self.bmp3]:
|
|
# draw the plain bitmap
|
|
gc.DrawBitmap(bmp, 20,20,
|
|
bmp.GetWidth(), bmp.GetHeight())
|
|
|
|
# translate and scale by using the w, and h parameters
|
|
gc.Translate(100, 0)
|
|
gc.DrawBitmap(bmp, 20,20,
|
|
bmp.GetWidth()*1.5, bmp.GetHeight()*1.5)
|
|
|
|
# translate and scale using Scale()
|
|
gc.Translate(125, 0)
|
|
gc.PushState()
|
|
gc.Scale(0.75, 0.75)
|
|
gc.DrawBitmap(bmp, 20,20,
|
|
bmp.GetWidth(), bmp.GetHeight())
|
|
gc.PopState()
|
|
|
|
# translate and rotate
|
|
gc.Translate(125, 0)
|
|
gc.PushState()
|
|
gc.Rotate(math.radians(45))
|
|
gc.DrawBitmap(bmp, 20,20,
|
|
bmp.GetWidth(), bmp.GetHeight())
|
|
gc.PopState()
|
|
|
|
# move back to the left side, and down a row
|
|
gc.Translate(-350, 150)
|
|
|
|
|
|
def main():
|
|
app = wx.App(False)
|
|
frm = wx.Frame(None, size=(500,500))
|
|
pnl = TestPanel(frm)
|
|
frm.Show()
|
|
app.MainLoop()
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
from wx import ImageFromStream, BitmapFromImage
|
|
from wx import EmptyIcon
|
|
import cStringIO
|
|
|
|
|
|
def getTest2Data():
|
|
return \
|
|
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00@\x00\x00\x00@\x08\x02\x00\
|
|
\x00\x00%\x0b\xe6\x89\x00\x00\x00\x03sBIT\x08\x08\x08\xdb\xe1O\xe0\x00\x00\
|
|
\x08\xeeIDATh\x81\xd5\x9aKl\x1b\xd7\x15\x86\xbf\xcb\xe1\xf0\xa1\xa1(\x91\x92\
|
|
(\xc9\x96T\xd9q,Ar\xdc\xbarb\xa0F\xd1\xb8\x81\xd3\xa0\xb0\x03gS\x04\xf0>\xd3\
|
|
\x14\x857Aw\x0e\x8a\x00\xc9*\xe821h\x04\xe8&\x01\xb2k\x10\x07E\xd0\x00u\xb2p\
|
|
\x16\x85\x1f\x01\x92\xc8\xae\xe3\x1a\x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\xbd\x04F\r{\x07|\x91v\x06\xa1\x15\x01<\xb6\x06\xbd\x93mO9#<:`\xdbP\x9d\xee(\
|
|
{\x9a\xf5\xef\x1a\x08h\x9bD\xa7\xd97\xc5\xff\x00n\xb9j)\xe8*\xac\xf1\x00\x00\
|
|
\x00\x00IEND\xaeB`\x82'
|
|
|
|
def getTest2Bitmap():
|
|
return BitmapFromImage(getTest2Image())
|
|
|
|
def getTest2Image():
|
|
stream = cStringIO.StringIO(getTest2Data())
|
|
return ImageFromStream(stream)
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
if __name__ == '__main__':
|
|
main()
|