Setting a transparent region on a bitmap

Sorry Chris, full code as follows....

class SplashScreen(wx.Frame):
    """ Splash screen configured so that it destroys once the main
    Console frame has instigated or if the timer times out."""

    def __init__(self, bmp, timeout=10000):

        self.bmp = bmp
        pos=wx.DefaultPosition
        size=wx.DefaultSize
        style= wx.FRAME_SHAPED | wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR
        
        wx.Frame.__init__(self, None, -1, "", pos, size, style)
        
        mask = wx.Mask(self.bmp, wx.WHITE)
        self.bmp.SetMask(mask)
        self.reg = wx.RegionFromBitmap(self.bmp)
        self.SetShape(self.reg)
        
        #Starts The Timer. Once Expired, AdvancedSplash Is Destroyed
        self._splashtimer = wx.PyTimer(self.Close)
        self._splashtimer.Start(timeout)

        # Set The AdvancedSplash Size To The Bitmap Size
        w = self.bmp.GetWidth()
        h = self.bmp.GetHeight()
        self.SetSize((w, h))
     
        # Bind the close event and display the screen
        self.Bind(wx.EVT_CLOSE, self.CloseTest)
        self.CenterOnScreen()
        self.Show()
        
    def CloseTest(self,event):
        """ Closing
        """
        app.frConsole.Show()
        event.Skip()

Note - Since the original post I have upgraded to Python 2.5 from 2.4.
can't get the full bitmap to display at all now. Probably a red herring but
I mention it just in case.

I will try other forms of bitmap as per Andrea's class notes. Will report
back.

- Thanks

···

-----Original Message-----
From: Christopher Barker [mailto:Chris.Barker@noaa.gov]
Sent: 02 January 2008 19:51
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Setting a transparent region on a bitmap

David Poundall wrote:
> I am trying to get to grips with masking a bitmap and I am have a
> problem. Based on AG’s code I am running this in a frame …
>
>
>
> mask = wx.Mask(self.bmp, wx.WHITE)
> self.bmp.SetMask(mask)
> self.reg = wx.RegionFromBitmap(self.bmp)
> self.SetShape(self.reg)
> self.Show()

Do try to make a complete, running sample, so we can try it out and know
all of what you are trying to do, but:

I don't think you want self.SetShape(self.reg) -- that sets the "Shape"
of the Window, so it will only draw within that shape. If you just set
the mast and Show() you should be done, but it's hard to know without
knowing what your Paint handler is doing.

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.17.13/1206 - Release Date:
01/01/2008 12:09

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.17.13/1206 - Release Date: 01/01/2008
12:09

Bitmap I am running with is attached.

spinnakerlogo.bmp (214 KB)

···

-----Original Message-----
From: David Poundall [mailto:david.poundall@treatmentservices.co.uk]
Sent: 02 January 2008 22:24
To: wxPython-users@lists.wxwidgets.org
Subject: RE: [wxPython-users] Setting a transparent region on a bitmap

Sorry Chris, full code as follows....

class SplashScreen(wx.Frame):
    """ Splash screen configured so that it destroys once the main
    Console frame has instigated or if the timer times out."""

    def __init__(self, bmp, timeout=10000):

        self.bmp = bmp
        pos=wx.DefaultPosition
        size=wx.DefaultSize
        style= wx.FRAME_SHAPED | wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR

        wx.Frame.__init__(self, None, -1, "", pos, size, style)

        mask = wx.Mask(self.bmp, wx.WHITE)
        self.bmp.SetMask(mask)
        self.reg = wx.RegionFromBitmap(self.bmp)
        self.SetShape(self.reg)

        #Starts The Timer. Once Expired, AdvancedSplash Is Destroyed
        self._splashtimer = wx.PyTimer(self.Close)
        self._splashtimer.Start(timeout)

        # Set The AdvancedSplash Size To The Bitmap Size
        w = self.bmp.GetWidth()
        h = self.bmp.GetHeight()
        self.SetSize((w, h))

        # Bind the close event and display the screen
        self.Bind(wx.EVT_CLOSE, self.CloseTest)
        self.CenterOnScreen()
        self.Show()

    def CloseTest(self,event):
        """ Closing
        """
        app.frConsole.Show()
        event.Skip()

Note - Since the original post I have upgraded to Python 2.5 from 2.4.
can't get the full bitmap to display at all now. Probably a red herring
but
I mention it just in case.

I will try other forms of bitmap as per Andrea's class notes. Will report
back.

- Thanks

> -----Original Message-----
> From: Christopher Barker [mailto:Chris.Barker@noaa.gov]
> Sent: 02 January 2008 19:51
> To: wxPython-users@lists.wxwidgets.org
> Subject: Re: [wxPython-users] Setting a transparent region on a bitmap
>
> David Poundall wrote:
> > I am trying to get to grips with masking a bitmap and I am have a
> > problem. Based on AG’s code I am running this in a frame …
> >
> >
> >
> > mask = wx.Mask(self.bmp, wx.WHITE)
> > self.bmp.SetMask(mask)
> > self.reg = wx.RegionFromBitmap(self.bmp)
> > self.SetShape(self.reg)
> > self.Show()
>
> Do try to make a complete, running sample, so we can try it out and know
> all of what you are trying to do, but:
>
> I don't think you want self.SetShape(self.reg) -- that sets the "Shape"
> of the Window, so it will only draw within that shape. If you just set
> the mast and Show() you should be done, but it's hard to know without
> knowing what your Paint handler is doing.
>
>
> -Chris
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> Chris.Barker@noaa.gov
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.516 / Virus Database: 269.17.13/1206 - Release Date:
> 01/01/2008 12:09
>

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.17.13/1206 - Release Date:
01/01/2008
12:09

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.17.13/1206 - Release Date:
01/01/2008 12:09

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.17.13/1206 - Release Date: 01/01/2008
12:09

David Poundall wrote:

Sorry Chris, full code as follows....

But not quite a running app! (you might want to enclose your bitmap too, if it's not too big.

I'm also not quite sure what you are trying to do. It looks like you want a Frame shaped as the "real" part of your bitmap. You've provided the shape for the Frame, but not actualy drawn anything on it -- you need to draw the bitmap somewhere, like in a Paint handler for instance:

class SplashScreen(wx.Frame):

...

        pos=wx.DefaultPosition
        size=wx.DefaultSize
        style= wx.FRAME_SHAPED | wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR

           # just leave size and pos out if you want to use the defaults:
          wx.Frame.__init__(self, None, style=style)
...
           self.bind(wx.EVT_PAINT), self.OnPaint)
...
         def OnPaint(self, event):
             dc = wx.PaintDC(self)
             dc.DrawBitmap(self.bmp, x, y, True)

Does that get you closer?

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

           self.bind(wx.EVT_PAINT), self.OnPaint)
...
         def OnPaint(self, event):
             dc = wx.PaintDC(self)
             dc.DrawBitmap(self.bmp, x, y, True)

Does that get you closer?

Yes it does - thank you Chris. When I was cribbing Andrea's code I missed
the paint section. In the end what worked was....

    def OnPaint(self, event):
        dc = wx.PaintDC(self)
        dc.DrawBitmap(self.bmp, 0, 0, True)
        wx.SafeYield()
        event.Skip()

That's a relief I thought I was going mad. The learning curve on wx.Python
is all but doing my head in.

- David

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.17.13/1206 - Release Date: 01/01/2008
12:09