Currently I have a splash screen in place. However, it does not work as a real splash screen - as it halts the execution of the rest of the code (instead of allowing them to run in the background).
This is the current (reduced) arquitecture of my program, with the important bits displayed in full. How can I adapt the splash screen currently in place to actually allow the rest of the program to load in the background? Is it possible in python?
Thanks!
import ...
(many other imports)
def ...
def ...
(many other definitions)class VFrams(wxFrame):wx.Frame.__init__(self, parent, -1, _("Software"), size=(1024, 768), style=wx.DEFAULT_FRAME_STYLE)(a lot of code goes in here)class MySplashScreen(wx.SplashScreen):def __init__(self, parent=None):aBitmap = wx.Image(name=VarFiles["img_splash"]).ConvertToBitmap()splashStyle = wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUTsplashDuration = 5000 # mswx.SplashScreen.__init__(self, aBitmap, splashStyle, splashDuration, parent)self.Bind(wx.EVT_CLOSE, self.CloseSplash)wx.Yield()def CloseSplash(self, evt):self.Hide()global frameframe = VFrame(parent=None)app.SetTopWindow(frame)frame.Show(True)evt.Skip()class MyApp(wx.App):def OnInit(self):MySplash = MySplashScreen()MySplash.Show()return Trueif __name__ == '__main__':DEBUG = viz.addText('DEBUG:', viz.SCREEN)DEBUG.setPosition(0, 0)DEBUG.fontSize(16)DEBUG.color(viz.BLACK)Start_Mainvars() Start_Config()Start_Translation()Start_DB()Start_Themes()Start_Gui()Start_Get_Isos()Start_Bars()Start_Menus()Start_Event_Handlers()app = MyApp()app.MainLoop()
Thank you for all the help, this is how I changed the code (following the provided advice):
def show_splash():# create, show and return the splash screenglobal splashbitmap = wx.Image(name=VarFiles["img_splash"]).ConvertToBitmap()splash = wx.SplashScreen(bitmap, wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_NO_TIMEOUT, 0, None, -1)splash.Show()return splashclass MyApp(wx.App):def OnInit(self):global frame, splashsplash = show_splash()Start_Config()Start_Translation()Start_DB()Start_Themes()Start_Gui()Start_Get_Isos()Start_Bars("GDP1POP1_20091224_gdp", "1 pork")Start_Menus()Start_Event_Handlers()frame = VFrame(parent=None)frame.Show(True)splash.Destroy()return Trueif __name__ == '__main__':DEBUG = viz.addText('DEBUG:', viz.SCREEN)DEBUG.setPosition(0, 0)DEBUG.fontSize(16)DEBUG.color(viz.BLACK)Start_Mainvars() app = MyApp()app.MainLoop()