annotate Mac/scripts/BuildApplication.py @ 12972:fc77e34ef274 legacy-trunk

Replaced OpenResFile calls with FSpOpenResFile calls (which are carbon-compatible).
author Jack Jansen <jack.jansen@cwi.nl>
date Tue, 20 Jun 2000 21:59:25 +0000
parents 6f2119cd99d2
children cb29d4a2c17b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 """Create a standalone application from a Python script.
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 This puts up a dialog asking for a Python source file ('TEXT').
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 The output is a file with the same name but its ".py" suffix dropped.
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 It is created by copying an applet template, all used shared libs and
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 then adding 'PYC ' resources containing compiled versions of all used
11437
32a480d0823c Typo fixed in docstring; removed unneccesary import. (jvr)
Just van Rossum <just@lettererror.com>
parents: 10739
diff changeset
7 modules written in Python and the main script itself, as __main__.
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 """
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 import sys
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 import string
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14 import os
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 import macfs
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 import MacOS
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 import Res
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 import Dlg
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 import EasyDialogs
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 import buildtools
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22 # Hmmm...
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 MACFREEZEPATH = os.path.join(sys.prefix, ":Mac:Tools:macfreeze")
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 if MACFREEZEPATH not in sys.path:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 sys.path.append(MACFREEZEPATH)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 import macgen_bin
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 # dialog, items
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 DLG_ID = 400
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 OK_BUTTON = 1
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 CANCEL_BUTTON = 2
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 GENFAT_BUTTON = 4
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 GENPPC_BUTTON = 5
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 GEN68K_BUTTON = 6
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38 try:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 Res.GetResource('DITL', DLG_ID)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 except Res.Error:
12972
fc77e34ef274 Replaced OpenResFile calls with FSpOpenResFile calls (which are carbon-compatible).
Jack Jansen <jack.jansen@cwi.nl>
parents: 11623
diff changeset
41 Res.FSpOpenResFile("BuildApplication.rsrc", 1)
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 else:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 pass # we're an applet
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 def main():
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 try:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 buildapplication()
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 except buildtools.BuildError, detail:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 EasyDialogs.Message(detail)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 def buildapplication(debug = 0):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 buildtools.DEBUG = debug
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 # Ask for source text if not specified in sys.argv[1:]
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58 if not sys.argv[1:]:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 srcfss, ok = macfs.PromptGetFile('Select Python source:', 'TEXT')
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60 if not ok:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 return
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 filename = srcfss.as_pathname()
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 else:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 if sys.argv[2:]:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65 raise buildtools.BuildError, "please select one file at a time"
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 filename = sys.argv[1]
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 tp, tf = os.path.split(filename)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69 # interact with user
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70 architecture, ok = interact(tf)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 if not ok:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 return
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 if tf[-3:] == '.py':
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 tf = tf[:-3]
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 else:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76 tf = tf + '.app'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 dstfss, ok = macfs.StandardPutFile('Save application as:', tf)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79 if not ok:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 return
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 dstfilename = dstfss.as_pathname()
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 macgen_bin.generate(filename, dstfilename, None, architecture, 1)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 class radio:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
88 def __init__(self, dlg, *items):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
89 self.items = {}
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90 for item in items:
11623
6f2119cd99d2 Converted to Appearance.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11437
diff changeset
91 ctl = dlg.GetDialogItemAsControl(item)
6f2119cd99d2 Converted to Appearance.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11437
diff changeset
92 self.items[item] = ctl
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 def set(self, setitem):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 for item, ctl in self.items.items():
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 if item == setitem:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 ctl.SetControlValue(1)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 else:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 ctl.SetControlValue(0)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 def get(self):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 for item, ctl in self.items.items():
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103 if ctl.GetControlValue():
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 return item
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 def hasitem(self, item):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 return self.items.has_key(item)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
109
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 def interact(scriptname):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111 d = Dlg.GetNewDialog(DLG_ID, -1)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112 if not d:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
113 print "Can't get DLOG resource with id =", DLG_ID
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 return
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 d.SetDialogDefaultItem(OK_BUTTON)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
116 d.SetDialogCancelItem(CANCEL_BUTTON)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 Dlg.ParamText(scriptname, "", "", "")
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
118
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
119 radiogroup = radio(d, GENFAT_BUTTON, GENPPC_BUTTON, GEN68K_BUTTON)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 radiogroup.set(GENFAT_BUTTON)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122 gentype = 'fat'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123 while 1:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124 n = Dlg.ModalDialog(None)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 if n == OK_BUTTON or n == CANCEL_BUTTON:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126 break
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
127 elif radiogroup.hasitem(n):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 radiogroup.set(n)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129 genitem = radiogroup.get()
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
130 del radiogroup
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
131 del d
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132 if genitem == GENFAT_BUTTON:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
133 gentype = 'fat'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
134 elif genitem == GENPPC_BUTTON:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
135 gentype = 'pwpc'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
136 elif genitem == GEN68K_BUTTON:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
137 gentype = 'm68k'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138 return gentype, n == OK_BUTTON
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
139
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
140
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
141 if __name__ == '__main__':
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142 main()