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 from Tools.Directories import resolveFilename, SCOPE_SKIN
20 skinfile = file(resolveFilename(SCOPE_SKIN, 'skin.xml'), 'r')
21 dom = xml.dom.minidom.parseString(skinfile.read())
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 == 'zPosition':
72 guiObject.setZPosition(int(value))
73 elif attrib == "pixmap":
75 desktop.makeCompatiblePixmap(ptr.__deref__())
76 guiObject.setPixmap(ptr.__deref__())
77 # guiObject.setPixmapFromFile(value)
78 elif attrib == "alphatest": # used by ePixmap
79 guiObject.setAlphatest(
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 == "selectionDisabled":
123 guiObject.setSelectionEnable(0)
124 elif attrib == "transparent":
125 guiObject.setTransparent(int(value))
126 elif attrib == "borderColor":
127 guiObject.setBorderColor(parseColor(value))
128 elif attrib == "borderWidth":
129 guiObject.setBorderWidth(int(value))
130 elif attrib == "scrollbarMode":
131 guiObject.setScrollbarMode(
132 { "showOnDemand": guiObject.showOnDemand,
133 "showAlways": guiObject.showAlways,
134 "showNever": guiObject.showNever
136 elif attrib != 'name':
137 print "unsupported attribute " + attrib + "=" + value
140 print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib)
142 def applyAllAttributes(guiObject, desktop, attributes):
143 for (attrib, value) in attributes:
144 applySingleAttribute(guiObject, desktop, attrib, value)
146 def loadSkin(desktop):
147 print "loading skin..."
149 skin = dom.childNodes[0]
150 assert skin.tagName == "skin", "root element in skin must be 'skin'!"
152 for c in elementsWithTag(skin.childNodes, "colors"):
153 for color in elementsWithTag(c.childNodes, "color"):
154 name = str(color.getAttribute("name"))
155 color = str(color.getAttribute("value"))
158 raise ("need color and name, got %s %s" % (name, color))
160 colorNames[name] = parseColor(color)
162 for windowstyle in elementsWithTag(skin.childNodes, "windowstyle"):
163 style = eWindowStyleSkinned()
165 style.setTitleFont(gFont("Regular", 20));
166 style.setTitleOffset(eSize(20, 5));
168 for borderset in elementsWithTag(windowstyle.childNodes, "borderset"):
169 bsName = str(borderset.getAttribute("name"))
170 for pixmap in elementsWithTag(borderset.childNodes, "pixmap"):
171 bpName = str(pixmap.getAttribute("pos"))
172 filename = str(pixmap.getAttribute("filename"))
174 png = loadPNG(filename)
177 desktop.makeCompatiblePixmap(png.__deref__())
178 style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png.__deref__())
180 for color in elementsWithTag(windowstyle.childNodes, "color"):
181 type = str(color.getAttribute("name"))
182 color = parseColor(color.getAttribute("color"))
185 style.setColor(eWindowStyleSkinned.__dict__["col" + type], color)
187 raise ("Unknown color %s" % (type))
189 x = eWindowStyleManagerPtr()
190 eWindowStyleManager.getInstance(x)
193 def readSkin(screen, skin, name, desktop):
196 # first, find the corresponding screen element
197 skin = dom.childNodes[0]
199 for x in elementsWithTag(skin.childNodes, "screen"):
200 if x.getAttribute('name') == name:
206 print screen.__dict__
207 if "parsedSkin" in screen.__dict__:
208 myscreen = screen.parsedSkin
209 elif "skin" in screen.__dict__:
210 myscreen = screen.parsedSkin = xml.dom.minidom.parseString(screen.skin).childNodes[0]
212 assert myscreen is not None, "no skin for screen '" + name + "' found!"
214 screen.skinAttributes = [ ]
215 collectAttributes(screen.skinAttributes, myscreen)
217 screen.additionalWidgets = [ ]
219 # now walk all widgets
220 for widget in elementsWithTag(myscreen.childNodes, "widget"):
221 wname = widget.getAttribute('name')
223 print "widget has no name!"
226 # get corresponding gui object
228 attributes = screen[wname].skinAttributes = [ ]
230 raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
232 collectAttributes(attributes, widget)
234 # now walk additional objects
235 for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
236 if widget.tagName == "applet":
237 codeText = mergeText(widget.childNodes).strip()
238 type = widget.getAttribute('type')
240 code = compile(codeText, "skin applet", "exec")
242 if type == "onLayoutFinish":
243 screen.onLayoutFinish.append(code)
245 raise str("applet type '%s' unknown!" % type)
249 class additionalWidget:
252 w = additionalWidget()
254 if widget.tagName == "eLabel":
256 elif widget.tagName == "ePixmap":
259 raise str("unsupported stuff : %s" % widget.tagName)
261 w.skinAttributes = [ ]
262 collectAttributes(w.skinAttributes, widget)
264 # applyAttributes(guiObject, widget, desktop)
265 # guiObject.thisown = 0
266 screen.additionalWidgets.append(w)