]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/splashscreen.py
Give BitmapButton its own demo, get rid of ErrorDialogs
[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 # 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
14 #
15 # o 2.5 compatability update.
16 # o Untested.
17 #
18
19 """
20 A Splash Screen implemented in Python.
21
22 NOTE: Now that wxWindows has a wxSplashScrren class and it is wrapped
23 in wxPython this class is deprecated. See the docs for more details.
24 """
25
26 import warnings
27 import wx
28
29 warningmsg = r"""\
30
31 #####################################################\
32 # THIS MODULE IS NOW DEPRECATED |
33 # |
34 # The core wx library now contains an implementation |
35 # of the 'real' wx.SpashScreen. |
36 #####################################################/
37
38 """
39
40 warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
41
42
43 #----------------------------------------------------------------------
44
45 class SplashScreen(wx.Frame):
46 def __init__(self, parent, ID=-1, title="SplashScreen",
47 style=wx.SIMPLE_BORDER|wx.STAY_ON_TOP,
48 duration=1500, bitmapfile="bitmaps/splashscreen.bmp",
49 callback = None):
50 '''
51 parent, ID, title, style -- see wx.Frame
52 duration -- milliseconds to display the splash screen
53 bitmapfile -- absolute or relative pathname to image file
54 callback -- if specified, is called when timer completes, callback is
55 responsible for closing the splash screen
56 '''
57 ### Loading bitmap
58 self.bitmap = bmp = wx.Image(bitmapfile, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
59
60 ### Determine size of bitmap to size window...
61 size = (bmp.GetWidth(), bmp.GetHeight())
62
63 # size of screen
64 width = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
65 height = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
66 pos = ((width-size[0])/2, (height-size[1])/2)
67
68 # check for overflow...
69 if pos[0] < 0:
70 size = (wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_X), size[1])
71 if pos[1] < 0:
72 size = (size[0], wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_Y))
73
74 wx.Frame.__init__(self, parent, ID, title, pos, size, style)
75 self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseClick)
76 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
77 self.Bind(wx.EVT_PAINT, self.OnPaint)
78 self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBG)
79
80 self.Show(True)
81
82
83 class SplashTimer(wx.Timer):
84 def __init__(self, targetFunction):
85 self.Notify = targetFunction
86 wx.Timer.__init__(self)
87
88 if callback is None:
89 callback = self.OnSplashExitDefault
90
91 self.timer = SplashTimer(callback)
92 self.timer.Start(duration, 1) # one-shot only
93
94 def OnPaint(self, event):
95 dc = wx.PaintDC(self)
96 dc.DrawBitmap(self.bitmap, (0,0), False)
97
98 def OnEraseBG(self, event):
99 pass
100
101 def OnSplashExitDefault(self, event=None):
102 self.Close(True)
103
104 def OnCloseWindow(self, event=None):
105 self.Show(False)
106 self.timer.Stop()
107 del self.timer
108 self.Destroy()
109
110 def OnMouseClick(self, event):
111 self.timer.Notify()
112
113 #----------------------------------------------------------------------
114
115
116 if __name__ == "__main__":
117 class DemoApp(wx.App):
118 def OnInit(self):
119 wx.InitAllImageHandlers()
120 self.splash = SplashScreen(None, bitmapfile="splashscreen.jpg", callback=self.OnSplashExit)
121 self.splash.Show(True)
122 self.SetTopWindow(self.splash)
123 return True
124 def OnSplashExit(self, event=None):
125 print "Yay! Application callback worked!"
126 self.splash.Close(True)
127 del self.splash
128 ### Build working windows here...
129 def test(sceneGraph=None):
130 app = DemoApp(0)
131 app.MainLoop()
132 test()