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 desktop.makeCompatiblePixmap(ptr.__deref__())
79 guiObject.setPixmap(ptr.__deref__())
80 # guiObject.setPixmapFromFile(value)
81 elif attrib == "alphatest": # used by ePixmap
82 guiObject.setAlphatest(
86 elif attrib == "orientation": # used by eSlider
88 guiObject.setOrientation(
89 { "orVertical": guiObject.orVertical,
90 "orHorizontal": guiObject.orHorizontal
93 print "oprientation must be either orVertical or orHorizontal!"
94 elif attrib == "valign":
97 { "top": guiObject.alignTop,
98 "center": guiObject.alignCenter,
99 "bottom": guiObject.alignBottom
102 print "valign must be either top, center or bottom!"
103 elif attrib == "halign":
106 { "left": guiObject.alignLeft,
107 "center": guiObject.alignCenter,
108 "right": guiObject.alignRight,
109 "block": guiObject.alignBlock
112 print "halign must be either left, center, right or block!"
113 elif attrib == "flags":
114 flags = value.split(',')
117 fv = eWindow.__dict__[f]
118 guiObject.setFlag(fv)
120 print "illegal flag %s!" % f
121 elif attrib == "backgroundColor":
122 guiObject.setBackgroundColor(parseColor(value))
123 elif attrib == "foregroundColor":
124 guiObject.setForegroundColor(parseColor(value))
125 elif attrib == "selectionDisabled":
126 guiObject.setSelectionEnable(0)
127 elif attrib == "transparent":
128 guiObject.setTransparent(int(value))
129 elif attrib == "borderColor":
130 guiObject.setBorderColor(parseColor(value))
131 elif attrib == "borderWidth":
132 guiObject.setBorderWidth(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..."
146 skin = dom.childNodes[0]
147 assert skin.tagName == "skin", "root element in skin must be 'skin'!"
149 for c in elementsWithTag(skin.childNodes, "colors"):
150 for color in elementsWithTag(c.childNodes, "color"):
151 name = str(color.getAttribute("name"))
152 color = str(color.getAttribute("value"))
155 raise ("need color and name, got %s %s" % (name, color))
157 colorNames[name] = parseColor(color)
159 for windowstyle in elementsWithTag(skin.childNodes, "windowstyle"):
160 style = eWindowStyleSkinned()
162 style.setTitleFont(gFont("Arial", 20));
163 style.setTitleOffset(eSize(20, 5));
165 for borderset in elementsWithTag(windowstyle.childNodes, "borderset"):
166 bsName = str(borderset.getAttribute("name"))
167 for pixmap in elementsWithTag(borderset.childNodes, "pixmap"):
168 bpName = str(pixmap.getAttribute("pos"))
169 filename = str(pixmap.getAttribute("filename"))
171 png = loadPNG(filename)
174 desktop.makeCompatiblePixmap(png.__deref__())
175 style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png.__deref__())
177 for color in elementsWithTag(windowstyle.childNodes, "color"):
178 type = str(color.getAttribute("name"))
179 color = parseColor(color.getAttribute("color"))
182 style.setColor(eWindowStyleSkinned.__dict__["col" + type], color)
184 raise ("Unknown color %s" % (type))
186 x = eWindowStyleManagerPtr()
187 eWindowStyleManager.getInstance(x)
190 def readSkin(screen, skin, name, desktop):
193 # first, find the corresponding screen element
194 skin = dom.childNodes[0]
196 for x in elementsWithTag(skin.childNodes, "screen"):
197 if x.getAttribute('name') == name:
203 print screen.__dict__
204 if "parsedSkin" in screen.__dict__:
205 myscreen = screen.parsedSkin
206 elif "skin" in screen.__dict__:
207 myscreen = screen.parsedSkin = xml.dom.minidom.parseString(screen.skin).childNodes[0]
209 assert myscreen is not None, "no skin for screen '" + name + "' found!"
211 screen.skinAttributes = [ ]
212 collectAttributes(screen.skinAttributes, myscreen)
214 screen.additionalWidgets = [ ]
216 # now walk all widgets
217 for widget in elementsWithTag(myscreen.childNodes, "widget"):
218 wname = widget.getAttribute('name')
220 print "widget has no name!"
223 # get corresponding gui object
225 attributes = screen[wname].skinAttributes = [ ]
227 raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
229 collectAttributes(attributes, widget)
231 # now walk additional objects
232 for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
233 if widget.tagName == "applet":
234 codeText = mergeText(widget.childNodes).strip()
235 type = widget.getAttribute('type')
237 code = compile(codeText, "skin applet", "exec")
239 if type == "onLayoutFinish":
240 screen.onLayoutFinish.append(code)
242 raise str("applet type '%s' unknown!" % type)
246 class additionalWidget:
249 w = additionalWidget()
251 if widget.tagName == "eLabel":
253 elif widget.tagName == "ePixmap":
256 raise str("unsupported stuff : %s" % widget.tagName)
258 w.skinAttributes = [ ]
259 collectAttributes(w.skinAttributes, widget)
261 # applyAttributes(guiObject, widget, desktop)
262 # guiObject.thisown = 0
263 screen.additionalWidgets.append(w)