3 # Helper script when freezing Pmw applications. It concatenates all
4 # Pmw megawidget files into a single file, 'Pmw.py', in the current
5 # directory. The script must be called with one argument, being the
6 # path to the 'lib' directory of the required version of Pmw.
7 # To freeze a Pmw application, you will also need to copy the
8 # following files to the application directory before freezing:
10 # PmwBlt.py PmwColor.py
17 # The order of these files is significant. Files which reference
18 # other files must appear later. Files may be deleted if they are not
21 'Dialog', 'TimeFuncs', 'Balloon', 'ButtonBox', 'EntryField',
22 'Group', 'LabeledWidget', 'MainMenuBar', 'MenuBar', 'MessageBar',
23 'MessageDialog', 'NoteBook', 'OptionMenu', 'PanedWidget', 'PromptDialog',
24 'RadioSelect', 'ScrolledCanvas', 'ScrolledField', 'ScrolledFrame',
25 'ScrolledListBox', 'ScrolledText', 'HistoryText', 'SelectionDialog',
26 'TextDialog', 'TimeCounter', 'AboutDialog', 'ComboBox', 'ComboBoxDialog',
27 'Counter', 'CounterDialog',
30 # Set this to 0 if you do not use any of the Pmw.Color functions:
33 # Set this to 0 if you do not use any of the Pmw.Blt functions:
36 def expandLinks(path):
37 if not os.path.isabs(path):
38 path = os.path.join(os.getcwd(), path)
40 if not os.path.islink(path):
42 dir = os.path.dirname(path)
43 path = os.path.join(dir, os.readlink(path))
48 # Read the file and modify it so that it can be bundled with the
50 file = 'Pmw' + file + '.py'
51 text = open(os.path.join(srcdir, file)).read()
52 text = regsub.gsub('import Pmw\>', '', text)
53 text = regsub.gsub('INITOPT = Pmw.INITOPT', '', text)
54 text = regsub.gsub('\<Pmw\.', '', text)
55 text = '\n' + ('#' * 70) + '\n' + '### File: ' + file + '\n' + text
58 # Work out which version is being bundled.
60 file = os.path.normpath(file)
61 file = expandLinks(file)
63 dir = os.path.dirname(file)
64 dir = expandLinks(dir)
65 dir = os.path.dirname(dir)
66 dir = expandLinks(dir)
67 dir = os.path.basename(dir)
69 version = string.replace(dir[4:], '_', '.')
71 # Code to import the Color module.
78 # Code to import the Blt module.
85 # Code used when not linking with PmwBlt.py.
91 # Code to define the functions normally supplied by the dynamic loader.
98 def setversion(version):
99 if version != _VERSION:
100 raise ValueError, 'Dynamic versioning not available'
102 def setalphaversions(*alpha_versions):
103 if alpha_versions != ():
104 raise ValueError, 'Dynamic versioning not available'
106 def version(alpha = 0):
112 def installedversions(alpha = 0):
120 if '-noblt' in sys.argv:
121 sys.argv.remove('-noblt')
124 if '-nocolor' in sys.argv:
125 sys.argv.remove('-nocolor')
128 if len(sys.argv) != 2:
129 print 'usage: bundlepmw.py [-noblt] [-nocolor] /path/to/Pmw/Pmw_X_X_X/lib'
134 if os.path.exists('Pmw.py'):
135 print 'Pmw.py already exists. Remove it and try again.'
138 outfile = open('Pmw.py', 'w')
141 outfile.write(colorCode)
144 outfile.write(bltCode)
146 outfile.write(extraCode % version)
148 # Specially handle PmwBase.py file:
149 text = mungeFile('Base')
150 text = regsub.gsub('import PmwLogicalFont', '', text)
151 text = regsub.gsub('PmwLogicalFont._font_initialise', '_font_initialise', text)
154 outfile.write(ignoreBltCode)
156 files.append('LogicalFont')
158 text = mungeFile(file)
162 print ' Pmw.py has been created.'
164 if needColor or needBlt:
165 print ' Before running freeze, also copy the following file(s):'
167 print ' ' + os.path.join(srcdir, 'PmwBlt.py')
169 print ' ' + os.path.join(srcdir, 'PmwColor.py')