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