first step for skin support
[enigma2.git] / skin.py
diff --git a/skin.py b/skin.py
index 415f3412bc17955f49c20817fb668a1ff049b930..5d482fdb32f0ab4b751f22f2a331a6aa5626fb47 100644 (file)
--- a/skin.py
+++ b/skin.py
@@ -1,5 +1,6 @@
 from enigma import *
 import xml.dom.minidom
+from xml.dom import EMPTY_NAMESPACE
 
 def dump(x, i=0):
        print " " * i + str(x)
@@ -10,19 +11,54 @@ def dump(x, i=0):
                None
 
 dom = xml.dom.minidom.parseString(
-       "<screen name=\"clockDialog\"> \
+       "<screen name=\"clockDialog\" position=\"300,100\" size=\"300,300\"> \
                <widget name=\"okbutton\" position=\"10,10\" size=\"280,40\" /> \
                <widget name=\"theClock\" position=\"10,60\" size=\"280,50\" /> \
                <widget name=\"title\" position=\"10,120\" size=\"280,50\" /> \
        </screen>")
 
-def applyGUIskin(screen, skin, name):
-       dump(dom[screen])
-       screen.data["okbutton"]["instance"].move(ePoint(10, 10))
-       screen.data["okbutton"]["instance"].resize(eSize(280, 40))
+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))
 
-       screen.data["theClock"]["instance"].move(ePoint(10, 60))
-       screen.data["theClock"]["instance"].resize(eSize(280, 50))
+def applyAttributes(guiObject, node):
+       # walk all attributes
+       for p in range(node.attributes.length):
+               a = node.attributes.item(p)
+               
+               # 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
 
-       screen.data["title"]["instance"].move(ePoint(10, 120))
-       screen.data["title"]["instance"].resize(eSize(280, 50))
+def applyGUIskin(screen, skin, name):
+       
+       myscreen = None
+       
+       # first, find the corresponding screen element
+       screens = dom.getElementsByTagName("screen")
+       for x in screens:
+               if x.getAttribute('name') == name:
+                       myscreen = x
+       
+       if myscreen == None:
+               print "no skin for screen " + name + " found!"
+               return;
+       
+       # now walk all widgets
+       for widget in myscreen.getElementsByTagName("widget"):
+               name = widget.getAttribute('name')
+               if name == None:
+                       print "widget has no name!"
+                       continue
+               
+               # get corresponding gui object
+               guiObject = screen.data[name]["instance"]
+               applyAttributes(guiObject, widget)