]>
Dogcows Code - chaz/openbox/blob - tools/themeupdate/themeupdate.py
3 # themeupdate.py for the Openbox window manager
4 # Copyright (c) 2003 Ben Jansens
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # See the COPYING file for a copy of the GNU General Public License.
29 inp
= sys
.stdin
.readline(1).strip()
30 if inp
== 'y' or inp
== '': return True
31 if inp
== 'n': return False
34 key
= line
[:line
.find(':')].strip()
35 value
= line
[line
.find(':') + 1:].strip()
36 if not (key
and value
):
40 def find_key(data
, keysubstr
, exact
= False):
45 key
, value
= getkeyval(l
)
47 if (exact
and key
== keysubstr
) or \
48 (not exact
and key
.find(keysubstr
) != -1):
53 def simple_replace(data
):
55 pairs
['.picColor'] = '.imageColor'
56 pairs
['menu.frame'] = 'menu.items'
57 pairs
['menu.hilite'] = 'menu.selected'
58 pairs
['borderColor'] = 'border.color'
59 pairs
['imageColor'] = 'image.color'
60 pairs
['textColor'] = 'text.color'
61 pairs
['interlaceColor'] = 'interlace.color'
63 for k
in pairs
.keys():
65 i
, key
, nul
= find_key(data
, k
);
67 newl
= data
[i
].replace(k
, pairs
[k
])
68 out('Updating "' + key
+
69 '" to "' + key
.replace(k
, pairs
[k
]) + '"\n')
75 pairs
['window.focus.font'] = 'window.active.label.text.font'
76 pairs
['window.unfocus.font'] = 'window.inactive.label.text.font'
77 pairs
['window.justify'] = 'window.label.justify'
78 pairs
['menu.frame.disableColor'] = 'menu.disabled.textColor'
79 pairs
['window.label.focus.font'] = 'window.active.label.text.font'
80 pairs
['window.label.unfocus.font'] = 'window.inactive.label.text.font'
81 pairs
['window.label.justify'] = 'window.label.text.justify'
82 pairs
['menu.title.font'] = 'menu.title.text.font'
83 pairs
['menu.title.justify'] = 'menu.title.text.justify'
84 pairs
['menuOverlap'] = 'menu.overlap'
85 pairs
['handleWidth'] = 'window.handle.width'
86 pairs
['borderWidth'] = 'border.width'
87 pairs
['bevelWidth'] = 'padding.width'
88 pairs
['frameWidth'] = 'window.client.padding.width'
89 pairs
['window.frame.focusColor'] = 'window.active.client.color'
90 pairs
['window.frame.unfocusColor'] = 'window.inactive.client.color'
91 pairs
['window.title.focus'] = 'window.active.title.bg'
92 pairs
['window.title.unfocus'] = 'window.inactive.title.bg'
93 pairs
['window.label.focus'] = 'window.active.label.bg'
94 pairs
['window.label.unfocus'] = 'window.inactive.label.bg'
95 pairs
['window.handle.focus'] = 'window.active.handle.bg'
96 pairs
['window.handle.unfocus'] = 'window.inactive.handle.bg'
97 pairs
['window.grip.focus'] = 'window.active.grip.bg'
98 pairs
['window.grip.unfocus'] = 'window.inactive.grip.bg'
99 pairs
['menu.items'] = 'menu.items.bg'
100 pairs
['menu.title'] = 'menu.title.bg'
101 pairs
['menu.selected'] = 'menu.items.active.bg'
102 pairs
['window.title.focus'] = 'window.active.title.bg'
103 pairs
['window.label.focus'] = 'window.active.label.bg'
104 pairs
['window.title.unfocus'] = 'window.inactive.title.bg'
105 pairs
['window.label.unfocus'] = 'window.inactive.label.bg'
106 pairs
['window.button.disabled.focus'] = 'window.active.button.disabled.bg'
107 pairs
['window.button.disabled.unfocus'] = \
108 'window.inactive.button.disabled.bg'
109 pairs
['window.button.pressed.focus'] = 'window.active.button.pressed.bg'
110 pairs
['window.button.pressed.unfocus'] = \
111 'window.inactive.button.pressed.bg'
112 pairs
['window.button.toggled.focus'] = 'window.active.button.toggled.bg'
113 pairs
['window.button.toggled.unfocus'] = \
114 'window.inactive.button.toggled.bg'
115 pairs
['window.button.focus'] = 'window.active.button.unpressed.bg'
116 pairs
['window.button.unfocus'] = 'window.inactive.button.unpressed.bg'
117 pairs
['window.button.hover.focus'] = 'window.active.button.hover.bg'
118 pairs
['window.button.hover.unfocus'] = 'window.inactive.button.hover.bg'
120 for k
in pairs
.keys():
122 i
, key
, nul
= find_key(data
, k
, True);
124 newl
= data
[i
].replace(k
, pairs
[k
])
125 out('Updating "' + key
+
126 '" to "' + key
.replace(k
, pairs
[k
]) + '"\n')
132 pairs
['window.title.focus'] = 'window.active.title'
133 pairs
['window.title.unfocus'] = 'window.inactive.title'
134 pairs
['window.label.focus'] = 'window.active.label'
135 pairs
['window.label.unfocus'] = 'window.inactive.label'
136 pairs
['window.handle.focus'] = 'window.active.handle'
137 pairs
['window.handle.unfocus'] = 'window.inactive.handle'
138 pairs
['window.grip.focus'] = 'window.active.grip'
139 pairs
['window.grip.unfocus'] = 'window.inactive.grip'
140 pairs
['menu.selected'] = 'menu.items.active'
141 pairs
['window.title.focus'] = 'window.active.title'
142 pairs
['window.label.focus'] = 'window.active.label'
143 pairs
['window.title.unfocus'] = 'window.inactive.title'
144 pairs
['window.label.unfocus'] = 'window.inactive.label'
145 pairs
['window.button.disabled.focus'] = 'window.active.button.disabled'
146 pairs
['window.button.disabled.unfocus'] = \
147 'window.inactive.button.disabled'
148 pairs
['window.button.pressed.focus'] = 'window.active.button.pressed'
149 pairs
['window.button.pressed.unfocus'] = \
150 'window.inactive.button.pressed'
151 pairs
['window.button.toggled.focus'] = 'window.active.button.toggled'
152 pairs
['window.button.toggled.unfocus'] = \
153 'window.inactive.button.toggled'
154 pairs
['window.button.focus'] = 'window.active.button'
155 pairs
['window.button.unfocus'] = 'window.inactive.button'
156 pairs
['window.button.hover.focus'] = 'window.active.button.hover'
157 pairs
['window.button.hover.unfocus'] = 'window.inactive.button.hover'
158 pairs
['window.label.unfocus'] = 'window.inactive.label'
159 pairs
['window.label.focus'] = 'window.active.label'
160 pairs
['window.button.focus'] = 'window.active.button.unpressed'
161 pairs
['menu.disabled'] = 'menu.items.disabled'
162 pairs
['menu.selected'] = 'menu.items.active'
163 pairs
['window.button.unfocus'] = 'window.inactive.button.unpressed'
164 pairs
['window.button.pressed.focus'] = 'window.active.button.pressed'
165 pairs
['window.button.pressed.unfocus'] = 'window.inactive.button.pressed'
166 pairs
['window.button.disabled.focus'] = 'window.active.button.disabled'
167 pairs
['window.button.disabled.unfocus'] = 'window.inactive.button.disabled'
168 pairs
['window.button.hover.focus'] = 'window.active.button.hover'
169 pairs
['window.button.hover.unfocus'] = 'window.inactive.button.hover'
170 pairs
['window.button.toggled.focus'] = 'window.active.button.toggled'
171 pairs
['window.button.toggled.unfocus'] = 'window.inactive.button.toggled'
173 for k
in pairs
.keys():
175 i
, key
, nul
= find_key(data
, k
);
177 newl
= data
[i
].replace(k
, pairs
[k
])
178 out('Updating "' + key
+
179 '" to "' + key
.replace(k
, pairs
[k
]) + '"\n')
184 def replace_colors(data
):
189 key
, value
= getkeyval(l
)
191 if key
.find('.color') != -1:
192 if key
.find('client.color') == -1 \
193 and key
.find('image.color') == -1 \
194 and key
.find('bg.color') == -1 \
195 and key
.find('border.color') == -1 \
196 and key
.find('interlace.color') == -1 \
197 and key
.find('text.color') == -1:
198 newl
= data
[i
].replace('.color', '.bg.color')
199 out('Updating "' + key
+
200 '" to "' + key
.replace('.color', '.bg.color') + '"\n')
202 if key
.find('.border.color') != -1 \
203 and key
.find('bg.border.color') == -1:
204 newl
= data
[i
].replace('.border.color', '.bg.border.color')
205 out('Updating "' + key
+
206 '" to "' + key
.replace('.border.color',
207 '.bg.border.color') + '"\n')
209 if key
.find('.interlace.color') != -1 \
210 and key
.find('bg.interlace.color') == -1:
211 newl
= data
[i
].replace('.interlace.color',
212 '.bg.interlace.color')
213 out('Updating "' + key
+
214 '" to "' + key
.replace('.interlace.color',
215 '.bg.interlace.color') + '"\n')
221 invalid
.append('toolbar')
224 i
, key
, nul
= find_key(data
, inv
)
226 out(key
+ ' is no longer supported.\nRemove (Y/n)? ')
228 out('Removing "' + key
+ '"\n')
232 invalid
.append('rootCommand')
233 invalid
.append('menu.bullet')
234 invalid
.append('menu.bullet.image.color')
235 invalid
.append('menu.bullet.selected.image.color')
236 invalid
.append('menu.frame.justify')
239 i
, key
, nul
= find_key(data
, inv
, True)
241 out(key
+ ' is no longer supported.\nRemove (Y/n)? ')
243 out('Removing "' + key
+ '"\n')
249 i
, nul
, nul
= find_key(data
, 'window.button.pressed', True)
251 out('The window.button.pressed option has been replaced by ' +
252 'window.button.pressed.focus and ' +
253 'window.button.pressed.unfocus.\nUpdate (Y/n)? ')
256 out('Removing "window.button.pressed"\n')
258 out('Adding "window.button.pressed.unfocus"\n')
259 data
.insert(i
, l
.replace('window.button.pressed',
260 'window.button.pressed.unfocus'))
261 out('Adding "window.button.pressed.focus"\n')
262 data
.insert(i
, l
.replace('window.button.pressed',
263 'window.button.pressed.focus'))
266 i
, nul
, nul
= find_key(data
, 'window.font')
268 out('You appear to specify fonts using the old X fonts ' +
269 'syntax.\nShall I remove all fonts from the theme (Y/n)? ')
274 i
, key
= key_find(data
, '.font')
277 out('Removing "' + key
+ '"\n')
281 i
, nul
, nul
= find_key(data
, '.xft.')
283 out('You appear to specify fonts using the old Xft fonts ' +
284 'syntax.\nShall I update these to the new syntax (Y/n)? ')
289 fonts
['window'] = 'window.label.focus.font'
290 fonts
['menu.items'] = 'menu.items.font'
291 fonts
['menu.title'] = 'menu.title.font'
292 for f
in fonts
.keys():
293 li
, nul
, flags
= find_key(data
, f
+ '.xft.flags')
295 li
, nul
, flags
= find_key(data
, '*.xft.flags')
297 out('Removing ' + f
+ '.xft.flags\n')
299 oi
, nul
, offset
= find_key(data
, f
+ '.xft.shadow.offset')
301 oi
, nul
, offset
= find_key(data
, '*.xft.shadow.offset')
303 out('Removing ' + f
+ '.xft.shadow.offset\n')
305 ti
, nul
, tint
= find_key(data
, f
+ '.xft.shadow.tint')
307 ti
, nul
, tint
= find_key(data
, '*.xft.shadow.tint')
309 out('Removing ' + f
+ '.xft.shadow.tint\n')
311 fi
, nul
, face
= find_key(data
, f
+ '.xft.font')
313 fi
, nul
, face
= find_key(data
, '*.xft.font')
314 if fi
>= 0: fi
= len(data
) - 1
316 out('Removing ' + f
+ '.xft.font\n')
322 if flags
.find('bold'):
324 if flags
.find('shadow'):
327 s
= s
+ ':shadowoffset=' + offset
329 s
= s
+ ':shadowtint=' + tint
330 out('Adding ' + fonts
[f
] + '\n')
331 data
.insert(fi
, fonts
[f
] + ': ' + s
)
333 for stars
in ('*.xft.flags', '*.xft.shadow.offset' ,
334 '*.xft.shadow.tint', '*.xft.font'):
335 i
, key
, nul
= find_key(data
, stars
)
337 out('Removing ' + key
+ '\n')
341 fonts
= ('window.label.focus.font',
345 i
, key
, value
= find_key(data
, f
, True)
347 if value
.find('pixelsize') == -1:
348 out('*** ERROR *** The ' + key
+ ' font size is not being '
349 'specified by pixelsize. It is recommended that you use '
350 'pixelsize instead of pointsize for specifying theme '
351 'fonts. e.g. "sans:pixelsize=12"\n')
355 def warn_missing(data
):
356 need
= ('window.active.button.hover', 'window.inactive.button.hover',
359 i
, nul
, nul
= find_key(data
, n
)
361 out('The ' + n
+ ' value was not found in the theme, but it '
362 'can optionally be set.\n')
364 def err_missing(data
):
365 need
= ('window.active.button.disabled',
366 'window.inactive.button.disabled',
367 'window.active.client.color',
368 'window.inactive.client.color')
370 i
, nul
, nul
= find_key(data
, n
)
372 out('*** ERROR *** The ' + n
+ ' value was not found in the '
373 'theme, but it is required to be set.\n')
379 out('Usage: themupdate.py /path/to/themerc > newthemerc\n\n')
383 file = open(sys
.argv
[1])
387 out('Unable to open file "' + sys
.argv
[1] + '"\n\n')
390 data
= file.readlines()
391 for i
in range(len(data
)):
392 data
[i
] = data
[i
].strip()
This page took 0.058291 seconds and 4 git commands to generate.