tools/themeupdate/themeupdate.py (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
#! /usr/bin/python # themeupdate.py for the Openbox window manager # Copyright (c) 2003 Ben Jansens # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # See the COPYING file for a copy of the GNU General Public License. import sys data = [] valid = True def out(str): sys.stderr.write(str) sys.stderr.flush() def read_bool(): while True: inp = sys.stdin.readline(1).strip() if inp == 'y' or inp == '': return True if inp == 'n': return False def getkeyval(line): key = line[:line.find(':')].strip() value = line[line.find(':') + 1:].strip() if not (key and value): key = value = None return key, value def find_key(data, keysubstr, exact = False): i = 0 n = len(data) while i < n: l = data[i] key, value = getkeyval(l) if key and value: if (exact and key == keysubstr) or \ (not exact and key.find(keysubstr) != -1): return i, key, value i += 1 return -1, None, None def simple_replace(data): pairs = {} pairs['.picColor'] = '.imageColor' pairs['menu.frame'] = 'menu.items' pairs['menu.hilite'] = 'menu.selected' pairs['borderColor'] = 'border.color' pairs['imageColor'] = 'image.color' pairs['textColor'] = 'text.color' pairs['interlaceColor'] = 'interlace.color' for k in pairs.keys(): while 1: i, key, nul = find_key(data, k); if i >= 0: newl = data[i].replace(k, pairs[k]) out('Updating "' + key + '" to "' + key.replace(k, pairs[k]) + '"\n') data[i] = newl else: break pairs = {} pairs['window.focus.font'] = 'window.active.label.text.font' pairs['window.unfocus.font'] = 'window.inactive.label.text.font' pairs['window.justify'] = 'window.label.justify' pairs['menu.frame.disableColor'] = 'menu.disabled.textColor' pairs['window.label.focus.font'] = 'window.active.label.text.font' pairs['window.label.unfocus.font'] = 'window.inactive.label.text.font' pairs['window.label.justify'] = 'window.label.text.justify' pairs['menu.title.font'] = 'menu.title.text.font' pairs['menu.title.justify'] = 'menu.title.text.justify' pairs['menuOverlap'] = 'menu.overlap' pairs['handleWidth'] = 'window.handle.width' pairs['borderWidth'] = 'border.width' pairs['bevelWidth'] = 'padding.width' pairs['frameWidth'] = 'window.client.padding.width' pairs['window.frame.focusColor'] = 'window.active.client.color' pairs['window.frame.unfocusColor'] = 'window.inactive.client.color' pairs['window.title.focus'] = 'window.active.title.bg' pairs['window.title.unfocus'] = 'window.inactive.title.bg' pairs['window.label.focus'] = 'window.active.label.bg' pairs['window.label.unfocus'] = 'window.inactive.label.bg' pairs['window.handle.focus'] = 'window.active.handle.bg' pairs['window.handle.unfocus'] = 'window.inactive.handle.bg' pairs['window.grip.focus'] = 'window.active.grip.bg' pairs['window.grip.unfocus'] = 'window.inactive.grip.bg' pairs['menu.items'] = 'menu.items.bg' pairs['menu.title'] = 'menu.title.bg' pairs['menu.selected'] = 'menu.items.active.bg' pairs['window.title.focus'] = 'window.active.title.bg' pairs['window.label.focus'] = 'window.active.label.bg' pairs['window.title.unfocus'] = 'window.inactive.title.bg' pairs['window.label.unfocus'] = 'window.inactive.label.bg' pairs['window.button.disabled.focus'] = 'window.active.button.disabled.bg' pairs['window.button.disabled.unfocus'] = \ 'window.inactive.button.disabled.bg' pairs['window.button.pressed.focus'] = 'window.active.button.pressed.bg' pairs['window.button.pressed.unfocus'] = \ 'window.inactive.button.pressed.bg' pairs['window.button.toggled.focus'] = 'window.active.button.toggled.bg' pairs['window.button.toggled.unfocus'] = \ 'window.inactive.button.toggled.bg' pairs['window.button.focus'] = 'window.active.button.unpressed.bg' pairs['window.button.unfocus'] = 'window.inactive.button.unpressed.bg' pairs['window.button.hover.focus'] = 'window.active.button.hover.bg' pairs['window.button.hover.unfocus'] = 'window.inactive.button.hover.bg' for k in pairs.keys(): while 1: i, key, nul = find_key(data, k, True); if i >= 0: newl = data[i].replace(k, pairs[k]) out('Updating "' + key + '" to "' + key.replace(k, pairs[k]) + '"\n') data[i] = newl else: break pairs = {} pairs['window.title.focus'] = 'window.active.title' pairs['window.title.unfocus'] = 'window.inactive.title' pairs['window.label.focus'] = 'window.active.label' pairs['window.label.unfocus'] = 'window.inactive.label' pairs['window.handle.focus'] = 'window.active.handle' pairs['window.handle.unfocus'] = 'window.inactive.handle' pairs['window.grip.focus'] = 'window.active.grip' pairs['window.grip.unfocus'] = 'window.inactive.grip' pairs['menu.selected'] = 'menu.items.active' pairs['window.title.focus'] = 'window.active.title' pairs['window.label.focus'] = 'window.active.label' pairs['window.title.unfocus'] = 'window.inactive.title' pairs['window.label.unfocus'] = 'window.inactive.label' pairs['window.button.disabled.focus'] = 'window.active.button.disabled' pairs['window.button.disabled.unfocus'] = \ 'window.inactive.button.disabled' pairs['window.button.pressed.focus'] = 'window.active.button.pressed' pairs['window.button.pressed.unfocus'] = \ 'window.inactive.button.pressed' pairs['window.button.toggled.focus'] = 'window.active.button.toggled' pairs['window.button.toggled.unfocus'] = \ 'window.inactive.button.toggled' pairs['window.button.focus'] = 'window.active.button' pairs['window.button.unfocus'] = 'window.inactive.button' pairs['window.button.hover.focus'] = 'window.active.button.hover' pairs['window.button.hover.unfocus'] = 'window.inactive.button.hover' pairs['window.label.unfocus'] = 'window.inactive.label' pairs['window.label.focus'] = 'window.active.label' pairs['window.button.focus'] = 'window.active.button.unpressed' pairs['menu.disabled'] = 'menu.items.disabled' pairs['menu.selected'] = 'menu.items.active' pairs['window.button.unfocus'] = 'window.inactive.button.unpressed' pairs['window.button.pressed.focus'] = 'window.active.button.pressed' pairs['window.button.pressed.unfocus'] = 'window.inactive.button.pressed' pairs['window.button.disabled.focus'] = 'window.active.button.disabled' pairs['window.button.disabled.unfocus'] = 'window.inactive.button.disabled' pairs['window.button.hover.focus'] = 'window.active.button.hover' pairs['window.button.hover.unfocus'] = 'window.inactive.button.hover' pairs['window.button.toggled.focus'] = 'window.active.button.toggled' pairs['window.button.toggled.unfocus'] = 'window.inactive.button.toggled' for k in pairs.keys(): while 1: i, key, nul = find_key(data, k); if i >= 0: newl = data[i].replace(k, pairs[k]) out('Updating "' + key + '" to "' + key.replace(k, pairs[k]) + '"\n') data[i] = newl else: break def replace_colors(data): i = 0 n = len(data) while i < n: l = data[i] key, value = getkeyval(l) if key and value: if key.find('.color') != -1: if key.find('client.color') == -1 \ and key.find('image.color') == -1 \ and key.find('bg.color') == -1 \ and key.find('border.color') == -1 \ and key.find('interlace.color') == -1 \ and key.find('text.color') == -1: newl = data[i].replace('.color', '.bg.color') out('Updating "' + key + '" to "' + key.replace('.color', '.bg.color') + '"\n') data[i] = newl if key.find('.border.color') != -1 \ and key.find('bg.border.color') == -1: newl = data[i].replace('.border.color', '.bg.border.color') out('Updating "' + key + '" to "' + key.replace('.border.color', '.bg.border.color') + '"\n') data[i] = newl if key.find('.interlace.color') != -1 \ and key.find('bg.interlace.color') == -1: newl = data[i].replace('.interlace.color', '.bg.interlace.color') out('Updating "' + key + '" to "' + key.replace('.interlace.color', '.bg.interlace.color') + '"\n') data[i] = newl i += 1 def remove(data): invalid = [] invalid.append('toolbar') for inv in invalid: while 1: i, key, nul = find_key(data, inv) if i >= 0: out(key + ' is no longer supported.\nRemove (Y/n)? ') if read_bool(): out('Removing "' + key + '"\n') data.pop(i) else: break invalid.append('rootCommand') invalid.append('menu.bullet') invalid.append('menu.bullet.image.color') invalid.append('menu.bullet.selected.image.color') invalid.append('menu.frame.justify') for inv in invalid: while 1: i, key, nul = find_key(data, inv, True) if i >= 0: out(key + ' is no longer supported.\nRemove (Y/n)? ') if read_bool(): out('Removing "' + key + '"\n') data.pop(i) else: break def pressed(data): i, nul, nul = find_key(data, 'window.button.pressed', True) if i >= 0: out('The window.button.pressed option has been replaced by ' + 'window.button.pressed.focus and ' + 'window.button.pressed.unfocus.\nUpdate (Y/n)? ') if read_bool(): l = data[i] out('Removing "window.button.pressed"\n') data.pop(i) out('Adding "window.button.pressed.unfocus"\n') data.insert(i, l.replace('window.button.pressed', 'window.button.pressed.unfocus')) out('Adding "window.button.pressed.focus"\n') data.insert(i, l.replace('window.button.pressed', 'window.button.pressed.focus')) def x_fonts(data): i, nul, nul = find_key(data, 'window.font') if i >= 0: out('You appear to specify fonts using the old X fonts ' + 'syntax.\nShall I remove all fonts from the theme (Y/n)? ') if not read_bool(): return else: return while 1: i, key = key_find(data, '.font') if i < 0: break out('Removing "' + key + '"\n') data.pop(i) def xft_fonts(data): i, nul, nul = find_key(data, '.xft.') if i >= 0: out('You appear to specify fonts using the old Xft fonts ' + 'syntax.\nShall I update these to the new syntax (Y/n)? ') if not read_bool(): return else: return fonts = {} fonts['window'] = 'window.label.focus.font' fonts['menu.items'] = 'menu.items.font' fonts['menu.title'] = 'menu.title.font' for f in fonts.keys(): li, nul, flags = find_key(data, f + '.xft.flags') if li < 0: li, nul, flags = find_key(data, '*.xft.flags') else: out('Removing ' + f + '.xft.flags\n') data.pop(li) oi, nul, offset = find_key(data, f + '.xft.shadow.offset') if oi < 0: oi, nul, offset = find_key(data, '*.xft.shadow.offset') else: out('Removing ' + f + '.xft.shadow.offset\n') data.pop(oi) ti, nul, tint = find_key(data, f + '.xft.shadow.tint') if ti < 0: ti, nul, tint = find_key(data, '*.xft.shadow.tint') else: out('Removing ' + f + '.xft.shadow.tint\n') data.pop(ti) fi, nul, face = find_key(data, f + '.xft.font') if fi < 0: fi, nul, face = find_key(data, '*.xft.font') if fi >= 0: fi = len(data) - 1 else: out('Removing ' + f + '.xft.font\n') data.pop(fi) if fi >= 0: s = face if li >= 0: if flags.find('bold'): s = s + ':bold' if flags.find('shadow'): s = s + ':shadow=y' if oi >= 0: s = s + ':shadowoffset=' + offset if ti >= 0: s = s + ':shadowtint=' + tint out('Adding ' + fonts[f] + '\n') data.insert(fi, fonts[f] + ': ' + s) for stars in ('*.xft.flags', '*.xft.shadow.offset' , '*.xft.shadow.tint', '*.xft.font'): i, key, nul = find_key(data, stars) if i >= 0: out('Removing ' + key + '\n') data.pop(i) def pixelsize(data): fonts = ('window.label.focus.font', 'menu.items.font', 'menu.title.font') for f in fonts: i, key, value = find_key(data, f, True) if value: if value.find('pixelsize') == -1: out('*** ERROR *** The ' + key + ' font size is not being ' 'specified by pixelsize. It is recommended that you use ' 'pixelsize instead of pointsize for specifying theme ' 'fonts. e.g. "sans:pixelsize=12"\n') global valid valid = False def warn_missing(data): need = ('window.active.button.hover', 'window.inactive.button.hover', 'menu.overlap') for n in need: i, nul, nul = find_key(data, n) if i < 0: out('The ' + n + ' value was not found in the theme, but it ' 'can optionally be set.\n') def err_missing(data): need = ('window.active.button.disabled', 'window.inactive.button.disabled', 'window.active.client.color', 'window.inactive.client.color') for n in need: i, nul, nul = find_key(data, n) if i < 0: out('*** ERROR *** The ' + n + ' value was not found in the ' 'theme, but it is required to be set.\n') global valid valid = False def usage(): out('Usage: themupdate.py /path/to/themerc > newthemerc\n\n') sys.exit() try: file = open(sys.argv[1]) except IndexError: usage() except IOError: out('Unable to open file "' + sys.argv[1] + '"\n\n') usage() data = file.readlines() for i in range(len(data)): data[i] = data[i].strip() simple_replace(data) replace_colors(data) remove(data) pressed(data) x_fonts(data) xft_fonts(data) pixelsize(data) warn_missing(data) err_missing(data) for l in data: print l sys.exit(not valid) |