Reputation: 33
I am struggling with wxPython and animated (gif) splash during long taking function. So far I have:
class Splash(wx.SplashScreen):
def __init__(self, parent=None, id=-1):
image = "spinner.gif"
aBitmap = wx.Image(name =image).ConvertToBitmap()
splashStyle = wx.SPLASH_CENTRE_ON_PARENT
splashDuration = 0 # milliseconds
wx.SplashScreen.__init__(self, aBitmap, splashStyle,
splashDuration, parent)
gif = wx.animate.GIFAnimationCtrl(self, id, image,)
self.Show()
self.gif = gif
def Run(self,):
self.gif.Play()
I would like to do something like:
splash = Splash()
splash.Run()
result = very_time_consuming_function()
splash.Close()
...
use the result
Any input will be appreciated
Upvotes: 0
Views: 828
Reputation: 2034
You should perform the time consuming work on another thread, otherwise GUI will block and not respond.
Here is a snippet:
import wx
import wx.animate
from threading import Thread
import time
def wrap_very_time_consuming_function():
print "sleeping"
time.sleep(5) # very time consuming function
print "waking up"
wx.CallAfter(splash.gif.Stop)
return 0
app = wx.App()
splash = Splash()
splash.Run()
Thread(target=wrap_very_time_consuming_function).start()
app.MainLoop()
Upvotes: 1