fake autoscan
[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             # if (norotor)
90             tlist = []
91             SatList = nimmanager.getSatListForNim(config.scan.nims.value)
92
93             for x in SatList:
94                 if self.Satexists(tlist, x[1]) == 0:
95                     tlist.append(x[1])
96                     sat = configElement_nonSave(x[1], configSelection, 0, ("Enable", "Disable"))
97                     self.list.append(getConfigListEntry(nimmanager.getSatDescription(x[1]), sat))
98             
99             # if (rotor):
100            # for sat in nimmanager.satList:
101             #    self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))                
102                 
103         self["config"].list = self.list
104         self["config"].l.setList(self.list)
105         
106     def Satexists(self, tlist, pos):
107         for x in tlist:
108             if x == pos:
109                 return 1
110         return 0    
111     
112     def newConfig(self):
113         print self["config"].getCurrent()
114         if self["config"].getCurrent()[0] == "Type of scan":
115             self.createSetup()
116         if self["config"].getCurrent()[0] == "Tuner":
117             self.createSetup()
118             
119     def createConfig(self):
120             config.scan = ConfigSubsection()
121             config.scan.sat = ConfigSubsection()
122             config.scan.cab = ConfigSubsection()
123             config.scan.ter = ConfigSubsection()        
124         
125             config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, ("Single transponder", "Single satellite", "Multisat"))
126             nimList = [ ]
127             for nim in nimmanager.nimList():
128                 nimList.append(nim[0])
129             nimList.append("all")
130             config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
131             
132             # sat
133             config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [12187], configsequencearg.get("INTEGER", (10000, 14000)))
134             config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 0, ("off", "on"))
135             config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 30000)))
136             config.scan.sat.polarzation = configElement_nonSave("config.scan.sat.polarzation", configSelection, 0, ("horizontal", "vertical"))
137             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"))
138         
139             # cable
140             config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (10000, 14000)))
141             config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 0, ("off", "on"))
142             config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, 0, ("Auto", "16-QAM", "32-QAM", "64-QAM", "128-QAM", "256-QAM"))
143             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"))
144             config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 30000)))
145             
146             # terrestial
147             config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (10000, 14000)))
148             config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 0, ("off", "on"))
149             config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 0, ("Auto", "6 MHz", "7MHz", "8MHz"))
150             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"))
151             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"))
152             config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 0, ("Auto", "16-QAM", "32-QAM", "64-QAM", "128-QAM", "256-QAM"))
153             config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 0, ("Auto", "2K", "8K"))
154             config.scan.ter.guard = configElement_nonSave("config.scan.ter.guard", configSelection, 0, ("Auto", "1/4", "1/8", "1/16", "1/32"))
155             config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 0, ("Auto", "1", "2", "4"))
156             
157             config.scan.scansat = {}
158             for sat in nimmanager.satList:
159                 #print sat[1]
160                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, ("yes", "no"))
161                 
162             config.scan.satselection = []
163             slotid = 0
164             for slot in nimmanager.nimslots:
165                 config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
166         
167     def keyLeft(self):
168         self["config"].handleKey(config.key["prevElement"])
169         self.newConfig()
170
171     def keyRight(self):
172         self["config"].handleKey(config.key["nextElement"])
173         self.newConfig()
174
175     def keyNumberGlobal(self, number):
176         print "You pressed number " + str(number)
177         if (self["config"].getCurrent()[1].parent.enabled == True):
178             self["config"].handleKey(config.key[str(number)])
179
180     def keyGo(self):
181         for x in self["config"].list:
182             x[1].save()
183         self.session.openWithCallback(self.keyCancel, ServiceScan)        
184
185         #self.close()
186
187     def keyCancel(self):
188         for x in self["config"].list:
189             x[1].cancel()
190         self.close()
191
192 class ScanSimple(Screen):
193
194         def keyOK(self):
195                 print "start scan for sats:"
196                 for x in self.list:
197                         if x[1].parent.value == 0:
198                                 print "   " + str(x[1].parent.configPath)
199
200                 self.session.openWithCallback(self.keyCancel, ServiceScan)        
201                 
202         def keyCancel(self):
203                 self.close()
204
205         def keyLeft(self):
206                 self["config"].handleKey(config.key["prevElement"])
207
208         def keyRight(self):
209                 self["config"].handleKey(config.key["nextElement"])
210
211         def Satexists(self, tlist, pos):
212                 for x in tlist:
213                         if x == pos:
214                                 return 1
215                 return 0
216
217         def __init__(self, session):
218                 Screen.__init__(self, session)
219
220                 self["actions"] = ActionMap(["SetupActions"],
221                 {
222                         "ok": self.keyOK,
223                         "cancel": self.keyCancel,
224                         "left": self.keyLeft,
225                         "right": self.keyRight,
226                 }, -1)
227                 
228                 self.list = []
229                 tlist = []
230                 
231                 SatList = nimmanager.getConfiguredSats()
232
233                 for x in SatList:
234                         if self.Satexists(tlist, x) == 0:
235                                 tlist.append(x)
236                                 sat = configElement_nonSave(x, configSelection, 0, ("Enable", "Disable"))
237                                 self.list.append(getConfigListEntry(nimmanager.getSatDescription(x), sat))
238
239                 self["config"] = ConfigList(self.list)
240                 self["header"] = Label("Automatic Scan")
241                 self["footer"] = Label("Press OK to scan")