]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
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 | #---------------------------------------------------------------------- | |
b881fc78 RD |
13 | # 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
14 | # | |
15 | # o 2.5 compatability update. | |
16 | # o Untested. | |
17 | # | |
1fded56b | 18 | |
d14a1e28 RD |
19 | """ |
20 | A Splash Screen implemented in Python. | |
1fded56b | 21 | |
d14a1e28 RD |
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 | ||
b881fc78 RD |
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 | ||
d14a1e28 RD |
42 | |
43 | #---------------------------------------------------------------------- | |
44 | ||
b881fc78 | 45 | class SplashScreen(wx.Frame): |
d14a1e28 | 46 | def __init__(self, parent, ID=-1, title="SplashScreen", |
b881fc78 | 47 | style=wx.SIMPLE_BORDER|wx.STAY_ON_TOP, |
d14a1e28 RD |
48 | duration=1500, bitmapfile="bitmaps/splashscreen.bmp", |
49 | callback = None): | |
50 | ''' | |
b881fc78 | 51 | parent, ID, title, style -- see wx.Frame |
d14a1e28 RD |
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 | |
b881fc78 | 58 | self.bitmap = bmp = wx.Image(bitmapfile, wx.BITMAP_TYPE_ANY).ConvertToBitmap() |
d14a1e28 RD |
59 | |
60 | ### Determine size of bitmap to size window... | |
61 | size = (bmp.GetWidth(), bmp.GetHeight()) | |
62 | ||
63 | # size of screen | |
b881fc78 RD |
64 | width = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X) |
65 | height = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y) | |
d14a1e28 RD |
66 | pos = ((width-size[0])/2, (height-size[1])/2) |
67 | ||
68 | # check for overflow... | |
69 | if pos[0] < 0: | |
b881fc78 | 70 | size = (wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_X), size[1]) |
d14a1e28 | 71 | if pos[1] < 0: |
b881fc78 | 72 | size = (size[0], wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_Y)) |
d14a1e28 | 73 | |
b881fc78 RD |
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) | |
d14a1e28 RD |
79 | |
80 | self.Show(True) | |
81 | ||
82 | ||
b881fc78 | 83 | class SplashTimer(wx.Timer): |
d14a1e28 RD |
84 | def __init__(self, targetFunction): |
85 | self.Notify = targetFunction | |
b881fc78 | 86 | wx.Timer.__init__(self) |
d14a1e28 RD |
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): | |
b881fc78 | 95 | dc = wx.PaintDC(self) |
d7403ad2 | 96 | dc.DrawBitmap(self.bitmap, 0,0, False) |
d14a1e28 RD |
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__": | |
b881fc78 | 117 | class DemoApp(wx.App): |
d14a1e28 | 118 | def OnInit(self): |
b881fc78 RD |
119 | wx.InitAllImageHandlers() |
120 | self.splash = SplashScreen(None, bitmapfile="splashscreen.jpg", callback=self.OnSplashExit) | |
d14a1e28 RD |
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() |