1998-07-31 06:44:58 -03:00
|
|
|
"""Create a standalone application 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, all used shared libs and
|
|
|
|
then adding 'PYC ' resources containing compiled versions of all used
|
1999-11-04 06:30:13 -04:00
|
|
|
modules written in Python and the main script itself, as __main__.
|
1998-07-31 06:44:58 -03:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import string
|
|
|
|
import os
|
|
|
|
import MacOS
|
2001-08-25 09:15:04 -03:00
|
|
|
from Carbon import Res
|
|
|
|
from Carbon import Dlg
|
1998-07-31 06:44:58 -03:00
|
|
|
import EasyDialogs
|
|
|
|
import buildtools
|
2001-08-27 18:41:23 -03:00
|
|
|
import macresource
|
1998-07-31 06:44:58 -03:00
|
|
|
|
|
|
|
# Hmmm...
|
|
|
|
MACFREEZEPATH = os.path.join(sys.prefix, ":Mac:Tools:macfreeze")
|
|
|
|
if MACFREEZEPATH not in sys.path:
|
|
|
|
sys.path.append(MACFREEZEPATH)
|
|
|
|
|
|
|
|
import macgen_bin
|
|
|
|
|
|
|
|
# dialog, items
|
|
|
|
DLG_ID = 400
|
|
|
|
OK_BUTTON = 1
|
|
|
|
CANCEL_BUTTON = 2
|
|
|
|
GENFAT_BUTTON = 4
|
|
|
|
GENPPC_BUTTON = 5
|
|
|
|
GEN68K_BUTTON = 6
|
|
|
|
|
2000-07-24 16:44:17 -03:00
|
|
|
# Define this if we cannot generate 68/fat binaries (Python 1.6)
|
|
|
|
PPC_ONLY=1
|
|
|
|
|
1998-07-31 06:44:58 -03:00
|
|
|
|
2001-08-27 18:41:23 -03:00
|
|
|
macresource.need('DITL', DLG_ID, "BuildApplication.rsrc")
|
1998-07-31 06:44:58 -03:00
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
buildapplication()
|
|
|
|
except buildtools.BuildError, detail:
|
|
|
|
EasyDialogs.Message(detail)
|
|
|
|
|
|
|
|
|
|
|
|
def buildapplication(debug = 0):
|
|
|
|
buildtools.DEBUG = debug
|
|
|
|
|
|
|
|
# Ask for source text if not specified in sys.argv[1:]
|
|
|
|
|
|
|
|
if not sys.argv[1:]:
|
2003-01-22 10:03:12 -04:00
|
|
|
filename = EasyDialogs.AskFileForOpen(message='Select Python source:',
|
|
|
|
fileTypes=('TEXT',))
|
|
|
|
if not filename:
|
1998-07-31 06:44:58 -03:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
if sys.argv[2:]:
|
|
|
|
raise buildtools.BuildError, "please select one file at a time"
|
|
|
|
filename = sys.argv[1]
|
|
|
|
tp, tf = os.path.split(filename)
|
|
|
|
|
|
|
|
# interact with user
|
|
|
|
architecture, ok = interact(tf)
|
|
|
|
if not ok:
|
|
|
|
return
|
|
|
|
if tf[-3:] == '.py':
|
|
|
|
tf = tf[:-3]
|
|
|
|
else:
|
|
|
|
tf = tf + '.app'
|
|
|
|
|
2003-01-22 10:03:12 -04:00
|
|
|
dstfilename = EasyDialogs.AskFileForSate(message='Save application as:',
|
|
|
|
savedFileName=tf)
|
1998-07-31 06:44:58 -03:00
|
|
|
if not ok:
|
|
|
|
return
|
|
|
|
|
|
|
|
macgen_bin.generate(filename, dstfilename, None, architecture, 1)
|
|
|
|
|
|
|
|
|
|
|
|
class radio:
|
|
|
|
|
|
|
|
def __init__(self, dlg, *items):
|
|
|
|
self.items = {}
|
|
|
|
for item in items:
|
1999-12-23 10:33:20 -04:00
|
|
|
ctl = dlg.GetDialogItemAsControl(item)
|
|
|
|
self.items[item] = ctl
|
1998-07-31 06:44:58 -03:00
|
|
|
|
|
|
|
def set(self, setitem):
|
|
|
|
for item, ctl in self.items.items():
|
|
|
|
if item == setitem:
|
|
|
|
ctl.SetControlValue(1)
|
|
|
|
else:
|
|
|
|
ctl.SetControlValue(0)
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
for item, ctl in self.items.items():
|
|
|
|
if ctl.GetControlValue():
|
|
|
|
return item
|
|
|
|
|
|
|
|
def hasitem(self, item):
|
|
|
|
return self.items.has_key(item)
|
|
|
|
|
|
|
|
|
|
|
|
def interact(scriptname):
|
2000-07-24 16:44:17 -03:00
|
|
|
if PPC_ONLY:
|
2000-12-14 19:34:15 -04:00
|
|
|
return 'pwpc', 1
|
1998-07-31 06:44:58 -03:00
|
|
|
d = Dlg.GetNewDialog(DLG_ID, -1)
|
|
|
|
if not d:
|
2000-12-14 19:34:15 -04:00
|
|
|
raise "Can't get DLOG resource with id =", DLG_ID
|
1998-07-31 06:44:58 -03:00
|
|
|
d.SetDialogDefaultItem(OK_BUTTON)
|
|
|
|
d.SetDialogCancelItem(CANCEL_BUTTON)
|
|
|
|
Dlg.ParamText(scriptname, "", "", "")
|
|
|
|
|
|
|
|
radiogroup = radio(d, GENFAT_BUTTON, GENPPC_BUTTON, GEN68K_BUTTON)
|
|
|
|
radiogroup.set(GENFAT_BUTTON)
|
|
|
|
|
|
|
|
gentype = 'fat'
|
|
|
|
while 1:
|
|
|
|
n = Dlg.ModalDialog(None)
|
|
|
|
if n == OK_BUTTON or n == CANCEL_BUTTON:
|
|
|
|
break
|
|
|
|
elif radiogroup.hasitem(n):
|
|
|
|
radiogroup.set(n)
|
|
|
|
genitem = radiogroup.get()
|
|
|
|
del radiogroup
|
|
|
|
del d
|
|
|
|
if genitem == GENFAT_BUTTON:
|
|
|
|
gentype = 'fat'
|
|
|
|
elif genitem == GENPPC_BUTTON:
|
|
|
|
gentype = 'pwpc'
|
|
|
|
elif genitem == GEN68K_BUTTON:
|
|
|
|
gentype = 'm68k'
|
|
|
|
return gentype, n == OK_BUTTON
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|