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="#294a6b" />
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,300" 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" />
56 <screen name="ScartLoopThrough" position="0,0" size="720,576">
58 <screen name="ConfigMenu" position="300,100" size="300,300" title="real main menu">
59 <widget name="txt_var_1" position="20,20" size="100,20" />
60 <widget name="btn_var_1" position="110,20" size="200,20" />
61 <widget name="txt_var_2" position="20,60" size="100,20" />
62 <widget name="btn_var_2" position="110,60" size="200,20" />
64 <screen name="configOSD" position="140,125" size="460,350" title="OSD Settings">
65 <widget name="okbutton" position="20,245" size="205,40" />
66 <widget name="txt_alpha" position="20,20" size="110,20" />
67 <widget name="sld_alpha" position="150,20" size="290,20" />
68 <widget name="txt_brightness" position="20,60" size="120,20" />
69 <widget name="sld_brightness" position="150,20" size="290,20" />
70 <widget name="txt_gamma" position="20,100" size="120,20" />
71 <widget name="sld_gamma" position="150,100" size="290,20" />
73 <screen name="configTest" position="300,100" size="300,300" title="config menu">
74 <widget name="config" position="10,30" size="280,140" />
76 <screen name="TimerEditList" position="160,100" size="420,430" title="Timer Editor">
77 <widget name="timerlist" position="10,30" size="400,300" />
79 <screen name="clockDisplay" position="300,100" size="300,300">
80 <widget name="okbutton" position="10,10" size="280,40" />
81 <widget name="title" position="10,120" size="280,50" />
82 <widget name="theClock" position="10,60" size="280,50" />
84 <screen name="InfoBar" flags="wfNoBorder" position="0,380" size="720,148" title="InfoBar">
85 <ePixmap position="0,0" size="720,148" pixmap="data/info-bg.png" />
87 <widget name="ServiceName" position="69,30" size="427,26" valign="center" font="Arial;32" backgroundColor="#101258" />
88 <widget name="CurrentTime" position="575,10" size="66,30" backgroundColor="dark" font="Arial;16" />
89 <widget name="Event_Now" position="273,68" size="282,30" font="Arial;29" backgroundColor="dark" />
90 <widget name="Event_Next" position="273,98" size="282,30" font="Arial;29" backgroundColor="dark" />
91 <widget name="Event_Now_Duration" position="555,68" size="70,26" font="Arial;26" backgroundColor="dark" />
92 <widget name="Event_Next_Duration" position="555,98" size="70,26" font="Arial;26" backgroundColor="dark" />
93 <!-- <eLabel position="70,0" size="300,30" text=".oO skin Oo." font="Arial;20" /> -->
95 <screen name="ChannelSelection" position="90,100" size="560,420" title="Channel Selection">
96 <widget name="list" position="0,50" size="560,340" />
97 <!-- <widget name="okbutton" position="340,50" size="140,30" />-->
98 <widget name="key_red" position="0,0" size="140,40" backgroundColor="red" />
99 <widget name="key_green" position="140,0" size="140,40" backgroundColor="green" />
100 <widget name="key_yellow" position="280,0" size="140,40" backgroundColor="yellow" />
101 <widget name="key_blue" position="420,0" size="140,40" backgroundColor="blue" />
103 <screen name="ServiceScan" position="150,100" size="300,200" title="Service Scan">
104 <widget name="scan_progress" position="10,10" size="280,50" />
105 <widget name="scan_state" position="10,60" size="280,30" />
107 <screen name="TimerEdit" position="70,100" size="590,335" title="Timer Edit">
108 <widget name="description" position="10,10" size="580,40" font="Arial;25" />
109 <widget name="lbegin" position="405,102" size="103,30" font="Arial;25" foregroundColor="red" />
110 <widget name="lend" position="405,158" size="103,30" font="Arial;25" foregroundColor="green" />
111 <widget name="begin" position="508,105" size="72,35" font="Arial;25" />
112 <widget name="end" position="508,150" size="72,35" font="Arial;25" />
113 <widget name="apply" position="10,240" size="250,35" />
115 <screen name="MessageBox" position="0,300" size="720,10" title="Message">
116 <widget name="text" position="0,0" size="500,0" font="Arial;25" />
117 <applet type="onLayoutFinish">
118 # this should be factored out into some helper code, but currently demonstrated applets.
119 from enigma import eSize, ePoint
121 orgwidth = self.instance.size().width()
122 orgpos = self.instance.position()
123 textsize = self["text"].getSize()
125 # y size still must be fixed in font stuff...
126 textsize = (textsize[0], textsize[1] + 20)
127 wsize = (textsize[0] + 20, textsize[1] + 20)
130 self.instance.resize(eSize(*wsize))
133 self["text"].instance.resize(eSize(*textsize))
137 self.instance.move(ePoint(orgpos.x() + (orgwidth - newwidth)/2, orgpos.y()))
142 def parsePosition(str):
143 x, y = str.split(',')
144 return ePoint(int(x), int(y))
147 x, y = str.split(',')
148 return eSize(int(x), int(y))
151 name, size = str.split(';')
152 return gFont(name, int(size))
157 return colorNames[str]
159 raise ("color '%s' must be #aarrggbb or valid named color" % (str))
160 return gRGB(int(str[1:], 0x10))
162 def collectAttributes(skinAttributes, node):
163 # walk all attributes
164 for p in range(node.attributes.length):
165 a = node.attributes.item(p)
167 # convert to string (was: unicode)
169 # TODO: proper UTF8 translation?! (for value)
170 # TODO: localization? as in e1?
173 skinAttributes.append((attrib, value))
175 def applySingleAttribute(guiObject, desktop, attrib, value):
178 if attrib == 'position':
179 guiObject.move(parsePosition(value))
180 elif attrib == 'size':
181 guiObject.resize(parseSize(value))
182 elif attrib == 'title':
183 guiObject.setTitle(value)
184 elif attrib == 'text':
185 guiObject.setText(value)
186 elif attrib == 'font':
187 guiObject.setFont(parseFont(value))
188 elif attrib == "pixmap":
190 if loadPNG(ptr, value):
191 raise "loading PNG failed!"
193 ptr = ptr.__deref__()
194 desktop.makeCompatiblePixmap(ptr)
195 guiObject.setPixmap(ptr)
196 # guiObject.setPixmapFromFile(value)
197 elif attrib == "valign":
200 { "top": guiObject.alignTop,
201 "center": guiObject.alignCenter,
202 "bottom": guiObject.alignBottom
205 print "valign must be either top, center or bottom!"
206 elif attrib == "halign":
209 { "left": guiObject.alignLeft,
210 "center": guiObject.alignCenter,
211 "right": guiObject.alignRight,
212 "block": guiObject.alignBlock
215 print "halign must be either left, center, right or block!"
216 elif attrib == "flags":
217 flags = value.split(',')
220 fv = eWindow.__dict__[f]
221 guiObject.setFlag(fv)
223 print "illegal flag %s!" % f
224 elif attrib == "backgroundColor":
225 guiObject.setBackgroundColor(parseColor(value))
226 elif attrib == "foregroundColor":
227 guiObject.setForegroundColor(parseColor(value))
228 elif attrib != 'name':
229 print "unsupported attribute " + attrib + "=" + value
232 print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib)
234 def applyAllAttributes(guiObject, desktop, attributes):
235 for (attrib, value) in attributes:
236 applySingleAttribute(guiObject, desktop, attrib, value)
238 def loadSkin(desktop):
239 print "loading skin..."
247 skin = dom.childNodes[0]
248 assert skin.tagName == "skin", "root element in skin must be 'skin'!"
250 for c in elementsWithTag(skin.childNodes, "colors"):
251 for color in elementsWithTag(c.childNodes, "color"):
252 name = str(color.getAttribute("name"))
253 color = str(color.getAttribute("value"))
256 raise ("need color and name, got %s %s" % (name, color))
258 colorNames[name] = parseColor(color)
260 for windowstyle in elementsWithTag(skin.childNodes, "windowstyle"):
261 style = eWindowStyleSkinned()
263 for borderset in elementsWithTag(windowstyle.childNodes, "borderset"):
264 bsName = str(borderset.getAttribute("name"))
265 for pixmap in elementsWithTag(borderset.childNodes, "pixmap"):
266 bpName = str(pixmap.getAttribute("pos"))
267 filename = str(pixmap.getAttribute("filename"))
269 png = getPNG(filename)
272 desktop.makeCompatiblePixmap(png)
273 style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png)
275 for color in elementsWithTag(windowstyle.childNodes, "color"):
276 type = str(color.getAttribute("name"))
277 color = parseColor(color.getAttribute("color"))
280 style.setColor(eWindowStyleSkinned.__dict__["col" + type], color)
282 raise ("Unknown color %s" % (type))
284 x = eWindowStyleManagerPtr()
285 eWindowStyleManager.getInstance(x)
288 def readSkin(screen, skin, name, desktop):
291 # first, find the corresponding screen element
292 skin = dom.childNodes[0]
294 for x in elementsWithTag(skin.childNodes, "screen"):
295 if x.getAttribute('name') == name:
299 assert myscreen != None, "no skin for screen '" + name + "' found!"
301 screen.skinAttributes = [ ]
302 collectAttributes(screen.skinAttributes, myscreen)
304 screen.additionalWidgets = [ ]
306 # now walk all widgets
307 for widget in elementsWithTag(myscreen.childNodes, "widget"):
308 wname = widget.getAttribute('name')
310 print "widget has no name!"
313 # get corresponding gui object
315 attributes = screen[wname].skinAttributes = [ ]
317 raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
319 collectAttributes(attributes, widget)
321 # now walk additional objects
322 for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
323 if widget.tagName == "applet":
324 codeText = mergeText(widget.childNodes).strip()
325 type = widget.getAttribute('type')
327 code = compile(codeText, "skin applet", "exec")
329 if type == "onLayoutFinish":
330 screen.onLayoutFinish.append(code)
332 raise str("applet type '%s' unknown!" % type)
336 class additionalWidget:
339 w = additionalWidget()
341 if widget.tagName == "eLabel":
343 elif widget.tagName == "ePixmap":
346 raise str("unsupported stuff : %s" % widget.tagName)
348 w.skinAttributes = [ ]
349 collectAttributes(w.skinAttributes, widget)
351 # applyAttributes(guiObject, widget, desktop)
352 # guiObject.thisown = 0
353 print screen.additionalWidgets
354 screen.additionalWidgets.append(w)