add rfmod include
[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                 if (self["config"].getCurrent()[1].parent.enabled == True):
55                         self["config"].handleKey(config.choseElement)
56         def keyLeft(self):
57                 if (self["config"].getCurrent()[1].parent.enabled == True):
58                         self["config"].handleKey(config.prevElement)
59         def keyRight(self):
60                 if (self["config"].getCurrent()[1].parent.enabled == True):
61                         self["config"].handleKey(config.nextElement)
62
63         def keySave(self):
64                 print "save requested"
65                 for x in self["config"].list:
66                         x[1].save()
67                 self.close()
68
69         def keyCancel(self):
70                 print "cancel requested"
71                 for x in self["config"].list:
72                         x[1].cancel()
73                 self.close()
74
75         def __init__(self, session, setup):
76                 Screen.__init__(self, session)
77
78                 print "request setup for " + setup
79                 
80                 xmldata = setupdom.childNodes[0]
81                 
82                 entries = xmldata.childNodes
83
84                 list = []
85                                 
86                 for x in entries:             #walk through the actual nodelist
87                         if x.nodeType != xml.dom.minidom.Element.nodeType:
88                                 continue
89                         elif x.tagName == 'setup':
90                                 ItemText = getValbyAttr(x, "key")
91                                 if ItemText != setup:
92                                         continue
93                                 self.addItems(list, x.childNodes);
94                 
95                 #check for list.entries > 0 else self.close
96                 
97                 self["config"] = ConfigList(list)
98
99                 self["ok"] = Label("OK")
100                 self["cancel"] = Label("Cancel")
101
102                 self["actions"] = ActionMap(["SetupActions"], 
103                         {
104                                 "cancel": self.keyCancel,
105                                 "ok": self.keyOk,
106                                 "left": self.keyLeft,
107                                 "right": self.keyRight,
108                                 "save": self.keySave
109                         }, -1)