Michael Poznecki February 2016

Dynamic text on top of wx.SplashScreen

I am using wxPython to create a splash screen. It actually works great, but now I want to put some loading feedback on the splashscreen. Does anyone know how I can put a dynamic label on top of the splashscreen? Here is the code I am using:

class myFrame(wxFrame):
    wx.Frame.__init__(self, parent, -1, _("Radar"), 
                      size=(800, 600), style=wx.DEFAULT_FRAME_STYLE)


class MySplash(wx.SplashScreen):
    def __init__(self, parent=None):
        aBitmap = wx.Image(name=VarFiles["Radar_Splash"]).ConvertToBitmap()
        splashStyle = wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT
        splashDuration = 12000 # ms
        wx.SplashScreen.__init__(self, aBitmap, splashStyle, splashDuration, parent)
        self.Bind(wx.EVT_CLOSE, self.CloseSplash)
        wx.Yield()
    def CloseSplash(self, evt):
        self.Hide()
        global frame
        frame = myFrame(parent=None)
        app.SetTopWindow(frame)
        frame.Show(True)
        evt.Skip()

class MyAwesomeApp(wx.App):
    def OnInit(self):
        MySplash = MySplash()
        MySplash.Show()
        return True

Answers


nepix32 February 2016

As the SplashScreen is essentially a window displaying a bitmap, you will need to modify the provided bitmap, doing the layouting yourself.

def _draw_bmp(bmp, txt_lst):
    dc = wx.MemoryDC()
    dc.SelectObject(bmp)
    dc.Clear()
    gc = wx.GraphicsContext.Create(dc)
    font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
    gc.SetFont(font)
    for i, line in enumerate(txt_lst):
        dc.DrawText(line, 10, i * 20 + 15)
    dc.SelectObject(wx.NullBitmap)

    # ...
        aBitmap = #...
        _draw_bmp(aBitmap, ['splash', 'screen', 'text'])

The wx.GraphicsContext will be helpful to have antialiased text looking the same as in the underlying OS.

Post Status

Asked in February 2016
Viewed 3,690 times
Voted 10
Answered 1 times

Search




Leave an answer