Mercurial > cpython-lru_cache-weakref
annotate Mac/scripts/BuildApplet.py @ 3720:b341def4eef8 legacy-trunk
Ignore latex intermediate products.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 26 Jun 1996 19:30:01 +0000 |
| parents | 1709d5fed528 |
| children | a71a43d247b0 |
| 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 * |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
22 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
23 # .pyc file (and 'PYC ' resource magic number) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
24 MAGIC = imp.get_magic() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
25 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
26 # Template file (searched on sys.path) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
27 TEMPLATE = "PythonApplet" |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
28 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
29 # Specification of our resource |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
30 RESTYPE = 'PYC ' |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
31 RESNAME = '__main__' |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
32 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
33 # 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
|
34 # XXXX Should look for id=0 |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
35 OWNERNAME = "owner resource" |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
36 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
37 # OpenResFile mode parameters |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
38 READ = 1 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
39 WRITE = 2 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
40 |
|
3062
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
41 def findtemplate(): |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
42 """Locate the applet template along sys.path""" |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
43 for p in sys.path: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
44 template = os.path.join(p, TEMPLATE) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
45 try: |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
46 template, d1, d2 = macfs.ResolveAliasFile(template) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
47 break |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
48 except (macfs.error, ValueError): |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
49 continue |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
50 else: |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
51 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
|
52 return |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
53 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
|
54 return template |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
55 |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
56 def main(): |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
57 global DEBUG |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
58 DEBUG=1 |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
59 |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
60 # Find the template |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
61 # (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
|
62 |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
63 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
|
64 if DEBUG: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
65 print 'Using template', template |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
66 |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
67 # 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
|
68 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
69 if not sys.argv[1:]: |
|
2979
7eea9b426802
Added prompts to various file-select dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents:
2873
diff
changeset
|
70 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
|
71 if not ok: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
72 return |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
73 filename = srcfss.as_pathname() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
74 tp, tf = os.path.split(filename) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
75 if tf[-3:] == '.py': |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
76 tf = tf[:-3] |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
77 else: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
78 tf = tf + '.applet' |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
79 dstfss, ok = macfs.StandardPutFile('Save application as:', tf) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
80 if not ok: return |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
81 process(template, filename, dstfss.as_pathname()) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
82 else: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
83 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
84 # Loop over all files to be processed |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
85 for filename in sys.argv[1:]: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
86 process(template, filename, '') |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
87 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
88 def process(template, filename, output): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
89 |
|
3062
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
90 if DEBUG: |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
91 print "Processing", `filename`, "..." |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
92 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
93 # Read the source and compile it |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
94 # (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
|
95 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
96 fp = open(filename) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
97 text = fp.read() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
98 fp.close() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
99 try: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
100 code = compile(text, filename, "exec") |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
101 except (SyntaxError, EOFError): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
102 die("Syntax error in script %s" % `filename`) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
103 return |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
104 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
105 # Set the destination file name |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
106 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
107 if string.lower(filename[-3:]) == ".py": |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
108 destname = filename[:-3] |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
109 rsrcname = destname + '.rsrc' |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
110 else: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
111 destname = filename + ".applet" |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
112 rsrcname = filename + '.rsrc' |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
113 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
114 if output: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
115 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
|
116 |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
117 # 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
|
118 try: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
119 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
|
120 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
|
121 pass |
|
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 |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
124 # 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
|
125 |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
126 template_fss = macfs.FSSpec(template) |
|
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
127 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
|
128 dest_fss = macfs.FSSpec(destname) |
|
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
129 |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
130 # 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
|
131 |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
132 tmpl = open(template, "rb") |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
133 dest = open(destname, "wb") |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
134 data = tmpl.read() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
135 if data: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
136 dest.write(data) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
137 dest.close() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
138 tmpl.close() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
139 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
140 # Open the output resource fork |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
141 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
142 try: |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
143 output = FSpOpenResFile(dest_fss, WRITE) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
144 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
|
145 if DEBUG: |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
146 print "Creating resource fork..." |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
147 CreateResFile(destname) |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
148 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
|
149 |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
150 # 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
|
151 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
|
152 try: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
153 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
|
154 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
|
155 pass |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
156 else: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
157 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
|
158 CloseResFile(input) |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
159 |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
160 # 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
|
161 skiptypes = [] |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
162 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
|
163 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
|
164 '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
|
165 skipowner = (ownertype <> None) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
166 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
167 # Copy the resources from the template |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
168 |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 ownertype = tmplowner |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
173 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
|
174 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
|
175 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
|
176 |
|
3045
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
177 # 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
|
178 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
|
179 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
|
180 dest_finfo.Type = 'APPL' |
|
3045
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.kHasBundle |
|
bda54ea23a80
- Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents:
2979
diff
changeset
|
182 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
|
183 dest_fss.SetFInfo(dest_finfo) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
184 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
185 # 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
|
186 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
187 UseResFile(output) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
188 |
|
3121
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
189 # Delete any existing 'PYC ' resource named __main__ |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
190 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
191 try: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
192 res = Get1NamedResource(RESTYPE, RESNAME) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
193 res.RemoveResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
194 except Error: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
195 pass |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
196 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
197 # 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
|
198 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
199 data = marshal.dumps(code) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
200 del code |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
201 data = (MAGIC + '\0\0\0\0') + data |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
202 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
203 # Create the resource and write it |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
204 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
205 id = 0 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
206 while id < 128: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
207 id = Unique1ID(RESTYPE) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
208 res = Resource(data) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
209 res.AddResource(RESTYPE, id, RESNAME) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
210 res.WriteResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
211 res.ReleaseResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
212 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
213 # Close the output file |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
214 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
215 CloseResFile(output) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
216 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
217 # Give positive feedback |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
218 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
219 message("Applet %s created." % `destname`) |
|
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 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
222 # 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
|
223 # 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
|
224 # 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
|
225 # |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
226 def copyres(input, output, skiptypes, skipowner): |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
227 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
|
228 alltypes = [] |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
229 UseResFile(input) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
230 ntypes = Count1Types() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
231 for itype in range(1, 1+ntypes): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
232 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
|
233 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
|
234 continue |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
235 alltypes.append(type) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
236 nresources = Count1Resources(type) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
237 for ires in range(1, 1+nresources): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
238 res = Get1IndResource(type, ires) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
239 id, type, name = res.GetResInfo() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
240 lcname = string.lower(name) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
241 if (type, lcname) == (RESTYPE, RESNAME): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
242 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
|
243 # 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
|
244 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
|
245 if skipowner: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
246 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
|
247 else: |
|
c10f55b46a11
Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents:
3062
diff
changeset
|
248 ctor = type |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
249 size = res.size |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
250 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
|
251 if DEBUG: |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
252 print id, type, name, size, hex(attrs) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
253 res.LoadResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
254 res.DetachResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
255 UseResFile(output) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
256 try: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
257 res2 = Get1Resource(type, id) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
258 except MacOS.Error: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
259 res2 = None |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
260 if res2: |
|
3062
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
261 if DEBUG: |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
262 print "Overwriting..." |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
263 res2.RemoveResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
264 res.AddResource(type, id, name) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
265 res.WriteResource() |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
266 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
|
267 if DEBUG: |
|
8d5179277858
Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents:
3045
diff
changeset
|
268 print "New attrs =", hex(attrs) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
269 res.SetResAttrs(attrs) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
270 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
|
271 return alltypes, ctor |
|
2873
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 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
274 # Show a message and exit |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
275 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
276 def die(str): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
277 message(str) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
278 sys.exit(1) |
|
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 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
281 # Show a message |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
282 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
283 def message(str, id = 256): |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
284 from Dlg import * |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
285 d = GetNewDialog(id, -1) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
286 if not d: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
287 print "Error:", `str` |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
288 print "DLOG id =", id, "not found." |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
289 return |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
290 tp, h, rect = d.GetDialogItem(2) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
291 SetDialogItemText(h, str) |
|
3345
1709d5fed528
Set default item for dialog
Jack Jansen <jack.jansen@cwi.nl>
parents:
3121
diff
changeset
|
292 d.SetDialogDefaultItem(1) |
|
2873
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
293 while 1: |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
294 n = ModalDialog(None) |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
295 if n == 1: break |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
296 del d |
|
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 |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
299 if __name__ == '__main__': |
|
315760ba0041
A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
300 main() |
