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 #----------------------------------------------------------------------
14 from wxPython
.wx
import *
16 #----------------------------------------------------------------------
18 class SplashScreen(wxFrame
):
19 def __init__(self
, parent
, ID
=-1, title
="SplashScreen",
20 style
=wxSIMPLE_BORDER|wxSTAY_ON_TOP
,
21 duration
=1500, bitmapfile
="bitmaps/splashscreen.bmp",
24 parent, ID, title, style -- see wxFrame
25 duration -- milliseconds to display the splash screen
26 bitmapfile -- absolute or relative pathname to image file
27 callback -- if specified, is called when timer completes, callback is
28 responsible for closing the splash screen
31 self
.bitmap
= bmp
= wxImage(bitmapfile
, wxBITMAP_TYPE_ANY
).ConvertToBitmap()
32 ### Determine size of bitmap to size window...
33 size
= (bmp
.GetWidth(), bmp
.GetHeight())
35 width
= wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X
)
36 height
= wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y
)
37 pos
= ((width
-size
[0])/2, (height
-size
[1])/2)
39 # check for overflow...
41 size
= (wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X
), size
[1])
43 size
= (size
[0], wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y
))
45 wxFrame
.__init
__(self
, parent
, ID
, title
, pos
, size
, style
)
46 EVT_LEFT_DOWN(self
, self
.OnMouseClick
)
47 EVT_CLOSE(self
, self
.OnCloseWindow
)
48 EVT_PAINT(self
, self
.OnPaint
)
49 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBG
)
54 class SplashTimer(wxTimer
):
55 def __init__(self
, targetFunction
):
56 self
.Notify
= targetFunction
57 wxTimer
.__init
__(self
)
60 callback
= self
.OnSplashExitDefault
62 self
.timer
= SplashTimer(callback
)
63 self
.timer
.Start(duration
, 1) # one-shot only
65 def OnPaint(self
, event
):
67 dc
.DrawBitmap(self
.bitmap
, 0,0, false
)
69 def OnEraseBG(self
, event
):
72 def OnSplashExitDefault(self
, event
=None):
75 def OnCloseWindow(self
, event
=None):
81 def OnMouseClick(self
, event
):
84 #----------------------------------------------------------------------
87 if __name__
== "__main__":
90 wxImage_AddHandler(wxJPEGHandler())
91 wxImage_AddHandler(wxPNGHandler())
92 wxImage_AddHandler(wxGIFHandler())
93 self
.splash
= SplashScreen(NULL
, bitmapfile
="splashscreen.jpg", callback
=self
.OnSplashExit
)
94 self
.splash
.Show(true
)
95 self
.SetTopWindow(self
.splash
)
97 def OnSplashExit(self
, event
=None):
98 print "Yay! Application callback worked!"
99 self
.splash
.Close(true
)
101 ### Build working windows here...
102 def test(sceneGraph
=None):