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