blob: 5293295dcc4340bccb75d8b4d0cde2fbf3332fdc [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:
Jack Jansen106fcea2001-08-19 22:00:20 +000035 from Fonts import geneva
Just van Rossum40f9b7b1999-01-30 22:39:17 +000036 fontID = geneva
37 Qd.TextFont(fontID)
38 Qd.TextSize(9)
Just van Rossumdc3c6172001-06-19 21:37:33 +000039 labelrect = (35, _about_height - 35, _about_width - 35, _about_height - 19)
40 framerect = (35, _about_height - 19, _about_width - 35, _about_height - 11)
41 l, t, r, b = progrect = Qd.InsetRect(framerect, 1, 1)
Just van Rossum40f9b7b1999-01-30 22:39:17 +000042 if module:
Just van Rossumdc3c6172001-06-19 21:37:33 +000043 TE.TETextBox('Importing: ' + module, labelrect, 0)
Just van Rossum40f9b7b1999-01-30 22:39:17 +000044 if not _progress:
Just van Rossumdc3c6172001-06-19 21:37:33 +000045 Qd.FrameRect(framerect)
46 pos = min(r, l + ((r - l) * _progress) / 44)
47 Qd.PaintRect((l, t, pos, b))
Just van Rossum40f9b7b1999-01-30 22:39:17 +000048 _progress = _progress + 1
49 else:
Just van Rossumdc3c6172001-06-19 21:37:33 +000050 Qd.EraseRect(labelrect)
51 Qd.PaintRect((l, t, pos, b))
Jack Jansen06646a12001-03-15 14:35:33 +000052 Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None)
Just van Rossum40f9b7b1999-01-30 22:39:17 +000053
54def my__import__(name, globals=None, locals=None, fromlist=None):
55 try:
56 return sys.modules[name]
57 except KeyError:
58 try:
59 importing(name)
60 except:
61 try:
62 rv = _real__import__(name)
63 finally:
64 uninstall_importhook()
65 return rv
66 return _real__import__(name)
67
Jack Jansen106fcea2001-08-19 22:00:20 +000068#install_importhook()
Just van Rossum40f9b7b1999-01-30 22:39:17 +000069
70kHighLevelEvent = 23
71import Win
72from Fonts import *
73from QuickDraw import *
74from TextEdit import *
75import string
76import sys
77
78_keepsplashscreenopen = 0
79
Just van Rossumdc3c6172001-06-19 21:37:33 +000080abouttext1 = """The Python Integrated Development Environment for the Macintosh\xaa
Just van Rossum40f9b7b1999-01-30 22:39:17 +000081Version: %s
Just van Rossumdc3c6172001-06-19 21:37:33 +000082Copyright 1997-2001 Just van Rossum, Letterror. <just@letterror.com>
Just van Rossum40f9b7b1999-01-30 22:39:17 +000083Python %s
84%s
Just van Rossum40f9b7b1999-01-30 22:39:17 +000085See: <http://www.python.org/> for information and documentation."""
86
Just van Rossumdc3c6172001-06-19 21:37:33 +000087flauwekul = [ "Goodday, Bruce.",
88 "What's new?",
89 "Nudge, nudge, say no more!",
90 "No, no sir, it's not dead. It's resting.",
91 "Albatros!",
92 "It's . . .",
93 "Is your name not Bruce, then?",
Just van Rossum40f9b7b1999-01-30 22:39:17 +000094 """But Mr F.G. Superman has a secret identity . . .
95when trouble strikes at any time . . .
96at any place . . . he is ready to become . . .
97Bicycle Repair Man!"""
98 ]
99
Just van Rossumc9246612000-10-20 07:35:33 +0000100def skipdoublereturns(text):
101 return string.replace(text, '\n\n', '\n')
102
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000103def nl2return(text):
Just van Rossumc9246612000-10-20 07:35:33 +0000104 return string.replace(text, '\n', '\r')
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000105
106def UpdateSplash(drawdialog = 0, what = 0):
107 if drawdialog:
108 splash.DrawDialog()
109 drawtext(what)
Jack Jansen73023402001-01-23 14:58:20 +0000110 splash.GetDialogWindow().ValidWindowRect(splash.GetDialogPort().portRect)
Jack Jansen06646a12001-03-15 14:35:33 +0000111 Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000112
113def drawtext(what = 0):
114 Qd.SetPort(splash)
115 fontID = Fm.GetFNum("Python-Sans")
116 if not fontID:
117 fontID = geneva
118 Qd.TextFont(fontID)
119 Qd.TextSize(9)
Just van Rossumdc3c6172001-06-19 21:37:33 +0000120 rect = (10, 115, _about_width - 10, _about_height - 30)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000121 if not what:
122 import __main__
Just van Rossumc9246612000-10-20 07:35:33 +0000123 abouttxt = nl2return(abouttext1 % (
124 __main__.__version__, sys.version, skipdoublereturns(sys.copyright)))
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000125 else:
126 import random
127 abouttxt = nl2return(random.choice(flauwekul))
128 TE.TETextBox(abouttxt, rect, teJustCenter)
129
130UpdateSplash(1)
131
132def wait():
133 import Evt
Jack Jansendef0d8d2001-02-09 15:56:19 +0000134 import Events
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000135 global splash
136 try:
137 splash
138 except NameError:
139 return
140 Qd.InitCursor()
141 time = Evt.TickCount()
142 whattext = 0
Just van Rossumdc3c6172001-06-19 21:37:33 +0000143 drawtext(whattext)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000144 while _keepsplashscreenopen:
Jack Jansendef0d8d2001-02-09 15:56:19 +0000145 ok, event = Evt.EventAvail(Events.highLevelEventMask)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000146 if ok:
147 # got apple event, back to mainloop
148 break
Jack Jansendef0d8d2001-02-09 15:56:19 +0000149 ok, event = Evt.EventAvail(Events.mDownMask | Events.keyDownMask | Events.updateMask)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000150 if ok:
Jack Jansendef0d8d2001-02-09 15:56:19 +0000151 ok, event = Evt.WaitNextEvent(Events.mDownMask | Events.keyDownMask | Events.updateMask, 30)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000152 if ok:
153 (what, message, when, where, modifiers) = event
Jack Jansendef0d8d2001-02-09 15:56:19 +0000154 if what == Events.updateEvt:
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000155 if Win.WhichWindow(message) == splash:
156 UpdateSplash(1, whattext)
157 else:
158 break
159 if Evt.TickCount() - time > 360:
160 whattext = not whattext
161 drawtext(whattext)
162 time = Evt.TickCount()
163 del splash
Just van Rossumdc3c6172001-06-19 21:37:33 +0000164
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000165
166def about():
167 global splash, splashresfile, _keepsplashscreenopen
168 _keepsplashscreenopen = 1
169 splash = Dlg.GetNewDialog(468, -1)
170 splash.DrawDialog()
171 wait()