]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/splashscreen.py
18042549dc79550b0cbef719e04bf5a3a0074551
[wxWidgets.git] / wxPython / wxPython / lib / splashscreen.py
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.
5 #
6 # Author: Mike Fletcher, Robin Dunn
7 #
8 # Created: 19-Nov-1999
9 # RCS-ID: $Id$
10 # Copyright: (c) 1999 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------
13
14 from wxPython.wx import *
15
16 #----------------------------------------------------------------------
17
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",
22 callback = None):
23 '''
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
29 '''
30 ### Loading bitmap
31 self.bitmap = bmp = wxImage(bitmapfile, wxBITMAP_TYPE_ANY).ConvertToBitmap()
32 ### Determine size of bitmap to size window...
33 size = (bmp.GetWidth(), bmp.GetHeight())
34 # size of screen
35 width = wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X)
36 height = wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y)
37 pos = ((width-size[0])/2, (height-size[1])/2)
38
39 # check for overflow...
40 if pos[0] < 0:
41 size = (wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X), size[1])
42 if pos[1] < 0:
43 size = (size[0], wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y))
44
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)
50
51 self.Show(true)
52
53
54 class SplashTimer(wxTimer):
55 def __init__(self, targetFunction):
56 self.Notify = targetFunction
57 wxTimer.__init__(self)
58
59 if callback is None:
60 callback = self.OnSplashExitDefault
61
62 self.timer = SplashTimer(callback)
63 self.timer.Start(duration, 1) # one-shot only
64
65 def OnPaint(self, event):
66 dc = wxPaintDC(self)
67 dc.DrawBitmap(self.bitmap, 0,0, false)
68
69 def OnEraseBG(self, event):
70 pass
71
72 def OnSplashExitDefault(self, event=None):
73 self.Close(true)
74
75 def OnCloseWindow(self, event=None):
76 self.Show(false)
77 self.timer.Stop()
78 del self.timer
79 self.Destroy()
80
81 def OnMouseClick(self, event):
82 self.timer.Notify()
83
84 #----------------------------------------------------------------------
85
86
87 if __name__ == "__main__":
88 class DemoApp(wxApp):
89 def OnInit(self):
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)
96 return true
97 def OnSplashExit(self, event=None):
98 print "Yay! Application callback worked!"
99 self.splash.Close(true)
100 del self.splash
101 ### Build working windows here...
102 def test(sceneGraph=None):
103 app = DemoApp(0)
104 app.MainLoop()
105 test()