1995-07-29 10:48:41 -03:00
|
|
|
"""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.
|
|
|
|
"""
|
|
|
|
|
1995-09-01 08:54:11 -03:00
|
|
|
|
1995-07-29 10:48:41 -03:00
|
|
|
import sys
|
|
|
|
sys.stdout = sys.stderr
|
|
|
|
|
|
|
|
import os
|
|
|
|
import macfs
|
|
|
|
import MacOS
|
1997-05-13 12:42:26 -03:00
|
|
|
import EasyDialogs
|
1998-07-31 06:44:23 -03:00
|
|
|
import buildtools
|
1995-07-29 10:48:41 -03:00
|
|
|
|
|
|
|
|
1998-07-31 06:44:23 -03:00
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
buildapplet()
|
|
|
|
except buildtools.BuildError, detail:
|
|
|
|
EasyDialogs.Message(detail)
|
1995-07-29 10:48:41 -03:00
|
|
|
|
1995-09-01 08:54:11 -03:00
|
|
|
|
1998-07-31 06:44:23 -03:00
|
|
|
def buildapplet():
|
|
|
|
buildtools.DEBUG=1
|
1995-09-01 08:54:11 -03:00
|
|
|
|
|
|
|
# Find the template
|
|
|
|
# (there's no point in proceeding if we can't find it)
|
|
|
|
|
1998-07-31 06:44:23 -03:00
|
|
|
template = buildtools.findtemplate()
|
|
|
|
|
1995-07-29 10:48:41 -03:00
|
|
|
# Ask for source text if not specified in sys.argv[1:]
|
|
|
|
|
|
|
|
if not sys.argv[1:]:
|
1998-02-20 12:06:56 -04:00
|
|
|
srcfss, ok = macfs.PromptGetFile('Select Python source or applet:', 'TEXT', 'APPL')
|
1995-07-29 10:48:41 -03:00
|
|
|
if not ok:
|
|
|
|
return
|
|
|
|
filename = srcfss.as_pathname()
|
|
|
|
tp, tf = os.path.split(filename)
|
|
|
|
if tf[-3:] == '.py':
|
|
|
|
tf = tf[:-3]
|
|
|
|
else:
|
1998-07-31 06:44:23 -03:00
|
|
|
tf = tf + '.applet'
|
1995-07-29 10:48:41 -03:00
|
|
|
dstfss, ok = macfs.StandardPutFile('Save application as:', tf)
|
|
|
|
if not ok: return
|
1998-02-20 12:06:56 -04:00
|
|
|
dstfilename = dstfss.as_pathname()
|
|
|
|
cr, tp = MacOS.GetCreatorAndType(filename)
|
|
|
|
if tp == 'APPL':
|
1998-07-31 06:44:23 -03:00
|
|
|
buildtools.update(template, filename, dstfilename)
|
1998-02-20 12:06:56 -04:00
|
|
|
else:
|
1998-07-31 06:44:23 -03:00
|
|
|
buildtools.process(template, filename, dstfilename, 1)
|
1995-07-29 10:48:41 -03:00
|
|
|
else:
|
|
|
|
|
|
|
|
# Loop over all files to be processed
|
|
|
|
for filename in sys.argv[1:]:
|
1998-02-20 12:06:56 -04:00
|
|
|
cr, tp = MacOS.GetCreatorAndType(filename)
|
|
|
|
if tp == 'APPL':
|
1998-07-31 06:44:23 -03:00
|
|
|
buildtools.update(template, filename, '')
|
1998-02-20 12:06:56 -04:00
|
|
|
else:
|
1998-07-31 06:44:23 -03:00
|
|
|
buildtools.process(template, filename, '', 1)
|
1995-07-29 10:48:41 -03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|