]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/splashscreen.py
Added wxAutoNSAutoreleasePool to Create(Tool|Status)Bar
[wxWidgets.git] / wxPython / wx / 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 """
15 A Splash Screen implemented in Python.
16
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.
19 """
20
21 from wxPython.wx import *
22
23 #----------------------------------------------------------------------
24
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",
29 callback = None):
30 '''
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
36 '''
37 ### Loading bitmap
38 self.bitmap = bmp = wxImage(bitmapfile, wxBITMAP_TYPE_ANY).ConvertToBitmap()
39
40 ### Determine size of bitmap to size window...
41 size = (bmp.GetWidth(), bmp.GetHeight())
42
43 # size of screen
44 width = wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X)
45 height = wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y)
46 pos = ((width-size[0])/2, (height-size[1])/2)
47
48 # check for overflow...
49 if pos[0] < 0:
50 size = (wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_X), size[1])
51 if pos[1] < 0:
52 size = (size[0], wxSystemSettings_GetSystemMetric(wxSYS_SCREEN_Y))
53
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)
59
60 self.Show(True)
61
62
63 class SplashTimer(wxTimer):
64 def __init__(self, targetFunction):
65 self.Notify = targetFunction
66 wxTimer.__init__(self)
67
68 if callback is None:
69 callback = self.OnSplashExitDefault
70
71 self.timer = SplashTimer(callback)
72 self.timer.Start(duration, 1) # one-shot only
73
74 def OnPaint(self, event):
75 dc = wxPaintDC(self)
76 dc.DrawBitmap(self.bitmap, 0,0, False)
77
78 def OnEraseBG(self, event):
79 pass
80
81 def OnSplashExitDefault(self, event=None):
82 self.Close(True)
83
84 def OnCloseWindow(self, event=None):
85 self.Show(False)
86 self.timer.Stop()
87 del self.timer
88 self.Destroy()
89
90 def OnMouseClick(self, event):
91 self.timer.Notify()
92
93 #----------------------------------------------------------------------
94
95
96 if __name__ == "__main__":
97 class DemoApp(wxApp):
98 def OnInit(self):
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)
105 return True
106 def OnSplashExit(self, event=None):
107 print "Yay! Application callback worked!"
108 self.splash.Close(True)
109 del self.splash
110 ### Build working windows here...
111 def test(sceneGraph=None):
112 app = DemoApp(0)
113 app.MainLoop()
114 test()