2020import MacOS
2121from Res import *
2222import macostools
23+ import EasyDialogs
2324
2425# .pyc file (and 'PYC ' resource magic number)
2526MAGIC = imp .get_magic ()
@@ -55,13 +56,13 @@ def findtemplate():
5556 return template
5657
5758def main ():
59+ global DEBUG
60+ DEBUG = 1
5861
5962 # Find the template
6063 # (there's no point in proceeding if we can't find it)
6164
6265 template = findtemplate ()
63- if DEBUG :
64- print 'Using template' , template
6566
6667 # Ask for source text if not specified in sys.argv[1:]
6768
@@ -87,7 +88,10 @@ def main():
8788def process (template , filename , output ):
8889
8990 if DEBUG :
90- print "Processing" , `filename` , "..."
91+ progress = EasyDialogs .ProgressBar ("Processing %s..." % os .path .split (filename )[1 ], 120 )
92+ progress .label ("Compiling..." )
93+ else :
94+ progress = None
9195
9296 # Read the source and compile it
9397 # (there's no point overwriting the destination if it has a syntax error)
@@ -127,6 +131,9 @@ def process(template, filename, output):
127131 dest_fss = macfs .FSSpec (destname )
128132
129133 # Copy data (not resources, yet) from the template
134+ if DEBUG :
135+ progress .label ("Copy data fork..." )
136+ progress .set (10 )
130137
131138 tmpl = open (template , "rb" )
132139 dest = open (destname , "wb" )
@@ -138,11 +145,12 @@ def process(template, filename, output):
138145
139146 # Open the output resource fork
140147
148+ if DEBUG :
149+ progress .label ("Copy resources..." )
150+ progress .set (20 )
141151 try :
142152 output = FSpOpenResFile (dest_fss , WRITE )
143153 except MacOS .Error :
144- if DEBUG :
145- print "Creating resource fork..."
146154 CreateResFile (destname )
147155 output = FSpOpenResFile (dest_fss , WRITE )
148156
@@ -152,8 +160,10 @@ def process(template, filename, output):
152160 input = FSpOpenResFile (rsrcname , READ )
153161 except (MacOS .Error , ValueError ):
154162 pass
163+ if DEBUG :
164+ progress .inc (50 )
155165 else :
156- typesfound , ownertype = copyres (input , output , [], 0 )
166+ typesfound , ownertype = copyres (input , output , [], 0 , progress )
157167 CloseResFile (input )
158168
159169 # Check which resource-types we should not copy from the template
@@ -166,7 +176,7 @@ def process(template, filename, output):
166176 # Copy the resources from the template
167177
168178 input = FSpOpenResFile (template_fss , READ )
169- dummy , tmplowner = copyres (input , output , skiptypes , skipowner )
179+ dummy , tmplowner = copyres (input , output , skiptypes , skipowner , progress )
170180 if ownertype == None :
171181 ownertype = tmplowner
172182 CloseResFile (input )
@@ -194,6 +204,9 @@ def process(template, filename, output):
194204 pass
195205
196206 # Create the raw data for the resource from the code object
207+ if DEBUG :
208+ progress .label ("Write PYC resource..." )
209+ progress .set (120 )
197210
198211 data = marshal .dumps (code )
199212 del code
@@ -215,24 +228,26 @@ def process(template, filename, output):
215228
216229 macostools .touched (dest_fss )
217230 if DEBUG :
218- print "Applet created:" , destname
231+ progress . label ( "Done." )
219232
220233
221234# Copy resources between two resource file descriptors.
222235# skip a resource named '__main__' or (if skipowner is set) 'Owner resource'.
223236# Also skip resources with a type listed in skiptypes.
224237#
225- def copyres (input , output , skiptypes , skipowner ):
238+ def copyres (input , output , skiptypes , skipowner , progress = None ):
226239 ctor = None
227240 alltypes = []
228241 UseResFile (input )
229242 ntypes = Count1Types ()
243+ progress_type_inc = 50 / ntypes
230244 for itype in range (1 , 1 + ntypes ):
231245 type = Get1IndType (itype )
232246 if type in skiptypes :
233247 continue
234248 alltypes .append (type )
235249 nresources = Count1Resources (type )
250+ progress_cur_inc = progress_type_inc / nresources
236251 for ires in range (1 , 1 + nresources ):
237252 res = Get1IndResource (type , ires )
238253 id , type , name = res .GetResInfo ()
@@ -247,8 +262,9 @@ def copyres(input, output, skiptypes, skipowner):
247262 ctor = type
248263 size = res .size
249264 attrs = res .GetResAttrs ()
250- if DEBUG :
251- print id , type , name , size , hex (attrs )
265+ if DEBUG and progress :
266+ progress .label ("Copy %s %d %s" % (type , id , name ))
267+ progress .inc (progress_cur_inc )
252268 res .LoadResource ()
253269 res .DetachResource ()
254270 UseResFile (output )
@@ -257,14 +273,12 @@ def copyres(input, output, skiptypes, skipowner):
257273 except MacOS .Error :
258274 res2 = None
259275 if res2 :
260- if DEBUG :
261- print "Overwriting..."
276+ if DEBUG and progress :
277+ progress . label ( "Overwrite %s %d %s" % ( type , id , name ))
262278 res2 .RemoveResource ()
263279 res .AddResource (type , id , name )
264280 res .WriteResource ()
265281 attrs = attrs | res .GetResAttrs ()
266- if DEBUG :
267- print "New attrs =" , hex (attrs )
268282 res .SetResAttrs (attrs )
269283 UseResFile (input )
270284 return alltypes , ctor
0 commit comments