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 == 'zPosition':
75 guiObject.setZPosition(int(value))
76 elif attrib == "pixmap":
78 if loadPNG(ptr, value):
79 raise "loading PNG failed!"
82 desktop.makeCompatiblePixmap(ptr)
83 guiObject.setPixmap(ptr)
84 # guiObject.setPixmapFromFile(value)
85 elif attrib == "alphatest": # used by ePixmap
86 guiObject.setAlphatest(
90 elif attrib == "orientation": # used by eSlider
92 guiObject.setOrientation(
93 { "orVertical": guiObject.orVertical,
94 "orHorizontal": guiObject.orHorizontal
97 print "oprientation must be either orVertical or orHorizontal!"
98 elif attrib == "valign":
101 { "top": guiObject.alignTop,
102 "center": guiObject.alignCenter,
103 "bottom": guiObject.alignBottom
106 print "valign must be either top, center or bottom!"
107 elif attrib == "halign":
110 { "left": guiObject.alignLeft,
111 "center": guiObject.alignCenter,
112 "right": guiObject.alignRight,
113 "block": guiObject.alignBlock
116 print "halign must be either left, center, right or block!"
117 elif attrib == "flags":
118 flags = value.split(',')
121 fv = eWindow.__dict__[f]
122 guiObject.setFlag(fv)
124 print "illegal flag %s!" % f
125 elif attrib == "backgroundColor":
126 guiObject.setBackgroundColor(parseColor(value))
127 elif attrib == "foregroundColor":
128 guiObject.setForegroundColor(parseColor(value))
129 elif attrib == "selectionDisabled":
130 guiObject.setSelectionEnable(0)
131 elif attrib == "transparent":
132 guiObject.setTransparent(int(value))
133 elif attrib != 'name':
134 print "unsupported attribute " + attrib + "=" + value
137 print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib)
139 def applyAllAttributes(guiObject, desktop, attributes):
140 for (attrib, value) in attributes:
141 applySingleAttribute(guiObject, desktop, attrib, value)
143 def loadSkin(desktop):
144 print "loading skin..."
152 skin = dom.childNodes[0]
153 assert skin.tagName == "skin", "root element in skin must be 'skin'!"
155 for c in elementsWithTag(skin.childNodes, "colors"):
156 for color in elementsWithTag(c.childNodes, "color"):
157 name = str(color.getAttribute("name"))
158 color = str(color.getAttribute("value"))
161 raise ("need color and name, got %s %s" % (name, color))
163 colorNames[name] = parseColor(color)
165 for windowstyle in elementsWithTag(skin.childNodes, "windowstyle"):
166 style = eWindowStyleSkinned()
168 style.setTitleFont(gFont("Arial", 20));
169 style.setTitleOffset(eSize(20, 5));
171 for borderset in elementsWithTag(windowstyle.childNodes, "borderset"):
172 bsName = str(borderset.getAttribute("name"))
173 for pixmap in elementsWithTag(borderset.childNodes, "pixmap"):
174 bpName = str(pixmap.getAttribute("pos"))
175 filename = str(pixmap.getAttribute("filename"))
177 png = getPNG(filename)
180 desktop.makeCompatiblePixmap(png)
181 style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png)
183 for color in elementsWithTag(windowstyle.childNodes, "color"):
184 type = str(color.getAttribute("name"))
185 color = parseColor(color.getAttribute("color"))
188 style.setColor(eWindowStyleSkinned.__dict__["col" + type], color)
190 raise ("Unknown color %s" % (type))
192 x = eWindowStyleManagerPtr()
193 eWindowStyleManager.getInstance(x)
196 def readSkin(screen, skin, name, desktop):
199 # first, find the corresponding screen element
200 skin = dom.childNodes[0]
202 for x in elementsWithTag(skin.childNodes, "screen"):
203 if x.getAttribute('name') == name:
209 print screen.__dict__
210 if "parsedSkin" in screen.__dict__:
211 myscreen = screen.parsedSkin
212 elif "skin" in screen.__dict__:
213 myscreen = screen.parsedSkin = xml.dom.minidom.parseString(screen.skin).childNodes[0]
215 assert myscreen is not None, "no skin for screen '" + name + "' found!"
217 screen.skinAttributes = [ ]
218 collectAttributes(screen.skinAttributes, myscreen)
220 screen.additionalWidgets = [ ]
222 # now walk all widgets
223 for widget in elementsWithTag(myscreen.childNodes, "widget"):
224 wname = widget.getAttribute('name')
226 print "widget has no name!"
229 # get corresponding gui object
231 attributes = screen[wname].skinAttributes = [ ]
233 raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
235 collectAttributes(attributes, widget)
237 # now walk additional objects
238 for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
239 if widget.tagName == "applet":
240 codeText = mergeText(widget.childNodes).strip()
241 type = widget.getAttribute('type')
243 code = compile(codeText, "skin applet", "exec")
245 if type == "onLayoutFinish":
246 screen.onLayoutFinish.append(code)
248 raise str("applet type '%s' unknown!" % type)
252 class additionalWidget:
255 w = additionalWidget()
257 if widget.tagName == "eLabel":
259 elif widget.tagName == "ePixmap":
262 raise str("unsupported stuff : %s" % widget.tagName)
264 w.skinAttributes = [ ]
265 collectAttributes(w.skinAttributes, widget)
267 # applyAttributes(guiObject, widget, desktop)
268 # guiObject.thisown = 0
269 screen.additionalWidgets.append(w)