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 # that __deref__ still scares me!
76 desktop.makeCompatiblePixmap(ptr.__deref__())
77 guiObject.setPixmap(ptr.__deref__())
78 # guiObject.setPixmapFromFile(value)
79 elif attrib == "alphatest": # used by ePixmap
80 guiObject.setAlphatest(
84 elif attrib == "orientation": # used by eSlider
86 guiObject.setOrientation(
87 { "orVertical": guiObject.orVertical,
88 "orHorizontal": guiObject.orHorizontal
91 print "oprientation must be either orVertical or orHorizontal!"
92 elif attrib == "valign":
95 { "top": guiObject.alignTop,
96 "center": guiObject.alignCenter,
97 "bottom": guiObject.alignBottom
100 print "valign must be either top, center or bottom!"
101 elif attrib == "halign":
104 { "left": guiObject.alignLeft,
105 "center": guiObject.alignCenter,
106 "right": guiObject.alignRight,
107 "block": guiObject.alignBlock
110 print "halign must be either left, center, right or block!"
111 elif attrib == "flags":
112 flags = value.split(',')
115 fv = eWindow.__dict__[f]
116 guiObject.setFlag(fv)
118 print "illegal flag %s!" % f
119 elif attrib == "backgroundColor":
120 guiObject.setBackgroundColor(parseColor(value))
121 elif attrib == "foregroundColor":
122 guiObject.setForegroundColor(parseColor(value))
123 elif attrib == "selectionDisabled":
124 guiObject.setSelectionEnable(0)
125 elif attrib == "transparent":
126 guiObject.setTransparent(int(value))
127 elif attrib == "borderColor":
128 guiObject.setBorderColor(parseColor(value))
129 elif attrib == "borderWidth":
130 guiObject.setBorderWidth(int(value))
131 elif attrib == "scrollbarMode":
132 guiObject.setScrollbarMode(
133 { "showOnDemand": guiObject.showOnDemand,
134 "showAlways": guiObject.showAlways,
135 "showNever": guiObject.showNever
137 elif attrib == "enableWrapAround":
138 guiObject.setWrapAround(True)
139 elif attrib == "pointer":
140 (name, pos) = value.split(':')
141 pos = parsePosition(pos)
143 desktop.makeCompatiblePixmap(ptr.__deref__())
144 guiObject.setPointer(ptr.__deref__(), pos)
145 elif attrib != 'name':
146 print "unsupported attribute " + attrib + "=" + value
149 print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib)
151 def applyAllAttributes(guiObject, desktop, attributes):
152 for (attrib, value) in attributes:
153 applySingleAttribute(guiObject, desktop, attrib, value)
155 def loadSkin(desktop):
156 print "loading skin..."
158 skin = dom.childNodes[0]
159 assert skin.tagName == "skin", "root element in skin must be 'skin'!"
161 for c in elementsWithTag(skin.childNodes, "colors"):
162 for color in elementsWithTag(c.childNodes, "color"):
163 name = str(color.getAttribute("name"))
164 color = str(color.getAttribute("value"))
167 raise ("need color and name, got %s %s" % (name, color))
169 colorNames[name] = parseColor(color)
171 for windowstyle in elementsWithTag(skin.childNodes, "windowstyle"):
172 style = eWindowStyleSkinned()
174 style.setTitleFont(gFont("Regular", 20));
175 style.setTitleOffset(eSize(20, 5));
177 for borderset in elementsWithTag(windowstyle.childNodes, "borderset"):
178 bsName = str(borderset.getAttribute("name"))
179 for pixmap in elementsWithTag(borderset.childNodes, "pixmap"):
180 bpName = str(pixmap.getAttribute("pos"))
181 filename = str(pixmap.getAttribute("filename"))
183 png = loadPNG(filename)
186 desktop.makeCompatiblePixmap(png.__deref__())
187 style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png.__deref__())
189 for color in elementsWithTag(windowstyle.childNodes, "color"):
190 type = str(color.getAttribute("name"))
191 color = parseColor(color.getAttribute("color"))
194 style.setColor(eWindowStyleSkinned.__dict__["col" + type], color)
196 raise ("Unknown color %s" % (type))
198 x = eWindowStyleManagerPtr()
199 eWindowStyleManager.getInstance(x)
202 def readSkin(screen, skin, name, desktop):
205 # first, find the corresponding screen element
206 skin = dom.childNodes[0]
208 for x in elementsWithTag(skin.childNodes, "screen"):
209 if x.getAttribute('name') == name:
215 if "parsedSkin" in screen.__dict__:
216 myscreen = screen.parsedSkin
217 elif "skin" in screen.__dict__:
218 myscreen = screen.parsedSkin = xml.dom.minidom.parseString(screen.skin).childNodes[0]
220 assert myscreen is not None, "no skin for screen '" + name + "' found!"
222 screen.skinAttributes = [ ]
223 collectAttributes(screen.skinAttributes, myscreen)
225 screen.additionalWidgets = [ ]
227 # now walk all widgets
228 for widget in elementsWithTag(myscreen.childNodes, "widget"):
229 wname = widget.getAttribute('name')
231 print "widget has no name!"
234 # get corresponding gui object
236 attributes = screen[wname].skinAttributes = [ ]
238 raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
240 collectAttributes(attributes, widget)
242 # now walk additional objects
243 for widget in elementsWithTag(myscreen.childNodes, lambda x: x != "widget"):
244 if widget.tagName == "applet":
245 codeText = mergeText(widget.childNodes).strip()
246 type = widget.getAttribute('type')
248 code = compile(codeText, "skin applet", "exec")
250 if type == "onLayoutFinish":
251 screen.onLayoutFinish.append(code)
253 raise str("applet type '%s' unknown!" % type)
257 class additionalWidget:
260 w = additionalWidget()
262 if widget.tagName == "eLabel":
264 elif widget.tagName == "ePixmap":
267 raise str("unsupported stuff : %s" % widget.tagName)
269 w.skinAttributes = [ ]
270 collectAttributes(w.skinAttributes, widget)
272 # applyAttributes(guiObject, widget, desktop)
273 # guiObject.thisown = 0
274 screen.additionalWidgets.append(w)