blob: 4fb040dce2c0ac545032fe09fd768379f88a67a7 [file] [log] [blame]
Guido van Rossum4cbb0e31995-02-20 23:42:50 +00001# Script (applet) to run any Python command
2
3def main():
4 import sys
Guido van Rossum8656ad51995-02-21 21:00:32 +00005 sys.stdout = sys.stderr
Guido van Rossum4cbb0e31995-02-20 23:42:50 +00006 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 Rossum8656ad51995-02-21 21:00:32 +000020 print "exit", `msg`
21 #sys.exit(msg)
Guido van Rossum4cbb0e31995-02-20 23:42:50 +000022 except:
23 etype = sys.exc_type
24 if hasattr(etype, "__name__"): etype = etype.__name__
25 message("%s: %s" % (etype, sys.exc_value))
Guido van Rossum8656ad51995-02-21 21:00:32 +000026 print "exit 1"
27 #sys.exit(1)
Guido van Rossum4cbb0e31995-02-20 23:42:50 +000028
Guido van Rossum8656ad51995-02-21 21:00:32 +000029def message(str = "Hello, world!", id = 256):
Guido van Rossum4cbb0e31995-02-20 23:42:50 +000030 import Dlg
31 d = Dlg.GetNewDialog(id, -1)
Guido van Rossum8656ad51995-02-21 21:00:32 +000032 if not d:
33 print str
34 return
Guido van Rossum4cbb0e31995-02-20 23:42:50 +000035 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
41main()