add very simple scan
[enigma2.git] / lib / python / Screens / ScanSetup.py
1 from Screen import Screen
2 from ServiceScan import *
3 from Components.config import *
4 from Components.ActionMap import NumberActionMap
5 from Components.ConfigList import ConfigList
6 from Components.config import config
7 from Components.config import getConfigListEntry
8 from Components.NimManager import nimmanager
9 from Components.Label import Label
10
11 class ScanSetup(Screen):
12     def __init__(self, session):
13         Screen.__init__(self, session)
14         
15         self.updateSatList()
16         self.createConfig()
17
18         
19         self["actions"] = NumberActionMap(["SetupActions"],
20         {
21             "ok": self.keyGo,
22             "cancel": self.keyCancel,
23             "left": self.keyLeft,
24             "right": self.keyRight,
25             "1": self.keyNumberGlobal,
26             "2": self.keyNumberGlobal,
27             "3": self.keyNumberGlobal,
28             "4": self.keyNumberGlobal,
29             "5": self.keyNumberGlobal,
30             "6": self.keyNumberGlobal,
31             "7": self.keyNumberGlobal,
32             "8": self.keyNumberGlobal,
33             "9": self.keyNumberGlobal,
34             "0": self.keyNumberGlobal
35         }, -1)
36                 
37         self.list = []
38         self["config"] = ConfigList(self.list)
39         self.createSetup()
40
41         self["introduction"] = Label("Press OK to start the scan")
42
43     def updateSatList(self):
44         self.satList = []
45         for slot in nimmanager.nimslots:
46             self.satList.append(nimmanager.getSatListForNim(slot.slotid))
47             
48     def createSetup(self):
49         self.list = []
50         
51         self.list.append(getConfigListEntry("Type of scan", config.scan.type))
52         self.list.append(getConfigListEntry("Tuner", config.scan.nims))
53         
54         # single transponder scan
55         if (config.scan.type.value == 0):
56             if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
57                 self.list.append(getConfigListEntry("Frequency", config.scan.sat.frequency))
58                 self.list.append(getConfigListEntry("Inversion", config.scan.sat.inversion))
59                 self.list.append(getConfigListEntry("Symbolrate", config.scan.sat.symbolrate))
60                 self.list.append(getConfigListEntry("Polarity", config.scan.sat.polarzation))
61                 self.list.append(getConfigListEntry("FEC", config.scan.sat.fec))
62             if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
63                 self.list.append(getConfigListEntry("Frequency", config.scan.cab.frequency))
64                 self.list.append(getConfigListEntry("Inversion", config.scan.cab.inversion))
65                 self.list.append(getConfigListEntry("Symbolrate", config.scan.cab.symbolrate))
66                 self.list.append(getConfigListEntry("Modulation", config.scan.cab.modulation))
67                 self.list.append(getConfigListEntry("FEC", config.scan.cab.fec))
68             if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
69                 self.list.append(getConfigListEntry("Frequency", config.scan.ter.frequency))
70                 self.list.append(getConfigListEntry("Inversion", config.scan.ter.inversion))
71                 self.list.append(getConfigListEntry("Bandwidth", config.scan.ter.bandwidth))
72                 self.list.append(getConfigListEntry("Code rate high", config.scan.ter.fechigh))
73                 self.list.append(getConfigListEntry("Code rate low", config.scan.ter.feclow))
74                 self.list.append(getConfigListEntry("Modulation", config.scan.ter.modulation))
75                 self.list.append(getConfigListEntry("Transmission mode", config.scan.ter.transmission))
76                 self.list.append(getConfigListEntry("Guard interval mode", config.scan.ter.guard))
77                 self.list.append(getConfigListEntry("Hierarchy mode", config.scan.ter.hierarchy))
78
79         # single satellite scan
80         print config.scan.satselection
81         if (config.scan.type.value == 1):
82             self.updateSatList()
83             print config.scan.satselection[config.scan.nims.value]
84             self.list.append(getConfigListEntry("Satellite", config.scan.satselection[config.scan.nims.value]))
85             
86         
87         # multi sat scan
88         if (config.scan.type.value == 2):
89             for sat in nimmanager.satList:
90                 self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))                
91                 
92         self["config"].list = self.list
93         self["config"].l.setList(self.list)
94         
95     def newConfig(self):
96         print self["config"].getCurrent()
97         if self["config"].getCurrent()[0] == "Type of scan":
98             self.createSetup()
99         if self["config"].getCurrent()[0] == "Tuner":
100             self.createSetup()
101             
102     def createConfig(self):
103             config.scan = ConfigSubsection()
104             config.scan.sat = ConfigSubsection()
105             config.scan.cab = ConfigSubsection()
106             config.scan.ter = ConfigSubsection()        
107         
108             config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, ("Single transponder", "Single satellite", "Multisat"))
109             nimList = [ ]
110             for nim in nimmanager.nimList():
111                 nimList.append(nim[0])
112             nimList.append("all")
113             config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
114             
115             # sat
116             config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [12187], configsequencearg.get("INTEGER", (10000, 14000)))
117             config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 0, ("off", "on"))
118             config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 30000)))
119             config.scan.sat.polarzation = configElement_nonSave("config.scan.sat.polarzation", configSelection, 0, ("horizontal", "vertical"))
120             config.scan.sat.fec = configElement_nonSave("config.scan.sat.fec", configSelection, 0, ("Auto", "1/2", "2/3", "3/4", "4/5", "5/6", "7/8", "8/9"))
121         
122             # cable
123             config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (10000, 14000)))
124             config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 0, ("off", "on"))
125             config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, 0, ("Auto", "16-QAM", "32-QAM", "64-QAM", "128-QAM", "256-QAM"))
126             config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, 0, ("Auto", "1/2", "2/3", "3/4", "4/5", "5/6", "7/8", "8/9"))
127             config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 30000)))
128             
129             # terrestial
130             config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (10000, 14000)))
131             config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 0, ("off", "on"))
132             config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 0, ("Auto", "6 MHz", "7MHz", "8MHz"))
133             config.scan.ter.fechigh = configElement_nonSave("config.scan.ter.fechigh", configSelection, 0, ("Auto", "1/2", "2/3", "3/4", "4/5", "5/6", "7/8", "8/9"))
134             config.scan.ter.feclow = configElement_nonSave("config.scan.ter.feclow", configSelection, 0, ("Auto", "1/2", "2/3", "3/4", "4/5", "5/6", "7/8", "8/9"))
135             config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 0, ("Auto", "16-QAM", "32-QAM", "64-QAM", "128-QAM", "256-QAM"))
136             config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 0, ("Auto", "2K", "8K"))
137             config.scan.ter.guard = configElement_nonSave("config.scan.ter.guard", configSelection, 0, ("Auto", "1/4", "1/8", "1/16", "1/32"))
138             config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 0, ("Auto", "1", "2", "4"))
139             
140             config.scan.scansat = {}
141             for sat in nimmanager.satList:
142                 #print sat[1]
143                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, ("yes", "no"))
144                 
145             config.scan.satselection = []
146             slotid = 0
147             for slot in nimmanager.nimslots:
148                 config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
149         
150     def keyLeft(self):
151         self["config"].handleKey(config.key["prevElement"])
152         self.newConfig()
153
154     def keyRight(self):
155         self["config"].handleKey(config.key["nextElement"])
156         self.newConfig()
157
158     def keyNumberGlobal(self, number):
159         print "You pressed number " + str(number)
160         if (self["config"].getCurrent()[1].parent.enabled == True):
161             self["config"].handleKey(config.key[str(number)])
162
163     def keyGo(self):
164         for x in self["config"].list:
165             x[1].save()
166         self.session.openWithCallback(self.keyCancel, ServiceScan)        
167
168         #self.close()
169
170     def keyCancel(self):
171         for x in self["config"].list:
172             x[1].cancel()
173         self.close()
174
175 class ScanSimple(Screen):
176
177         def keyOK(self):
178                 print "start scan for sats:"
179                 for x in self.list:
180                         if x[1].parent.value == 0:
181                                 print "   " + str(x[1].parent.configPath)
182                 
183         def keyCancel(self):
184                 self.close()
185
186         def keyLeft(self):
187                 self["config"].handleKey(config.key["prevElement"])
188
189         def keyRight(self):
190                 self["config"].handleKey(config.key["nextElement"])
191
192         def __init__(self, session):
193                 Screen.__init__(self, session)
194
195                 self["actions"] = ActionMap(["SetupActions"],
196                 {
197                         "ok": self.keyOK,
198                         "cancel": self.keyCancel,
199                         "left": self.keyLeft,
200                         "right": self.keyRight,
201                 }, -1)
202                 
203                 self.list = []
204                 
205                 SatList = nimmanager.getConfiguredSats()
206
207                 for x in SatList:
208                         sat = configElement_nonSave(x, configSelection, 0, ("Enable", "Disable"))
209                         self.list.append(getConfigListEntry(nimmanager.getSatDescription(x), sat))
210
211                 self["config"] = ConfigList(self.list)
212                 self["header"] = Label("Automatic Scan")
213                 self["footer"] = Label("Press OK to scan")