from enigma import * import xml.dom.minidom from xml.dom import EMPTY_NAMESPACE def dump(x, i=0): print " " * i + str(x) try: for n in x.childNodes: dump(n, i + 1) except: None dom = xml.dom.minidom.parseString( """ """) def parsePosition(str): x, y = str.split(',') return ePoint(int(x), int(y)) def parseSize(str): x, y = str.split(',') return eSize(int(x), int(y)) def applyAttributes(guiObject, node): # walk all attributes for p in range(node.attributes.length): a = node.attributes.item(p) # convert to string (was: unicode) attrib = str(a.name) # TODO: proper UTF8 translation?! (for value) # TODO: localization? as in e1? value = str(a.value) # and set attributes if attrib == 'position': guiObject.move(parsePosition(value)) elif attrib == 'size': guiObject.resize(parseSize(value)) elif attrib == 'title': guiObject.setTitle(value) elif attrib != 'name': print "unsupported attribute " + attrib + "=" + value def applyGUIskin(screen, parent, skin, name): myscreen = None # first, find the corresponding screen element skin = dom.getElementsByTagName("skin")[0] screens = skin.getElementsByTagName("screen") del skin for x in screens: if x.getAttribute('name') == name: myscreen = x assert myscreen != None, "no skin for screen '" + name + "' found!" applyAttributes(parent, myscreen) # now walk all widgets for widget in myscreen.getElementsByTagName("widget"): wname = widget.getAttribute('name') if wname == None: print "widget has no name!" continue # get corresponding gui object try: guiObject = screen.data[wname]["instance"] except: raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!") applyAttributes(guiObject, widget)