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 def bitmapFromFile(filename
):
19 '''Non-portable test for bitmap type...'''
21 BITMAPTYPEGUESSDICT
= {
22 "bmp" :wxBITMAP_TYPE_BMP
,
23 "png" :wxBITMAP_TYPE_PNG
,
24 "jpeg":wxBITMAP_TYPE_JPEG
,
25 "gif" :wxBITMAP_TYPE_GIF
,
26 "xbm" :wxBITMAP_TYPE_XBM
,
28 # following assumes bitmap type if we cannot resolve image type
29 typ
= BITMAPTYPEGUESSDICT
.get(imghdr
.what(filename
), wxBITMAP_TYPE_BMP
)
30 bitmap
= wxImage(filename
, typ
).ConvertToBitmap()
33 #----------------------------------------------------------------------
35 class SplashScreen(wxFrame
):
36 def __init__(self
, parent
, ID
=-1, title
="SplashScreen",
37 style
=wxSIMPLE_BORDER|wxSTAY_ON_TOP
,
38 duration
=1500, bitmapfile
="bitmaps/splashscreen.bmp",
41 parent, ID, title, style -- see wxFrame
42 duration -- milliseconds to display the splash screen
43 bitmapfile -- absolute or relative pathname, extension used for type negotiation
44 callback -- if specified, is called when timer completes, callback is responsible for closing the splash screen
47 self
.bitmap
= bmp
= bitmapFromFile(bitmapfile
)
48 ### Determine size of bitmap to size window...
49 size
= (bmp
.GetWidth(), bmp
.GetHeight())
51 width
= wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X
)
52 height
= wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y
)
53 pos
= ((width
-size
[0])/2, (height
-size
[1])/2)
55 # check for overflow...
57 size
= (wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X
), size
[1])
59 size
= (size
[0], wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y
))
61 wxFrame
.__init
__(self
, parent
, ID
, title
, pos
, size
, style
)
64 dc
.DrawBitmap(self
.bitmap
, 0,0, false
)
66 class SplashTimer(wxTimer
):
67 def __init__(self
, targetFunction
):
68 self
.Notify
= targetFunction
69 wxTimer
.__init
__(self
)
72 callback
= self
.OnSplashExitDefault
74 self
.timer
= SplashTimer(callback
)
75 self
.timer
.Start(duration
, 1) # one-shot only
76 EVT_LEFT_DOWN(self
, self
.OnMouseClick
)
78 def OnPaint(self
, event
):
80 dc
.DrawBitmap(self
.bitmap
, 0,0, false
)
83 def OnSplashExitDefault(self
, event
=None):
87 def OnCloseWindow(self
, event
=None):
94 def OnMouseClick(self
, event
):
97 #----------------------------------------------------------------------
100 if __name__
== "__main__":
101 class DemoApp(wxApp
):
103 wxImage_AddHandler(wxJPEGHandler())
104 wxImage_AddHandler(wxPNGHandler())
105 wxImage_AddHandler(wxGIFHandler())
106 self
.splash
= SplashScreen(NULL
, bitmapfile
="splashscreen.jpg", callback
=self
.OnSplashExit
)
107 self
.splash
.Show(true
)
108 self
.SetTopWindow(self
.splash
)
110 def OnSplashExit(self
, event
=None):
111 print "Yay! Application callback worked!"
112 self
.splash
.Close(true
)
114 ### Build working windows here...
115 def test(sceneGraph
=None):