- fixed dvb scan
[enigma2.git] / skin.py
diff --git a/skin.py b/skin.py
index 415f341..9fbdfeb 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,73 @@ def dump(x, i=0):
                None
 
 dom = xml.dom.minidom.parseString(
-       "<screen name=\"clockDialog\"> \
-               <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>")
+       """
+       <skin>
+               <screen name="testDialog">
+                       <widget name="okbutton" position="10,190" size="280,50" />
+                       <widget name="title" position="10,10" size="280,20" />
+                       <widget name="menu" position="10,30" size="280,140" />
+               </screen>
+               <screen name="clockDisplay" position="300,100" size="300,300">
+                       <widget name="okbutton" position="10,10" size="280,40" />
+                       <widget name="title" position="10,120" size="280,50" />
+                       <widget name="theClock" position="10,60" size="280,50" />
+               </screen>
+               <screen name="mainMenu" position="300,100" size="300,300">
+                       <widget name="title" position="10,10" size="280,80" />
+                       <widget name="okbutton" position="10,190" size="280,50" />
+               </screen>
+       </skin>
+""")
 
-def applyGUIskin(screen, skin, name):
-       dump(dom[screen])
-       screen.data["okbutton"]["instance"].move(ePoint(10, 10))
-       screen.data["okbutton"]["instance"].resize(eSize(280, 40))
 
-       screen.data["theClock"]["instance"].move(ePoint(10, 60))
-       screen.data["theClock"]["instance"].resize(eSize(280, 50))
 
-       screen.data["title"]["instance"].move(ePoint(10, 120))
-       screen.data["title"]["instance"].resize(eSize(280, 50))
+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)
+               
+               # 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
+
+def applyGUIskin(screen, 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!"
+       
+       # 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)