- fixed console input mode restore
[enigma2.git] / skin.py
diff --git a/skin.py b/skin.py
index 415f3412bc17955f49c20817fb668a1ff049b930..936dcc965ab96dacd18f81d805e4f9111aec6462 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,91 @@ 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>")
-
-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))
+       """
+       <skin>
+               <screen name="mainMenu" position="300,100" size="300,300" title="real main menu">
+                       <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="infoBar" position="100,100" size="300,400" title="InfoBar">
+                       <widget name="channelSwitcher" position="10,190" size="280,50" />
+               </screen>
+               <screen name="channelSelection" position="300,100" size="300,300" title="Channel Selection">
+                       <widget name="okbutton" position="10,190" size="280,50" />
+                       <widget name="list" position="10,30" size="280,140" />
+               </screen>
+               <screen name="serviceScan" position="150,100" size="300,200" title="Service Scan">
+                       <widget name="scan_progress" position="10,10" size="280,50" />
+                       <widget name="scan_state" position="10,60" size="280,30" />
+                       <widget name="okbutton" position="10,100" size="280,40" />
+               </screen>
+       </skin>
+""")
+
+
+
+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)