annotate Mac/scripts/BuildApplication.py @ 27343:412e66e3530e legacy-trunk

Getting rid of StandardGetFile
author Jack Jansen <jack.jansen@cwi.nl>
date Wed, 22 Jan 2003 14:03:12 +0000
parents 546ef318ba5d
children 097437634968
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 MacOS
19488
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15571
diff changeset
16 from Carbon import Res
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15571
diff changeset
17 from Carbon import Dlg
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 import EasyDialogs
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 import buildtools
19515
546ef318ba5d Use the new macresource module to open the accompanying resource file (if needed).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
20 import macresource
8799
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
13698
cb29d4a2c17b Added a "compile-time" flag PPC_ONLY, if set we make ppc-only applications without posting the dialog. This is the normal situation since 1.6alfa (no more 68k support).
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
37 # Define this if we cannot generate 68/fat binaries (Python 1.6)
cb29d4a2c17b Added a "compile-time" flag PPC_ONLY, if set we make ppc-only applications without posting the dialog. This is the normal situation since 1.6alfa (no more 68k support).
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
38 PPC_ONLY=1
cb29d4a2c17b Added a "compile-time" flag PPC_ONLY, if set we make ppc-only applications without posting the dialog. This is the normal situation since 1.6alfa (no more 68k support).
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
39
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40
19515
546ef318ba5d Use the new macresource module to open the accompanying resource file (if needed).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
41 macresource.need('DITL', DLG_ID, "BuildApplication.rsrc")
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 def main():
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 try:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 buildapplication()
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 except buildtools.BuildError, detail:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 EasyDialogs.Message(detail)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 def buildapplication(debug = 0):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 buildtools.DEBUG = debug
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 # 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
54
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 if not sys.argv[1:]:
27343
412e66e3530e Getting rid of StandardGetFile
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
56 filename = EasyDialogs.AskFileForOpen(message='Select Python source:',
412e66e3530e Getting rid of StandardGetFile
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
57 fileTypes=('TEXT',))
412e66e3530e Getting rid of StandardGetFile
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
58 if not filename:
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 return
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60 else:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 if sys.argv[2:]:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 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
63 filename = sys.argv[1]
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 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
65
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 # interact with user
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 architecture, ok = interact(tf)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 if not ok:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69 return
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70 if tf[-3:] == '.py':
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 tf = tf[:-3]
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 else:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 tf = tf + '.app'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74
27343
412e66e3530e Getting rid of StandardGetFile
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
75 dstfilename = EasyDialogs.AskFileForSate(message='Save application as:',
412e66e3530e Getting rid of StandardGetFile
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
76 savedFileName=tf)
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 if not ok:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 return
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 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
81
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 class radio:
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 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
86 self.items = {}
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 for item in items:
11623
6f2119cd99d2 Converted to Appearance.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11437
diff changeset
88 ctl = dlg.GetDialogItemAsControl(item)
6f2119cd99d2 Converted to Appearance.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11437
diff changeset
89 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
90
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91 def set(self, setitem):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 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
93 if item == setitem:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 ctl.SetControlValue(1)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 else:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 ctl.SetControlValue(0)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 def get(self):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 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
100 if ctl.GetControlValue():
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 return item
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103 def hasitem(self, item):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 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
105
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 def interact(scriptname):
13698
cb29d4a2c17b Added a "compile-time" flag PPC_ONLY, if set we make ppc-only applications without posting the dialog. This is the normal situation since 1.6alfa (no more 68k support).
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
108 if PPC_ONLY:
15571
027ee9a870d2 Oops, interaction() returned a single value in stead of a tuple (I thought that bug was loooong fixed??!?).
Jack Jansen <jack.jansen@cwi.nl>
parents: 13698
diff changeset
109 return 'pwpc', 1
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 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
111 if not d:
15571
027ee9a870d2 Oops, interaction() returned a single value in stead of a tuple (I thought that bug was loooong fixed??!?).
Jack Jansen <jack.jansen@cwi.nl>
parents: 13698
diff changeset
112 raise "Can't get DLOG resource with id =", DLG_ID
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
113 d.SetDialogDefaultItem(OK_BUTTON)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 d.SetDialogCancelItem(CANCEL_BUTTON)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 Dlg.ParamText(scriptname, "", "", "")
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
116
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 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
118 radiogroup.set(GENFAT_BUTTON)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
119
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 gentype = 'fat'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121 while 1:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122 n = Dlg.ModalDialog(None)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123 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
124 break
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 elif radiogroup.hasitem(n):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126 radiogroup.set(n)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
127 genitem = radiogroup.get()
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 del radiogroup
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129 del d
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
130 if genitem == GENFAT_BUTTON:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
131 gentype = 'fat'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132 elif genitem == GENPPC_BUTTON:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
133 gentype = 'pwpc'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
134 elif genitem == GEN68K_BUTTON:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
135 gentype = 'm68k'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
136 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
137
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
139 if __name__ == '__main__':
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
140 main()