be10ba6168960f04d371bb8555fa80ebf651ccdf
[vuplus_dvbapp] / lib / python / Screens / Setup.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.config import config                            #global config instance
4 from Components.config import configEntry
5 from Components.config import configBoolean
6 from Components.ConfigList import ConfigList
7
8 import xml.dom.minidom
9 from xml.dom import EMPTY_NAMESPACE
10 from skin import elementsWithTag
11
12 from Tools import XMLTools
13
14 setupdom = xml.dom.minidom.parseString(
15         """
16         <setup key="rc" title="RC Menu">
17                 <item text="Repeat Rate">config.inputDevices.repeat</item>
18                 <item text="Delay Rate">config.inputDevices.delay</item>
19         </setup>
20         """)
21
22 def getValbyAttr(x, attr):
23         for p in range(x.attributes.length):
24                 a = x.attributes.item(p)
25                 attrib = str(a.name)
26                 value = str(a.value)
27                 if attrib == attr:
28                         return value
29         
30         return ""
31
32 class Setup(Screen):
33
34         def addItems(self, list, childNode):
35                 for x in childNode:
36                         if x.nodeType != xml.dom.minidom.Element.nodeType:
37                                 continue
38                         elif x.tagName == 'item':
39                                 ItemText = getValbyAttr(x, "text")
40                                 b = eval(XMLTools.mergeText(x.childNodes));
41                                 print "item " + ItemText + " " + b.configPath
42                                 if b == "":
43                                         continue
44                                 #add to configlist
45                                 list.append( (ItemText, b.controlType(b) ) )
46
47         def keyOk(self):
48                 self["config"].handleKey(0)
49         def keyLeft(self):
50                 self["config"].handleKey(1)
51         def keyRight(self):
52                 self["config"].handleKey(2)
53                                 
54         def __init__(self, session, setup):
55                 Screen.__init__(self, session)
56
57                 print "request setup for " + setup
58                 
59                 entries = setupdom.childNodes
60
61                 list = []
62                                 
63                 for x in entries:             #walk through the actual nodelist
64                         if x.nodeType != xml.dom.minidom.Element.nodeType:
65                                 continue
66                         elif x.tagName == 'setup':
67                                 ItemText = getValbyAttr(x, "key")
68                                 if ItemText != setup:
69                                         continue
70                                 self.addItems(list, x.childNodes);
71                 
72                 #check for list.entries > 0 else self.close
73                 
74                 self["config"] = ConfigList(list)
75
76                 self["actions"] = ActionMap(["SetupActions"], 
77                         {
78                                 "cancel": self.close,
79                                 "ok": self.keyOk,
80                                 "left": self.keyLeft,
81                                 "right": self.keyRight
82                         })