3 # A simple converter to convert splashy themes to fbsplash format.
5 # Copyright (C) 2008, Michal Januszewski <spock@gentoo.org>
7 # This file is a part of the splashutils package.
9 # This file is subject to the terms and conditions of the GNU General Public
10 # License v2. See the file COPYING in the main directory of this archive for
13 import os
, sys
, shutil
14 import xml
.etree
.ElementTree
as et
18 print 'splashy2fbsplash/splashutils'
19 print 'Usage: %s <path/theme.xml> <fbsplash_name>' % sys
.argv
[0]
21 print 'A splashy to fbsplash theme converter.'
28 f
= open(sys
.argv
[1], 'r');
31 print >>sys
.stderr
, 'Failed to open or parse %s' % sys
.argv
[1]
35 os
.mkdir('@themedir@/%s' % (sys
.argv
[2]))
36 os
.mkdir('@themedir@/%s/images' % (sys
.argv
[2]))
38 print >>sys
.stderr
, 'Failed to create @themedir@/%s' % sys
.argv
[2]
42 return (int(el
.find('color/red').text
) * 0x1000000 +
43 int(el
.find('color/green').text
) * 0x10000 +
44 int(el
.find('color/blue').text
) * 0x100 +
45 int(el
.find('color/alpha').text
))
47 def processBorder(el
, x
, y
, w
, h
):
48 if el
.find('border/enable').text
== 'yes':
49 print >>out
, '# Border'
50 brdcol
= getColor(prg
.find('border'))
51 print >>out
, 'box silent %d %d %d %d #%08x' % (x
- 1, y
- 1, x
+ w
+ 1, y
- 1, brdcol
)
52 print >>out
, 'box silent %d %d %d %d #%08x' % (x
- 1, y
+ h
+ 1, x
+ w
+ 1, y
+ h
+ 1, brdcol
)
53 print >>out
, 'box silent %d %d %d %d #%08x' % (x
- 1, y
, x
- 1, y
+ h
, brdcol
)
54 print >>out
, 'box silent %d %d %d %d #%08x' % (x
+ w
+ 1, y
, x
+ w
+ 1, y
+ h
, brdcol
)
57 if int(d
.find('background/dimension/width').text
) > 0 and int(d
.find('background/dimension/height').text
) > 0:
62 def getSize(size
, type):
66 return size
* im
.size
[type] / 100
68 ## Process the background picture.
69 ## -------------------------------
72 def appendType(list, type):
78 if type == 'shutdown':
83 i
= d
.find('background/%s' % type).text
84 if not images
.has_key(i
):
86 appendType(images
[i
], type);
89 processImg('shutdown')
93 im
= Image
.open('%s/%s' % (os
.path
.dirname(sys
.argv
[1]), d
.find('background/boot').text
))
94 res
= '%dx%d' % (im
.size
[0], im
.size
[1])
96 out
= open('@themedir@/%s/%s.cfg' % (sys
.argv
[2], res
), 'w')
98 print >>out
, '# Background images'
99 for k
, v
in images
.iteritems():
100 print >>out
, '<type %s>' % ' '.join(v
)
101 print >>out
, ' silentpic = images/%s' % k
102 print >>out
, '</type>'
103 shutil
.copy('%s/%s' % (os
.path
.dirname(sys
.argv
[1]), k
),
104 '@themedir@/%s/images/%s' % (sys
.argv
[2], k
))
107 ## Process the progress bar.
108 ## -------------------------
109 print >>out
, '## Progress bar'
110 prg
= d
.find('progressbar')
115 for type in ['boot', 'shutdown', 'resume', 'suspend']:
116 if prg
.find('visibility/' + type).text
== 'yes':
117 if prg
.find('direction/' + type).text
== 'forward':
118 appendType(forward
, type)
120 appendType(backward
, type)
122 dim
= prg
.find('dimension')
123 x
= getSize(int(dim
.find('x').text
), 0)
124 y
= getSize(int(dim
.find('y').text
), 1)
125 w
= getSize(int(dim
.find('width').text
), 0)
126 h
= getSize(int(dim
.find('height').text
), 1)
128 processBorder(prg
, x
, y
, w
, h
)
130 print >>out
, '# Background'
131 print >>out
, 'box silent %d %d %d %d #%08x' % (x
, y
, x
+ w
, y
+ h
, getColor(prg
.find('background')))
133 print >>out
, '# Progress bar(s)'
136 print >>out
, '<type %s>' % (' '.join(forward
))
137 print >>out
, ' box silent inter %d %d %d %d #%08x' % (x
, y
, x
, y
, getColor(prg
))
138 print >>out
, ' box silent %d %d %d %d #%08x' % (x
, y
, x
+ w
, y
+ h
, getColor(prg
))
139 print >>out
, '</type>'
142 print >>out
, '<type %s>' % (' '.join(backward
))
143 print >>out
, ' box silent inter %d %d %d %d #%8x' % (x
, y
, x
+ w
, y
+ h
, getColor(prg
))
144 print >>out
, ' box silent %d %d %d %d #%8x' % (x
, y
, x
, y
, getColor(prg
))
145 print >>out
, '</type>'
149 ## Process the textbox.
150 ## --------------------
151 print >>out
, '## Textbox'
152 txt
= d
.find('textbox')
153 dim
= txt
.find('dimension')
155 x
= getSize(int(dim
.find('x').text
), 0)
156 y
= getSize(int(dim
.find('y').text
), 1)
157 w
= getSize(int(dim
.find('width').text
), 0)
158 h
= getSize(int(dim
.find('height').text
), 1)
160 processBorder(txt
, x
, y
, w
, h
)
162 print >>out
, '# Background'
163 print >>out
, 'box silent %d %d %d %d #%08x' % (x
, y
, x
+ w
, y
+ h
, getColor(txt
))
165 print >>out
, '# Text area'
166 print >>out
, 'text %s %s %d %d #%08x msglog' % (txt
.find('text/font/file').text
, txt
.find('text/font/height').text
,
167 x
, y
, getColor(txt
.find('text')))
169 print >>out
, 'log_lines = %d' % (h
/ (int(txt
.find('text/font/height').text
) * 1.3))
171 shutil
.copy('%s/%s' % (os
.path
.dirname(sys
.argv
[1]), txt
.find('text/font/file').text
),
172 '@themedir@/%s/%s' % (sys
.argv
[2], txt
.find('text/font/file').text
))