14 inp = sys.stdin.readline(1).strip()
15 if inp == 'y' or inp == '': return True
16 if inp == 'n': return False
19 key = line[:line.find(':')].strip()
20 value = line[line.find(':') + 1:].strip()
21 if not (key and value):
25 def find_key(data, keysubstr, exact = False):
30 key, value = getkeyval(l)
32 if (exact and key == keysubstr) or \
33 (not exact and key.find(keysubstr) != -1):
38 def simple_replace(data):
40 pairs['window.focus.font'] = 'window.label.focus.font'
41 pairs['window.unfocus.font'] = 'window.label.unfocus.font'
42 pairs['window.justify'] = 'window.label.justify'
43 pairs['menu.frame.disableColor'] = 'menu.disabled.textColor'
44 pairs['menu.frame'] = 'menu.items'
45 pairs['menu.hilite'] = 'menu.selected'
46 pairs['.picColor'] = '.imageColor'
48 for k in pairs.keys():
50 i, key, nul = find_key(data, k);
52 newl = data[i].replace(k, pairs[k])
53 out('Updating "' + key +
54 '" to "' + key.replace(k, pairs[k]) + '"\n')
61 invalid.append('toolbar')
62 invalid.append('menu.bullet')
63 invalid.append('rootCommand')
64 invalid.append('menu.frame.justify')
67 i, key, nul = find_key(data, inv)
69 out(key + ' is no longer supported.\nRemove (Y/n)? ')
71 out('Removing "' + key + '"\n')
77 i, nul, nul = find_key(data, 'window.button.pressed', True)
79 out('The window.button.pressed option has been replaced by ' +
80 'window.button.pressed.focus and ' +
81 'window.button.pressed.unfocus.\nUpdate (Y/n)? ')
84 out('Removing "window.button.pressed"\n')
86 out('Adding "window.button.pressed.unfocus"\n')
87 data.insert(i, l.replace('window.button.pressed',
88 'window.button.pressed.unfocus'))
89 out('Adding "window.button.pressed.focus"\n')
90 data.insert(i, l.replace('window.button.pressed',
91 'window.button.pressed.focus'))
94 i, nul, nul = find_key(data, 'window.font')
96 out('You appear to specify fonts using the old X fonts ' +
97 'syntax.\nShall I remove all fonts from the theme (Y/n)? ')
102 i, key = key_find(data, '.font')
105 out('Removing "' + key + '"\n')
109 i, nul, nul = find_key(data, '.xft.')
111 out('You appear to specify fonts using the old Xft fonts ' +
112 'syntax.\nShall I update these to the new syntax (Y/n)? ')
117 fonts['window'] = 'window.label.focus.font'
118 fonts['menu.items'] = 'menu.items.font'
119 fonts['menu.title'] = 'menu.title.font'
120 for f in fonts.keys():
121 li, nul, flags = find_key(data, f + '.xft.flags')
123 li, nul, flags = find_key(data, '*.xft.flags')
125 out('Removing ' + f + '.xft.flags\n')
127 oi, nul, offset = find_key(data, f + '.xft.shadow.offset')
129 oi, nul, offset = find_key(data, '*.xft.shadow.offset')
131 out('Removing ' + f + '.xft.shadow.offset\n')
133 ti, nul, tint = find_key(data, f + '.xft.shadow.tint')
135 ti, nul, tint = find_key(data, '*.xft.shadow.tint')
137 out('Removing ' + f + '.xft.shadow.tint\n')
139 fi, nul, face = find_key(data, f + '.xft.font')
141 fi, nul, face = find_key(data, '*.xft.font')
142 if fi >= 0: fi = len(data) - 1
144 out('Removing ' + f + '.xft.font\n')
150 if flags.find('bold'):
152 if flags.find('shadow'):
155 s = s + ':shadowoffset=' + offset
157 s = s + ':shadowtint=' + tint
158 out('Adding ' + fonts[f] + '\n')
159 data.insert(fi, fonts[f] + ': ' + s)
161 for stars in ('*.xft.flags', '*.xft.shadow.offset' ,
162 '*.xft.shadow.tint', '*.xft.font'):
163 i, key, nul = find_key(data, stars)
165 out('Removing ' + key + '\n')
169 fonts = ('window.label.focus.font',
173 i, key, value = find_key(data, f, True)
175 if value.find('pixelsize') == -1:
176 out('*** ERROR *** The ' + key + ' font size is not being '
177 'specified by pixelsize. It is recommended that you use '
178 'pixelsize instead of pointsize for specifying theme '
179 'fonts. e.g. "sans:pixelsize=12"\n')
183 def warn_missing(data):
184 need = ('window.button.hover.focus', 'window.button.hover.unfocus',
187 i, nul, nul = find_key(data, n)
189 out('The ' + n + ' value was not found in the theme, but it '
190 'can optionally be set.\n')
192 def err_missing(data):
193 need = ('window.button.disabled.focus', 'window.button.disabled.unfocus',
194 'window.frame.focusColor', 'window.frame.unfocusColor')
196 i, nul, nul = find_key(data, n)
198 out('*** ERROR *** The ' + n + ' value was not found in the '
199 'theme, but it is required to be set.\n')
205 out('Usage: themupdate.py /path/to/themerc > newthemerc\n\n')
209 file = open(sys.argv[1])
213 out('Unable to open file "' + sys.argv[1] + '"\n\n')
216 data = file.readlines()
217 for i in range(len(data)):
218 data[i] = data[i].strip()