2003-11-12 16:34:20 -05:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Name: wxPython.lib.splashscreen
|
|
|
|
# Purpose: A simple frame that can display a bitmap and closes itself
|
|
|
|
# after a specified timeout or a mouse click.
|
|
|
|
#
|
|
|
|
# Author: Mike Fletcher, Robin Dunn
|
|
|
|
#
|
|
|
|
# Created: 19-Nov-1999
|
|
|
|
# RCS-ID: $Id$
|
|
|
|
# Copyright: (c) 1999 by Total Control Software
|
|
|
|
# Licence: wxWindows license
|
|
|
|
#----------------------------------------------------------------------
|
2003-12-16 19:34:40 -05:00
|
|
|
# 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o 2.5 compatability update.
|
|
|
|
# o Untested.
|
|
|
|
#
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
"""
|
|
|
|
A Splash Screen implemented in Python.
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
NOTE: Now that wxWindows has a wxSplashScrren class and it is wrapped
|
|
|
|
in wxPython this class is deprecated. See the docs for more details.
|
|
|
|
"""
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
import warnings
|
|
|
|
import wx
|
|
|
|
|
|
|
|
warningmsg = r"""\
|
|
|
|
|
|
|
|
#####################################################\
|
|
|
|
# THIS MODULE IS NOW DEPRECATED |
|
|
|
|
# |
|
|
|
|
# The core wx library now contains an implementation |
|
|
|
|
# of the 'real' wx.SpashScreen. |
|
|
|
|
#####################################################/
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
class SplashScreen(wx.Frame):
|
2003-11-12 16:34:20 -05:00
|
|
|
def __init__(self, parent, ID=-1, title="SplashScreen",
|
2003-12-16 19:34:40 -05:00
|
|
|
style=wx.SIMPLE_BORDER|wx.STAY_ON_TOP,
|
2003-11-12 16:34:20 -05:00
|
|
|
duration=1500, bitmapfile="bitmaps/splashscreen.bmp",
|
|
|
|
callback = None):
|
|
|
|
'''
|
2003-12-16 19:34:40 -05:00
|
|
|
parent, ID, title, style -- see wx.Frame
|
2003-11-12 16:34:20 -05:00
|
|
|
duration -- milliseconds to display the splash screen
|
|
|
|
bitmapfile -- absolute or relative pathname to image file
|
|
|
|
callback -- if specified, is called when timer completes, callback is
|
|
|
|
responsible for closing the splash screen
|
|
|
|
'''
|
|
|
|
### Loading bitmap
|
2003-12-16 19:34:40 -05:00
|
|
|
self.bitmap = bmp = wx.Image(bitmapfile, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
### Determine size of bitmap to size window...
|
|
|
|
size = (bmp.GetWidth(), bmp.GetHeight())
|
|
|
|
|
|
|
|
# size of screen
|
2003-12-16 19:34:40 -05:00
|
|
|
width = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
|
|
|
|
height = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
|
2003-11-12 16:34:20 -05:00
|
|
|
pos = ((width-size[0])/2, (height-size[1])/2)
|
|
|
|
|
|
|
|
# check for overflow...
|
|
|
|
if pos[0] < 0:
|
2003-12-16 19:34:40 -05:00
|
|
|
size = (wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_X), size[1])
|
2003-11-12 16:34:20 -05:00
|
|
|
if pos[1] < 0:
|
2003-12-16 19:34:40 -05:00
|
|
|
size = (size[0], wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_Y))
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.Frame.__init__(self, parent, ID, title, pos, size, style)
|
|
|
|
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseClick)
|
|
|
|
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
|
|
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
|
|
|
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBG)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
self.Show(True)
|
|
|
|
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
class SplashTimer(wx.Timer):
|
2003-11-12 16:34:20 -05:00
|
|
|
def __init__(self, targetFunction):
|
|
|
|
self.Notify = targetFunction
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.Timer.__init__(self)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
if callback is None:
|
|
|
|
callback = self.OnSplashExitDefault
|
|
|
|
|
|
|
|
self.timer = SplashTimer(callback)
|
|
|
|
self.timer.Start(duration, 1) # one-shot only
|
|
|
|
|
|
|
|
def OnPaint(self, event):
|
2003-12-16 19:34:40 -05:00
|
|
|
dc = wx.PaintDC(self)
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawBitmap(self.bitmap, 0,0, False)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
def OnEraseBG(self, event):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def OnSplashExitDefault(self, event=None):
|
|
|
|
self.Close(True)
|
|
|
|
|
|
|
|
def OnCloseWindow(self, event=None):
|
|
|
|
self.Show(False)
|
|
|
|
self.timer.Stop()
|
|
|
|
del self.timer
|
|
|
|
self.Destroy()
|
|
|
|
|
|
|
|
def OnMouseClick(self, event):
|
|
|
|
self.timer.Notify()
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2003-12-16 19:34:40 -05:00
|
|
|
class DemoApp(wx.App):
|
2003-11-12 16:34:20 -05:00
|
|
|
def OnInit(self):
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.InitAllImageHandlers()
|
|
|
|
self.splash = SplashScreen(None, bitmapfile="splashscreen.jpg", callback=self.OnSplashExit)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.splash.Show(True)
|
|
|
|
self.SetTopWindow(self.splash)
|
|
|
|
return True
|
|
|
|
def OnSplashExit(self, event=None):
|
|
|
|
print "Yay! Application callback worked!"
|
|
|
|
self.splash.Close(True)
|
|
|
|
del self.splash
|
|
|
|
### Build working windows here...
|
|
|
|
def test(sceneGraph=None):
|
|
|
|
app = DemoApp(0)
|
|
|
|
app.MainLoop()
|
|
|
|
test()
|