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 written 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
)
37 # Define this if we cannot generate 68/fat binaries (Python 1.6)
42 Res
.GetResource('DITL', DLG_ID
)
44 Res
.FSpOpenResFile("BuildApplication.rsrc", 1)
46 pass # we're an applet
52 except buildtools
.BuildError
, detail
:
53 EasyDialogs
.Message(detail
)
56 def buildapplication(debug
= 0):
57 buildtools
.DEBUG
= debug
59 # Ask for source text if not specified in sys.argv[1:]
62 srcfss
, ok
= macfs
.PromptGetFile('Select Python source:', 'TEXT')
65 filename
= srcfss
.as_pathname()
68 raise buildtools
.BuildError
, "please select one file at a time"
69 filename
= sys
.argv
[1]
70 tp
, tf
= os
.path
.split(filename
)
73 architecture
, ok
= interact(tf
)
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 ctl
= dlg
.GetDialogItemAsControl(item
)
95 self
.items
[item
] = ctl
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
):
116 d
= Dlg
.GetNewDialog(DLG_ID
, -1)
118 print "Can't get DLOG resource with id =", DLG_ID
120 d
.SetDialogDefaultItem(OK_BUTTON
)
121 d
.SetDialogCancelItem(CANCEL_BUTTON
)
122 Dlg
.ParamText(scriptname
, "", "", "")
124 radiogroup
= radio(d
, GENFAT_BUTTON
, GENPPC_BUTTON
, GEN68K_BUTTON
)
125 radiogroup
.set(GENFAT_BUTTON
)
129 n
= Dlg
.ModalDialog(None)
130 if n
== OK_BUTTON
or n
== CANCEL_BUTTON
:
132 elif radiogroup
.hasitem(n
):
134 genitem
= radiogroup
.get()
137 if genitem
== GENFAT_BUTTON
:
139 elif genitem
== GENPPC_BUTTON
:
141 elif genitem
== GEN68K_BUTTON
:
143 return gentype
, n
== OK_BUTTON
146 if __name__
== '__main__':