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
)
39 Res
.GetResource('DITL', DLG_ID
)
41 Res
.OpenResFile("BuildApplication.rsrc")
43 pass # we're an applet
49 except buildtools
.BuildError
, detail
:
50 EasyDialogs
.Message(detail
)
53 def buildapplication(debug
= 0):
54 buildtools
.DEBUG
= debug
56 # Ask for source text if not specified in sys.argv[1:]
59 srcfss
, ok
= macfs
.PromptGetFile('Select Python source:', 'TEXT')
62 filename
= srcfss
.as_pathname()
65 raise buildtools
.BuildError
, "please select one file at a time"
66 filename
= sys
.argv
[1]
67 tp
, tf
= os
.path
.split(filename
)
70 architecture
, ok
= interact(tf
)
78 dstfss
, ok
= macfs
.StandardPutFile('Save application as:', tf
)
81 dstfilename
= dstfss
.as_pathname()
83 macgen_bin
.generate(filename
, dstfilename
, None, architecture
, 1)
88 def __init__(self
, dlg
, *items
):
91 ctl
= dlg
.GetDialogItemAsControl(item
)
92 self
.items
[item
] = ctl
94 def set(self
, setitem
):
95 for item
, ctl
in self
.items
.items():
97 ctl
.SetControlValue(1)
99 ctl
.SetControlValue(0)
102 for item
, ctl
in self
.items
.items():
103 if ctl
.GetControlValue():
106 def hasitem(self
, item
):
107 return self
.items
.has_key(item
)
110 def interact(scriptname
):
111 d
= Dlg
.GetNewDialog(DLG_ID
, -1)
113 print "Can't get DLOG resource with id =", DLG_ID
115 d
.SetDialogDefaultItem(OK_BUTTON
)
116 d
.SetDialogCancelItem(CANCEL_BUTTON
)
117 Dlg
.ParamText(scriptname
, "", "", "")
119 radiogroup
= radio(d
, GENFAT_BUTTON
, GENPPC_BUTTON
, GEN68K_BUTTON
)
120 radiogroup
.set(GENFAT_BUTTON
)
124 n
= Dlg
.ModalDialog(None)
125 if n
== OK_BUTTON
or n
== CANCEL_BUTTON
:
127 elif radiogroup
.hasitem(n
):
129 genitem
= radiogroup
.get()
132 if genitem
== GENFAT_BUTTON
:
134 elif genitem
== GENPPC_BUTTON
:
136 elif genitem
== GEN68K_BUTTON
:
138 return gentype
, n
== OK_BUTTON
141 if __name__
== '__main__':