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__.
17 from Carbon
import Res
18 from Carbon
import Dlg
24 MACFREEZEPATH
= os
.path
.join(sys
.prefix
, ":Mac:Tools:macfreeze")
25 if MACFREEZEPATH
not in sys
.path
:
26 sys
.path
.append(MACFREEZEPATH
)
38 # Define this if we cannot generate 68/fat binaries (Python 1.6)
42 macresource
.need('DITL', DLG_ID
, "BuildApplication.rsrc")
47 except buildtools
.BuildError
, detail
:
48 EasyDialogs
.Message(detail
)
51 def buildapplication(debug
= 0):
52 buildtools
.DEBUG
= debug
54 # Ask for source text if not specified in sys.argv[1:]
57 srcfss
, ok
= macfs
.PromptGetFile('Select Python source:', 'TEXT')
60 filename
= srcfss
.as_pathname()
63 raise buildtools
.BuildError
, "please select one file at a time"
64 filename
= sys
.argv
[1]
65 tp
, tf
= os
.path
.split(filename
)
68 architecture
, ok
= interact(tf
)
76 dstfss
, ok
= macfs
.StandardPutFile('Save application as:', tf
)
79 dstfilename
= dstfss
.as_pathname()
81 macgen_bin
.generate(filename
, dstfilename
, None, architecture
, 1)
86 def __init__(self
, dlg
, *items
):
89 ctl
= dlg
.GetDialogItemAsControl(item
)
90 self
.items
[item
] = ctl
92 def set(self
, setitem
):
93 for item
, ctl
in self
.items
.items():
95 ctl
.SetControlValue(1)
97 ctl
.SetControlValue(0)
100 for item
, ctl
in self
.items
.items():
101 if ctl
.GetControlValue():
104 def hasitem(self
, item
):
105 return self
.items
.has_key(item
)
108 def interact(scriptname
):
111 d
= Dlg
.GetNewDialog(DLG_ID
, -1)
113 raise "Can't get DLOG resource with id =", DLG_ID
114 d
.SetDialogDefaultItem(OK_BUTTON
)
115 d
.SetDialogCancelItem(CANCEL_BUTTON
)
116 Dlg
.ParamText(scriptname
, "", "", "")
118 radiogroup
= radio(d
, GENFAT_BUTTON
, GENPPC_BUTTON
, GEN68K_BUTTON
)
119 radiogroup
.set(GENFAT_BUTTON
)
123 n
= Dlg
.ModalDialog(None)
124 if n
== OK_BUTTON
or n
== CANCEL_BUTTON
:
126 elif radiogroup
.hasitem(n
):
128 genitem
= radiogroup
.get()
131 if genitem
== GENFAT_BUTTON
:
133 elif genitem
== GENPPC_BUTTON
:
135 elif genitem
== GEN68K_BUTTON
:
137 return gentype
, n
== OK_BUTTON
140 if __name__
== '__main__':