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__.
16 from Carbon
import Res
17 from Carbon
import Dlg
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)
41 macresource
.need('DITL', DLG_ID
, "BuildApplication.rsrc")
46 except buildtools
.BuildError
, detail
:
47 EasyDialogs
.Message(detail
)
50 def buildapplication(debug
= 0):
51 buildtools
.DEBUG
= debug
53 # Ask for source text if not specified in sys.argv[1:]
56 filename
= EasyDialogs
.AskFileForOpen(message
='Select Python source:',
62 raise buildtools
.BuildError
, "please select one file at a time"
63 filename
= sys
.argv
[1]
64 tp
, tf
= os
.path
.split(filename
)
67 architecture
, ok
= interact(tf
)
75 dstfilename
= EasyDialogs
.AskFileForSate(message
='Save application as:',
80 macgen_bin
.generate(filename
, dstfilename
, None, architecture
, 1)
85 def __init__(self
, dlg
, *items
):
88 ctl
= dlg
.GetDialogItemAsControl(item
)
89 self
.items
[item
] = ctl
91 def set(self
, setitem
):
92 for item
, ctl
in self
.items
.items():
94 ctl
.SetControlValue(1)
96 ctl
.SetControlValue(0)
99 for item
, ctl
in self
.items
.items():
100 if ctl
.GetControlValue():
103 def hasitem(self
, item
):
104 return self
.items
.has_key(item
)
107 def interact(scriptname
):
110 d
= Dlg
.GetNewDialog(DLG_ID
, -1)
112 raise "Can't get DLOG resource with id =", DLG_ID
113 d
.SetDialogDefaultItem(OK_BUTTON
)
114 d
.SetDialogCancelItem(CANCEL_BUTTON
)
115 Dlg
.ParamText(scriptname
, "", "", "")
117 radiogroup
= radio(d
, GENFAT_BUTTON
, GENPPC_BUTTON
, GEN68K_BUTTON
)
118 radiogroup
.set(GENFAT_BUTTON
)
122 n
= Dlg
.ModalDialog(None)
123 if n
== OK_BUTTON
or n
== CANCEL_BUTTON
:
125 elif radiogroup
.hasitem(n
):
127 genitem
= radiogroup
.get()
130 if genitem
== GENFAT_BUTTON
:
132 elif genitem
== GENPPC_BUTTON
:
134 elif genitem
== GEN68K_BUTTON
:
136 return gentype
, n
== OK_BUTTON
139 if __name__
== '__main__':