blob: 60cd7c6dceda3882125a994163832d27c4bac38b [file] [log] [blame]
Just van Rossum40f9b7b1999-01-30 22:39:17 +00001import Dlg
2import Res
3
4splash = Dlg.GetNewDialog(468, -1)
5splash.DrawDialog()
6
7import Qd, TE, Fm, sys
8
9_real__import__ = None
10
11def 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__
17
18def 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
24
25_progress = 0
26
Just van Rossumdc3c6172001-06-19 21:37:33 +000027_about_width = 440
28_about_height = 340
29
Just van Rossum40f9b7b1999-01-30 22:39:17 +000030def importing(module):
31 global _progress
32 Qd.SetPort(splash)
33 fontID = Fm.GetFNum("Python-Sans")
34 if not fontID:
35 fontID = geneva
36 Qd.TextFont(fontID)
37 Qd.TextSize(9)
Just van Rossumdc3c6172001-06-19 21:37:33 +000038 labelrect = (35, _about_height - 35, _about_width - 35, _about_height - 19)
39 framerect = (35, _about_height - 19, _about_width - 35, _about_height - 11)
40 l, t, r, b = progrect = Qd.InsetRect(framerect, 1, 1)
Just van Rossum40f9b7b1999-01-30 22:39:17 +000041 if module:
Just van Rossumdc3c6172001-06-19 21:37:33 +000042 TE.TETextBox('Importing: ' + module, labelrect, 0)
Just van Rossum40f9b7b1999-01-30 22:39:17 +000043 if not _progress:
Just van Rossumdc3c6172001-06-19 21:37:33 +000044 Qd.FrameRect(framerect)
45 pos = min(r, l + ((r - l) * _progress) / 44)
46 Qd.PaintRect((l, t, pos, b))
Just van Rossum40f9b7b1999-01-30 22:39:17 +000047 _progress = _progress + 1
48 else:
Just van Rossumdc3c6172001-06-19 21:37:33 +000049 Qd.EraseRect(labelrect)
50 Qd.PaintRect((l, t, pos, b))
Jack Jansen06646a12001-03-15 14:35:33 +000051 Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None)
Just van Rossum40f9b7b1999-01-30 22:39:17 +000052
53def my__import__(name, globals=None, locals=None, fromlist=None):
54 try:
55 return sys.modules[name]
56 except KeyError:
57 try:
58 importing(name)
59 except:
60 try:
61 rv = _real__import__(name)
62 finally:
63 uninstall_importhook()
64 return rv
65 return _real__import__(name)
66
67install_importhook()
68
69kHighLevelEvent = 23
70import Win
71from Fonts import *
72from QuickDraw import *
73from TextEdit import *
74import string
75import sys
76
77_keepsplashscreenopen = 0
78
Just van Rossumdc3c6172001-06-19 21:37:33 +000079abouttext1 = """The Python Integrated Development Environment for the Macintosh\xaa
Just van Rossum40f9b7b1999-01-30 22:39:17 +000080Version: %s
Just van Rossumdc3c6172001-06-19 21:37:33 +000081Copyright 1997-2001 Just van Rossum, Letterror. <just@letterror.com>
Just van Rossum40f9b7b1999-01-30 22:39:17 +000082Python %s
83%s
Just van Rossum40f9b7b1999-01-30 22:39:17 +000084See: <http://www.python.org/> for information and documentation."""
85
Just van Rossumdc3c6172001-06-19 21:37:33 +000086flauwekul = [ "Goodday, Bruce.",
87 "What's new?",
88 "Nudge, nudge, say no more!",
89 "No, no sir, it's not dead. It's resting.",
90 "Albatros!",
91 "It's . . .",
92 "Is your name not Bruce, then?",
Just van Rossum40f9b7b1999-01-30 22:39:17 +000093 """But Mr F.G. Superman has a secret identity . . .
94when trouble strikes at any time . . .
95at any place . . . he is ready to become . . .
96Bicycle Repair Man!"""
97 ]
98
Just van Rossumc9246612000-10-20 07:35:33 +000099def skipdoublereturns(text):
100 return string.replace(text, '\n\n', '\n')
101
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000102def nl2return(text):
Just van Rossumc9246612000-10-20 07:35:33 +0000103 return string.replace(text, '\n', '\r')
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000104
105def UpdateSplash(drawdialog = 0, what = 0):
106 if drawdialog:
107 splash.DrawDialog()
108 drawtext(what)
Jack Jansen73023402001-01-23 14:58:20 +0000109 splash.GetDialogWindow().ValidWindowRect(splash.GetDialogPort().portRect)
Jack Jansen06646a12001-03-15 14:35:33 +0000110 Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000111
112def drawtext(what = 0):
113 Qd.SetPort(splash)
114 fontID = Fm.GetFNum("Python-Sans")
115 if not fontID:
116 fontID = geneva
117 Qd.TextFont(fontID)
118 Qd.TextSize(9)
Just van Rossumdc3c6172001-06-19 21:37:33 +0000119 rect = (10, 115, _about_width - 10, _about_height - 30)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000120 if not what:
121 import __main__
Just van Rossumc9246612000-10-20 07:35:33 +0000122 abouttxt = nl2return(abouttext1 % (
123 __main__.__version__, sys.version, skipdoublereturns(sys.copyright)))
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000124 else:
125 import random
126 abouttxt = nl2return(random.choice(flauwekul))
127 TE.TETextBox(abouttxt, rect, teJustCenter)
128
129UpdateSplash(1)
130
131def wait():
132 import Evt
Jack Jansendef0d8d2001-02-09 15:56:19 +0000133 import Events
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000134 global splash
135 try:
136 splash
137 except NameError:
138 return
139 Qd.InitCursor()
140 time = Evt.TickCount()
141 whattext = 0
Just van Rossumdc3c6172001-06-19 21:37:33 +0000142 drawtext(whattext)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000143 while _keepsplashscreenopen:
Jack Jansendef0d8d2001-02-09 15:56:19 +0000144 ok, event = Evt.EventAvail(Events.highLevelEventMask)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000145 if ok:
146 # got apple event, back to mainloop
147 break
Jack Jansendef0d8d2001-02-09 15:56:19 +0000148 ok, event = Evt.EventAvail(Events.mDownMask | Events.keyDownMask | Events.updateMask)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000149 if ok:
Jack Jansendef0d8d2001-02-09 15:56:19 +0000150 ok, event = Evt.WaitNextEvent(Events.mDownMask | Events.keyDownMask | Events.updateMask, 30)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000151 if ok:
152 (what, message, when, where, modifiers) = event
Jack Jansendef0d8d2001-02-09 15:56:19 +0000153 if what == Events.updateEvt:
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000154 if Win.WhichWindow(message) == splash:
155 UpdateSplash(1, whattext)
156 else:
157 break
158 if Evt.TickCount() - time > 360:
159 whattext = not whattext
160 drawtext(whattext)
161 time = Evt.TickCount()
162 del splash
Just van Rossumdc3c6172001-06-19 21:37:33 +0000163
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000164
165def about():
166 global splash, splashresfile, _keepsplashscreenopen
167 _keepsplashscreenopen = 1
168 splash = Dlg.GetNewDialog(468, -1)
169 splash.DrawDialog()
170 wait()