a694ab164951437b819fe181ed428b1a8ab1b1c2
[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 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 setupdom = xml.dom.minidom.parseString(
16         """
17         <setupxml>
18                 <setup key="rc" title="RC Menu">
19                         <item text="Repeat Rate">config.inputDevices.repeat</item>
20                         <item text="Delay Rate">config.inputDevices.delay</item>
21                         <item text="Keymap">config.rc.map</item>
22                 </setup>
23                 <setup key="timezone" title="RC Menu">
24                         <item text="Timezone">config.timezone.val</item>
25                 </setup>
26                 <setup key="avsetup" title="A/V Settings">
27                         <item text="Color Format">config.av.colorformat</item>
28                         <item text="Aspect Ratio">config.av.aspectratio</item>
29                         <item text="TV System">config.av.tvsystem</item>
30                         <item text="WSS">config.av.wss</item>
31                         <item text="AC3 default">config.av.defaultac3</item>
32                         <item text="VCR Switch">config.av.vcrswitch</item>
33                 </setup>
34                 <setup key="rfmod" title="UHF Modulator">
35                         <item text="Modulator">config.rfmod.enable</item>
36                         <item text="Testmode">config.rfmod.test</item>
37                         <item text="Sound">config.rfmod.sound</item>
38                         <item text="Soundcarrier">config.rfmod.soundcarrier</item>
39                         <item text="Channel">config.rfmod.channel</item>
40                         <item text="Finetune">config.rfmod.finetune</item>
41                 </setup>
42                 <setup key="keyboard" title="Keyboard Setup">
43                         <item text="Keyboard Map">config.keyboard.keymap</item>
44                 </setup>
45                 <setup key="osd" title="OSD Settings">
46                         <item text="Alpha">config.osd.alpha</item>
47                         <item text="Brightness">config.osd.bright</item>
48                         <item text="Contrast">config.osd.contrast</item>
49                         <item text="Language">config.osd.language</item>
50                 </setup>
51                 <setup key="lcd" title="LCD Setup">
52                         <item text="Brightness">config.lcd.bright</item>
53                         <item text="Standby">config.lcd.standby</item>
54                         <item text="Invert">config.lcd.invert</item>
55                 </setup>
56                 <setup key="parental" title="Parental Control">
57                         <item text="Parental Lock">config.parental.lock</item>
58                         <item text="Setup Lock">config.parental.setuplock</item>
59                 </setup>
60                 <setup key="expert" title="Expert Setup">
61                         <item text="Record Splitsize">config.expert.splitsize</item>
62                         <item text="Show Satposition">config.expert.satpos</item>
63                         <item text="Fast zapping">config.expert.fastzap</item>
64                         <item text="Skip confirmations">config.expert.skipconfirm</item>
65                         <item text="Hide error windows">config.expert.hideerrors</item>
66                         <item text="Auto show inforbar">config.expert.autoinfo</item>
67                 </setup>
68                 <setup key="satconfig" title="Sat/Dish Setup">
69                         <item text="Tuner-A Control">config.sat.diseqcA</item>
70                         <item text="Tuner-A Position">config.sat.posA</item>
71                         <item text="Tuner-A Sat">config.sat.satA</item>
72                         <item text="Tuner-B Control">config.sat.diseqcB</item>
73                         <item text="Tuner-A Position">config.sat.posB</item>
74                         <item text="Tuner-B Sat">config.sat.satB</item>
75                 </setup>
76         </setupxml>
77         """)
78
79 def getValbyAttr(x, attr):
80         for p in range(x.attributes.length):
81                 a = x.attributes.item(p)
82                 attrib = str(a.name)
83                 value = str(a.value)
84                 if attrib == attr:
85                         return value
86         
87         return ""
88
89 class Setup(Screen):
90
91         def addItems(self, list, childNode):
92                 for x in childNode:
93                         if x.nodeType != xml.dom.minidom.Element.nodeType:
94                                 continue
95                         elif x.tagName == 'item':
96                                 ItemText = getValbyAttr(x, "text")
97                                 b = eval(XMLTools.mergeText(x.childNodes));
98                                 print "item " + ItemText + " " + b.configPath
99                                 if b == "":
100                                         continue
101                                 #add to configlist
102                                 item = b.controlType(b)
103                                 
104                                 # the first b is the item itself, ignored by the configList.
105                                 # the second one is converted to string.
106                                 list.append( (ItemText, item) )
107
108         def keyOk(self):
109                 self["config"].handleKey(0)
110         def keyLeft(self):
111                 self["config"].handleKey(1)
112         def keyRight(self):
113                 self["config"].handleKey(2)
114
115         def keySave(self):
116                 print "save requested"
117                 for x in self["config"]:
118                         selection =     self["config"].getCurrent()
119                         selection.save()
120
121         def __init__(self, session, setup):
122                 Screen.__init__(self, session)
123
124                 print "request setup for " + setup
125                 
126                 xmldata = setupdom.childNodes[0]
127                 
128                 entries = xmldata.childNodes
129
130                 list = []
131                                 
132                 for x in entries:             #walk through the actual nodelist
133                         if x.nodeType != xml.dom.minidom.Element.nodeType:
134                                 continue
135                         elif x.tagName == 'setup':
136                                 ItemText = getValbyAttr(x, "key")
137                                 if ItemText != setup:
138                                         continue
139                                 self.addItems(list, x.childNodes);
140                 
141                 #check for list.entries > 0 else self.close
142                 
143                 self["config"] = ConfigList(list)
144
145                 self["ok"] = Label("OK")
146                 self["cancel"] = Label("Cancel")
147
148                 self["actions"] = ActionMap(["SetupActions"], 
149                         {
150                                 "cancel": self.close,
151                                 "ok": self.keyOk,
152                                 "left": self.keyLeft,
153                                 "right": self.keyRight,
154                                 "save": self.keySave
155                         })