- added iStaticServiceInformation
[openblackhole/openblackhole-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="mainMenu" position="300,100" size="300,300" title="real main menu">
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="infoBar" position="100,100" size="500,400" title="InfoBar">
27                         <widget name="channelSwitcher" position="10,190" size="280,50" />
28                 </screen>
29                 <screen name="channelSelection" position="300,100" size="300,300" title="Channel Selection">
30                         <widget name="okbutton" position="10,190" size="280,50" />
31                         <widget name="list" position="10,30" size="280,140" />
32                 </screen>
33         </skin>
34 """)
35
36
37
38 def parsePosition(str):
39         x, y = str.split(',')
40         return ePoint(int(x), int(y))
41
42 def parseSize(str):
43         x, y = str.split(',')
44         return eSize(int(x), int(y))
45
46 def applyAttributes(guiObject, node):
47         # walk all attributes
48         for p in range(node.attributes.length):
49                 a = node.attributes.item(p)
50                 
51                 # convert to string (was: unicode)
52                 attrib = str(a.name)
53                 # TODO: proper UTF8 translation?! (for value)
54                 # TODO: localization? as in e1?
55                 value = str(a.value)
56                 
57                 # and set attributes
58                 if attrib == 'position':
59                         guiObject.move(parsePosition(value))
60                 elif attrib == 'size':
61                         guiObject.resize(parseSize(value))
62                 elif attrib == 'title':
63                         guiObject.setTitle(value)
64                 elif attrib != 'name':
65                         print "unsupported attribute " + attrib + "=" + value
66
67 def applyGUIskin(screen, parent, skin, name):
68         
69         myscreen = None
70         
71         # first, find the corresponding screen element
72         skin = dom.getElementsByTagName("skin")[0]
73         screens = skin.getElementsByTagName("screen")
74         del skin
75         for x in screens:
76                 if x.getAttribute('name') == name:
77                         myscreen = x
78         
79         assert myscreen != None, "no skin for screen '" + name + "' found!"
80         
81         applyAttributes(parent, myscreen)
82         
83         # now walk all widgets
84         for widget in myscreen.getElementsByTagName("widget"):
85                 wname = widget.getAttribute('name')
86                 if wname == None:
87                         print "widget has no name!"
88                         continue
89                 
90                 # get corresponding gui object
91                 try:
92                         guiObject = screen.data[wname]["instance"]
93                 except:
94                         raise str("component with name '" + wname + "' was not found in skin of screen '" + name + "'!")
95                 
96                 applyAttributes(guiObject, widget)