fill configlist with correct entries
[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 = XMLTools.mergeText(x.childNodes);
41                                 print "item " + ItemText + " " + b
42                                 #add to configlist
43                                 list.append( (ItemText, config.getControlType(b) ) )
44                                 
45         def __init__(self, session, setup):
46                 Screen.__init__(self, session)
47
48                 print "request setup for " + setup
49                 
50                 entries = setupdom.childNodes
51
52                 list = []
53                                 
54                 for x in entries:             #walk through the actual nodelist
55                         if x.nodeType != xml.dom.minidom.Element.nodeType:
56                                 continue
57                         elif x.tagName == 'setup':
58                                 ItemText = getValbyAttr(x, "key")
59                                 if ItemText != setup:
60                                         continue
61                                 self.addItems(list, x.childNodes);
62                 
63                 #check for list.entries > 0 else self.close
64                 self["config"] = ConfigList(list)
65
66                 self["actions"] = ActionMap(["OkCancelActions"], 
67                         {
68                                 "ok": self["config"].toggle,
69                                 "cancel": self.close
70                         })