X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/47d24e1d25002485f1cb90f1682b4bc3070cad0b..1cdf6cb021fcaa6548b90ba7b6765cf1e8b8b37b:/skin.py diff --git a/skin.py b/skin.py index 5d482fdb..46a14292 100644 --- a/skin.py +++ b/skin.py @@ -11,11 +11,37 @@ def dump(x, i=0): None dom = xml.dom.minidom.parseString( - " \ - \ - \ - \ - ") + """ + + + + + + + + + + + + + + + + + + + + + + + + + + + +""") + + def parsePosition(str): x, y = str.split(',') @@ -30,35 +56,49 @@ def applyAttributes(guiObject, node): 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 a.name == 'position': - guiObject.move(parsePosition(a.value)) - elif a.name == 'size': - guiObject.resize(parseSize(a.value)) - elif a.name != 'name': - print "unsupported attribute " + a.name + 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, skin, name): +def applyGUIskin(screen, parent, skin, name): myscreen = None # first, find the corresponding screen element - screens = dom.getElementsByTagName("screen") + skin = dom.getElementsByTagName("skin")[0] + screens = skin.getElementsByTagName("screen") + del skin for x in screens: if x.getAttribute('name') == name: myscreen = x - if myscreen == None: - print "no skin for screen " + name + " found!" - return; + assert myscreen != None, "no skin for screen '" + name + "' found!" + + applyAttributes(parent, myscreen) # now walk all widgets for widget in myscreen.getElementsByTagName("widget"): - name = widget.getAttribute('name') - if name == None: + wname = widget.getAttribute('name') + if wname == None: print "widget has no name!" continue # get corresponding gui object - guiObject = screen.data[name]["instance"] + try: + guiObject = screen[wname].instance + except: + raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!") + applyAttributes(guiObject, widget)