blob: 31271cc587bf1a175fcf4192fe8f29548d825eb0 [file] [log] [blame]
Jack Jansen5a6fdcd2001-08-25 12:15:04 +00001from Carbon import Dlg
2from Carbon import Res
Just van Rossum40f9b7b1999-01-30 22:39:17 +00003
4splash = Dlg.GetNewDialog(468, -1)
5splash.DrawDialog()
6
Jack Jansen5a6fdcd2001-08-25 12:15:04 +00007from Carbon import Qd, TE, Fm
8import sys
Just van Rossum40f9b7b1999-01-30 22:39:17 +00009
10_real__import__ = None
11
12def install_importhook():
13 global _real__import__
14 import __builtin__
15 if _real__import__ is None:
16 _real__import__ = __builtin__.__import__
17 __builtin__.__import__ = my__import__
18
19def uninstall_importhook():
20 global _real__import__
21 if _real__import__ is not None:
22 import __builtin__
23 __builtin__.__import__ = _real__import__
24 _real__import__ = None
25
26_progress = 0
27
Just van Rossumdc3c6172001-06-19 21:37:33 +000028_about_width = 440
29_about_height = 340
30
Just van Rossum40f9b7b1999-01-30 22:39:17 +000031def importing(module):
32 global _progress
33 Qd.SetPort(splash)
34 fontID = Fm.GetFNum("Python-Sans")
35 if not fontID:
Jack Jansen5a6fdcd2001-08-25 12:15:04 +000036 from Carbon.Fonts import geneva
Just van Rossum40f9b7b1999-01-30 22:39:17 +000037 fontID = geneva
38 Qd.TextFont(fontID)
39 Qd.TextSize(9)
Just van Rossumdc3c6172001-06-19 21:37:33 +000040 labelrect = (35, _about_height - 35, _about_width - 35, _about_height - 19)
41 framerect = (35, _about_height - 19, _about_width - 35, _about_height - 11)
42 l, t, r, b = progrect = Qd.InsetRect(framerect, 1, 1)
Just van Rossum40f9b7b1999-01-30 22:39:17 +000043 if module:
Just van Rossumdc3c6172001-06-19 21:37:33 +000044 TE.TETextBox('Importing: ' + module, labelrect, 0)
Just van Rossum40f9b7b1999-01-30 22:39:17 +000045 if not _progress:
Just van Rossumdc3c6172001-06-19 21:37:33 +000046 Qd.FrameRect(framerect)
47 pos = min(r, l + ((r - l) * _progress) / 44)
48 Qd.PaintRect((l, t, pos, b))
Just van Rossum40f9b7b1999-01-30 22:39:17 +000049 _progress = _progress + 1
50 else:
Just van Rossumdc3c6172001-06-19 21:37:33 +000051 Qd.EraseRect(labelrect)
52 Qd.PaintRect((l, t, pos, b))
Jack Jansen06646a12001-03-15 14:35:33 +000053 Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None)
Just van Rossum40f9b7b1999-01-30 22:39:17 +000054
55def my__import__(name, globals=None, locals=None, fromlist=None):
56 try:
57 return sys.modules[name]
58 except KeyError:
59 try:
60 importing(name)
61 except:
62 try:
63 rv = _real__import__(name)
64 finally:
65 uninstall_importhook()
66 return rv
67 return _real__import__(name)
68
Jack Jansen106fcea2001-08-19 22:00:20 +000069#install_importhook()
Just van Rossum40f9b7b1999-01-30 22:39:17 +000070
71kHighLevelEvent = 23
Jack Jansen5a6fdcd2001-08-25 12:15:04 +000072from Carbon import Win
73from Carbon.Fonts import *
74from Carbon.QuickDraw import *
75from Carbon.TextEdit import *
Just van Rossum40f9b7b1999-01-30 22:39:17 +000076import string
77import sys
78
79_keepsplashscreenopen = 0
80
Just van Rossumdc3c6172001-06-19 21:37:33 +000081abouttext1 = """The Python Integrated Development Environment for the Macintosh\xaa
Just van Rossum40f9b7b1999-01-30 22:39:17 +000082Version: %s
Just van Rossumdc3c6172001-06-19 21:37:33 +000083Copyright 1997-2001 Just van Rossum, Letterror. <just@letterror.com>
Just van Rossum40f9b7b1999-01-30 22:39:17 +000084Python %s
85%s
Just van Rossum40f9b7b1999-01-30 22:39:17 +000086See: <http://www.python.org/> for information and documentation."""
87
Just van Rossumdc3c6172001-06-19 21:37:33 +000088flauwekul = [ "Goodday, Bruce.",
89 "What's new?",
90 "Nudge, nudge, say no more!",
91 "No, no sir, it's not dead. It's resting.",
92 "Albatros!",
93 "It's . . .",
94 "Is your name not Bruce, then?",
Just van Rossum40f9b7b1999-01-30 22:39:17 +000095 """But Mr F.G. Superman has a secret identity . . .
96when trouble strikes at any time . . .
97at any place . . . he is ready to become . . .
98Bicycle Repair Man!"""
99 ]
100
Just van Rossumc9246612000-10-20 07:35:33 +0000101def skipdoublereturns(text):
102 return string.replace(text, '\n\n', '\n')
103
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000104def nl2return(text):
Just van Rossumc9246612000-10-20 07:35:33 +0000105 return string.replace(text, '\n', '\r')
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000106
107def UpdateSplash(drawdialog = 0, what = 0):
108 if drawdialog:
109 splash.DrawDialog()
110 drawtext(what)
Jack Jansen73023402001-01-23 14:58:20 +0000111 splash.GetDialogWindow().ValidWindowRect(splash.GetDialogPort().portRect)
Jack Jansen06646a12001-03-15 14:35:33 +0000112 Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000113
114def drawtext(what = 0):
115 Qd.SetPort(splash)
116 fontID = Fm.GetFNum("Python-Sans")
117 if not fontID:
118 fontID = geneva
119 Qd.TextFont(fontID)
120 Qd.TextSize(9)
Just van Rossumdc3c6172001-06-19 21:37:33 +0000121 rect = (10, 115, _about_width - 10, _about_height - 30)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000122 if not what:
123 import __main__
Just van Rossumc9246612000-10-20 07:35:33 +0000124 abouttxt = nl2return(abouttext1 % (
125 __main__.__version__, sys.version, skipdoublereturns(sys.copyright)))
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000126 else:
127 import random
128 abouttxt = nl2return(random.choice(flauwekul))
129 TE.TETextBox(abouttxt, rect, teJustCenter)
130
131UpdateSplash(1)
132
133def wait():
Jack Jansen5a6fdcd2001-08-25 12:15:04 +0000134 from Carbon import Evt
135 from Carbon import Events
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000136 global splash
137 try:
138 splash
139 except NameError:
140 return
141 Qd.InitCursor()
142 time = Evt.TickCount()
143 whattext = 0
Just van Rossumdc3c6172001-06-19 21:37:33 +0000144 drawtext(whattext)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000145 while _keepsplashscreenopen:
Jack Jansendef0d8d2001-02-09 15:56:19 +0000146 ok, event = Evt.EventAvail(Events.highLevelEventMask)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000147 if ok:
148 # got apple event, back to mainloop
149 break
Jack Jansendef0d8d2001-02-09 15:56:19 +0000150 ok, event = Evt.EventAvail(Events.mDownMask | Events.keyDownMask | Events.updateMask)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000151 if ok:
Jack Jansendef0d8d2001-02-09 15:56:19 +0000152 ok, event = Evt.WaitNextEvent(Events.mDownMask | Events.keyDownMask | Events.updateMask, 30)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000153 if ok:
154 (what, message, when, where, modifiers) = event
Jack Jansendef0d8d2001-02-09 15:56:19 +0000155 if what == Events.updateEvt:
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000156 if Win.WhichWindow(message) == splash:
157 UpdateSplash(1, whattext)
158 else:
159 break
160 if Evt.TickCount() - time > 360:
161 whattext = not whattext
162 drawtext(whattext)
163 time = Evt.TickCount()
164 del splash
Just van Rossumdc3c6172001-06-19 21:37:33 +0000165
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000166
167def about():
168 global splash, splashresfile, _keepsplashscreenopen
169 _keepsplashscreenopen = 1
170 splash = Dlg.GetNewDialog(468, -1)
171 splash.DrawDialog()
172 wait()