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