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?
这是我的程序的当前(减少)结构,重要位显示完整。如何调整当前的启动画面以实际允许程序的其余部分在后台加载?在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_TIMEOUT
splashDuration = 5000 # 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 = VFrame(parent=None)
app.SetTopWindow(frame)
frame.Show(True)
evt.Skip()
class MyApp(wx.App):
def OnInit(self):
MySplash = MySplashScreen()
MySplash.Show()
return True
if __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 screen
global splash
bitmap = 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 splash
class MyApp(wx.App):
def OnInit(self):
global frame, splash
splash = 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 True
if __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()
2 个解决方案
#1
12
Your code is pretty messy/complicated. There's no need to override wx.SplashScreen and no reason your splash screen close event should be creating the main application window. Here's how I do splash screens.
你的代码非常混乱/复杂。没有必要覆盖wx.SplashScreen,没有理由你的启动画面关闭事件应该创建主应用程序窗口。这是我如何进行启动画面。
import wx
def show_splash():
# create, show and return the splash screen
bitmap = wx.Bitmap('images/splash.png')
splash = wx.SplashScreen(bitmap, wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_NO_TIMEOUT, 0, None, -1)
splash.Show()
return splash
def main():
app = wx.PySimpleApp()
splash = show_splash()
# do processing/initialization here and create main window
frame = MyFrame(...)
frame.Show()
splash.Destroy()
app.MainLoop()
if __name__ == '__main__':
main()
Just create the splash screen as soon as possible with no timeout. Continue loading and create your application's main window. Then destroy the splash screen so it goes away. Showing the splash screen doesn't stop other processing from happening.
只需尽快创建启动画面,不会超时。继续加载并创建应用程序的主窗口。然后摧毁闪屏,使其消失。显示启动画面不会阻止其他处理发生。
#2
0
You'll want to use two threads: one for the splash screen, one for whatever other code you want to execute. Both threads would run at the same time, providing the result you desire.
您将需要使用两个线程:一个用于启动屏幕,一个用于您要执行的任何其他代码。两个线程将同时运行,提供您想要的结果。
#1
12
Your code is pretty messy/complicated. There's no need to override wx.SplashScreen and no reason your splash screen close event should be creating the main application window. Here's how I do splash screens.
你的代码非常混乱/复杂。没有必要覆盖wx.SplashScreen,没有理由你的启动画面关闭事件应该创建主应用程序窗口。这是我如何进行启动画面。
import wx
def show_splash():
# create, show and return the splash screen
bitmap = wx.Bitmap('images/splash.png')
splash = wx.SplashScreen(bitmap, wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_NO_TIMEOUT, 0, None, -1)
splash.Show()
return splash
def main():
app = wx.PySimpleApp()
splash = show_splash()
# do processing/initialization here and create main window
frame = MyFrame(...)
frame.Show()
splash.Destroy()
app.MainLoop()
if __name__ == '__main__':
main()
Just create the splash screen as soon as possible with no timeout. Continue loading and create your application's main window. Then destroy the splash screen so it goes away. Showing the splash screen doesn't stop other processing from happening.
只需尽快创建启动画面,不会超时。继续加载并创建应用程序的主窗口。然后摧毁闪屏,使其消失。显示启动画面不会阻止其他处理发生。
#2
0
You'll want to use two threads: one for the splash screen, one for whatever other code you want to execute. Both threads would run at the same time, providing the result you desire.
您将需要使用两个线程:一个用于启动屏幕,一个用于您要执行的任何其他代码。两个线程将同时运行,提供您想要的结果。