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