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 == "enableWrapAround":
137 guiObject.setWrapAround(True)
138 elif attrib != 'name':
139 print "unsupported attribute " + attrib + "=" + value
142 print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib)
144 def applyAllAttributes(guiObject, desktop, attributes):
145 for (attrib, value) in attributes:
146 applySingleAttribute(guiObject, desktop, attrib, value)
148 def loadSkin(desktop):
149 print "loading skin..."
151 skin = dom.childNodes[0]
152 assert skin.tagName == "skin", "root element in skin must be 'skin'!"
154 for c in elementsWithTag(skin.childNodes, "colors"):
155 for color in elementsWithTag(c.childNodes, "color"):
156 name = str(color.getAttribute("name"))
157 color = str(color.getAttribute("value"))
160 raise ("need color and name, got %s %s" % (name, color))
162 colorNames[name] = parseColor(color)
164 for windowstyle in elementsWithTag(skin.childNodes, "windowstyle"):
165 style = eWindowStyleSkinned()
167 style.setTitleFont(gFont("Regular", 20));
168 style.setTitleOffset(eSize(20, 5));
170 for borderset in elementsWithTag(windowstyle.childNodes, "borderset"):
171 bsName = str(borderset.getAttribute("name"))
172 for pixmap in elementsWithTag(borderset.childNodes, "pixmap"):
173 bpName = str(pixmap.getAttribute("pos"))
174 filename = str(pixmap.getAttribute("filename"))
176 png = loadPNG(filename)
179 desktop.makeCompatiblePixmap(png.__deref__())
180 style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png.__deref__())
182 for color in elementsWithTag(windowstyle.childNodes, "color"):
183 type = str(color.getAttribute("name"))
184 color = parseColor(color.getAttribute("color"))
187 style.setColor(eWindowStyleSkinned.__dict__["col" + type], color)
189 raise ("Unknown color %s" % (type))
191 x = eWindowStyleManagerPtr()
192 eWindowStyleManager.getInstance(x)
195 def readSkin(screen, skin, name, desktop):
198 # first, find the corresponding screen element
199 skin = dom.childNodes[0]
201 for x in elementsWithTag(skin.childNodes, "screen"):
202 if x.getAttribute('name') == name:
208 print screen.__dict__
209 if "parsedSkin" in screen.__dict__:
210 myscreen = screen.parsedSkin
211 elif "skin" in screen.__dict__:
212 myscreen = screen.parsedSkin = xml.dom.minidom.parseString(screen.skin).childNodes[0]
214 assert myscreen is not None, "no skin for screen '" + name + "' found!"
216 screen.skinAttributes = [ ]
217 collectAttributes(screen.skinAttributes, myscreen)
219 screen.additionalWidgets = [ ]
221 # now walk all widgets
222 for widget in elementsWithTag(myscreen.childNodes, "widget"):
223 wname = widget.getAttribute('name')
225 print "widget has no name!"
228 # get corresponding gui object
230 attributes = screen[wname].skinAttributes = [ ]
232 raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
234 collectAttributes(attributes, widget)
236 # now walk additional objects
237 for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
238 if widget.tagName == "applet":
239 codeText = mergeText(widget.childNodes).strip()
240 type = widget.getAttribute('type')
242 code = compile(codeText, "skin applet", "exec")
244 if type == "onLayoutFinish":
245 screen.onLayoutFinish.append(code)
247 raise str("applet type '%s' unknown!" % type)
251 class additionalWidget:
254 w = additionalWidget()
256 if widget.tagName == "eLabel":
258 elif widget.tagName == "ePixmap":
261 raise str("unsupported stuff : %s" % widget.tagName)
263 w.skinAttributes = [ ]
264 collectAttributes(w.skinAttributes, widget)
266 # applyAttributes(guiObject, widget, desktop)
267 # guiObject.thisown = 0
268 screen.additionalWidgets.append(w)