Drawing a transparently overlayed image over a bitmap

I have a series of thumbnails, which are wx.BitmapButtons. What I want to achieve is something similar to PDF viewers/PowerPoint, where the current slide in a side-panel of thumbnails is highlighted by some blue colour

i.e. - http://clarkbw.net/portfolio/images/evince/pdf-reference.png

I just don't have a clue how to go about creating the actual bitmap of one pasted onto the other.

I've tried:

        copy = self.GetBitmapLabel()
        mask = wx.BufferedDC(None, wx.EmptyBitmapRGBA(150, 150, 0, 0, 255, 25))

        dc = wx.MemoryDC()
        dc.SelectObject(copy)
        dc.Blit(0, 0, 150, 150, mask, 0, 0, useMask=True)
        dc.SelectObject(wx.NullBitmap)

        self.SetBitmapLabel(copy)

or:

        copy = wx.ImageFromBitmap(self.GetBitmapLabel())
        temp = wx.ImageFromBitmap(wx.EmptyBitmapRGBA(150, 150, 0, 0, 255, 25))
        temp.ConvertAlphaToMask()
        copy.Paste(temp, 0, 0)

        bmp = wx.BitmapFromImage(copy)
        self.SetBitmapLabel(bmp)

to no avail. Does anyone have any pointers? Currently my thumbnails update when a panel is drawn upon, so my aim is to preserve that feature while still highlighting the current tab, but I'll solve that once I implement the highlighting

cheers,
Steven

Hi Steven,

I have a series of thumbnails, which are wx.BitmapButtons. What I want to
achieve is something similar to PDF viewers/PowerPoint, where the current
slide in a side-panel of thumbnails is highlighted by some blue colour

i.e. - http://clarkbw.net/portfolio/images/evince/pdf-reference.png

I just don't have a clue how to go about creating the actual bitmap of one
pasted onto the other.

I've tried:

  copy = self\.GetBitmapLabel\(\)
  mask = wx\.BufferedDC\(None, wx\.EmptyBitmapRGBA\(150, 150, 0, 0, 255,

25))

  dc = wx\.MemoryDC\(\)
  dc\.SelectObject\(copy\)
  dc\.Blit\(0, 0, 150, 150, mask, 0, 0, useMask=True\)
  dc\.SelectObject\(wx\.NullBitmap\)

  self\.SetBitmapLabel\(copy\)

or:

  copy = wx\.ImageFromBitmap\(self\.GetBitmapLabel\(\)\)
  temp = wx\.ImageFromBitmap\(wx\.EmptyBitmapRGBA\(150, 150, 0, 0, 255, 25\)\)
  temp\.ConvertAlphaToMask\(\)
  copy\.Paste\(temp, 0, 0\)

  bmp = wx\.BitmapFromImage\(copy\)
  self\.SetBitmapLabel\(bmp\)

to no avail. Does anyone have any pointers? Currently my thumbnails update
when a panel is drawn upon, so my aim is to preserve that feature while
still highlighting the current tab, but I'll solve that once I implement the
highlighting

Have you tried looking at ThumbnailCtrl in wx.lib.agw? It may give you
some ideas on how to do what you are looking for. Otherwise, after
having called SetBitmapLabel, have you tried calling:

yourButton.Refresh() and/or
yourButton.Update() and/or
wx.SafeYield()

?

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

···

On Wed, Mar 11, 2009 at 6:57 AM, Steven Sproat wrote:

Steven Sproat wrote:

I have a series of thumbnails, which are wx.BitmapButtons. What I want to achieve is something similar to PDF viewers/PowerPoint, where the current slide in a side-panel of thumbnails is highlighted by some blue colour

i.e. - http://clarkbw.net/portfolio/images/evince/pdf-reference.png

I just don't have a clue how to go about creating the actual bitmap of one pasted onto the other.

You might try using a wx.GCDC with your MemoryDC as the target, and then just set a brush with an alpha value and draw a rectangle.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Steven Sproat wrote:

I have a series of thumbnails, which are wx.BitmapButtons. What I want to achieve is something similar to PDF viewers/PowerPoint, where the current slide in a side-panel of thumbnails is highlighted by some blue colour

i.e. - http://clarkbw.net/portfolio/images/evince/pdf-reference.png

I just don't have a clue how to go about creating the actual bitmap of one pasted onto the other.

You might try using a wx.GCDC with your MemoryDC as the target, and then just set a brush with an alpha value and draw a rectangle.

Ah, wow Rob, thanks a lot buddy, it worked perfectly! I was receiving many Cairo errors:
(python:19829): Gdk-CRITICAL **: gdk_cairo_create: assertion `GDK_IS_DRAWABLE (drawable)' failed

until I switched my statements around, and did

        _copy = copy(self.buffer)
        dc = wx.MemoryDC()
        dc.SelectObject(_copy)
        gcdc = wx.GCDC(dc)

instead of

        dc = wx.MemoryDC()
        gcdc = wx.GCDC(dc)
        dc.SelectObject(_copy)

Thanks a lot, it's looking really cool too, I just have to adjust the colours a bit:

http://img13.imageshack.us/img13/6007/screenshotmoz.png