bug
[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 from Components.Label import Label
8
9 import xml.dom.minidom
10 from xml.dom import EMPTY_NAMESPACE
11 from skin import elementsWithTag
12
13 from Tools import XMLTools
14
15 # read the setupmenu
16 try:
17         # first we search in the current path
18         setupfile = file('data/setup.xml', 'r')
19 except:
20         # if not found in the current path, we use the global datadir-path
21         setupfile = file('/usr/share/enigma2/setup.xml', 'r')
22 setupdom = xml.dom.minidom.parseString(setupfile.read())
23 setupfile.close()
24
25 def getValbyAttr(x, attr):
26         for p in range(x.attributes.length):
27                 a = x.attributes.item(p)
28                 attrib = str(a.name)
29                 value = str(a.value)
30                 if attrib == attr:
31                         return value
32         
33         return ""
34
35 class Setup(Screen):
36
37         def addItems(self, list, childNode):
38                 for x in childNode:
39                         if x.nodeType != xml.dom.minidom.Element.nodeType:
40                                 continue
41                         elif x.tagName == 'item':
42                                 ItemText = getValbyAttr(x, "text")
43                                 b = eval(XMLTools.mergeText(x.childNodes));
44                                 print "item " + ItemText + " " + b.configPath
45                                 if b == "":
46                                         continue
47                                 #add to configlist
48                                 item = b.controlType(b)
49                                 
50                                 # the first b is the item itself, ignored by the configList.
51                                 # the second one is converted to string.
52                                 list.append( (ItemText, item) )
53
54         def keyOk(self):
55                 self["config"].handleKey(0)
56         def keyLeft(self):
57                 self["config"].handleKey(1)
58         def keyRight(self):
59                 self["config"].handleKey(2)
60
61         def keySave(self):
62                 print "save requested"
63                 for x in self["config"]:
64                         selection =     self["config"].getCurrent()
65                         selection.save()
66
67         def __init__(self, session, setup):
68                 Screen.__init__(self, session)
69
70                 print "request setup for " + setup
71                 
72                 xmldata = setupdom.childNodes[0]
73                 
74                 entries = xmldata.childNodes
75
76                 list = []
77                                 
78                 for x in entries:             #walk through the actual nodelist
79                         if x.nodeType != xml.dom.minidom.Element.nodeType:
80                                 continue
81                         elif x.tagName == 'setup':
82                                 ItemText = getValbyAttr(x, "key")
83                                 if ItemText != setup:
84                                         continue
85                                 self.addItems(list, x.childNodes);
86                 
87                 #check for list.entries > 0 else self.close
88                 
89                 self["config"] = ConfigList(list)
90
91                 self["ok"] = Label("OK")
92                 self["cancel"] = Label("Cancel")
93
94                 self["actions"] = ActionMap(["SetupActions"], 
95                         {
96                                 "cancel": self.close,
97                                 "ok": self.keyOk,
98                                 "left": self.keyLeft,
99                                 "right": self.keyRight,
100                                 "save": self.keySave
101                         })