1 #----------------------------------------------------------------------
2 # Name: wxPython.lib.splashscreen
3 # Purpose: A simple frame that can display a bitmap and closes itself
4 # after a specified timeout or a mouse click.
6 # Author: Mike Fletcher, Robin Dunn
10 # Copyright: (c) 1999 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------
15 A Splash Screen implemented in Python.
17 NOTE: Now that wxWindows has a wxSplashScrren class and it is wrapped
18 in wxPython this class is deprecated. See the docs for more details.
21 from wxPython
.wx
import *
23 #----------------------------------------------------------------------
25 class SplashScreen(wxFrame
):
26 def __init__(self
, parent
, ID
=-1, title
="SplashScreen",
27 style
=wxSIMPLE_BORDER|wxSTAY_ON_TOP
,
28 duration
=1500, bitmapfile
="bitmaps/splashscreen.bmp",
31 parent, ID, title, style -- see wxFrame
32 duration -- milliseconds to display the splash screen
33 bitmapfile -- absolute or relative pathname to image file
34 callback -- if specified, is called when timer completes, callback is
35 responsible for closing the splash screen
38 self
.bitmap
= bmp
= wxImage(bitmapfile
, wxBITMAP_TYPE_ANY
).ConvertToBitmap()
40 ### Determine size of bitmap to size window...
41 size
= (bmp
.GetWidth(), bmp
.GetHeight())
44 width
= wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X
)
45 height
= wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y
)
46 pos
= ((width
-size
[0])/2, (height
-size
[1])/2)
48 # check for overflow...
50 size
= (wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X
), size
[1])
52 size
= (size
[0], wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y
))
54 wxFrame
.__init
__(self
, parent
, ID
, title
, pos
, size
, style
)
55 EVT_LEFT_DOWN(self
, self
.OnMouseClick
)
56 EVT_CLOSE(self
, self
.OnCloseWindow
)
57 EVT_PAINT(self
, self
.OnPaint
)
58 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBG
)
63 class SplashTimer(wxTimer
):
64 def __init__(self
, targetFunction
):
65 self
.Notify
= targetFunction
66 wxTimer
.__init
__(self
)
69 callback
= self
.OnSplashExitDefault
71 self
.timer
= SplashTimer(callback
)
72 self
.timer
.Start(duration
, 1) # one-shot only
74 def OnPaint(self
, event
):
76 dc
.DrawBitmap(self
.bitmap
, 0,0, False)
78 def OnEraseBG(self
, event
):
81 def OnSplashExitDefault(self
, event
=None):
84 def OnCloseWindow(self
, event
=None):
90 def OnMouseClick(self
, event
):
93 #----------------------------------------------------------------------
96 if __name__
== "__main__":
99 wxImage_AddHandler(wxJPEGHandler())
100 wxImage_AddHandler(wxPNGHandler())
101 wxImage_AddHandler(wxGIFHandler())
102 self
.splash
= SplashScreen(NULL
, bitmapfile
="splashscreen.jpg", callback
=self
.OnSplashExit
)
103 self
.splash
.Show(True)
104 self
.SetTopWindow(self
.splash
)
106 def OnSplashExit(self
, event
=None):
107 print "Yay! Application callback worked!"
108 self
.splash
.Close(True)
110 ### Build working windows here...
111 def test(sceneGraph
=None):