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 # first we search in the current path
20 skinfile = file('data/skin.xml', 'r')
22 # if not found in the current path, we use the global datadir-path
23 skinfile = file('/usr/share/enigma2/skin.xml', 'r')
24 dom = xml.dom.minidom.parseString(skinfile.read())
28 def parsePosition(str):
30 return ePoint(int(x), int(y))
34 return eSize(int(x), int(y))
37 name, size = str.split(';')
38 return gFont(name, int(size))
43 return colorNames[str]
45 raise ("color '%s' must be #aarrggbb or valid named color" % (str))
46 return gRGB(int(str[1:], 0x10))
48 def collectAttributes(skinAttributes, node):
50 for p in range(node.attributes.length):
51 a = node.attributes.item(p)
53 # convert to string (was: unicode)
55 # TODO: proper UTF8 translation?! (for value)
56 # TODO: localization? as in e1?
59 skinAttributes.append((attrib, value))
61 def applySingleAttribute(guiObject, desktop, attrib, value):
64 if attrib == 'position':
65 guiObject.move(parsePosition(value))
66 elif attrib == 'size':
67 guiObject.resize(parseSize(value))
68 elif attrib == 'title':
69 guiObject.setTitle(value)
70 elif attrib == 'text':
71 guiObject.setText(value)
72 elif attrib == 'font':
73 guiObject.setFont(parseFont(value))
74 elif attrib == "pixmap":
76 if loadPNG(ptr, value):
77 raise "loading PNG failed!"
80 desktop.makeCompatiblePixmap(ptr)
81 guiObject.setPixmap(ptr)
82 # guiObject.setPixmapFromFile(value)
83 elif attrib == "orientation": # used by eSlider
85 guiObject.setOrientation(
86 { "orVertical": guiObject.orVertical,
87 "orHorizontal": guiObject.orHorizontal
90 print "oprientation must be either orVertical or orHorizontal!"
91 elif attrib == "valign":
94 { "top": guiObject.alignTop,
95 "center": guiObject.alignCenter,
96 "bottom": guiObject.alignBottom
99 print "valign must be either top, center or bottom!"
100 elif attrib == "halign":
103 { "left": guiObject.alignLeft,
104 "center": guiObject.alignCenter,
105 "right": guiObject.alignRight,
106 "block": guiObject.alignBlock
109 print "halign must be either left, center, right or block!"
110 elif attrib == "flags":
111 flags = value.split(',')
114 fv = eWindow.__dict__[f]
115 guiObject.setFlag(fv)
117 print "illegal flag %s!" % f
118 elif attrib == "backgroundColor":
119 guiObject.setBackgroundColor(parseColor(value))
120 elif attrib == "foregroundColor":
121 guiObject.setForegroundColor(parseColor(value))
122 elif attrib != 'name':
123 print "unsupported attribute " + attrib + "=" + value
126 print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib)
128 def applyAllAttributes(guiObject, desktop, attributes):
129 for (attrib, value) in attributes:
130 applySingleAttribute(guiObject, desktop, attrib, value)
132 def loadSkin(desktop):
133 print "loading skin..."
141 skin = dom.childNodes[0]
142 assert skin.tagName == "skin", "root element in skin must be 'skin'!"
144 for c in elementsWithTag(skin.childNodes, "colors"):
145 for color in elementsWithTag(c.childNodes, "color"):
146 name = str(color.getAttribute("name"))
147 color = str(color.getAttribute("value"))
150 raise ("need color and name, got %s %s" % (name, color))
152 colorNames[name] = parseColor(color)
154 for windowstyle in elementsWithTag(skin.childNodes, "windowstyle"):
155 style = eWindowStyleSkinned()
157 style.setTitleFont(gFont("Arial", 20));
158 style.setTitleOffset(eSize(20, 5));
160 for borderset in elementsWithTag(windowstyle.childNodes, "borderset"):
161 bsName = str(borderset.getAttribute("name"))
162 for pixmap in elementsWithTag(borderset.childNodes, "pixmap"):
163 bpName = str(pixmap.getAttribute("pos"))
164 filename = str(pixmap.getAttribute("filename"))
166 png = getPNG(filename)
169 desktop.makeCompatiblePixmap(png)
170 style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png)
172 for color in elementsWithTag(windowstyle.childNodes, "color"):
173 type = str(color.getAttribute("name"))
174 color = parseColor(color.getAttribute("color"))
177 style.setColor(eWindowStyleSkinned.__dict__["col" + type], color)
179 raise ("Unknown color %s" % (type))
181 x = eWindowStyleManagerPtr()
182 eWindowStyleManager.getInstance(x)
185 def readSkin(screen, skin, name, desktop):
188 # first, find the corresponding screen element
189 skin = dom.childNodes[0]
191 for x in elementsWithTag(skin.childNodes, "screen"):
192 if x.getAttribute('name') == name:
198 print screen.__dict__
199 if "parsedSkin" in screen.__dict__:
200 myscreen = screen.parsedSkin
201 elif "skin" in screen.__dict__:
202 myscreen = screen.parsedSkin = xml.dom.minidom.parseString(screen.skin).childNodes[0]
204 assert myscreen is not None, "no skin for screen '" + name + "' found!"
206 screen.skinAttributes = [ ]
207 collectAttributes(screen.skinAttributes, myscreen)
209 screen.additionalWidgets = [ ]
211 # now walk all widgets
212 for widget in elementsWithTag(myscreen.childNodes, "widget"):
213 wname = widget.getAttribute('name')
215 print "widget has no name!"
218 # get corresponding gui object
220 attributes = screen[wname].skinAttributes = [ ]
222 raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
224 collectAttributes(attributes, widget)
226 # now walk additional objects
227 for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
228 if widget.tagName == "applet":
229 codeText = mergeText(widget.childNodes).strip()
230 type = widget.getAttribute('type')
232 code = compile(codeText, "skin applet", "exec")
234 if type == "onLayoutFinish":
235 screen.onLayoutFinish.append(code)
237 raise str("applet type '%s' unknown!" % type)
241 class additionalWidget:
244 w = additionalWidget()
246 if widget.tagName == "eLabel":
248 elif widget.tagName == "ePixmap":
251 raise str("unsupported stuff : %s" % widget.tagName)
253 w.skinAttributes = [ ]
254 collectAttributes(w.skinAttributes, widget)
256 # applyAttributes(guiObject, widget, desktop)
257 # guiObject.thisown = 0
258 screen.additionalWidgets.append(w)