I am trying to create wx.Frame with variable transparency (based on png displayed in erase bk event)

I am trying to create a special splash screen displayed during application loading, it displays messages about loading various components and shows a progress bar.

The first task I do is display a .png image in a frame on which the splash screen will be placed.

import wx

class edSplash(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, size=(410, 410), style=wx.NO_BORDER)
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.Center()
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
        return

    def OnEraseBackground(self, evt):
        dc = evt.GetDC() 
        if not dc:
            dc = wx.ClientDC(self)
            rect = self.GetUpdateRegion().GetBox()
            dc.SetClippingRect(rect)

        tempBrush = wx.Brush((0,0,0,0),wx.TRANSPARENT)
        print tempBrush
        dc.SetBackground(tempBrush)
        dc.SetBackgroundMode(wx.TRANSPARENT)
        #dc.Clear()
        img = wx.Image("splash.png", wx.BITMAP_TYPE_PNG, -1)
        bmp = wx.BitmapFromImage(img)
        dc.DrawBitmap(bmp, 0, 0, True)

    def PushMessage(self, mesage):
        print mesage


class edApp(wx.App):
    def OnInit(self):
        splash = edSplash(None, 'Ed')
        self.SetTopWindow(splash)
        splash.Show(True)
        return True

if __name__ == '__main__':
    edApp(redirect=False).MainLoop()

code>

The problem is that dc.Clear () clears to an opaque rectangle, although I set the brush and transparency mode (I think: D). Commenting, dc.Clear () gives me the desired variable transparency based on the .png alpha channel, but the window collects image noise from neighboring windows.

.png , ?

+3

Source: https://habr.com/ru/post/1756734/


All Articles