introduce BlinkingPointConditional, which blinks, if a condition-function returns...
[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 from enigma import eDVBFrontendParametersSatellite, eComponentScan
11
12 def getInitialTransponderList(tlist, pos):
13         print pos
14         list = nimmanager.getTransponders(pos)
15
16         for x in list:
17                 if x[0] == 0:           #SAT
18                         parm = eDVBFrontendParametersSatellite()
19                         parm.frequency = x[1]
20                         parm.symbol_rate = x[2]
21                         parm.polarisation = x[3] # eDVBFrontendParametersSatellite.Polarisation.Vertical
22                         #parm.fec = x[4]                        # eDVBFrontendParametersSatellite.FEC.f3_4;
23                         parm.fec = 6                                    # AUTO
24                         #parm.inversion = 1     #eDVBFrontendParametersSatellite.Inversion.Off;
25                         parm.inversion = 2              #AUTO
26                         parm.orbital_position = pos
27                         tlist.append(parm)
28
29 class ScanSetup(Screen):
30         def __init__(self, session):
31                 Screen.__init__(self, session)
32
33                 self.updateSatList()
34                 self.createConfig()
35
36
37                 self["actions"] = NumberActionMap(["SetupActions"],
38                 {
39                         "ok": self.keyGo,
40                         "cancel": self.keyCancel,
41                         "left": self.keyLeft,
42                         "right": self.keyRight,
43                         "1": self.keyNumberGlobal,
44                         "2": self.keyNumberGlobal,
45                         "3": self.keyNumberGlobal,
46                         "4": self.keyNumberGlobal,
47                         "5": self.keyNumberGlobal,
48                         "6": self.keyNumberGlobal,
49                         "7": self.keyNumberGlobal,
50                         "8": self.keyNumberGlobal,
51                         "9": self.keyNumberGlobal,
52                         "0": self.keyNumberGlobal
53                 }, -1)
54
55                 self.list = []
56                 self["config"] = ConfigList(self.list)
57                 self.createSetup()
58
59                 self["introduction"] = Label(_("Press OK to start the scan"))
60
61         def updateSatList(self):
62                 self.satList = []
63                 for slot in nimmanager.nimslots:
64                         if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
65                                 self.satList.append(nimmanager.getSatListForNim(slot.slotid))
66                         else:
67                                 self.satList.append(None)
68                                 
69         def createSetup(self):
70                 self.list = []
71
72                 print "ID: " + str(config.scan.nims.value)
73
74                 self.list.append(getConfigListEntry(_("Tuner"), config.scan.nims))
75                 
76                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
77                         self.list.append(getConfigListEntry(_("Type of scan"), config.scan.type))
78                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
79                         self.list.append(getConfigListEntry(_("Type of scan"), config.scan.typecable))
80                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
81                         self.list.append(getConfigListEntry(_("Type of scan"), config.scan.typeterrestrial))
82
83
84                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
85                         if (config.scan.type.value == 0): # single transponder scan
86                                 self.list.append(getConfigListEntry(_('Satellite'), config.scan.satselection[config.scan.nims.value]))
87                                 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
88                                 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
89                                 self.list.append(getConfigListEntry(_('Symbolrate'), config.scan.sat.symbolrate))
90                                 self.list.append(getConfigListEntry(_("Polarity"), config.scan.sat.polarization))
91                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec))
92                         if (config.scan.type.value == 1): # single satellite scan
93                                 self.updateSatList()
94                                 print config.scan.satselection[config.scan.nims.value]
95                                 self.list.append(getConfigListEntry(_("Satellite"), config.scan.satselection[config.scan.nims.value]))
96                         if (config.scan.type.value == 2): # multi sat scan
97                                 # if (norotor)
98                                 tlist = []
99                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
100         
101                                 for x in SatList:
102                                         if self.Satexists(tlist, x[1]) == 0:
103                                                 tlist.append(x[1])
104                                                 sat = configElement_nonSave(x[1], configSelection, 0, (_("Enable"), _("Disable")))
105                                                 self.list.append(getConfigListEntry(nimmanager.getSatDescription(x[1]), sat))
106         
107                                 # if (rotor):
108                            # for sat in nimmanager.satList:
109                                 #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
110
111
112                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
113                         if (config.scan.typecable.value == 0): # single transponder
114                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.cab.frequency))
115                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.cab.inversion))
116                                 self.list.append(getConfigListEntry(_("Symbolrate"), config.scan.cab.symbolrate))
117                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.cab.modulation))
118                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.cab.fec))
119                         if (config.scan.typecable.value == 1): # complete
120                                 pass
121                                 
122                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
123                         if (config.scan.typeterrestrial.value == 0): # single transponder
124                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.ter.frequency))
125                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.ter.inversion))
126                                 self.list.append(getConfigListEntry(_("Bandwidth"), config.scan.ter.bandwidth))
127                                 self.list.append(getConfigListEntry(_("Code rate high"), config.scan.ter.fechigh))
128                                 self.list.append(getConfigListEntry(_("Code rate low"), config.scan.ter.feclow))
129                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.ter.modulation))
130                                 self.list.append(getConfigListEntry(_("Transmission mode"), config.scan.ter.transmission))
131                                 self.list.append(getConfigListEntry(_("Guard interval mode"), config.scan.ter.guard))
132                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), config.scan.ter.hierarchy))
133                         if (config.scan.typeterrestrial.value == 1): # complete
134                                 pass
135
136                 self["config"].list = self.list
137                 self["config"].l.setList(self.list)
138
139         def Satexists(self, tlist, pos):
140                 for x in tlist:
141                         if x == pos:
142                                 return 1
143                 return 0
144
145         def newConfig(self):
146                 print self["config"].getCurrent()
147                 if self["config"].getCurrent()[0] == _("Type of scan"):
148                         self.createSetup()
149                 if self["config"].getCurrent()[0] == _("Tuner"):
150                         self.createSetup()
151
152         def createConfig(self):
153                         config.scan = ConfigSubsection()
154                         config.scan.sat = ConfigSubsection()
155                         config.scan.cab = ConfigSubsection()
156                         config.scan.ter = ConfigSubsection()
157
158                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, ("Single transponder", "Single satellite", "Multisat"))
159                         config.scan.typecable = configElement_nonSave("config.scan.typecable", configSelection, 0, ("Single transponder", "Complete"))
160                         config.scan.typeterrestrial = configElement_nonSave("config.scan.typeterrestrial", configSelection, 0, ("Single transponder", "Complete"))
161
162                         nimList = [ ]
163                         for nim in nimmanager.nimList():
164                                 nimList.append(nim[0])
165                         nimList.append("all")
166                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
167
168                         # sat
169                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [11836], configsequencearg.get("INTEGER", (10000, 14000)))
170                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 2, (_("on"), _("off"), _("Auto")))
171                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 9999)))
172                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, 0, (_("horizontal"), _("vertical"),  _("circular left"), _("circular right")))
173                         config.scan.sat.fec = configElement_nonSave("config.scan.sat.fec", configSelection, 7, ("None", "1/2", "2/3", "3/4", "5/6", "7/8", "auto"))
174
175                         # cable
176                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (50, 9999)))
177                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 2, (_("off"), _("on"), _("Auto")))
178                         config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, 2, ("16-QAM", "32-QAM", "64-QAM", "128-QAM", "256-QAM", _("Auto")))
179                         config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, 9, (_("None"), "1/2", "2/3", "3/4", "4/5", "5/6", "6/7", "7/8", "8/9", _("Auto")))
180                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 30000)))
181
182                         # terrestial
183                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (10000, 14000)))
184                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 2, (_("off"), _("on"), _("Auto")))
185                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 3, ("8MHz", "7MHz", "6MHz", _("Auto")))
186                         config.scan.ter.fechigh = configElement_nonSave("config.scan.ter.fechigh", configSelection, 6, (_("None"), "1/2", "2/3", "3/4", "5/6", "7/8", _("Auto")))
187                         config.scan.ter.feclow = configElement_nonSave("config.scan.ter.feclow", configSelection, 6, (_("None"), "1/2", "2/3", "3/4", "5/6", "7/8", _("Auto")))
188                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 2, ("QPSK", "QAM16", _("Auto")))
189                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 2, ("2K", "8K", _("Auto")))
190                         config.scan.ter.guard = configElement_nonSave("config.scan.ter.guard", configSelection, 4, ("1/32", "1/16", "1/8", "1/4", _("Auto")))
191                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 4, (_("None"), "1", "2", "4", _("Auto")))
192
193                         config.scan.scansat = {}
194                         for sat in nimmanager.satList:
195                                 #print sat[1]
196                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, (_("yes"), _("no")))
197
198                         config.scan.satselection = []
199                         slotid = 0
200                         for slot in nimmanager.nimslots:
201                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
202                                         print str(slot.slotid) + " : " + str(self.satList)
203                                         config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
204                                 else:
205                                         config.scan.satselection.append(None)
206         def keyLeft(self):
207                 self["config"].handleKey(config.key["prevElement"])
208                 self.newConfig()
209
210         def keyRight(self):
211                 self["config"].handleKey(config.key["nextElement"])
212                 self.newConfig()
213
214         def keyNumberGlobal(self, number):
215                 print "You pressed number " + str(number)
216                 if (self["config"].getCurrent()[1].parent.enabled == True):
217                         self["config"].handleKey(config.key[str(number)])
218
219         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
220                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
221                 print "orbpos: " + str(orbital_position)
222                 parm = eDVBFrontendParametersSatellite()
223                 parm.frequency = frequency * 1000
224                 parm.symbol_rate = symbol_rate * 1000
225                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
226                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
227                 #parm.fec = 6                                   # AUTO
228                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
229                 #parm.inversion = 2             #AUTO
230                 parm.orbital_position = int(orbital_position)
231                 tlist.append(parm)
232
233         # FIXME use correct parameters
234         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
235                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
236                 parm = eDVBFrontendParametersCable()
237                 parm.frequency = frequency * 1000
238                 parm.symbol_rate = symbol_rate * 1000
239                 parm.modulation = modulation # eDVBFrontendParametersSatellite.Polarisation.Verti       
240                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
241                 #parm.fec = 6                                   # AUTO
242                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
243                 #parm.inversion = 2             #AUTO
244                 tlist.append(parm)
245
246         # FIXME use correct parameters
247         def addTerTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
248                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
249                 print "orbpos: " + str(orbital_position)
250                 parm = eDVBFrontendParametersTerrestrial()
251                 parm.frequency = frequency * 1000
252                 parm.symbol_rate = symbol_rate * 1000
253                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
254                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
255                 #parm.fec = 6                                   # AUTO
256                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
257                 #parm.inversion = 2             #AUTO
258                 parm.orbital_position = int(orbital_position)
259                 tlist.append(parm)
260
261         def keyGo(self):
262                 tlist = []
263                 flags = 0
264                 if (config.scan.type.value == 0): # single transponder scan
265                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
266                                 self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
267                                                                                           config.scan.sat.symbolrate.value[0],
268                                                                                           config.scan.sat.polarization.value,
269                                                                                           config.scan.sat.fec.value,
270                                                                                           config.scan.sat.inversion.value,
271                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
272                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
273                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
274                                                                                           config.scan.cab.symbolrate.value[0],
275                                                                                           config.scan.cab.modulation.value,
276                                                                                           config.scan.cab.fec.value,
277                                                                                           config.scan.cab.inversion.value)
278                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
279                                 self.addTerTransponder(tlist, config.scan.sat.frequency.value[0],
280                                                                                           config.scan.sat.symbolrate.value[0],
281                                                                                           config.scan.sat.polarization.value,
282                                                                                           config.scan.sat.fec.value,
283                                                                                           config.scan.sat.inversion.value,
284                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
285
286                 if (config.scan.type.value == 1): # single sat scan
287                         getInitialTransponderList(tlist, int(self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1]))
288                         flags |= eComponentScan.scanNetworkSearch
289
290                 if (config.scan.type.value == 2): # multi sat scan
291                         SatList = nimmanager.getSatListForNim(config.scan.nims.value)
292
293                         for x in self.list:
294                                 if x[1].parent.value == 0:
295                                         print "   " + str(x[1].parent.configPath)
296                                         getInitialTransponderList(tlist, x[1].parent.configPath)
297                         flags |= eComponentScan.scanNetworkSearch
298
299                 for x in self["config"].list:
300                         x[1].save()
301
302                 feid = config.scan.nims.value
303                 # flags |= eComponentScan.scanSearchBAT
304                 self.session.openWithCallback(self.keyCancel, ServiceScan, tlist, feid, flags)
305
306                 #self.close()
307
308         def keyCancel(self):
309                 for x in self["config"].list:
310                         x[1].cancel()
311                 self.close()
312
313 class ScanSimple(Screen):
314
315         def keyOK(self):
316                 print "start scan for sats:"
317                 tlist = [ ]
318                 for x in self.list:
319                         if x[1].parent.value == 0:
320                                 print "   " + str(x[1].parent.configPath)
321                                 getInitialTransponderList(tlist, x[1].parent.configPath)
322
323                 feid = 0 # FIXME
324                 self.session.openWithCallback(self.keyCancel, ServiceScan, tlist, feid, eComponentScan.scanNetworkSearch)
325
326         def keyCancel(self):
327                 self.close()
328
329         def keyLeft(self):
330                 self["config"].handleKey(config.key["prevElement"])
331
332         def keyRight(self):
333                 self["config"].handleKey(config.key["nextElement"])
334
335         def Satexists(self, tlist, pos):
336                 for x in tlist:
337                         if x == pos:
338                                 return 1
339                 return 0
340
341         def __init__(self, session):
342                 Screen.__init__(self, session)
343
344                 self["actions"] = ActionMap(["SetupActions"],
345                 {
346                         "ok": self.keyOK,
347                         "cancel": self.keyCancel,
348                         "left": self.keyLeft,
349                         "right": self.keyRight,
350                 }, -1)
351
352                 self.list = []
353                 tlist = []
354
355                 SatList = nimmanager.getConfiguredSats()
356
357                 for x in SatList:
358                         if self.Satexists(tlist, x) == 0:
359                                 tlist.append(x)
360                                 sat = configElement_nonSave(x, configSelection, 0, (_("Enable"), _("Disable")))
361                                 self.list.append(getConfigListEntry(nimmanager.getSatDescription(x), sat))
362
363                 self["config"] = ConfigList(self.list)
364                 self["header"] = Label(_("Automatic Scan"))
365                 self["footer"] = Label(_("Press OK to scan"))