add save
[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 keySave(self):
55                 print "save requested"
56                 for x in self["config"]:
57                         selection =     self["config"].getCurrent()
58                         selection.save()
59
60         def __init__(self, session, setup):
61                 Screen.__init__(self, session)
62
63                 print "request setup for " + setup
64                 
65                 entries = setupdom.childNodes
66
67                 list = []
68                                 
69                 for x in entries:             #walk through the actual nodelist
70                         if x.nodeType != xml.dom.minidom.Element.nodeType:
71                                 continue
72                         elif x.tagName == 'setup':
73                                 ItemText = getValbyAttr(x, "key")
74                                 if ItemText != setup:
75                                         continue
76                                 self.addItems(list, x.childNodes);
77                 
78                 #check for list.entries > 0 else self.close
79                 
80                 self["config"] = ConfigList(list)
81
82                 self["actions"] = ActionMap(["SetupActions"], 
83                         {
84                                 "cancel": self.close,
85                                 "ok": self.keyOk,
86                                 "left": self.keyLeft,
87                                 "right": self.keyRight,
88                                 "save": self.keySave
89                         })