Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 1 | import Dlg |
| 2 | import Res |
| 3 | |
| 4 | splash = Dlg.GetNewDialog(468, -1) |
| 5 | splash.DrawDialog() |
| 6 | |
| 7 | import Qd, TE, Fm, sys |
| 8 | |
| 9 | _real__import__ = None |
| 10 | |
| 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__ |
| 17 | |
| 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 |
| 24 | |
| 25 | _progress = 0 |
| 26 | |
Just van Rossum | dc3c617 | 2001-06-19 21:37:33 +0000 | [diff] [blame^] | 27 | _about_width = 440 |
| 28 | _about_height = 340 |
| 29 | |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 30 | def 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 Rossum | dc3c617 | 2001-06-19 21:37:33 +0000 | [diff] [blame^] | 38 | 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 Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 41 | if module: |
Just van Rossum | dc3c617 | 2001-06-19 21:37:33 +0000 | [diff] [blame^] | 42 | TE.TETextBox('Importing: ' + module, labelrect, 0) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 43 | if not _progress: |
Just van Rossum | dc3c617 | 2001-06-19 21:37:33 +0000 | [diff] [blame^] | 44 | Qd.FrameRect(framerect) |
| 45 | pos = min(r, l + ((r - l) * _progress) / 44) |
| 46 | Qd.PaintRect((l, t, pos, b)) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 47 | _progress = _progress + 1 |
| 48 | else: |
Just van Rossum | dc3c617 | 2001-06-19 21:37:33 +0000 | [diff] [blame^] | 49 | Qd.EraseRect(labelrect) |
| 50 | Qd.PaintRect((l, t, pos, b)) |
Jack Jansen | 06646a1 | 2001-03-15 14:35:33 +0000 | [diff] [blame] | 51 | Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 52 | |
| 53 | def 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 | |
| 67 | install_importhook() |
| 68 | |
| 69 | kHighLevelEvent = 23 |
| 70 | import Win |
| 71 | from Fonts import * |
| 72 | from QuickDraw import * |
| 73 | from TextEdit import * |
| 74 | import string |
| 75 | import sys |
| 76 | |
| 77 | _keepsplashscreenopen = 0 |
| 78 | |
Just van Rossum | dc3c617 | 2001-06-19 21:37:33 +0000 | [diff] [blame^] | 79 | abouttext1 = """The Python Integrated Development Environment for the Macintosh\xaa |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 80 | Version: %s |
Just van Rossum | dc3c617 | 2001-06-19 21:37:33 +0000 | [diff] [blame^] | 81 | Copyright 1997-2001 Just van Rossum, Letterror. <just@letterror.com> |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 82 | Python %s |
| 83 | %s |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 84 | See: <http://www.python.org/> for information and documentation.""" |
| 85 | |
Just van Rossum | dc3c617 | 2001-06-19 21:37:33 +0000 | [diff] [blame^] | 86 | flauwekul = [ "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 Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 93 | """But Mr F.G. Superman has a secret identity . . . |
| 94 | when trouble strikes at any time . . . |
| 95 | at any place . . . he is ready to become . . . |
| 96 | Bicycle Repair Man!""" |
| 97 | ] |
| 98 | |
Just van Rossum | c924661 | 2000-10-20 07:35:33 +0000 | [diff] [blame] | 99 | def skipdoublereturns(text): |
| 100 | return string.replace(text, '\n\n', '\n') |
| 101 | |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 102 | def nl2return(text): |
Just van Rossum | c924661 | 2000-10-20 07:35:33 +0000 | [diff] [blame] | 103 | return string.replace(text, '\n', '\r') |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 104 | |
| 105 | def UpdateSplash(drawdialog = 0, what = 0): |
| 106 | if drawdialog: |
| 107 | splash.DrawDialog() |
| 108 | drawtext(what) |
Jack Jansen | 7302340 | 2001-01-23 14:58:20 +0000 | [diff] [blame] | 109 | splash.GetDialogWindow().ValidWindowRect(splash.GetDialogPort().portRect) |
Jack Jansen | 06646a1 | 2001-03-15 14:35:33 +0000 | [diff] [blame] | 110 | Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 111 | |
| 112 | def 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 Rossum | dc3c617 | 2001-06-19 21:37:33 +0000 | [diff] [blame^] | 119 | rect = (10, 115, _about_width - 10, _about_height - 30) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 120 | if not what: |
| 121 | import __main__ |
Just van Rossum | c924661 | 2000-10-20 07:35:33 +0000 | [diff] [blame] | 122 | abouttxt = nl2return(abouttext1 % ( |
| 123 | __main__.__version__, sys.version, skipdoublereturns(sys.copyright))) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 124 | else: |
| 125 | import random |
| 126 | abouttxt = nl2return(random.choice(flauwekul)) |
| 127 | TE.TETextBox(abouttxt, rect, teJustCenter) |
| 128 | |
| 129 | UpdateSplash(1) |
| 130 | |
| 131 | def wait(): |
| 132 | import Evt |
Jack Jansen | def0d8d | 2001-02-09 15:56:19 +0000 | [diff] [blame] | 133 | import Events |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 134 | global splash |
| 135 | try: |
| 136 | splash |
| 137 | except NameError: |
| 138 | return |
| 139 | Qd.InitCursor() |
| 140 | time = Evt.TickCount() |
| 141 | whattext = 0 |
Just van Rossum | dc3c617 | 2001-06-19 21:37:33 +0000 | [diff] [blame^] | 142 | drawtext(whattext) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 143 | while _keepsplashscreenopen: |
Jack Jansen | def0d8d | 2001-02-09 15:56:19 +0000 | [diff] [blame] | 144 | ok, event = Evt.EventAvail(Events.highLevelEventMask) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 145 | if ok: |
| 146 | # got apple event, back to mainloop |
| 147 | break |
Jack Jansen | def0d8d | 2001-02-09 15:56:19 +0000 | [diff] [blame] | 148 | ok, event = Evt.EventAvail(Events.mDownMask | Events.keyDownMask | Events.updateMask) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 149 | if ok: |
Jack Jansen | def0d8d | 2001-02-09 15:56:19 +0000 | [diff] [blame] | 150 | ok, event = Evt.WaitNextEvent(Events.mDownMask | Events.keyDownMask | Events.updateMask, 30) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 151 | if ok: |
| 152 | (what, message, when, where, modifiers) = event |
Jack Jansen | def0d8d | 2001-02-09 15:56:19 +0000 | [diff] [blame] | 153 | if what == Events.updateEvt: |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 154 | 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 Rossum | dc3c617 | 2001-06-19 21:37:33 +0000 | [diff] [blame^] | 163 | |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 164 | |
| 165 | def about(): |
| 166 | global splash, splashresfile, _keepsplashscreenopen |
| 167 | _keepsplashscreenopen = 1 |
| 168 | splash = Dlg.GetNewDialog(468, -1) |
| 169 | splash.DrawDialog() |
| 170 | wait() |