transparency in gif animations

becker at melacorneta.cl becker at melacorneta.cl
Thu Aug 2 20:56:19 PDT 2007


Hi,
I'm trying to display a gif animation, which has a transparent background. I'm using a jpg image as
frame background. The code is basically the same as the 'DragImage' example in the wxPython demos.
Now, my problem is that the gif transparent background is showing up grey on screen. My code worked
properly with wxPython 2.6. I played a little with the code from the wxPython examples, and inserted the gif animations
from 'AnimateCtrl' inside the 'DragImage' code. The result is the same: the animations get a grey background instead
of the window background. I've tried many things and can't get this to work. I hope someone can give me a hand with 
this. I include the code I modified from the 'DragImage' example in the demos, this is the whole constructor for
the DragCanvas class.

thanks in advance.


class DragCanvas(wx.ScrolledWindow):
    def __init__(self, parent, ID):
        wx.ScrolledWindow.__init__(self, parent, ID)
        self.shapes = []
        self.dragImage = None
        self.dragShape = None
        self.hiliteShape = None

        self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
        self.bg_bmp = images.getBackgroundBitmap()
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)

        # Make a shape from an image and mask.  This one will demo
        # dragging outside the window
        bmp = images.getTestStarBitmap()
        #bmp = wx.Bitmap('bitmaps/toucan.png')
        shape = DragShape(bmp)
        shape.pos = (5, 5)
        shape.fullscreen = True
        self.shapes.append(shape)

        bmp = images.getTheKidBitmap()
        shape = DragShape(bmp)
        shape.pos = (200, 5)
        self.shapes.append(shape)

        # Make a shape from some text
        text = "Some Text"
        bg_colour = wx.Colour(57, 115, 57)  # matches the bg image
        font = wx.Font(15, wx.ROMAN, wx.NORMAL, wx.BOLD)
        textExtent = self.GetFullTextExtent(text, font)

        # create a bitmap the same size as our text
        bmp = wx.EmptyBitmap(textExtent[0], textExtent[1])

        # 'draw' the text onto the bitmap
        dc = wx.MemoryDC()
        dc.SelectObject(bmp)
        dc.SetBackground(wx.Brush(bg_colour, wx.SOLID))
        dc.Clear()
        dc.SetTextForeground(wx.RED)
        dc.SetFont(font)
        dc.DrawText(text, 0, 0)
        dc.SelectObject(wx.NullBitmap)
        mask = wx.Mask(bmp, bg_colour)
        bmp.SetMask(mask)
        shape = DragShape(bmp)
        shape.pos = (5, 100)
        shape.text = "Some dragging text"
        self.shapes.append(shape)


        ### inserting the animations
        from Main import opj

        GIFNames = ['bitmaps/AG00178_.gif',
                    'bitmaps/BD13656_.gif', 
                    'bitmaps/AG00185_.gif',
                    'bitmaps/AG00039_.gif',
                    'bitmaps/AG00183_.gif',
                    'bitmaps/AG00028_.gif',
        ]
        sizer = wx.FlexGridSizer(2,3,5,5)
        for name in GIFNames:
            ani = wx.animate.Animation(opj(name))
            ctrl = wx.animate.AnimationCtrl(self, -1, ani)
            ctrl.SetUseWindowBackgroundColour()
            ctrl.Play()
            sizer.AddF(ctrl, wx.SizerFlags().Border(wx.ALL, 10))
        border = wx.BoxSizer()
        border.AddF(sizer, wx.SizerFlags(1).Expand().Border(wx.ALL, 20))
        self.SetSizer(border)


        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
        self.Bind(wx.EVT_MOTION, self.OnMotion)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)





More information about the wxpython-users mailing list