Guido van Rossum | 4cbb0e3 | 1995-02-20 23:42:50 +0000 | [diff] [blame] | 1 | # Script (applet) to run any Python command |
| 2 | |
| 3 | def main(): |
| 4 | import sys |
Guido van Rossum | 8656ad5 | 1995-02-21 21:00:32 +0000 | [diff] [blame] | 5 | sys.stdout = sys.stderr |
Guido van Rossum | 4cbb0e3 | 1995-02-20 23:42:50 +0000 | [diff] [blame] | 6 | del sys.argv[:1] |
| 7 | if not sys.argv: |
| 8 | import macfs |
| 9 | srcfss, ok = macfs.StandardGetFile('TEXT') |
| 10 | if not ok: |
| 11 | return |
| 12 | filename = srcfss.as_pathname() |
| 13 | sys.argv.append(filename) |
| 14 | import __main__ |
| 15 | try: |
| 16 | execfile(sys.argv[0], __main__.__dict__) |
| 17 | except SystemExit, msg: |
| 18 | if msg: |
| 19 | message("Exit status: %s" % str(msg)) |
Guido van Rossum | 8656ad5 | 1995-02-21 21:00:32 +0000 | [diff] [blame] | 20 | print "exit", `msg` |
| 21 | #sys.exit(msg) |
Guido van Rossum | 4cbb0e3 | 1995-02-20 23:42:50 +0000 | [diff] [blame] | 22 | except: |
| 23 | etype = sys.exc_type |
| 24 | if hasattr(etype, "__name__"): etype = etype.__name__ |
| 25 | message("%s: %s" % (etype, sys.exc_value)) |
Guido van Rossum | 8656ad5 | 1995-02-21 21:00:32 +0000 | [diff] [blame] | 26 | print "exit 1" |
| 27 | #sys.exit(1) |
Guido van Rossum | 4cbb0e3 | 1995-02-20 23:42:50 +0000 | [diff] [blame] | 28 | |
Guido van Rossum | 8656ad5 | 1995-02-21 21:00:32 +0000 | [diff] [blame] | 29 | def message(str = "Hello, world!", id = 256): |
Guido van Rossum | 4cbb0e3 | 1995-02-20 23:42:50 +0000 | [diff] [blame] | 30 | import Dlg |
| 31 | d = Dlg.GetNewDialog(id, -1) |
Guido van Rossum | 8656ad5 | 1995-02-21 21:00:32 +0000 | [diff] [blame] | 32 | if not d: |
| 33 | print str |
| 34 | return |
Guido van Rossum | 4cbb0e3 | 1995-02-20 23:42:50 +0000 | [diff] [blame] | 35 | tp, h, rect = d.GetDItem(2) |
| 36 | Dlg.SetIText(h, str) |
| 37 | while 1: |
| 38 | n = Dlg.ModalDialog(None) |
| 39 | if n == 1: break |
| 40 | |
| 41 | main() |