add invalidate to eListboxPythonStringContent
[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 configSelection
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.key["choseElement"])
56         def keyLeft(self):
57                 if (self["config"].getCurrent()[1].parent.enabled == True):
58                         self["config"].handleKey(config.key["prevElement"])
59         def keyRight(self):
60                 if (self["config"].getCurrent()[1].parent.enabled == True):
61                         self["config"].handleKey(config.key["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 keyNumberGlobal(self, number):
76                 print "You pressed number " + str(number)
77                 if (self["config"].getCurrent()[1].parent.enabled == True):
78                         self["config"].handleKey(config.key[str(number)])
79
80
81         # TODO ugly as hell. any better ideas?
82         def keyNumber1(self):
83                 self.keyNumberGlobal(1)
84         def keyNumber2(self):
85                 self.keyNumberGlobal(2)
86         def keyNumber3(self):
87                 self.keyNumberGlobal(3)
88         def keyNumber4(self):
89                 self.keyNumberGlobal(4)
90         def keyNumber5(self):
91                 self.keyNumberGlobal(5)
92         def keyNumber6(self):
93                 self.keyNumberGlobal(6)
94         def keyNumber7(self):
95                 self.keyNumberGlobal(7)
96         def keyNumber8(self):
97                 self.keyNumberGlobal(8)
98         def keyNumber9(self):
99                 self.keyNumberGlobal(9)
100         def keyNumber0(self):
101                 self.keyNumberGlobal(0)
102
103
104
105         def __init__(self, session, setup):
106                 Screen.__init__(self, session)
107
108                 print "request setup for " + setup
109                 
110                 xmldata = setupdom.childNodes[0]
111                 
112                 entries = xmldata.childNodes
113
114                 list = []
115                                 
116                 for x in entries:             #walk through the actual nodelist
117                         if x.nodeType != xml.dom.minidom.Element.nodeType:
118                                 continue
119                         elif x.tagName == 'setup':
120                                 ItemText = getValbyAttr(x, "key")
121                                 if ItemText != setup:
122                                         continue
123                                 self.addItems(list, x.childNodes);
124                                 myTitle = getValbyAttr(x, "title")
125                 
126                 #check for list.entries > 0 else self.close
127                 
128                 self["config"] = ConfigList(list)
129
130                 self["title"] = Label(myTitle);
131
132                 self["ok"] = Label("OK")
133                 self["cancel"] = Label("Cancel")
134
135                 self["actions"] = ActionMap(["SetupActions"], 
136                         {
137                                 "cancel": self.keyCancel,
138                                 "ok": self.keyOk,
139                                 "left": self.keyLeft,
140                                 "right": self.keyRight,
141                                 "save": self.keySave,
142                                 "1": self.keyNumber1,
143                                 "2": self.keyNumber2,
144                                 "3": self.keyNumber3,
145                                 "4": self.keyNumber4,
146                                 "5": self.keyNumber5,
147                                 "6": self.keyNumber6,
148                                 "7": self.keyNumber7,
149                                 "8": self.keyNumber8,
150                                 "9": self.keyNumber9,
151                                 "0": self.keyNumber0
152                                 
153                         }, -1)