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 | |
| 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) |
Just van Rossum | ff88e46 | 2000-10-20 07:49:00 +0000 | [diff] [blame] | 35 | rect = (35, 265, 365, 281) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 36 | if module: |
| 37 | TE.TETextBox('Importing: ' + module, rect, 0) |
| 38 | if not _progress: |
Just van Rossum | ff88e46 | 2000-10-20 07:49:00 +0000 | [diff] [blame] | 39 | Qd.FrameRect((35, 281, 365, 289)) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 40 | pos = min(36 + 330 * _progress / 44, 364) |
Just van Rossum | ff88e46 | 2000-10-20 07:49:00 +0000 | [diff] [blame] | 41 | Qd.PaintRect((36, 282, pos, 288)) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 42 | _progress = _progress + 1 |
| 43 | else: |
| 44 | Qd.EraseRect(rect) |
Just van Rossum | ff88e46 | 2000-10-20 07:49:00 +0000 | [diff] [blame] | 45 | Qd.PaintRect((36, 282, pos, 288)) |
Jack Jansen | 06646a1 | 2001-03-15 14:35:33 +0000 | [diff] [blame^] | 46 | Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 47 | |
| 48 | def my__import__(name, globals=None, locals=None, fromlist=None): |
| 49 | try: |
| 50 | return sys.modules[name] |
| 51 | except KeyError: |
| 52 | try: |
| 53 | importing(name) |
| 54 | except: |
| 55 | try: |
| 56 | rv = _real__import__(name) |
| 57 | finally: |
| 58 | uninstall_importhook() |
| 59 | return rv |
| 60 | return _real__import__(name) |
| 61 | |
| 62 | install_importhook() |
| 63 | |
| 64 | kHighLevelEvent = 23 |
| 65 | import Win |
| 66 | from Fonts import * |
| 67 | from QuickDraw import * |
| 68 | from TextEdit import * |
| 69 | import string |
| 70 | import sys |
| 71 | |
| 72 | _keepsplashscreenopen = 0 |
| 73 | |
Just van Rossum | c924661 | 2000-10-20 07:35:33 +0000 | [diff] [blame] | 74 | abouttext1 = """The Python Integrated Development Environment for the Macintosh |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 75 | Version: %s |
Just van Rossum | 71017e5 | 1999-12-23 21:49:44 +0000 | [diff] [blame] | 76 | Copyright 1997-2000 Just van Rossum, Letterror. <just@letterror.com> |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 77 | Python %s |
| 78 | %s |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 79 | See: <http://www.python.org/> for information and documentation.""" |
| 80 | |
| 81 | flauwekul = [ 'Goodday, Bruce.', |
Just van Rossum | edab939 | 1999-02-02 22:31:05 +0000 | [diff] [blame] | 82 | 'What¹s new?', |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 83 | 'Nudge, nudge, say no more!', |
Just van Rossum | edab939 | 1999-02-02 22:31:05 +0000 | [diff] [blame] | 84 | 'No, no sir, it¹s not dead. It¹s resting.', |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 85 | 'Albatros!', |
Just van Rossum | edab939 | 1999-02-02 22:31:05 +0000 | [diff] [blame] | 86 | 'It¹s . . .', |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 87 | 'Is your name not Bruce, then?', |
| 88 | """But Mr F.G. Superman has a secret identity . . . |
| 89 | when trouble strikes at any time . . . |
| 90 | at any place . . . he is ready to become . . . |
| 91 | Bicycle Repair Man!""" |
| 92 | ] |
| 93 | |
Just van Rossum | c924661 | 2000-10-20 07:35:33 +0000 | [diff] [blame] | 94 | def skipdoublereturns(text): |
| 95 | return string.replace(text, '\n\n', '\n') |
| 96 | |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 97 | def nl2return(text): |
Just van Rossum | c924661 | 2000-10-20 07:35:33 +0000 | [diff] [blame] | 98 | return string.replace(text, '\n', '\r') |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 99 | |
| 100 | def UpdateSplash(drawdialog = 0, what = 0): |
| 101 | if drawdialog: |
| 102 | splash.DrawDialog() |
| 103 | drawtext(what) |
Jack Jansen | 7302340 | 2001-01-23 14:58:20 +0000 | [diff] [blame] | 104 | splash.GetDialogWindow().ValidWindowRect(splash.GetDialogPort().portRect) |
Jack Jansen | 06646a1 | 2001-03-15 14:35:33 +0000 | [diff] [blame^] | 105 | Qd.QDFlushPortBuffer(splash.GetDialogWindow().GetWindowPort(), None) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 106 | |
| 107 | def drawtext(what = 0): |
| 108 | Qd.SetPort(splash) |
| 109 | fontID = Fm.GetFNum("Python-Sans") |
| 110 | if not fontID: |
| 111 | fontID = geneva |
| 112 | Qd.TextFont(fontID) |
| 113 | Qd.TextSize(9) |
Just van Rossum | c924661 | 2000-10-20 07:35:33 +0000 | [diff] [blame] | 114 | rect = (10, 115, 390, 290) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 115 | if not what: |
| 116 | import __main__ |
Just van Rossum | c924661 | 2000-10-20 07:35:33 +0000 | [diff] [blame] | 117 | abouttxt = nl2return(abouttext1 % ( |
| 118 | __main__.__version__, sys.version, skipdoublereturns(sys.copyright))) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 119 | else: |
| 120 | import random |
| 121 | abouttxt = nl2return(random.choice(flauwekul)) |
| 122 | TE.TETextBox(abouttxt, rect, teJustCenter) |
| 123 | |
| 124 | UpdateSplash(1) |
| 125 | |
| 126 | def wait(): |
| 127 | import Evt |
Jack Jansen | def0d8d | 2001-02-09 15:56:19 +0000 | [diff] [blame] | 128 | import Events |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 129 | global splash |
| 130 | try: |
| 131 | splash |
| 132 | except NameError: |
| 133 | return |
| 134 | Qd.InitCursor() |
| 135 | time = Evt.TickCount() |
| 136 | whattext = 0 |
| 137 | while _keepsplashscreenopen: |
Jack Jansen | def0d8d | 2001-02-09 15:56:19 +0000 | [diff] [blame] | 138 | ok, event = Evt.EventAvail(Events.highLevelEventMask) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 139 | if ok: |
| 140 | # got apple event, back to mainloop |
| 141 | break |
Jack Jansen | def0d8d | 2001-02-09 15:56:19 +0000 | [diff] [blame] | 142 | ok, event = Evt.EventAvail(Events.mDownMask | Events.keyDownMask | Events.updateMask) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 143 | if ok: |
Jack Jansen | def0d8d | 2001-02-09 15:56:19 +0000 | [diff] [blame] | 144 | ok, event = Evt.WaitNextEvent(Events.mDownMask | Events.keyDownMask | Events.updateMask, 30) |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 145 | if ok: |
| 146 | (what, message, when, where, modifiers) = event |
Jack Jansen | def0d8d | 2001-02-09 15:56:19 +0000 | [diff] [blame] | 147 | if what == Events.updateEvt: |
Just van Rossum | 40f9b7b | 1999-01-30 22:39:17 +0000 | [diff] [blame] | 148 | if Win.WhichWindow(message) == splash: |
| 149 | UpdateSplash(1, whattext) |
| 150 | else: |
| 151 | break |
| 152 | if Evt.TickCount() - time > 360: |
| 153 | whattext = not whattext |
| 154 | drawtext(whattext) |
| 155 | time = Evt.TickCount() |
| 156 | del splash |
| 157 | #Res.CloseResFile(splashresfile) |
| 158 | |
| 159 | def about(): |
| 160 | global splash, splashresfile, _keepsplashscreenopen |
| 161 | _keepsplashscreenopen = 1 |
| 162 | splash = Dlg.GetNewDialog(468, -1) |
| 163 | splash.DrawDialog() |
| 164 | wait() |