the usual (part II)
[python/dscho.git] / Mac / Tools / IDE / Splash.py
blob868c6d2b41ca84758adc489bef64677f0d671d27
1 import Dlg
2 import Res
4 splash = Dlg.GetNewDialog(468, -1)
5 splash.DrawDialog()
7 import Qd, TE, Fm, sys
9 _real__import__ = None
11 def install_importhook():
12 global _real__import__
13 import __builtin__
14 if _real__import__ is None:
15 _real__import__ = __builtin__.__import__
16 __builtin__.__import__ = my__import__
18 def uninstall_importhook():
19 global _real__import__
20 if _real__import__ is not None:
21 import __builtin__
22 __builtin__.__import__ = _real__import__
23 _real__import__ = None
25 _progress = 0
27 def importing(module):
28 global _progress
29 Qd.SetPort(splash)
30 fontID = Fm.GetFNum("Python-Sans")
31 if not fontID:
32 fontID = geneva
33 Qd.TextFont(fontID)
34 Qd.TextSize(9)
35 rect = (35, 260, 365, 276)
36 if module:
37 TE.TETextBox('Importing: ' + module, rect, 0)
38 if not _progress:
39 Qd.FrameRect((35, 276, 365, 284))
40 pos = min(36 + 330 * _progress / 44, 364)
41 Qd.PaintRect((36, 277, pos, 283))
42 _progress = _progress + 1
43 else:
44 Qd.EraseRect(rect)
45 Qd.PaintRect((36, 277, pos, 283))
47 def my__import__(name, globals=None, locals=None, fromlist=None):
48 try:
49 return sys.modules[name]
50 except KeyError:
51 try:
52 importing(name)
53 except:
54 try:
55 rv = _real__import__(name)
56 finally:
57 uninstall_importhook()
58 return rv
59 return _real__import__(name)
61 install_importhook()
63 kHighLevelEvent = 23
64 import Win
65 from Fonts import *
66 from QuickDraw import *
67 from TextEdit import *
68 import string
69 import sys
71 _keepsplashscreenopen = 0
73 abouttext1 = """The Python Integrated Developement Environment for the Macintosh�
74 Version: %s
75 Copyright 1997-2000 Just van Rossum, Letterror. <just@letterror.com>
77 Python %s
79 Written by Guido van Rossum with Jack Jansen (and others)
81 See: <http://www.python.org/> for information and documentation."""
83 flauwekul = [ 'Goodday, Bruce.',
84 'What¹s new?',
85 'Nudge, nudge, say no more!',
86 'No, no sir, it¹s not dead. It¹s resting.',
87 'Albatros!',
88 'It¹s . . .',
89 'Is your name not Bruce, then?',
90 """But Mr F.G. Superman has a secret identity . . .
91 when trouble strikes at any time . . .
92 at any place . . . he is ready to become . . .
93 Bicycle Repair Man!"""
96 def nl2return(text):
97 return string.join(string.split(text, '\n'), '\r')
99 def UpdateSplash(drawdialog = 0, what = 0):
100 if drawdialog:
101 splash.DrawDialog()
102 drawtext(what)
103 Win.ValidRect(splash.GetWindowPort().portRect)
105 def drawtext(what = 0):
106 Qd.SetPort(splash)
107 fontID = Fm.GetFNum("Python-Sans")
108 if not fontID:
109 fontID = geneva
110 Qd.TextFont(fontID)
111 Qd.TextSize(9)
112 rect = (10, 125, 390, 260)
113 if not what:
114 import __main__
115 abouttxt = nl2return(abouttext1 \
116 % (__main__.__version__, sys.version, sys.copyright))
117 else:
118 import random
119 abouttxt = nl2return(random.choice(flauwekul))
120 TE.TETextBox(abouttxt, rect, teJustCenter)
122 UpdateSplash(1)
124 def wait():
125 import Evt
126 from Events import *
127 global splash
128 try:
129 splash
130 except NameError:
131 return
132 Qd.InitCursor()
133 time = Evt.TickCount()
134 whattext = 0
135 while _keepsplashscreenopen:
136 ok, event = Evt.EventAvail(highLevelEventMask)
137 if ok:
138 # got apple event, back to mainloop
139 break
140 ok, event = Evt.EventAvail(mDownMask | keyDownMask | updateMask)
141 if ok:
142 ok, event = Evt.WaitNextEvent(mDownMask | keyDownMask | updateMask, 30)
143 if ok:
144 (what, message, when, where, modifiers) = event
145 if what == updateEvt:
146 if Win.WhichWindow(message) == splash:
147 UpdateSplash(1, whattext)
148 else:
149 break
150 if Evt.TickCount() - time > 360:
151 whattext = not whattext
152 drawtext(whattext)
153 time = Evt.TickCount()
154 del splash
155 #Res.CloseResFile(splashresfile)
157 def about():
158 global splash, splashresfile, _keepsplashscreenopen
159 _keepsplashscreenopen = 1
160 splash = Dlg.GetNewDialog(468, -1)
161 splash.DrawDialog()
162 wait()