1 """Create a standalone application from a Python script.
3 This puts up a dialog asking for a Python source file ('TEXT').
4 The output is a file with the same name but its ".py" suffix dropped.
5 It is created by copying an applet template, all used shared libs and
6 then adding 'PYC ' resources containing compiled versions of all used
7 modules wirrten in Python and the main script itself, as __main__.
23 MACFREEZEPATH
= os
.path
.join(sys
.prefix
, ":Mac:Tools:macfreeze")
24 if MACFREEZEPATH
not in sys
.path
:
25 sys
.path
.append(MACFREEZEPATH
)
27 import macmodulefinder
40 Res
.GetResource('DITL', DLG_ID
)
42 Res
.OpenResFile("BuildApplication.rsrc")
44 pass # we're an applet
50 except buildtools
.BuildError
, detail
:
51 EasyDialogs
.Message(detail
)
54 def buildapplication(debug
= 0):
55 buildtools
.DEBUG
= debug
57 # Ask for source text if not specified in sys.argv[1:]
60 srcfss
, ok
= macfs
.PromptGetFile('Select Python source:', 'TEXT')
63 filename
= srcfss
.as_pathname()
66 raise buildtools
.BuildError
, "please select one file at a time"
67 filename
= sys
.argv
[1]
68 tp
, tf
= os
.path
.split(filename
)
71 architecture
, ok
= interact(tf
)
76 logfile
= tf
[:-3] + '.log'
81 dstfss
, ok
= macfs
.StandardPutFile('Save application as:', tf
)
84 dstfilename
= dstfss
.as_pathname()
86 macgen_bin
.generate(filename
, dstfilename
, None, architecture
, 1)
91 def __init__(self
, dlg
, *items
):
94 tp
, h
, rect
= dlg
.GetDialogItem(item
)
95 self
.items
[item
] = h
.as_Control()
97 def set(self
, setitem
):
98 for item
, ctl
in self
.items
.items():
100 ctl
.SetControlValue(1)
102 ctl
.SetControlValue(0)
105 for item
, ctl
in self
.items
.items():
106 if ctl
.GetControlValue():
109 def hasitem(self
, item
):
110 return self
.items
.has_key(item
)
113 def interact(scriptname
):
114 d
= Dlg
.GetNewDialog(DLG_ID
, -1)
116 print "Can't get DLOG resource with id =", DLG_ID
118 d
.SetDialogDefaultItem(OK_BUTTON
)
119 d
.SetDialogCancelItem(CANCEL_BUTTON
)
120 Dlg
.ParamText(scriptname
, "", "", "")
122 radiogroup
= radio(d
, GENFAT_BUTTON
, GENPPC_BUTTON
, GEN68K_BUTTON
)
123 radiogroup
.set(GENFAT_BUTTON
)
127 n
= Dlg
.ModalDialog(None)
128 if n
== OK_BUTTON
or n
== CANCEL_BUTTON
:
130 elif radiogroup
.hasitem(n
):
132 genitem
= radiogroup
.get()
135 if genitem
== GENFAT_BUTTON
:
137 elif genitem
== GENPPC_BUTTON
:
139 elif genitem
== GEN68K_BUTTON
:
141 return gentype
, n
== OK_BUTTON
144 if __name__
== '__main__':