annotate Mac/scripts/BuildApplet.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 2d133280129f
children a8059b96bc35
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
23 import EasyDialogs
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 # .pyc file (and 'PYC ' resource magic number)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 MAGIC = imp.get_magic()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 # Template file (searched on sys.path)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 TEMPLATE = "PythonApplet"
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 # Specification of our resource
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 RESTYPE = 'PYC '
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 RESNAME = '__main__'
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 # 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
36 # XXXX Should look for id=0
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37 OWNERNAME = "owner resource"
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 # OpenResFile mode parameters
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 READ = 1
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 WRITE = 2
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42
3062
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
43 def findtemplate():
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
44 """Locate the applet template along sys.path"""
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 for p in sys.path:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 template = os.path.join(p, TEMPLATE)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 try:
3045
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
48 template, d1, d2 = macfs.ResolveAliasFile(template)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 break
3045
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
50 except (macfs.error, ValueError):
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 continue
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52 else:
3045
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
53 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
54 return
3045
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
55 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
56 return template
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
57
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
58 def main():
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
59 global DEBUG
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
60 DEBUG=1
3062
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 # Find the template
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
63 # (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
64
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
65 template = findtemplate()
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:
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
91 progress = EasyDialogs.ProgressBar("Processing %s..."%os.path.split(filename)[1], 120)
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
92 progress.label("Compiling...")
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
93 else:
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
94 progress = None
2873
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 # Read the source and compile it
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 # (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
98
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 fp = open(filename)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100 text = fp.read()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 fp.close()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 try:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103 code = compile(text, filename, "exec")
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 except (SyntaxError, EOFError):
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 die("Syntax error in script %s" % `filename`)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 return
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108 # Set the destination file name
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
109
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 if string.lower(filename[-3:]) == ".py":
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111 destname = filename[:-3]
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112 rsrcname = destname + '.rsrc'
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
113 else:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 destname = filename + ".applet"
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 rsrcname = filename + '.rsrc'
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
116
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 if output:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
118 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
119
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
120 # 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
121 try:
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
122 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
123 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
124 pass
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
125
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
126
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
127 # 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
128
3045
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
129 template_fss = macfs.FSSpec(template)
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
130 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
131 dest_fss = macfs.FSSpec(destname)
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
132
3121
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
133 # Copy data (not resources, yet) from the template
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
134 if DEBUG:
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
135 progress.label("Copy data fork...")
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
136 progress.set(10)
3121
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
137
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138 tmpl = open(template, "rb")
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
139 dest = open(destname, "wb")
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
140 data = tmpl.read()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
141 if data:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142 dest.write(data)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143 dest.close()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
144 tmpl.close()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
145
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
146 # Open the output resource fork
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
147
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
148 if DEBUG:
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
149 progress.label("Copy resources...")
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
150 progress.set(20)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
151 try:
3045
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
152 output = FSpOpenResFile(dest_fss, WRITE)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
153 except MacOS.Error:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
154 CreateResFile(destname)
3045
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
155 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
156
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
157 # 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
158 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
159 try:
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
160 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
161 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
162 pass
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
163 if DEBUG:
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
164 progress.inc(50)
3121
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
165 else:
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
166 typesfound, ownertype = copyres(input, output, [], 0, progress)
3121
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
167 CloseResFile(input)
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
168
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
169 # 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
170 skiptypes = []
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
171 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
172 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
173 '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
174 skipowner = (ownertype <> None)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
175
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
176 # Copy the resources from the template
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
177
3045
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
178 input = FSpOpenResFile(template_fss, READ)
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
179 dummy, tmplowner = copyres(input, output, skiptypes, skipowner, progress)
3121
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
180 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
181 ownertype = tmplowner
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
182 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
183 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
184 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
185
3045
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
186 # 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
187 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
188 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
189 dest_finfo.Type = 'APPL'
3045
bda54ea23a80 - Allow PythonApplet to be an alias
Jack Jansen <jack.jansen@cwi.nl>
parents: 2979
diff changeset
190 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
191 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
192 dest_fss.SetFInfo(dest_finfo)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
193
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
194 # 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
195
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
196 UseResFile(output)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
197
3121
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
198 # Delete any existing 'PYC ' resource named __main__
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
199
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
200 try:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
201 res = Get1NamedResource(RESTYPE, RESNAME)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
202 res.RemoveResource()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
203 except Error:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
204 pass
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
205
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
206 # Create the raw data for the resource from the code object
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
207 if DEBUG:
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
208 progress.label("Write PYC resource...")
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
209 progress.set(120)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
210
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
211 data = marshal.dumps(code)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
212 del code
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
213 data = (MAGIC + '\0\0\0\0') + data
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 # Create the resource and write it
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 id = 0
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
218 while id < 128:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
219 id = Unique1ID(RESTYPE)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
220 res = Resource(data)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
221 res.AddResource(RESTYPE, id, RESNAME)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
222 res.WriteResource()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
223 res.ReleaseResource()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
224
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
225 # Close the output file
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
226
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
227 CloseResFile(output)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
228
4311
c97ffd2ebd53 Added macostools.touch() calls to inform the finder of our changes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4240
diff changeset
229 macostools.touched(dest_fss)
4166
a71a43d247b0 Removed silly dialog
Jack Jansen <jack.jansen@cwi.nl>
parents: 3345
diff changeset
230 if DEBUG:
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
231 progress.label("Done.")
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
232
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
233
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
234 # 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
235 # 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
236 # 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
237 #
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
238 def copyres(input, output, skiptypes, skipowner, progress=None):
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
239 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
240 alltypes = []
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
241 UseResFile(input)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
242 ntypes = Count1Types()
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
243 progress_type_inc = 50/ntypes
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
244 for itype in range(1, 1+ntypes):
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
245 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
246 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
247 continue
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
248 alltypes.append(type)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
249 nresources = Count1Resources(type)
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
250 progress_cur_inc = progress_type_inc/nresources
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
251 for ires in range(1, 1+nresources):
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
252 res = Get1IndResource(type, ires)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
253 id, type, name = res.GetResInfo()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
254 lcname = string.lower(name)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
255 if (type, lcname) == (RESTYPE, RESNAME):
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
256 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
257 # 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
258 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
259 if skipowner:
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
260 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
261 else:
c10f55b46a11 Changed the way .rsrc and template are copied: hopefully this will
Jack Jansen <jack.jansen@cwi.nl>
parents: 3062
diff changeset
262 ctor = type
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
263 size = res.size
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
264 attrs = res.GetResAttrs()
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
265 if DEBUG and progress:
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
266 progress.label("Copy %s %d %s"%(type, id, name))
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
267 progress.inc(progress_cur_inc)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
268 res.LoadResource()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
269 res.DetachResource()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
270 UseResFile(output)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
271 try:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
272 res2 = Get1Resource(type, id)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
273 except MacOS.Error:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
274 res2 = None
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
275 if res2:
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
276 if DEBUG and progress:
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
277 progress.label("Overwrite %s %d %s"%(type, id, name))
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
278 res2.RemoveResource()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
279 res.AddResource(type, id, name)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
280 res.WriteResource()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
281 attrs = attrs | res.GetResAttrs()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
282 res.SetResAttrs(attrs)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
283 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
284 return alltypes, ctor
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
285
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
286
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
287 # Show a message and exit
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
288
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
289 def die(str):
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
290 message(str)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
291 sys.exit(1)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
292
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
293
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
294 # Show a message
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
295
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
296 def message(str, id = 256):
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
297 from Dlg import *
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
298 d = GetNewDialog(id, -1)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
299 if not d:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
300 print "Error:", `str`
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
301 print "DLOG id =", id, "not found."
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
302 return
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
303 tp, h, rect = d.GetDialogItem(2)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
304 SetDialogItemText(h, str)
3345
1709d5fed528 Set default item for dialog
Jack Jansen <jack.jansen@cwi.nl>
parents: 3121
diff changeset
305 d.SetDialogDefaultItem(1)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
306 while 1:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
307 n = ModalDialog(None)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
308 if n == 1: break
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
309 del d
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
310
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
311
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
312 if __name__ == '__main__':
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
313 main()