Mercurial > cpython-lru_cache-weakref
annotate Mac/scripts/BuildApplet.py @ 4311:c97ffd2ebd53 legacy-trunk
Added macostools.touch() calls to inform the finder of our changes.
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Sun, 15 Sep 1996 22:13:59 +0000 |
| parents | 21e5b94b99b8 |
| children | 2d133280129f |
| rev | line source |
|---|---|
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
1 """Create an applet from a Python script. |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
2 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
3 This puts up a dialog asking for a Python source file ('TEXT'). |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
4 The output is a file with the same name but its ".py" suffix dropped. |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
5 It is created by copying an applet template and then adding a 'PYC ' |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
6 resource named __main__ containing the compiled, marshalled script. |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
7 """ |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
8 |
|
3062
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
9 DEBUG=0 |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
10 |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
11 import sys |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
12 sys.stdout = sys.stderr |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
13 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
14 import string |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
15 import os |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
16 import marshal |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
17 import imp |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
18 import macfs |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
19 import MACFS |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
20 import MacOS |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
21 from Res import * |
|
4311
c97ffd2ebd53
Added macostools.touch() calls to inform the finder of our changes.
Jack Jansen <jack.jansen@cwi.nl>
parents:
4240
diff
changeset
|
22 import macostools |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
23 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
24 # .pyc file (and 'PYC ' resource magic number) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
25 MAGIC = imp.get_magic() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
26 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
27 # Template file (searched on sys.path) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
28 TEMPLATE = "PythonApplet" |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
29 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
30 # Specification of our resource |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
31 RESTYPE = 'PYC ' |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
32 RESNAME = '__main__' |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
33 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
34 # A resource with this name sets the "owner" (creator) of the destination |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
35 # XXXX Should look for id=0 |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
36 OWNERNAME = "owner resource" |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
37 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
38 # OpenResFile mode parameters |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
39 READ = 1 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
40 WRITE = 2 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
41 |
|
3062
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
42 def findtemplate(): |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
43 """Locate the applet template along sys.path""" |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
44 for p in sys.path: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
45 template = os.path.join(p, TEMPLATE) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
46 try: |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
47 template, d1, d2 = macfs.ResolveAliasFile(template) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
48 break |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
49 except (macfs.error, ValueError): |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
50 continue |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
51 else: |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
52 die("Template %s not found on sys.path" % `TEMPLATE`) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
53 return |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
54 template = template.as_pathname() |
|
3062
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
55 return template |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
56 |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
57 def main(): |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
58 |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
59 # Find the template |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
60 # (there's no point in proceeding if we can't find it) |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
61 |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
62 template = findtemplate() |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
63 if DEBUG: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
64 print 'Using template', template |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
65 |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
66 # Ask for source text if not specified in sys.argv[1:] |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
67 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
68 if not sys.argv[1:]: |
|
2979
7eea9b426802
Added prompts to various file-select dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents:
2873
diff
changeset
|
69 srcfss, ok = macfs.PromptGetFile('Select Python source file:', 'TEXT') |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
70 if not ok: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
71 return |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
72 filename = srcfss.as_pathname() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
73 tp, tf = os.path.split(filename) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
74 if tf[-3:] == '.py': |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
75 tf = tf[:-3] |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
76 else: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
77 tf = tf + '.applet' |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
78 dstfss, ok = macfs.StandardPutFile('Save application as:', tf) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
79 if not ok: return |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
80 process(template, filename, dstfss.as_pathname()) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
81 else: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
82 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
83 # Loop over all files to be processed |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
84 for filename in sys.argv[1:]: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
85 process(template, filename, '') |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
86 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
87 def process(template, filename, output): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
88 |
|
3062
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
89 if DEBUG: |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
90 print "Processing", `filename`, "..." |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
91 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
92 # Read the source and compile it |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
93 # (there's no point overwriting the destination if it has a syntax error) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
94 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
95 fp = open(filename) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
96 text = fp.read() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
97 fp.close() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
98 try: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
99 code = compile(text, filename, "exec") |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
100 except (SyntaxError, EOFError): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
101 die("Syntax error in script %s" % `filename`) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
102 return |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
103 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
104 # Set the destination file name |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
105 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
106 if string.lower(filename[-3:]) == ".py": |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
107 destname = filename[:-3] |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
108 rsrcname = destname + '.rsrc' |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
109 else: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
110 destname = filename + ".applet" |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
111 rsrcname = filename + '.rsrc' |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
112 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
113 if output: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
114 destname = output |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
115 |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
116 # Try removing the output file |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
117 try: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
118 os.unlink(output) |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
119 except os.error: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
120 pass |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
121 |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
122 |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
123 # Create FSSpecs for the various files |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
124 |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
125 template_fss = macfs.FSSpec(template) |
|
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
126 template_fss, d1, d2 = macfs.ResolveAliasFile(template_fss) |
|
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
127 dest_fss = macfs.FSSpec(destname) |
|
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
128 |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
129 # Copy data (not resources, yet) from the template |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
130 |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
131 tmpl = open(template, "rb") |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
132 dest = open(destname, "wb") |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
133 data = tmpl.read() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
134 if data: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
135 dest.write(data) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
136 dest.close() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
137 tmpl.close() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
138 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
139 # Open the output resource fork |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
140 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
141 try: |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
142 output = FSpOpenResFile(dest_fss, WRITE) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
143 except MacOS.Error: |
|
3062
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
144 if DEBUG: |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
145 print "Creating resource fork..." |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
146 CreateResFile(destname) |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
147 output = FSpOpenResFile(dest_fss, WRITE) |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
148 |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
149 # Copy the resources from the target specific resource template, if any |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
150 typesfound, ownertype = [], None |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
151 try: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
152 input = FSpOpenResFile(rsrcname, READ) |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
153 except (MacOS.Error, ValueError): |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
154 pass |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
155 else: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
156 typesfound, ownertype = copyres(input, output, [], 0) |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
157 CloseResFile(input) |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
158 |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
159 # Check which resource-types we should not copy from the template |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
160 skiptypes = [] |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
161 if 'SIZE' in typesfound: skiptypes.append('SIZE') |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
162 if 'BNDL' in typesfound: skiptypes = skiptypes + ['BNDL', 'FREF', 'icl4', |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
163 'icl8', 'ics4', 'ics8', 'ICN#', 'ics#'] |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
164 skipowner = (ownertype <> None) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
165 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
166 # Copy the resources from the template |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
167 |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
168 input = FSpOpenResFile(template_fss, READ) |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
169 dummy, tmplowner = copyres(input, output, skiptypes, skipowner) |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
170 if ownertype == None: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
171 ownertype = tmplowner |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
172 CloseResFile(input) |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
173 if ownertype == None: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
174 die("No owner resource found in either resource file or template") |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
175 |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
176 # Now set the creator, type and bundle bit of the destination |
|
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
177 dest_finfo = dest_fss.GetFInfo() |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
178 dest_finfo.Creator = ownertype |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
179 dest_finfo.Type = 'APPL' |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
180 dest_finfo.Flags = dest_finfo.Flags | MACFS.kHasBundle |
|
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
181 dest_finfo.Flags = dest_finfo.Flags & ~MACFS.kHasBeenInited |
|
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
182 dest_fss.SetFInfo(dest_finfo) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
183 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
184 # Make sure we're manipulating the output resource file now |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
185 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
186 UseResFile(output) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
187 |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
188 # Delete any existing 'PYC ' resource named __main__ |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
189 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
190 try: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
191 res = Get1NamedResource(RESTYPE, RESNAME) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
192 res.RemoveResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
193 except Error: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
194 pass |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
195 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
196 # Create the raw data for the resource from the code object |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
197 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
198 data = marshal.dumps(code) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
199 del code |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
200 data = (MAGIC + '\0\0\0\0') + data |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
201 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
202 # Create the resource and write it |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
203 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
204 id = 0 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
205 while id < 128: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
206 id = Unique1ID(RESTYPE) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
207 res = Resource(data) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
208 res.AddResource(RESTYPE, id, RESNAME) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
209 res.WriteResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
210 res.ReleaseResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
211 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
212 # Close the output file |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
213 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
214 CloseResFile(output) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
215 |
|
4311
c97ffd2ebd53
Added macostools.touch() calls to inform the finder of our changes.
Jack Jansen <jack.jansen@cwi.nl>
parents:
4240
diff
changeset
|
216 macostools.touched(dest_fss) |
| 4166 | 217 if DEBUG: |
| 218 print "Applet created:", destname | |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
219 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
220 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
221 # Copy resources between two resource file descriptors. |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
222 # skip a resource named '__main__' or (if skipowner is set) 'Owner resource'. |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
223 # Also skip resources with a type listed in skiptypes. |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
224 # |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
225 def copyres(input, output, skiptypes, skipowner): |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
226 ctor = None |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
227 alltypes = [] |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
228 UseResFile(input) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
229 ntypes = Count1Types() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
230 for itype in range(1, 1+ntypes): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
231 type = Get1IndType(itype) |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
232 if type in skiptypes: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
233 continue |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
234 alltypes.append(type) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
235 nresources = Count1Resources(type) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
236 for ires in range(1, 1+nresources): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
237 res = Get1IndResource(type, ires) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
238 id, type, name = res.GetResInfo() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
239 lcname = string.lower(name) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
240 if (type, lcname) == (RESTYPE, RESNAME): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
241 continue # Don't copy __main__ from template |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
242 # XXXX should look for id=0 |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
243 if lcname == OWNERNAME: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
244 if skipowner: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
245 continue # Skip this one |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
246 else: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
247 ctor = type |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
248 size = res.size |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
249 attrs = res.GetResAttrs() |
|
3062
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
250 if DEBUG: |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
251 print id, type, name, size, hex(attrs) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
252 res.LoadResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
253 res.DetachResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
254 UseResFile(output) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
255 try: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
256 res2 = Get1Resource(type, id) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
257 except MacOS.Error: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
258 res2 = None |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
259 if res2: |
|
3062
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
260 if DEBUG: |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
261 print "Overwriting..." |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
262 res2.RemoveResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
263 res.AddResource(type, id, name) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
264 res.WriteResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
265 attrs = attrs | res.GetResAttrs() |
|
3062
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
266 if DEBUG: |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
267 print "New attrs =", hex(attrs) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
268 res.SetResAttrs(attrs) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
269 UseResFile(input) |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
270 return alltypes, ctor |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
271 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
272 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
273 # Show a message and exit |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
274 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
275 def die(str): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
276 message(str) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
277 sys.exit(1) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
278 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
279 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
280 # Show a message |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
281 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
282 def message(str, id = 256): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
283 from Dlg import * |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
284 d = GetNewDialog(id, -1) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
285 if not d: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
286 print "Error:", `str` |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
287 print "DLOG id =", id, "not found." |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
288 return |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
289 tp, h, rect = d.GetDialogItem(2) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
290 SetDialogItemText(h, str) |
|
3345
1709d5fed528
Set default item for dialog
Jack Jansen <jack.jansen@cwi.nl>
parents:
3121
diff
changeset
|
291 d.SetDialogDefaultItem(1) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
292 while 1: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
293 n = ModalDialog(None) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
294 if n == 1: break |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
295 del d |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
296 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
297 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
298 if __name__ == '__main__': |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
299 main() |
