- fixed dvb scan
[enigma2.git] / skin.py
1 from enigma import *
2 import xml.dom.minidom
3 from xml.dom import EMPTY_NAMESPACE
4
5 def dump(x, i=0):
6         print " " * i + str(x)
7         try:
8                 for n in x.childNodes:
9                         dump(n, i + 1)
10         except:
11                 None
12
13 dom = xml.dom.minidom.parseString(
14         """
15         <skin>
16                 <screen name="testDialog">
17                         <widget name="okbutton" position="10,190" size="280,50" />
18                         <widget name="title" position="10,10" size="280,20" />
19                         <widget name="menu" position="10,30" size="280,140" />
20                 </screen>
21                 <screen name="clockDisplay" position="300,100" size="300,300">
22                         <widget name="okbutton" position="10,10" size="280,40" />
23                         <widget name="title" position="10,120" size="280,50" />
24                         <widget name="theClock" position="10,60" size="280,50" />
25                 </screen>
26                 <screen name="mainMenu" position="300,100" size="300,300">
27                         <widget name="title" position="10,10" size="280,80" />
28                         <widget name="okbutton" position="10,190" size="280,50" />
29                 </screen>
30         </skin>
31 """)
32
33
34
35 def parsePosition(str):
36         x, y = str.split(',')
37         return ePoint(int(x), int(y))
38
39 def parseSize(str):
40         x, y = str.split(',')
41         return eSize(int(x), int(y))
42
43 def applyAttributes(guiObject, node):
44         # walk all attributes
45         for p in range(node.attributes.length):
46                 a = node.attributes.item(p)
47                 
48                 # and set attributes
49                 if a.name == 'position':
50                         guiObject.move(parsePosition(a.value))
51                 elif a.name == 'size':
52                         guiObject.resize(parseSize(a.value))
53                 elif a.name != 'name':
54                         print "unsupported attribute " + a.name
55
56 def applyGUIskin(screen, skin, name):
57         
58         myscreen = None
59         
60         # first, find the corresponding screen element
61         skin = dom.getElementsByTagName("skin")[0]
62         screens = skin.getElementsByTagName("screen")
63         del skin
64         for x in screens:
65                 if x.getAttribute('name') == name:
66                         myscreen = x
67         
68         assert myscreen != None, "no skin for screen '" + name + "' found!"
69         
70         # now walk all widgets
71         for widget in myscreen.getElementsByTagName("widget"):
72                 wname = widget.getAttribute('name')
73                 if wname == None:
74                         print "widget has no name!"
75                         continue
76                 
77                 # get corresponding gui object
78                 try:
79                         guiObject = screen.data[wname]["instance"]
80                 except:
81                         raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
82                 
83                 applyAttributes(guiObject, widget)