de27ff5ee9f235f9ce0e5cd26a0e3af2501bb7ef
[enigma2.git] / 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                                 item = b.controlType(b)
46                                 
47                                 # the first b is the item itself, ignored by the configList.
48                                 # the second one is converted to string.
49                                 list.append( (ItemText, item) )
50
51         def keyOk(self):
52                 self["config"].handleKey(0)
53         def keyLeft(self):
54                 self["config"].handleKey(1)
55         def keyRight(self):
56                 self["config"].handleKey(2)
57
58         def keySave(self):
59                 print "save requested"
60                 for x in self["config"]:
61                         selection =     self["config"].getCurrent()
62                         selection.save()
63
64         def __init__(self, session, setup):
65                 Screen.__init__(self, session)
66
67                 print "request setup for " + setup
68                 
69                 entries = setupdom.childNodes
70
71                 list = []
72                                 
73                 for x in entries:             #walk through the actual nodelist
74                         if x.nodeType != xml.dom.minidom.Element.nodeType:
75                                 continue
76                         elif x.tagName == 'setup':
77                                 ItemText = getValbyAttr(x, "key")
78                                 if ItemText != setup:
79                                         continue
80                                 self.addItems(list, x.childNodes);
81                 
82                 #check for list.entries > 0 else self.close
83                 
84                 self["config"] = ConfigList(list)
85
86                 self["actions"] = ActionMap(["SetupActions"], 
87                         {
88                                 "cancel": self.close,
89                                 "ok": self.keyOk,
90                                 "left": self.keyLeft,
91                                 "right": self.keyRight,
92                                 "save": self.keySave
93                         })