tags:

views:

41

answers:

1

I have a wx application which I just added a splash screen to, the problem is that sometimes (about 10% of the time) the splash screen frame pops up but is blank. I wrote the following test, which replicates the problem (below). The wx.Yield() helped somewhat, as the fail rate was more like 50% without it. Does anyone know how to fix this?

import wx

SLEEP_TIME = 1.0 # seconds

if __name__ == '__main__':
    app = wx.App()
    splash_image = wx.Image('spikepy_splash.bmp').ConvertToBitmap()

    splash_screen = wx.SplashScreen(splash_image, 
            wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_NO_TIMEOUT, 0, None)
    wx.Yield()
    #wx.SafeYield()
    #wx.GetApp().Yield()
    wx.Sleep(SLEEP_TIME)
A: 

It appears to be important to keep from doing anything before app.MainLoop(). To get around this limitation just use wx.CallLater or similar. That way you add what you wanted to do before the MainLoop() to the event stack so that it happens after the call to MainLoop().

This resolved the issue for me, both in the below test code and the main application I'm writing. I just added all my imports and gui construction to a function and then used wx.CallLater to run that function.

import wx

SLEEP_TIME = 1.0 # seconds

if __name__ == '__main__':
    app = wx.App()
    splash_image = wx.Image('spikepy_splash.bmp').ConvertToBitmap()

    splash_screen = wx.SplashScreen(splash_image, 
            wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_NO_TIMEOUT, 0, None)

    wx.CallLater(1000*SLEEP_TIME, splash_screen.Destroy)
    app.MainLoop()
David Morton