Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: 2d0f5aa9a14f63854dc1d4633effa7a24b9553a7 authored by cvs2svn on 29 March 2002, 21:23:40 UTC
This commit was manufactured by cvs2svn to create tag 'r22p1'.
Tip revision: 2d0f5aa
BuildApplet.py
"""Create an applet from a Python script.

This puts up a dialog asking for a Python source file ('TEXT').
The output is a file with the same name but its ".py" suffix dropped.
It is created by copying an applet template and then adding a 'PYC '
resource named __main__ containing the compiled, marshalled script.
"""


import sys
sys.stdout = sys.stderr

import os
import macfs
import MacOS
import EasyDialogs
import buildtools


def main():
	try:
		buildapplet()
	except buildtools.BuildError, detail:
		EasyDialogs.Message(detail)


def buildapplet():
	buildtools.DEBUG=1
	
	# Find the template
	# (there's no point in proceeding if we can't find it)
	
	template = buildtools.findtemplate()
	
	# Ask for source text if not specified in sys.argv[1:]
	
	if not sys.argv[1:]:
		srcfss, ok = macfs.PromptGetFile('Select Python source or applet:', 'TEXT', 'APPL')
		if not ok:
			return
		filename = srcfss.as_pathname()
		tp, tf = os.path.split(filename)
		if tf[-3:] == '.py':
			tf = tf[:-3]
		else:
			tf = tf + '.applet'
		dstfss, ok = macfs.StandardPutFile('Save application as:', tf)
		if not ok: return
		dstfilename = dstfss.as_pathname()
		cr, tp = MacOS.GetCreatorAndType(filename)
		if tp == 'APPL':
			buildtools.update(template, filename, dstfilename)
		else:
			buildtools.process(template, filename, dstfilename, 1)
	else:
		
		# Loop over all files to be processed
		for filename in sys.argv[1:]:
			cr, tp = MacOS.GetCreatorAndType(filename)
			if tp == 'APPL':
				buildtools.update(template, filename, '')
			else:
				buildtools.process(template, filename, '', 1)


if __name__ == '__main__':
	main()
back to top