3 from xml.dom import EMPTY_NAMESPACE
5 from Tools.XMLTools import elementsWithTag, mergeText
10 print " " * i + str(x)
12 for n in x.childNodes:
17 dom = xml.dom.minidom.parseString(
21 <color name="white" value="#ffffff" />
22 <color name="black" value="#000000" />
23 <color name="dark" value="#20294a6b" />
25 <color name="red" value="#ff0000" />
26 <color name="green" value="#00ff00" />
27 <color name="blue" value="#0000ff" />
28 <color name="yellow" value="#c0c000" />
30 <windowstyle type="skinned">
31 <color name="Background" color="#4075a7" />
32 <color name="LabelForeground" color="#ffffff" />
33 <color name="ListboxBackground" color="#4075a7" />
34 <color name="ListboxForeground" color="#ffffff" />
35 <color name="ListboxSelectedBackground" color="#404080" />
36 <color name="ListboxSelectedForeground" color="#ffffff" />
37 <color name="ListboxMarkedBackground" color="#ff0000" />
38 <color name="ListboxMarkedForeground" color="#ffffff" />
39 <borderset name="bsWindow">
40 <pixmap pos="bpTopLeft" filename="data/b_w_tl.png" />
41 <pixmap pos="bpTop" filename="data/b_w_t.png" />
42 <pixmap pos="bpTopRight" filename="data/b_w_tr.png" />
43 <pixmap pos="bpLeft" filename="data/b_w_l.png" />
44 <pixmap pos="bpRight" filename="data/b_w_r.png" />
45 <pixmap pos="bpBottomLeft" filename="data/b_w_bl.png" />
46 <pixmap pos="bpBottom" filename="data/b_w_b.png" />
47 <pixmap pos="bpBottomRight" filename="data/b_w_br.png" />
49 </windowstyle> """ """
50 <screen name="Menu" position="300,100" size="300,200" title="real main menu">
51 <!-- <widget name="okbutton" position="10,190" size="280,50" font="Arial;20" valign="center" halign="center" />-->
52 <widget name="title" position="10,10" size="280,20" />
53 <widget name="menu" position="10,30" size="280,200" />
55 <screen name="ScartLoopThrough" position="0,0" size="720,576">
57 <screen name="HarddiskSelection" position="140,165" size="360,100">
58 <widget name="hddlist" position="20,10" size="320,80" />
60 <screen name="HarddiskSetup" position="140,165" size="360,100">
61 <widget name="model" position="20,10" size="300,20" />
62 <widget name="capacity" position="20,30" size="300,20" />
63 <widget name="bus" position="20,50" size="300,20" />
64 <widget name="initialize" position="40,80" size="75,20" font="Arial;20" backgroundColor="red" />
66 <screen name="Setup" position="140,125" size="460,220" title="Setup">
67 <widget name="config" position="10,30" size="420,120" />
68 <widget name="ok" position="140,180" size="38,20" font="Arial;20" backgroundColor="green" />
69 <widget name="cancel" position="240,180" size="70,20" font="Arial;20" backgroundColor="red" />
71 <screen name="About" position="140,125" size="360,200" title="Setup">
72 <widget name="text" position="10,30" size="420,40" font="Arial;20"/>
73 <widget name="tuner" position="10,80" size="420,20"/>
74 <widget name="tunerA" position="10,100" size="420,20"/>
75 <widget name="tunerB" position="10,120" size="420,20"/>
76 <widget name="hdd" position="10,150" size="420,20"/>
77 <widget name="hddA" position="10,170" size="420,20"/>
79 <screen name="configOSD" position="140,125" size="460,350" title="OSD Settings">
80 <widget name="okbutton" position="20,245" size="205,40" />
81 <widget name="txt_alpha" position="20,20" size="110,20" />
82 <widget name="sld_alpha" position="150,20" size="290,20" />
83 <widget name="txt_brightness" position="20,60" size="120,20" />
84 <widget name="sld_brightness" position="150,20" size="290,20" />
85 <widget name="txt_gamma" position="20,100" size="120,20" />
86 <widget name="sld_gamma" position="150,100" size="290,20" />
88 <screen name="configTest" position="300,100" size="300,300" title="config menu">
89 <widget name="config" position="10,30" size="420,220" />
91 <screen name="TimerEditList" position="160,100" size="420,430" title="Timer Editor">
92 <widget name="timerlist" position="10,30" size="400,300" />
94 <screen name="clockDisplay" position="300,100" size="300,300">
95 <widget name="okbutton" position="10,10" size="280,40" />
96 <widget name="title" position="10,120" size="280,50" />
97 <widget name="theClock" position="10,60" size="280,50" />
99 <screen name="InfoBar" flags="wfNoBorder" position="0,380" size="720,148" title="InfoBar">
100 <ePixmap position="0,0" size="720,148" pixmap="data/info-bg.png" />
102 <widget name="ServiceName" position="69,25" size="427,26" valign="center" font="Arial;22" backgroundColor="#101258" />
103 <widget name="CurrentTime" position="575,10" size="90,30" backgroundColor="dark" font="Arial;19" />
104 <widget name="Volume" position="575,45" size="100,5" backgroundColor="dark" />
105 <widget name="Event_Now" position="273,68" size="282,30" font="Arial;22" backgroundColor="dark" />
106 <widget name="Event_Next" position="273,98" size="282,30" font="Arial;22" backgroundColor="dark" />
107 <widget name="Event_Now_Duration" position="555,68" size="70,26" font="Arial;22" backgroundColor="dark" />
108 <widget name="Event_Next_Duration" position="555,98" size="70,26" font="Arial;22" backgroundColor="dark" />
109 <!-- <eLabel position="70,0" size="300,30" text=".oO skin Oo." font="Arial;20" /> -->
111 <screen name="ChannelSelection" position="90,100" size="560,420" title="Channel Selection">
112 <widget name="list" position="0,50" size="560,320" />
113 <!-- <widget name="okbutton" position="340,50" size="140,30" />-->
114 <widget name="key_red" position="0,0" size="140,40" backgroundColor="red" />
115 <widget name="key_green" position="140,0" size="140,40" backgroundColor="green" />
116 <widget name="key_yellow" position="280,0" size="140,40" backgroundColor="yellow" />
117 <widget name="key_blue" position="420,0" size="140,40" backgroundColor="blue" />
119 <screen name="MovieSelection" position="150,100" size="400,420" title="Select-a-movie">
120 <widget name="list" position="0,50" size="400,300" />
122 <screen name="ServiceScan" position="150,100" size="300,90" title="Service Scan">
123 <widget name="scan_progress" position="10,10" size="300,20" />
124 <widget name="scan_state" position="10,40" size="280,30" />
126 <screen name="TimerEdit" position="70,100" size="590,335" title="Timer Edit">
127 <widget name="description" position="10,10" size="580,40" font="Arial;25" />
128 <widget name="lbegin" position="405,102" size="103,30" font="Arial;25" foregroundColor="red" />
129 <widget name="lend" position="405,158" size="103,30" font="Arial;25" foregroundColor="green" />
130 <widget name="begin" position="508,105" size="72,35" font="Arial;25" />
131 <widget name="end" position="508,150" size="72,35" font="Arial;25" />
132 <widget name="apply" position="10,240" size="250,35" />
134 <screen name="MessageBox" position="0,300" size="720,10" title="Message">
135 <widget name="text" position="0,0" size="500,0" font="Arial;25" />
136 <applet type="onLayoutFinish">
137 # this should be factored out into some helper code, but currently demonstrated applets.
138 from enigma import eSize, ePoint
140 orgwidth = self.instance.size().width()
141 orgpos = self.instance.position()
142 textsize = self["text"].getSize()
144 # y size still must be fixed in font stuff...
145 textsize = (textsize[0], textsize[1] + 20)
146 wsize = (textsize[0] + 20, textsize[1] + 20)
149 self.instance.resize(eSize(*wsize))
152 self["text"].instance.resize(eSize(*textsize))
156 self.instance.move(ePoint(orgpos.x() + (orgwidth - newwidth)/2, orgpos.y()))
161 def parsePosition(str):
162 x, y = str.split(',')
163 return ePoint(int(x), int(y))
166 x, y = str.split(',')
167 return eSize(int(x), int(y))
170 name, size = str.split(';')
171 return gFont(name, int(size))
176 return colorNames[str]
178 raise ("color '%s' must be #aarrggbb or valid named color" % (str))
179 return gRGB(int(str[1:], 0x10))
181 def collectAttributes(skinAttributes, node):
182 # walk all attributes
183 for p in range(node.attributes.length):
184 a = node.attributes.item(p)
186 # convert to string (was: unicode)
188 # TODO: proper UTF8 translation?! (for value)
189 # TODO: localization? as in e1?
192 skinAttributes.append((attrib, value))
194 def applySingleAttribute(guiObject, desktop, attrib, value):
197 if attrib == 'position':
198 guiObject.move(parsePosition(value))
199 elif attrib == 'size':
200 guiObject.resize(parseSize(value))
201 elif attrib == 'title':
202 guiObject.setTitle(value)
203 elif attrib == 'text':
204 guiObject.setText(value)
205 elif attrib == 'font':
206 guiObject.setFont(parseFont(value))
207 elif attrib == "pixmap":
209 if loadPNG(ptr, value):
210 raise "loading PNG failed!"
212 ptr = ptr.__deref__()
213 desktop.makeCompatiblePixmap(ptr)
214 guiObject.setPixmap(ptr)
215 # guiObject.setPixmapFromFile(value)
216 elif attrib == "valign":
219 { "top": guiObject.alignTop,
220 "center": guiObject.alignCenter,
221 "bottom": guiObject.alignBottom
224 print "valign must be either top, center or bottom!"
225 elif attrib == "halign":
228 { "left": guiObject.alignLeft,
229 "center": guiObject.alignCenter,
230 "right": guiObject.alignRight,
231 "block": guiObject.alignBlock
234 print "halign must be either left, center, right or block!"
235 elif attrib == "flags":
236 flags = value.split(',')
239 fv = eWindow.__dict__[f]
240 guiObject.setFlag(fv)
242 print "illegal flag %s!" % f
243 elif attrib == "backgroundColor":
244 guiObject.setBackgroundColor(parseColor(value))
245 elif attrib == "foregroundColor":
246 guiObject.setForegroundColor(parseColor(value))
247 elif attrib != 'name':
248 print "unsupported attribute " + attrib + "=" + value
251 print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib)
253 def applyAllAttributes(guiObject, desktop, attributes):
254 for (attrib, value) in attributes:
255 applySingleAttribute(guiObject, desktop, attrib, value)
257 def loadSkin(desktop):
258 print "loading skin..."
266 skin = dom.childNodes[0]
267 assert skin.tagName == "skin", "root element in skin must be 'skin'!"
269 for c in elementsWithTag(skin.childNodes, "colors"):
270 for color in elementsWithTag(c.childNodes, "color"):
271 name = str(color.getAttribute("name"))
272 color = str(color.getAttribute("value"))
275 raise ("need color and name, got %s %s" % (name, color))
277 colorNames[name] = parseColor(color)
279 for windowstyle in elementsWithTag(skin.childNodes, "windowstyle"):
280 style = eWindowStyleSkinned()
282 for borderset in elementsWithTag(windowstyle.childNodes, "borderset"):
283 bsName = str(borderset.getAttribute("name"))
284 for pixmap in elementsWithTag(borderset.childNodes, "pixmap"):
285 bpName = str(pixmap.getAttribute("pos"))
286 filename = str(pixmap.getAttribute("filename"))
288 png = getPNG(filename)
291 desktop.makeCompatiblePixmap(png)
292 style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png)
294 for color in elementsWithTag(windowstyle.childNodes, "color"):
295 type = str(color.getAttribute("name"))
296 color = parseColor(color.getAttribute("color"))
299 style.setColor(eWindowStyleSkinned.__dict__["col" + type], color)
301 raise ("Unknown color %s" % (type))
303 x = eWindowStyleManagerPtr()
304 eWindowStyleManager.getInstance(x)
307 def readSkin(screen, skin, name, desktop):
310 # first, find the corresponding screen element
311 skin = dom.childNodes[0]
313 for x in elementsWithTag(skin.childNodes, "screen"):
314 if x.getAttribute('name') == name:
318 assert myscreen != None, "no skin for screen '" + name + "' found!"
320 screen.skinAttributes = [ ]
321 collectAttributes(screen.skinAttributes, myscreen)
323 screen.additionalWidgets = [ ]
325 # now walk all widgets
326 for widget in elementsWithTag(myscreen.childNodes, "widget"):
327 wname = widget.getAttribute('name')
329 print "widget has no name!"
332 # get corresponding gui object
334 attributes = screen[wname].skinAttributes = [ ]
336 raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
338 collectAttributes(attributes, widget)
340 # now walk additional objects
341 for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
342 if widget.tagName == "applet":
343 codeText = mergeText(widget.childNodes).strip()
344 type = widget.getAttribute('type')
346 code = compile(codeText, "skin applet", "exec")
348 if type == "onLayoutFinish":
349 screen.onLayoutFinish.append(code)
351 raise str("applet type '%s' unknown!" % type)
355 class additionalWidget:
358 w = additionalWidget()
360 if widget.tagName == "eLabel":
362 elif widget.tagName == "ePixmap":
365 raise str("unsupported stuff : %s" % widget.tagName)
367 w.skinAttributes = [ ]
368 collectAttributes(w.skinAttributes, widget)
370 # applyAttributes(guiObject, widget, desktop)
371 # guiObject.thisown = 0
372 print screen.additionalWidgets
373 screen.additionalWidgets.append(w)