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:
19 skinfile = file('/usr/share/enigma2/skin.xml', 'r')
20 dom = xml.dom.minidom.parseString(skinfile.read())
23 print "Error opening skin.xml"
25 def parsePosition(str):
27 return ePoint(int(x), int(y))
31 return eSize(int(x), int(y))
34 name, size = str.split(';')
35 return gFont(name, int(size))
40 return colorNames[str]
42 raise ("color '%s' must be #aarrggbb or valid named color" % (str))
43 return gRGB(int(str[1:], 0x10))
45 def collectAttributes(skinAttributes, node):
47 for p in range(node.attributes.length):
48 a = node.attributes.item(p)
50 # convert to string (was: unicode)
52 # TODO: proper UTF8 translation?! (for value)
53 # TODO: localization? as in e1?
56 skinAttributes.append((attrib, value))
58 def applySingleAttribute(guiObject, desktop, attrib, value):
61 if attrib == 'position':
62 guiObject.move(parsePosition(value))
63 elif attrib == 'size':
64 guiObject.resize(parseSize(value))
65 elif attrib == 'title':
66 guiObject.setTitle(value)
67 elif attrib == 'text':
68 guiObject.setText(value)
69 elif attrib == 'font':
70 guiObject.setFont(parseFont(value))
71 elif attrib == "pixmap":
73 if loadPNG(ptr, value):
74 raise "loading PNG failed!"
77 desktop.makeCompatiblePixmap(ptr)
78 guiObject.setPixmap(ptr)
79 # guiObject.setPixmapFromFile(value)
80 elif attrib == "valign":
83 { "top": guiObject.alignTop,
84 "center": guiObject.alignCenter,
85 "bottom": guiObject.alignBottom
88 print "valign must be either top, center or bottom!"
89 elif attrib == "halign":
92 { "left": guiObject.alignLeft,
93 "center": guiObject.alignCenter,
94 "right": guiObject.alignRight,
95 "block": guiObject.alignBlock
98 print "halign must be either left, center, right or block!"
99 elif attrib == "flags":
100 flags = value.split(',')
103 fv = eWindow.__dict__[f]
104 guiObject.setFlag(fv)
106 print "illegal flag %s!" % f
107 elif attrib == "backgroundColor":
108 guiObject.setBackgroundColor(parseColor(value))
109 elif attrib == "foregroundColor":
110 guiObject.setForegroundColor(parseColor(value))
111 elif attrib != 'name':
112 print "unsupported attribute " + attrib + "=" + value
115 print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib)
117 def applyAllAttributes(guiObject, desktop, attributes):
118 for (attrib, value) in attributes:
119 applySingleAttribute(guiObject, desktop, attrib, value)
121 def loadSkin(desktop):
122 print "loading skin..."
130 skin = dom.childNodes[0]
131 assert skin.tagName == "skin", "root element in skin must be 'skin'!"
133 for c in elementsWithTag(skin.childNodes, "colors"):
134 for color in elementsWithTag(c.childNodes, "color"):
135 name = str(color.getAttribute("name"))
136 color = str(color.getAttribute("value"))
139 raise ("need color and name, got %s %s" % (name, color))
141 colorNames[name] = parseColor(color)
143 for windowstyle in elementsWithTag(skin.childNodes, "windowstyle"):
144 style = eWindowStyleSkinned()
146 for borderset in elementsWithTag(windowstyle.childNodes, "borderset"):
147 bsName = str(borderset.getAttribute("name"))
148 for pixmap in elementsWithTag(borderset.childNodes, "pixmap"):
149 bpName = str(pixmap.getAttribute("pos"))
150 filename = str(pixmap.getAttribute("filename"))
152 png = getPNG(filename)
155 desktop.makeCompatiblePixmap(png)
156 style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png)
158 for color in elementsWithTag(windowstyle.childNodes, "color"):
159 type = str(color.getAttribute("name"))
160 color = parseColor(color.getAttribute("color"))
163 style.setColor(eWindowStyleSkinned.__dict__["col" + type], color)
165 raise ("Unknown color %s" % (type))
167 x = eWindowStyleManagerPtr()
168 eWindowStyleManager.getInstance(x)
171 def readSkin(screen, skin, name, desktop):
174 # first, find the corresponding screen element
175 skin = dom.childNodes[0]
177 for x in elementsWithTag(skin.childNodes, "screen"):
178 if x.getAttribute('name') == name:
182 assert myscreen != None, "no skin for screen '" + name + "' found!"
184 screen.skinAttributes = [ ]
185 collectAttributes(screen.skinAttributes, myscreen)
187 screen.additionalWidgets = [ ]
189 # now walk all widgets
190 for widget in elementsWithTag(myscreen.childNodes, "widget"):
191 wname = widget.getAttribute('name')
193 print "widget has no name!"
196 # get corresponding gui object
198 attributes = screen[wname].skinAttributes = [ ]
200 raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
202 collectAttributes(attributes, widget)
204 # now walk additional objects
205 for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
206 if widget.tagName == "applet":
207 codeText = mergeText(widget.childNodes).strip()
208 type = widget.getAttribute('type')
210 code = compile(codeText, "skin applet", "exec")
212 if type == "onLayoutFinish":
213 screen.onLayoutFinish.append(code)
215 raise str("applet type '%s' unknown!" % type)
219 class additionalWidget:
222 w = additionalWidget()
224 if widget.tagName == "eLabel":
226 elif widget.tagName == "ePixmap":
229 raise str("unsupported stuff : %s" % widget.tagName)
231 w.skinAttributes = [ ]
232 collectAttributes(w.skinAttributes, widget)
234 # applyAttributes(guiObject, widget, desktop)
235 # guiObject.thisown = 0
236 print screen.additionalWidgets
237 screen.additionalWidgets.append(w)