ScanSetup - Predefined transponder - added system option (dvb-t/t2) for scan
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / ScanSetup.py
1 from Screen import Screen
2 from ServiceScan import ServiceScan
3 from Components.config import config, ConfigSubsection, ConfigSelection, \
4         ConfigYesNo, ConfigInteger, getConfigListEntry, ConfigSlider, ConfigEnableDisable
5 from Components.ActionMap import NumberActionMap, ActionMap
6 from Components.ConfigList import ConfigListScreen
7 from Components.NimManager import nimmanager, getConfigSatlist
8 from Components.Label import Label
9 from Tools.HardwareInfo import HardwareInfo
10 from Tools.Transponder import getChannelNumber, supportedChannels, channel2frequency
11 from Screens.InfoBar import InfoBar
12 from Screens.MessageBox import MessageBox
13 from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, \
14         eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial, \
15         eDVBFrontendParametersCable, eConsoleAppContainer, eDVBResourceManager
16
17 def buildTerTransponder(frequency,
18                 inversion=2, bandwidth = 7000000, fechigh = 6, feclow = 6,
19                 modulation = 2, transmission = 2, guard = 4,
20                 hierarchy = 4, system = 0, plpid = 0):
21 #       print "freq", frequency, "inv", inversion, "bw", bandwidth, "fech", fechigh, "fecl", feclow, "mod", modulation, "tm", transmission, "guard", guard, "hierarchy", hierarchy
22         parm = eDVBFrontendParametersTerrestrial()
23         parm.frequency = frequency
24         parm.inversion = inversion
25         parm.bandwidth = bandwidth
26         parm.code_rate_HP = fechigh
27         parm.code_rate_LP = feclow
28         parm.modulation = modulation
29         parm.transmission_mode = transmission
30         parm.guard_interval = guard
31         parm.hierarchy = hierarchy
32         parm.system = system
33         parm.plpid = plpid
34         return parm
35
36 def getInitialTransponderList(tlist, pos):
37         list = nimmanager.getTransponders(pos)
38         for x in list:
39                 if x[0] == 0:           #SAT
40                         parm = eDVBFrontendParametersSatellite()
41                         parm.frequency = x[1]
42                         parm.symbol_rate = x[2]
43                         parm.polarisation = x[3]
44                         parm.fec = x[4]
45                         parm.inversion = x[7]
46                         parm.orbital_position = pos
47                         parm.system = x[5]
48                         parm.modulation = x[6]
49                         parm.rolloff = x[8]
50                         parm.pilot = x[9]
51                         tlist.append(parm)
52
53 def getInitialCableTransponderList(tlist, nim):
54         list = nimmanager.getTranspondersCable(nim)
55         for x in list:
56                 if x[0] == 1: #CABLE
57                         parm = eDVBFrontendParametersCable()
58                         parm.frequency = x[1]
59                         parm.symbol_rate = x[2]
60                         parm.modulation = x[3]
61                         parm.fec_inner = x[4]
62                         parm.inversion = x[5]
63                         parm.system = x[6]
64                         tlist.append(parm)
65
66 def getInitialTerrestrialTransponderList(tlist, region):
67         list = nimmanager.getTranspondersTerrestrial(region)
68
69         #self.transponders[self.parsedTer].append((2,freq,bw,const,crh,crl,guard,transm,hierarchy,inv))
70
71         #def buildTerTransponder(frequency, inversion = 2, bandwidth = 3, fechigh = 6, feclow = 6,
72                                 #modulation = 2, transmission = 2, guard = 4, hierarchy = 4):
73
74         for x in list:
75                 if x[0] == 2: #TERRESTRIAL
76                         parm = buildTerTransponder(x[1], x[9], x[2], x[4], x[5], x[3], x[7], x[6], x[8], x[10], x[11])
77                         tlist.append(parm)
78
79 cable_bands = {
80         "DVBC_BAND_EU_VHF_I" : 1 << 0,
81         "DVBC_BAND_EU_MID" : 1 << 1,
82         "DVBC_BAND_EU_VHF_III" : 1 << 2,
83         "DVBC_BAND_EU_SUPER" : 1 << 3,
84         "DVBC_BAND_EU_HYPER" : 1 << 4,
85         "DVBC_BAND_EU_UHF_IV" : 1 << 5,
86         "DVBC_BAND_EU_UHF_V" : 1 << 6,
87         "DVBC_BAND_US_LO" : 1 << 7,
88         "DVBC_BAND_US_MID" : 1 << 8,
89         "DVBC_BAND_US_HI" : 1 << 9,
90         "DVBC_BAND_US_SUPER" : 1 << 10,
91         "DVBC_BAND_US_HYPER" : 1 << 11,
92 }
93
94 class CableTransponderSearchSupport:
95 #       def setCableTransponderSearchResult(self, tlist):
96 #               pass
97
98 #       def cableTransponderSearchFinished(self):
99 #               pass
100
101         def tryGetRawFrontend(self, feid):
102                 res_mgr = eDVBResourceManager.getInstance()
103                 if res_mgr:
104                         raw_channel = res_mgr.allocateRawChannel(self.feid)
105                         if raw_channel:
106                                 frontend = raw_channel.getFrontend()
107                                 if frontend:
108                                         frontend.closeFrontend() # immediate close...
109                                         del frontend
110                                         del raw_channel
111                                         return True
112                 return False
113
114         def cableTransponderSearchSessionClosed(self, *val):
115                 print "cableTransponderSearchSessionClosed, val", val
116                 self.cable_search_container.appClosed.remove(self.cableTransponderSearchClosed)
117                 self.cable_search_container.dataAvail.remove(self.getCableTransponderData)
118                 if val and len(val):
119                         if val[0]:
120                                 self.setCableTransponderSearchResult(self.__tlist)
121                         else:
122                                 self.cable_search_container.sendCtrlC()
123                                 self.setCableTransponderSearchResult(None)
124                 self.cable_search_container = None
125                 self.cable_search_session = None
126                 self.__tlist = None
127                 self.cableTransponderSearchFinished()
128
129         def cableTransponderSearchClosed(self, retval):
130                 print "cableTransponderSearch finished", retval
131                 self.cable_search_session.close(True)
132
133         def getCableTransponderData(self, str):
134                 #prepend any remaining data from the previous call
135                 str = self.remainingdata + str
136                 #split in lines
137                 lines = str.split('\n')
138                 #'str' should end with '\n', so when splitting, the last line should be empty. If this is not the case, we received an incomplete line
139                 if len(lines[-1]):
140                         #remember this data for next time
141                         self.remainingdata = lines[-1]
142                         lines = lines[0:-1]
143                 else:
144                         self.remainingdata = ""
145
146                 for line in lines:
147                         data = line.split()
148                         if len(data):
149                                 if data[0] == 'OK':
150                                         print str
151                                         parm = eDVBFrontendParametersCable()
152                                         qam = { "QAM16" : parm.Modulation_QAM16,
153                                                 "QAM32" : parm.Modulation_QAM32,
154                                                 "QAM64" : parm.Modulation_QAM64,
155                                                 "QAM128" : parm.Modulation_QAM128,
156                                                 "QAM256" : parm.Modulation_QAM256 }
157                                         inv = { "INVERSION_OFF" : parm.Inversion_Off,
158                                                 "INVERSION_ON" : parm.Inversion_On,
159                                                 "INVERSION_AUTO" : parm.Inversion_Unknown }
160                                         fec = { "FEC_AUTO" : parm.FEC_Auto,
161                                                 "FEC_1_2" : parm.FEC_1_2,
162                                                 "FEC_2_3" : parm.FEC_2_3,
163                                                 "FEC_3_4" : parm.FEC_3_4,
164                                                 "FEC_5_6" : parm.FEC_5_6,
165                                                 "FEC_7_8" : parm.FEC_7_8,
166                                                 "FEC_8_9" : parm.FEC_8_9,
167                                                 "FEC_3_5" : parm.FEC_3_5,
168                                                 "FEC_4_5" : parm.FEC_4_5,
169                                                 "FEC_9_10" : parm.FEC_9_10,
170                                                 "FEC_NONE" : parm.FEC_None }
171                                         parm.frequency = int(data[1])
172                                         parm.symbol_rate = int(data[2])
173                                         parm.fec_inner = fec[data[3]]
174                                         parm.modulation = qam[data[4]]
175                                         parm.inversion = inv[data[5]]
176                                         self.__tlist.append(parm)
177                                 tmpstr = _("Try to find used transponders in cable network.. please wait...")
178                                 tmpstr += "\n\n"
179                                 tmpstr += data[1].isdigit() and "%s MHz " % (int(data[1]) / 1000.) or data[1]
180                                 tmpstr += data[0]
181                                 self.cable_search_session["text"].setText(tmpstr)
182
183         def startCableTransponderSearch(self, nim_idx):
184                 if not self.tryGetRawFrontend(nim_idx):
185                         self.session.nav.stopService()
186                         if not self.tryGetRawFrontend(nim_idx):
187                                 if self.session.pipshown:
188                                         self.session.infobar.showPiP()
189                                 if not self.tryGetRawFrontend(nim_idx):
190                                         self.cableTransponderSearchFinished()
191                                         return
192                 self.__tlist = [ ]
193                 self.remainingdata = ""
194                 self.cable_search_container = eConsoleAppContainer()
195                 self.cable_search_container.appClosed.append(self.cableTransponderSearchClosed)
196                 self.cable_search_container.dataAvail.append(self.getCableTransponderData)
197                 cableConfig = config.Nims[nim_idx].cable
198                 tunername = nimmanager.getNimName(nim_idx)
199                 try:
200                         bus = nimmanager.getI2CDevice(nim_idx)
201                         if bus is None:
202                                 print "ERROR: could not get I2C device for nim", nim_idx, "for cable transponder search"
203                                 bus = 2
204                 except:
205                         # older API
206                         if nim_idx < 2:
207                                 if HardwareInfo().get_device_name() == "dm500hd":
208                                         bus = 2
209                                 else:
210                                         bus = nim_idx
211                         else:
212                                 if nim_idx == 2:
213                                         bus = 2 # DM8000 first nim is /dev/i2c/2
214                                 else:
215                                         bus = 4 # DM8000 second num is /dev/i2c/4
216
217                 if tunername == "CXD1981":
218                         cmd = "cxd1978 --init --scan --verbose --wakeup --inv 2 --bus %d" % bus
219                 elif tunername.startswith("Sundtek"):
220                         cmd = "mediaclient --blindscan %d" % nim_idx
221                 else:
222                         cmd = "tda1002x --init --scan --verbose --wakeup --inv 2 --bus %d" % bus
223
224                 if cableConfig.scan_type.value == "bands":
225                         cmd += " --scan-bands "
226                         bands = 0
227                         if cableConfig.scan_band_EU_VHF_I.value:
228                                 bands |= cable_bands["DVBC_BAND_EU_VHF_I"]
229                         if cableConfig.scan_band_EU_MID.value:
230                                 bands |= cable_bands["DVBC_BAND_EU_MID"]
231                         if cableConfig.scan_band_EU_VHF_III.value:
232                                 bands |= cable_bands["DVBC_BAND_EU_VHF_III"]
233                         if cableConfig.scan_band_EU_UHF_IV.value:
234                                 bands |= cable_bands["DVBC_BAND_EU_UHF_IV"]
235                         if cableConfig.scan_band_EU_UHF_V.value:
236                                 bands |= cable_bands["DVBC_BAND_EU_UHF_V"]
237                         if cableConfig.scan_band_EU_SUPER.value:
238                                 bands |= cable_bands["DVBC_BAND_EU_SUPER"]
239                         if cableConfig.scan_band_EU_HYPER.value:
240                                 bands |= cable_bands["DVBC_BAND_EU_HYPER"]
241                         if cableConfig.scan_band_US_LOW.value:
242                                 bands |= cable_bands["DVBC_BAND_US_LO"]
243                         if cableConfig.scan_band_US_MID.value:
244                                 bands |= cable_bands["DVBC_BAND_US_MID"]
245                         if cableConfig.scan_band_US_HIGH.value:
246                                 bands |= cable_bands["DVBC_BAND_US_HI"]
247                         if cableConfig.scan_band_US_SUPER.value:
248                                 bands |= cable_bands["DVBC_BAND_US_SUPER"]
249                         if cableConfig.scan_band_US_HYPER.value:
250                                 bands |= cable_bands["DVBC_BAND_US_HYPER"]
251                         cmd += str(bands)
252                 else:
253                         cmd += " --scan-stepsize "
254                         cmd += str(cableConfig.scan_frequency_steps.value)
255                 if cableConfig.scan_mod_qam16.value:
256                         cmd += " --mod 16"
257                 if cableConfig.scan_mod_qam32.value:
258                         cmd += " --mod 32"
259                 if cableConfig.scan_mod_qam64.value:
260                         cmd += " --mod 64"
261                 if cableConfig.scan_mod_qam128.value:
262                         cmd += " --mod 128"
263                 if cableConfig.scan_mod_qam256.value:
264                         cmd += " --mod 256"
265                 if cableConfig.scan_sr_6900.value:
266                         cmd += " --sr 6900000"
267                 if cableConfig.scan_sr_6875.value:
268                         cmd += " --sr 6875000"
269                 if cableConfig.scan_sr_ext1.value > 450:
270                         cmd += " --sr "
271                         cmd += str(cableConfig.scan_sr_ext1.value)
272                         cmd += "000"
273                 if cableConfig.scan_sr_ext2.value > 450:
274                         cmd += " --sr "
275                         cmd += str(cableConfig.scan_sr_ext2.value)
276                         cmd += "000"
277                 print "TDA1002x CMD is", cmd
278
279                 self.cable_search_container.execute(cmd)
280                 tmpstr = _("Try to find used transponders in cable network.. please wait...")
281                 tmpstr += "\n\n..."
282                 self.cable_search_session = self.session.openWithCallback(self.cableTransponderSearchSessionClosed, MessageBox, tmpstr, MessageBox.TYPE_INFO)
283
284 class ScanSetup(ConfigListScreen, Screen, CableTransponderSearchSupport):
285         def __init__(self, session):
286                 Screen.__init__(self, session)
287
288                 self.finished_cb = None
289                 self.updateSatList()
290                 self.service = session.nav.getCurrentService()
291                 self.feinfo = None
292                 self.networkid = 0
293                 frontendData = None
294                 if self.service is not None:
295                         self.feinfo = self.service.frontendInfo()
296                         frontendData = self.feinfo and self.feinfo.getAll(True)
297
298                 self.ter_channel_input = False
299                 self.ter_tnumber = None
300                 self.createConfig(frontendData)
301
302                 del self.feinfo
303                 del self.service
304
305                 self.session.postScanService = session.nav.getCurrentlyPlayingServiceOrGroup()
306
307                 self["actions"] = NumberActionMap(["SetupActions", "MenuActions"],
308                 {
309                         "ok": self.keyGo,
310                         "save": self.keyGo,
311                         "cancel": self.keyCancel,
312                         "menu": self.doCloseRecursive,
313                 }, -2)
314
315                 self.statusTimer = eTimer()
316                 self.statusTimer.callback.append(self.updateStatus)
317                 #self.statusTimer.start(5000, True)
318
319                 self.list = []
320                 ConfigListScreen.__init__(self, self.list)
321                 self["header"] = Label(_("Manual Scan"))
322                 if not self.scan_nims.value == "":
323                         self.createSetup()
324                         self["introduction"] = Label(_("Press OK to start the scan"))
325                 else:
326                         self["introduction"] = Label(_("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."))
327
328         def runAsync(self, finished_cb):
329                 self.finished_cb = finished_cb
330                 self.keyGo()
331
332         def updateSatList(self):
333                 self.satList = []
334                 for slot in nimmanager.nim_slots:
335                         if slot.isCompatible("DVB-S"):
336                                 self.satList.append(nimmanager.getSatListForNim(slot.slot))
337                         else:
338                                 self.satList.append(None)
339
340         def createSetup(self):
341                 self.list = []
342                 self.multiscanlist = []
343                 index_to_scan = int(self.scan_nims.value)
344                 print "ID: ", index_to_scan
345
346                 self.tunerEntry = getConfigListEntry(_("Tuner"), self.scan_nims)
347                 self.list.append(self.tunerEntry)
348
349                 if self.scan_nims == [ ]:
350                         return
351
352                 self.typeOfScanEntry = None
353                 self.typeOfInputEntry = None
354                 self.systemEntry = None
355                 self.modulationEntry = None
356                 self.preDefSatList = None
357                 self.TerrestrialTransponders = None
358                 self.TerrestrialRegionEntry = None
359                 nim = nimmanager.nim_slots[index_to_scan]
360                 if nim.isCompatible("DVB-S"):
361                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_type)
362                         self.list.append(self.typeOfScanEntry)
363                 elif nim.isCompatible("DVB-C"):
364                         if config.Nims[index_to_scan].cable.scan_type.value != "provider": # only show predefined transponder if in provider mode
365                                 if self.scan_typecable.value == "predefined_transponder":
366                                         self.scan_typecable.value = self.cable_toggle[self.last_scan_typecable]
367                         self.last_scan_typecable = self.scan_typecable.value
368                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typecable)
369                         self.list.append(self.typeOfScanEntry)
370                 elif nim.isCompatible("DVB-T"):
371                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typeterrestrial)
372                         self.list.append(self.typeOfScanEntry)
373                         if self.scan_typeterrestrial.value == "single_transponder":
374                                 self.typeOfInputEntry = getConfigListEntry(_("Use frequency or channel"), self.scan_input_as)
375                                 if self.ter_channel_input:
376                                         self.list.append(self.typeOfInputEntry)
377                                 else:
378                                         self.scan_input_as.value = self.scan_input_as.choices[0]
379
380                 self.scan_networkScan.value = False
381                 if nim.isCompatible("DVB-S"):
382                         if self.scan_type.value == "single_transponder":
383                                 self.updateSatList()
384                                 if nim.isCompatible("DVB-S2"):
385                                         self.systemEntry = getConfigListEntry(_('System'), self.scan_sat.system)
386                                         self.list.append(self.systemEntry)
387                                 else:
388                                         # downgrade to dvb-s, in case a -s2 config was active
389                                         self.scan_sat.system.value = eDVBFrontendParametersSatellite.System_DVB_S
390                                 self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[index_to_scan]))
391                                 self.list.append(getConfigListEntry(_('Frequency'), self.scan_sat.frequency))
392                                 self.list.append(getConfigListEntry(_('Inversion'), self.scan_sat.inversion))
393                                 self.list.append(getConfigListEntry(_('Symbol rate'), self.scan_sat.symbolrate))
394                                 self.list.append(getConfigListEntry(_('Polarization'), self.scan_sat.polarization))
395                                 if self.scan_sat.system.value == eDVBFrontendParametersSatellite.System_DVB_S:
396                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec))
397                                 elif self.scan_sat.system.value == eDVBFrontendParametersSatellite.System_DVB_S2:
398                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2))
399                                         self.modulationEntry = getConfigListEntry(_('Modulation'), self.scan_sat.modulation)
400                                         self.list.append(self.modulationEntry)
401                                         self.list.append(getConfigListEntry(_('Roll-off'), self.scan_sat.rolloff))
402                                         self.list.append(getConfigListEntry(_('Pilot'), self.scan_sat.pilot))
403                         elif self.scan_type.value == "predefined_transponder" and self.satList[index_to_scan]:
404                                 self.updateSatList()
405                                 self.preDefSatList = getConfigListEntry(_('Satellite'), self.scan_satselection[index_to_scan])
406                                 self.list.append(self.preDefSatList)
407                                 sat = self.satList[index_to_scan][self.scan_satselection[index_to_scan].index]
408                                 self.predefinedTranspondersList(sat[0])
409                                 self.list.append(getConfigListEntry(_('Transponder'), self.preDefTransponders))
410                         elif self.scan_type.value == "single_satellite":
411                                 self.updateSatList()
412                                 print self.scan_satselection[index_to_scan]
413                                 self.list.append(getConfigListEntry(_("Satellite"), self.scan_satselection[index_to_scan]))
414                                 self.scan_networkScan.value = True
415                         elif "multisat" in self.scan_type.value:
416                                 tlist = []
417                                 SatList = nimmanager.getSatListForNim(index_to_scan)
418                                 for x in SatList:
419                                         if self.Satexists(tlist, x[0]) == 0:
420                                                 tlist.append(x[0])
421                                                 sat = ConfigEnableDisable(default = "_yes" in self.scan_type.value and True or False)
422                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[0]), sat)
423                                                 self.list.append(configEntry)
424                                                 self.multiscanlist.append((x[0], sat))
425                                 self.scan_networkScan.value = True
426                 elif nim.isCompatible("DVB-C"):
427                         if self.scan_typecable.value == "single_transponder":
428                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_cab.frequency))
429                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_cab.inversion))
430                                 self.list.append(getConfigListEntry(_("Symbol rate"), self.scan_cab.symbolrate))
431                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_cab.modulation))
432                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_cab.fec))
433                         elif self.scan_typecable.value == "predefined_transponder":
434                                 self.predefinedCabTranspondersList()
435                                 self.list.append(getConfigListEntry(_('Transponder'), self.CableTransponders))
436                         if config.Nims[index_to_scan].cable.scan_networkid.value:
437                                 self.networkid = config.Nims[index_to_scan].cable.scan_networkid.value
438                                 self.scan_networkScan.value = True
439                 elif nim.isCompatible("DVB-T"):
440                         if self.scan_typeterrestrial.value == "single_transponder":
441                                 if nim.isCompatible("DVB-T2"):
442                                         self.systemEntry = getConfigListEntry(_('System'), self.scan_ter.system)
443                                         self.list.append(self.systemEntry)
444                                 else:
445                                         self.scan_ter.system.value = eDVBFrontendParametersTerrestrial.System_DVB_T
446                                 if self.ter_channel_input and self.scan_input_as.value == "channel":
447                                         channel = getChannelNumber(self.scan_ter.frequency.value*1000, self.ter_tnumber)
448                                         if channel:
449                                                 self.scan_ter.channel.value = int(channel.replace("+","").replace("-",""))
450                                         self.list.append(getConfigListEntry(_("Channel"), self.scan_ter.channel))
451                                 else:
452                                         prev_val = self.scan_ter.frequency.value
453                                         self.scan_ter.frequency.value = channel2frequency(self.scan_ter.channel.value, self.ter_tnumber)/1000
454                                         if self.scan_ter.frequency.value == 474000:
455                                                 self.scan_ter.frequency.value = prev_val
456                                         self.list.append(getConfigListEntry(_("Frequency"), self.scan_ter.frequency))
457                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_ter.inversion))
458                                 self.list.append(getConfigListEntry(_("Bandwidth"), self.scan_ter.bandwidth))
459                                 self.list.append(getConfigListEntry(_("Code rate HP"), self.scan_ter.fechigh))
460                                 self.list.append(getConfigListEntry(_("Code rate LP"), self.scan_ter.feclow))
461                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_ter.modulation))
462                                 self.list.append(getConfigListEntry(_("Transmission mode"), self.scan_ter.transmission))
463                                 self.list.append(getConfigListEntry(_("Guard interval"), self.scan_ter.guard))
464                                 self.list.append(getConfigListEntry(_("Hierarchy info"), self.scan_ter.hierarchy))
465                                 if self.scan_ter.system.value == eDVBFrontendParametersTerrestrial.System_DVB_T2:
466                                         self.list.append(getConfigListEntry(_('PLP ID'), self.scan_ter.plp_id))
467                         elif self.scan_typeterrestrial.value == "predefined_transponder":
468                                 if nim.isCompatible("DVB-T2"):
469                                         self.systemEntry = getConfigListEntry(_('System'), self.scan_ter.system)
470                                         self.list.append(self.systemEntry)
471                                 else:
472                                         self.scan_ter.system.value = eDVBFrontendParametersTerrestrial.System_DVB_T
473                                 self.TerrestrialRegion = self.terrestrial_nims_regions[index_to_scan]
474                                 self.TerrestrialRegionEntry = getConfigListEntry(_('Region'), self.TerrestrialRegion)
475                                 self.list.append(self.TerrestrialRegionEntry)
476                                 self.predefinedTerrTranspondersList()
477                                 self.list.append(getConfigListEntry(_('Transponder'), self.TerrestrialTransponders))
478                         elif self.scan_typeterrestrial.value == "complete":
479                                 self.TerrestrialRegion = self.terrestrial_nims_regions[index_to_scan]
480                                 self.TerrestrialRegionEntry = getConfigListEntry(_('Region'), self.TerrestrialRegion)
481                                 self.list.append(self.TerrestrialRegionEntry)
482                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
483                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
484                 self.list.append(getConfigListEntry(_("Only free scan"), self.scan_onlyfree))
485                 self["config"].list = self.list
486                 self["config"].l.setList(self.list)
487
488         def Satexists(self, tlist, pos):
489                 for x in tlist:
490                         if x == pos:
491                                 return 1
492                 return 0
493
494         def newConfig(self):
495                 cur = self["config"].getCurrent()
496                 print "cur is", cur
497                 if cur == self.typeOfScanEntry or \
498                         cur == self.typeOfInputEntry or \
499                         cur == self.tunerEntry or \
500                         cur == self.systemEntry or \
501                         cur == self.preDefSatList or \
502                         cur == self.TerrestrialRegionEntry or \
503                         (self.modulationEntry and self.systemEntry[1].value == eDVBFrontendParametersSatellite.System_DVB_S2 and cur == self.modulationEntry):
504                         self.createSetup()
505
506         def createConfig(self, frontendData):
507                 defaultSat = {
508                         "orbpos": 192,
509                         "system": eDVBFrontendParametersSatellite.System_DVB_S,
510                         "frequency": 11836,
511                         "inversion": eDVBFrontendParametersSatellite.Inversion_Unknown,
512                         "symbolrate": 27500,
513                         "polarization": eDVBFrontendParametersSatellite.Polarisation_Horizontal,
514                         "fec": eDVBFrontendParametersSatellite.FEC_Auto,
515                         "fec_s2": eDVBFrontendParametersSatellite.FEC_9_10,
516                         "modulation": eDVBFrontendParametersSatellite.Modulation_QPSK }
517                 defaultCab = {
518                         "frequency": 466,
519                         "inversion": eDVBFrontendParametersCable.Inversion_Unknown,
520                         "modulation": eDVBFrontendParametersCable.Modulation_QAM64,
521                         "fec": eDVBFrontendParametersCable.FEC_Auto,
522                         "symbolrate": 6900,
523                         "system": eDVBFrontendParametersCable.System_DVB_C_ANNEX_A }
524                 defaultTer = {
525                         "frequency" : 474000,
526                         "inversion" : eDVBFrontendParametersTerrestrial.Inversion_Unknown,
527                         "bandwidth" : 8000000,
528                         "fechigh" : eDVBFrontendParametersTerrestrial.FEC_Auto,
529                         "feclow" : eDVBFrontendParametersTerrestrial.FEC_Auto,
530                         "modulation" : eDVBFrontendParametersTerrestrial.Modulation_Auto,
531                         "transmission_mode" : eDVBFrontendParametersTerrestrial.TransmissionMode_Auto,
532                         "guard_interval" : eDVBFrontendParametersTerrestrial.GuardInterval_Auto,
533                         "hierarchy": eDVBFrontendParametersTerrestrial.Hierarchy_Auto,
534                         "system": eDVBFrontendParametersTerrestrial.System_DVB_T,
535                         "plp_id": 0 }
536
537                 if frontendData is not None:
538                         ttype = frontendData.get("tuner_type", "UNKNOWN")
539                         if ttype == "DVB-S":
540                                 defaultSat["system"] = frontendData.get("system", eDVBFrontendParametersSatellite.System_DVB_S)
541                                 defaultSat["frequency"] = frontendData.get("frequency", 0) / 1000
542                                 defaultSat["inversion"] = frontendData.get("inversion", eDVBFrontendParametersSatellite.Inversion_Unknown)
543                                 defaultSat["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
544                                 defaultSat["polarization"] = frontendData.get("polarization", eDVBFrontendParametersSatellite.Polarisation_Horizontal)
545                                 if defaultSat["system"] == eDVBFrontendParametersSatellite.System_DVB_S2:
546                                         defaultSat["fec_s2"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
547                                         defaultSat["rolloff"] = frontendData.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35)
548                                         defaultSat["pilot"] = frontendData.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown)
549                                 else:
550                                         defaultSat["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
551                                 defaultSat["modulation"] = frontendData.get("modulation", eDVBFrontendParametersSatellite.Modulation_QPSK)
552                                 defaultSat["orbpos"] = frontendData.get("orbital_position", 0)
553                         elif ttype == "DVB-C":
554                                 defaultCab["frequency"] = frontendData.get("frequency", 0) / 1000
555                                 defaultCab["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
556                                 defaultCab["inversion"] = frontendData.get("inversion", eDVBFrontendParametersCable.Inversion_Unknown)
557                                 defaultCab["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersCable.FEC_Auto)
558                                 defaultCab["modulation"] = frontendData.get("modulation", eDVBFrontendParametersCable.Modulation_QAM16)
559                                 defaultCab["system"] = frontendData.get("system", eDVBFrontendParametersCable.System_DVB_C_ANNEX_A)
560                         elif ttype == "DVB-T":
561                                 defaultTer["frequency"] = frontendData.get("frequency", 47400000) / 1000
562                                 defaultTer["inversion"] = frontendData.get("inversion", eDVBFrontendParametersTerrestrial.Inversion_Unknown)
563                                 defaultTer["bandwidth"] = frontendData.get("bandwidth", 8000000)
564                                 defaultTer["fechigh"] = frontendData.get("code_rate_hp", eDVBFrontendParametersTerrestrial.FEC_Auto)
565                                 defaultTer["feclow"] = frontendData.get("code_rate_lp", eDVBFrontendParametersTerrestrial.FEC_Auto)
566                                 defaultTer["modulation"] = frontendData.get("constellation", eDVBFrontendParametersTerrestrial.Modulation_Auto)
567                                 defaultTer["transmission_mode"] = frontendData.get("transmission_mode", eDVBFrontendParametersTerrestrial.TransmissionMode_Auto)
568                                 defaultTer["guard_interval"] = frontendData.get("guard_interval", eDVBFrontendParametersTerrestrial.GuardInterval_Auto)
569                                 defaultTer["hierarchy"] = frontendData.get("hierarchy_information", eDVBFrontendParametersTerrestrial.Hierarchy_Auto)
570                                 defaultTer["system"] = frontendData.get("system", eDVBFrontendParametersTerrestrial.System_DVB_T)
571                                 defaultTer["plp_id"] = frontendData.get("plp_id", 0)
572
573                 self.scan_sat = ConfigSubsection()
574                 self.scan_cab = ConfigSubsection()
575                 self.scan_ter = ConfigSubsection()
576
577                 nim_list = []
578                 # collect all nims which are *not* set to "nothing"
579                 for n in nimmanager.nim_slots:
580                         if n.config_mode == "nothing":
581                                 continue
582                         if n.config_mode == "advanced" and len(nimmanager.getSatListForNim(n.slot)) < 1:
583                                 continue
584                         if n.config_mode in ("loopthrough", "satposdepends"):
585                                 root_id = nimmanager.sec.getRoot(n.slot_id, int(n.config.connectedTo.value))
586                                 if n.type == nimmanager.nim_slots[root_id].type: # check if connected from a DVB-S to DVB-S2 Nim or vice versa
587                                         continue
588                         nim_list.append((str(n.slot), n.friendly_full_description))
589
590                 self.scan_nims = ConfigSelection(choices = nim_list)
591                 if frontendData is not None and len(nim_list) > 0:
592                         self.scan_nims.value = str(frontendData.get("tuner_number", nim_list[0][0]))
593
594                 for slot in nimmanager.nim_slots:
595                         if slot.isCompatible("DVB-T"):
596                                 self.ter_tnumber = slot.slot
597                 if self.ter_tnumber is not None:
598                         self.ter_channel_input = supportedChannels(self.ter_tnumber)
599
600                 # status
601                 self.scan_snr = ConfigSlider()
602                 self.scan_snr.enabled = False
603                 self.scan_agc = ConfigSlider()
604                 self.scan_agc.enabled = False
605                 self.scan_ber = ConfigSlider()
606                 self.scan_ber.enabled = False
607
608                 # sat
609                 self.scan_sat.system = ConfigSelection(default = defaultSat["system"], choices = [
610                         (eDVBFrontendParametersSatellite.System_DVB_S, _("DVB-S")),
611                         (eDVBFrontendParametersSatellite.System_DVB_S2, _("DVB-S2"))])
612                 self.scan_sat.frequency = ConfigInteger(default = defaultSat["frequency"], limits = (1, 99999))
613                 self.scan_sat.inversion = ConfigSelection(default = defaultSat["inversion"], choices = [
614                         (eDVBFrontendParametersSatellite.Inversion_Off, _("Off")),
615                         (eDVBFrontendParametersSatellite.Inversion_On, _("On")),
616                         (eDVBFrontendParametersSatellite.Inversion_Unknown, _("Auto"))])
617                 self.scan_sat.symbolrate = ConfigInteger(default = defaultSat["symbolrate"], limits = (1, 99999))
618                 self.scan_sat.polarization = ConfigSelection(default = defaultSat["polarization"], choices = [
619                         (eDVBFrontendParametersSatellite.Polarisation_Horizontal, _("horizontal")),
620                         (eDVBFrontendParametersSatellite.Polarisation_Vertical, _("vertical")),
621                         (eDVBFrontendParametersSatellite.Polarisation_CircularLeft, _("circular left")),
622                         (eDVBFrontendParametersSatellite.Polarisation_CircularRight, _("circular right"))])
623                 self.scan_sat.fec = ConfigSelection(default = defaultSat["fec"], choices = [
624                         (eDVBFrontendParametersSatellite.FEC_Auto, _("Auto")),
625                         (eDVBFrontendParametersSatellite.FEC_1_2, "1/2"),
626                         (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
627                         (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
628                         (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
629                         (eDVBFrontendParametersSatellite.FEC_7_8, "7/8"),
630                         (eDVBFrontendParametersSatellite.FEC_None, _("None"))])
631                 self.scan_sat.fec_s2 = ConfigSelection(default = defaultSat["fec_s2"], choices = [
632                         (eDVBFrontendParametersSatellite.FEC_1_2, "1/2"),
633                         (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
634                         (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
635                         (eDVBFrontendParametersSatellite.FEC_3_5, "3/5"),
636                         (eDVBFrontendParametersSatellite.FEC_4_5, "4/5"),
637                         (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
638                         (eDVBFrontendParametersSatellite.FEC_7_8, "7/8"),
639                         (eDVBFrontendParametersSatellite.FEC_8_9, "8/9"),
640                         (eDVBFrontendParametersSatellite.FEC_9_10, "9/10")])
641                 self.scan_sat.modulation = ConfigSelection(default = defaultSat["modulation"], choices = [
642                         (eDVBFrontendParametersSatellite.Modulation_QPSK, "QPSK"),
643                         (eDVBFrontendParametersSatellite.Modulation_8PSK, "8PSK")])
644                 self.scan_sat.rolloff = ConfigSelection(default = defaultSat.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35), choices = [
645                         (eDVBFrontendParametersSatellite.RollOff_alpha_0_35, "0.35"),
646                         (eDVBFrontendParametersSatellite.RollOff_alpha_0_25, "0.25"),
647                         (eDVBFrontendParametersSatellite.RollOff_alpha_0_20, "0.20"),
648                         (eDVBFrontendParametersSatellite.RollOff_auto, _("Auto"))])
649                 self.scan_sat.pilot = ConfigSelection(default = defaultSat.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown), choices = [
650                         (eDVBFrontendParametersSatellite.Pilot_Off, _("Off")),
651                         (eDVBFrontendParametersSatellite.Pilot_On, _("On")),
652                         (eDVBFrontendParametersSatellite.Pilot_Unknown, _("Auto"))])
653
654                 # cable
655                 self.scan_cab.frequency = ConfigInteger(default = defaultCab["frequency"], limits = (50, 999))
656                 self.scan_cab.inversion = ConfigSelection(default = defaultCab["inversion"], choices = [
657                         (eDVBFrontendParametersCable.Inversion_Off, _("Off")),
658                         (eDVBFrontendParametersCable.Inversion_On, _("On")),
659                         (eDVBFrontendParametersCable.Inversion_Unknown, _("Auto"))])
660                 self.scan_cab.modulation = ConfigSelection(default = defaultCab["modulation"], choices = [
661                         (eDVBFrontendParametersCable.Modulation_QAM16, "16-QAM"),
662                         (eDVBFrontendParametersCable.Modulation_QAM32, "32-QAM"),
663                         (eDVBFrontendParametersCable.Modulation_QAM64, "64-QAM"),
664                         (eDVBFrontendParametersCable.Modulation_QAM128, "128-QAM"),
665                         (eDVBFrontendParametersCable.Modulation_QAM256, "256-QAM")])
666                 self.scan_cab.fec = ConfigSelection(default = defaultCab["fec"], choices = [
667                         (eDVBFrontendParametersCable.FEC_Auto, _("Auto")),
668                         (eDVBFrontendParametersCable.FEC_1_2, "1/2"),
669                         (eDVBFrontendParametersCable.FEC_2_3, "2/3"),
670                         (eDVBFrontendParametersCable.FEC_3_4, "3/4"),
671                         (eDVBFrontendParametersCable.FEC_5_6, "5/6"),
672                         (eDVBFrontendParametersCable.FEC_7_8, "7/8"),
673                         (eDVBFrontendParametersCable.FEC_8_9, "8/9"),
674                         (eDVBFrontendParametersCable.FEC_3_5, "3/5"),
675                         (eDVBFrontendParametersCable.FEC_4_5, "4/5"),
676                         (eDVBFrontendParametersCable.FEC_9_10, "9/10"),
677                         (eDVBFrontendParametersCable.FEC_None, _("None"))])
678                 self.scan_cab.symbolrate = ConfigInteger(default = defaultCab["symbolrate"], limits = (1, 99999))
679                 self.scan_cab.system = ConfigSelection(default = defaultCab["system"], choices = [
680                         (eDVBFrontendParametersCable.System_DVB_C_ANNEX_A, _("DVB-C")),
681                         (eDVBFrontendParametersCable.System_DVB_C_ANNEX_C, _("DVB-C ANNEX C"))])
682
683                 # terrestial
684                 self.scan_ter.frequency = ConfigInteger(default = defaultTer["frequency"], limits = (50000, 999000))
685                 self.scan_ter.channel = ConfigInteger(default = 21, limits = (1, 99))
686                 self.scan_ter.inversion = ConfigSelection(default = defaultTer["inversion"], choices = [
687                         (eDVBFrontendParametersTerrestrial.Inversion_Off, _("Off")),
688                         (eDVBFrontendParametersTerrestrial.Inversion_On, _("On")),
689                         (eDVBFrontendParametersTerrestrial.Inversion_Unknown, _("Auto"))])
690                 # WORKAROUND: we can't use BW-auto
691                 self.scan_ter.bandwidth = ConfigSelection(default = defaultTer["bandwidth"], choices = [
692                         (1712000, "1.712MHz"),
693                         (5000000, "5MHz"),
694                         (6000000, "6MHz"),
695                         (7000000, "7MHz"),
696                         (8000000, "8MHz"),
697                         (10000000,"10MHz")
698                         ])
699                 #, (eDVBFrontendParametersTerrestrial.Bandwidth_Auto, _("Auto"))))
700                 self.scan_ter.fechigh = ConfigSelection(default = defaultTer["fechigh"], choices = [
701                         (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
702                         (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
703                         (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
704                         (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
705                         (eDVBFrontendParametersTerrestrial.FEC_6_7, "6/7"),
706                         (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
707                         (eDVBFrontendParametersTerrestrial.FEC_8_9, "8/9"),
708                         (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
709                 self.scan_ter.feclow = ConfigSelection(default = defaultTer["feclow"], choices = [
710                         (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
711                         (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
712                         (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
713                         (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
714                         (eDVBFrontendParametersTerrestrial.FEC_6_7, "6/7"),
715                         (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
716                         (eDVBFrontendParametersTerrestrial.FEC_8_9, "8/9"),
717                         (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
718                 self.scan_ter.modulation = ConfigSelection(default = defaultTer["modulation"], choices = [
719                         (eDVBFrontendParametersTerrestrial.Modulation_QPSK, "QPSK"),
720                         (eDVBFrontendParametersTerrestrial.Modulation_QAM16, "QAM16"),
721                         (eDVBFrontendParametersTerrestrial.Modulation_QAM64, "QAM64"),
722                         (eDVBFrontendParametersTerrestrial.Modulation_QAM256, "QAM256"),
723                         (eDVBFrontendParametersTerrestrial.Modulation_Auto, _("Auto"))])
724                 self.scan_ter.transmission = ConfigSelection(default = defaultTer["transmission_mode"], choices = [
725                         (eDVBFrontendParametersTerrestrial.TransmissionMode_1k, "1K"),
726                         (eDVBFrontendParametersTerrestrial.TransmissionMode_2k, "2K"),
727                         (eDVBFrontendParametersTerrestrial.TransmissionMode_4k, "4K"),
728                         (eDVBFrontendParametersTerrestrial.TransmissionMode_8k, "8K"),
729                         (eDVBFrontendParametersTerrestrial.TransmissionMode_16k, "16K"),
730                         (eDVBFrontendParametersTerrestrial.TransmissionMode_32k, "32K"),
731                         (eDVBFrontendParametersTerrestrial.TransmissionMode_Auto, _("Auto"))])
732                 self.scan_ter.guard = ConfigSelection(default = defaultTer["guard_interval"], choices = [
733                         (eDVBFrontendParametersTerrestrial.GuardInterval_1_32, "1/32"),
734                         (eDVBFrontendParametersTerrestrial.GuardInterval_1_16, "1/16"),
735                         (eDVBFrontendParametersTerrestrial.GuardInterval_1_8, "1/8"),
736                         (eDVBFrontendParametersTerrestrial.GuardInterval_1_4, "1/4"),
737                         (eDVBFrontendParametersTerrestrial.GuardInterval_1_128, "1/128"),
738                         (eDVBFrontendParametersTerrestrial.GuardInterval_19_128, "19/128"),
739                         (eDVBFrontendParametersTerrestrial.GuardInterval_19_256, "19/256"),
740                         (eDVBFrontendParametersTerrestrial.GuardInterval_Auto, _("Auto"))])
741                 self.scan_ter.hierarchy = ConfigSelection(default = defaultTer["hierarchy"], choices = [
742                         (eDVBFrontendParametersTerrestrial.Hierarchy_None, _("None")),
743                         (eDVBFrontendParametersTerrestrial.Hierarchy_1, "1"),
744                         (eDVBFrontendParametersTerrestrial.Hierarchy_2, "2"),
745                         (eDVBFrontendParametersTerrestrial.Hierarchy_4, "4"),
746                         (eDVBFrontendParametersTerrestrial.Hierarchy_Auto, _("Auto"))])
747                 self.scan_ter.system = ConfigSelection(default = defaultTer["system"], choices = [
748                         (eDVBFrontendParametersTerrestrial.System_DVB_T, _("DVB-T")),
749                         (eDVBFrontendParametersTerrestrial.System_DVB_T2, _("DVB-T2"))])
750                 self.scan_ter.plp_id = ConfigInteger(default = defaultTer["plp_id"], limits = (0, 255))
751
752                 self.scan_scansat = {}
753                 for sat in nimmanager.satList:
754                         #print sat[1]
755                         self.scan_scansat[sat[0]] = ConfigYesNo(default = False)
756
757                 self.scan_satselection = []
758                 for slot in nimmanager.nim_slots:
759                         if slot.isCompatible("DVB-S"):
760                                 self.scan_satselection.append(getConfigSatlist(defaultSat["orbpos"], self.satList[slot.slot]))
761                         else:
762                                 self.scan_satselection.append(None)
763
764                 self.terrestrial_nims_regions = []
765                 for slot in nimmanager.nim_slots:
766                         if slot.isCompatible("DVB-T"):
767                                 self.terrestrial_nims_regions.append(self.getTerrestrialRegionsList(slot.slot))
768                         else:
769                                 self.terrestrial_nims_regions.append(None)
770
771                 if frontendData is not None and ttype == "DVB-S" and self.predefinedTranspondersList(defaultSat["orbpos"]) is not None:
772                         defaultSatSearchType = "predefined_transponder"
773                 else:
774                         defaultSatSearchType = "single_transponder"
775                 if frontendData is not None and ttype == "DVB-T" and self.predefinedTerrTranspondersList() is not None:
776                         defaultTerrSearchType = "predefined_transponder"
777                 else:
778                         defaultTerrSearchType = "single_transponder"
779
780                 if frontendData is not None and ttype == "DVB-C" and self.predefinedCabTranspondersList() is not None:
781                         defaultCabSearchType = "predefined_transponder"
782                 else:
783                         defaultCabSearchType = "single_transponder"
784
785                 self.scan_type = ConfigSelection(default = defaultSatSearchType, choices = [("single_transponder", _("User defined transponder")), ("predefined_transponder", _("Predefined transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat")), ("multisat_yes", _("Multisat all select"))])
786                 self.scan_typecable = ConfigSelection(default = defaultCabSearchType, choices = [("single_transponder", _("User defined transponder")), ("predefined_transponder", _("Predefined transponder")), ("complete", _("Complete"))])
787                 self.last_scan_typecable = "single_transponder"
788                 self.cable_toggle = {"single_transponder":"complete", "complete":"single_transponder"}
789                 self.scan_typeterrestrial = ConfigSelection(default = defaultTerrSearchType, choices = [("single_transponder", _("User defined transponder")), ("predefined_transponder", _("Predefined transponder")), ("complete", _("Complete"))])
790                 self.scan_input_as = ConfigSelection(default = "channel", choices = [("frequency", _("Frequency")), ("channel", _("Channel"))])
791                 self.scan_clearallservices = ConfigSelection(default = "no", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
792                 self.scan_onlyfree = ConfigYesNo(default = False)
793                 self.scan_networkScan = ConfigYesNo(default = False)
794
795                 return True
796
797         def keyLeft(self):
798                 ConfigListScreen.keyLeft(self)
799                 self.newConfig()
800
801         def keyRight(self):
802                 ConfigListScreen.keyRight(self)
803                 self.newConfig()
804
805         def handleKeyFileCallback(self, answer):
806                 ConfigListScreen.handleKeyFileCallback(self, answer)
807                 self.newConfig()
808
809         def updateStatus(self):
810                 print "updatestatus"
811
812         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position, system, modulation, rolloff, pilot):
813                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion) + " modulation: " + str(modulation) + " system: " + str(system) + " rolloff" + str(rolloff) + " pilot" + str(pilot)
814                 print "orbpos: " + str(orbital_position)
815                 parm = eDVBFrontendParametersSatellite()
816                 parm.modulation = modulation
817                 parm.system = system
818                 parm.frequency = frequency * 1000
819                 parm.symbol_rate = symbol_rate * 1000
820                 parm.polarisation = polarisation
821                 parm.fec = fec
822                 parm.inversion = inversion
823                 parm.orbital_position = orbital_position
824                 parm.rolloff = rolloff
825                 parm.pilot = pilot
826                 tlist.append(parm)
827
828         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
829                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
830                 parm = eDVBFrontendParametersCable()
831                 parm.frequency = frequency
832                 parm.symbol_rate = symbol_rate
833                 parm.modulation = modulation
834                 parm.fec_inner = fec
835                 parm.inversion = inversion
836                 tlist.append(parm)
837
838         def addTerTransponder(self, tlist, *args, **kwargs):
839                 tlist.append(buildTerTransponder(*args, **kwargs))
840
841         def keyGo(self):
842                 infoBarInstance = InfoBar.instance
843                 if infoBarInstance:
844                         infoBarInstance.checkTimeshiftRunning(self.keyGoCheckTimeshiftCallback)
845                 else:
846                         self.keyGoCheckTimeshiftCallback(True)
847
848         def keyGoCheckTimeshiftCallback(self, answer):
849                 if not answer or self.scan_nims.value == "":
850                         return
851                 tlist = []
852                 flags = None
853                 startScan = True
854                 removeAll = True
855                 index_to_scan = int(self.scan_nims.value)
856
857                 if self.scan_nims == [ ]:
858                         self.session.open(MessageBox, _("No tuner is enabled!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
859                         return
860                 nim = nimmanager.nim_slots[index_to_scan]
861                 print "nim", nim.slot
862                 if nim.isCompatible("DVB-S"):
863                         print "is compatible with DVB-S"
864                         if self.scan_type.value == "single_transponder":
865                                 # these lists are generated for each tuner, so this has work.
866                                 assert len(self.satList) > index_to_scan
867                                 assert len(self.scan_satselection) > index_to_scan
868
869                                 nimsats = self.satList[index_to_scan]
870                                 selsatidx = self.scan_satselection[index_to_scan].index
871
872                                 # however, the satList itself could be empty. in that case, "index" is 0 (for "None").
873                                 if len(nimsats):
874                                         orbpos = nimsats[selsatidx][0]
875                                         if self.scan_sat.system.value == eDVBFrontendParametersSatellite.System_DVB_S:
876                                                 fec = self.scan_sat.fec.value
877                                         else:
878                                                 fec = self.scan_sat.fec_s2.value
879                                         print "add sat transponder"
880                                         self.addSatTransponder(tlist, self.scan_sat.frequency.value,
881                                                                 self.scan_sat.symbolrate.value,
882                                                                 self.scan_sat.polarization.value,
883                                                                 fec,
884                                                                 self.scan_sat.inversion.value,
885                                                                 orbpos,
886                                                                 self.scan_sat.system.value,
887                                                                 self.scan_sat.modulation.value,
888                                                                 self.scan_sat.rolloff.value,
889                                                                 self.scan_sat.pilot.value)
890                                 removeAll = False
891                         elif self.scan_type.value == "predefined_transponder":
892                                 nimsats = self.satList[index_to_scan]
893                                 selsatidx = self.scan_satselection[index_to_scan].index
894                                 if len(nimsats):
895                                         orbpos = nimsats[selsatidx][0]
896                                         tps = nimmanager.getTransponders(orbpos)
897                                         if len(tps) and len(tps) > self.preDefTransponders.index:
898                                                 tp = tps[self.preDefTransponders.index]
899                                                 self.addSatTransponder(tlist, tp[1] / 1000, tp[2] / 1000, tp[3], tp[4], tp[7], orbpos, tp[5], tp[6], tp[8], tp[9])
900                                 removeAll = False
901                         elif self.scan_type.value == "single_satellite":
902                                 sat = self.satList[index_to_scan][self.scan_satselection[index_to_scan].index]
903                                 getInitialTransponderList(tlist, sat[0])
904                         elif "multisat" in self.scan_type.value:
905                                 SatList = nimmanager.getSatListForNim(index_to_scan)
906                                 for x in self.multiscanlist:
907                                         if x[1].value:
908                                                 print "   " + str(x[0])
909                                                 getInitialTransponderList(tlist, x[0])
910
911                 elif nim.isCompatible("DVB-C"):
912                         if self.scan_typecable.value == "single_transponder":
913                                 self.addCabTransponder(tlist, self.scan_cab.frequency.value*1000,
914                                                                                           self.scan_cab.symbolrate.value*1000,
915                                                                                           self.scan_cab.modulation.value,
916                                                                                           self.scan_cab.fec.value,
917                                                                                           self.scan_cab.inversion.value)
918                                 removeAll = False
919                         elif self.scan_typecable.value == "predefined_transponder":
920                                 tps = nimmanager.getTranspondersCable(index_to_scan)
921                                 if len(tps) and len(tps) > self.CableTransponders.index :
922                                         tp = tps[self.CableTransponders.index]
923                                         # 0 transponder type, 1 freq, 2 sym, 3 mod, 4 fec, 5 inv, 6 sys
924                                         self.addCabTransponder(tlist, tp[1], tp[2], tp[3], tp[4], tp[5])
925                                 removeAll = False
926                         elif self.scan_typecable.value == "complete":
927                                 if config.Nims[index_to_scan].cable.scan_type.value == "provider":
928                                         getInitialCableTransponderList(tlist, index_to_scan)
929                                 else:
930                                         startScan = False
931
932                 elif nim.isCompatible("DVB-T"):
933                         if self.scan_typeterrestrial.value == "single_transponder":
934                                 if self.scan_input_as.value == "channel":
935                                         frequency = channel2frequency(self.scan_ter.channel.value, self.ter_tnumber)
936                                 else:
937                                         frequency = self.scan_ter.frequency.value * 1000
938                                 self.addTerTransponder(tlist,
939                                                 frequency,
940                                                 inversion = self.scan_ter.inversion.value,
941                                                 bandwidth = self.scan_ter.bandwidth.value,
942                                                 fechigh = self.scan_ter.fechigh.value,
943                                                 feclow = self.scan_ter.feclow.value,
944                                                 modulation = self.scan_ter.modulation.value,
945                                                 transmission = self.scan_ter.transmission.value,
946                                                 guard = self.scan_ter.guard.value,
947                                                 hierarchy = self.scan_ter.hierarchy.value,
948                                                 system = self.scan_ter.system.value,
949                                                 plpid = self.scan_ter.plp_id.value)
950                                 removeAll = False
951                         elif self.scan_typeterrestrial.value == "predefined_transponder":
952                                 if self.TerrestrialTransponders is not None:
953                                         region = self.terrestrial_nims_regions[index_to_scan].value
954                                         tps = nimmanager.getTranspondersTerrestrial(region)
955                                         if len(tps) and len(tps) > self.TerrestrialTransponders.index :
956                                                 tp = tps[self.TerrestrialTransponders.index]
957                                                 tlist.append(buildTerTransponder(tp[1], tp[9], tp[2], tp[4], tp[5], tp[3], tp[7], tp[6], tp[8], self.scan_ter.system.value, tp[11]))
958                                 removeAll = False
959                         elif self.scan_typeterrestrial.value == "complete":
960                                 getInitialTerrestrialTransponderList(tlist, self.TerrestrialRegion.value)
961
962                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
963
964                 tmp = self.scan_clearallservices.value
965                 if tmp == "yes":
966                         flags |= eComponentScan.scanRemoveServices
967                 elif tmp == "yes_hold_feeds":
968                         flags |= eComponentScan.scanRemoveServices
969                         flags |= eComponentScan.scanDontRemoveFeeds
970
971                 if tmp != "no" and not removeAll:
972                         flags |= eComponentScan.scanDontRemoveUnscanned
973
974                 if self.scan_onlyfree.value:
975                         flags |= eComponentScan.scanOnlyFree
976
977                 for x in self["config"].list:
978                         x[1].save()
979
980                 if startScan:
981                         self.startScan(tlist, flags, index_to_scan, self.networkid)
982                 else:
983                         self.flags = flags
984                         self.feid = index_to_scan
985                         self.tlist = []
986                         self.startCableTransponderSearch(self.feid)
987
988         def setCableTransponderSearchResult(self, tlist):
989                 self.tlist = tlist
990
991         def cableTransponderSearchFinished(self):
992                 if self.tlist is None:
993                         self.tlist = []
994                 else:
995                         self.startScan(self.tlist, self.flags, self.feid)
996
997         def predefinedTranspondersList(self, orbpos):
998                 default = None
999                 if orbpos is not None:
1000                         list = []
1001                         if self.scan_sat.system.value == eDVBFrontendParametersSatellite.System_DVB_S2:
1002                                 fec = self.scan_sat.fec_s2.value
1003                         else:
1004                                 fec = self.scan_sat.fec.value
1005                         compare = [0, self.scan_sat.frequency.value*1000, self.scan_sat.symbolrate.value*1000, self.scan_sat.polarization.value, fec]
1006                         i = 0
1007                         tps = nimmanager.getTransponders(orbpos)
1008                         for tp in tps:
1009                                 if tp[0] == 0:
1010                                         if default is None and self.compareTransponders(tp, compare):
1011                                                 default = str(i)
1012                                         list.append((str(i), self.humanReadableTransponder(tp)))
1013                                         i += 1
1014                         self.preDefTransponders = ConfigSelection(choices = list, default = default)
1015                 return default
1016
1017         def humanReadableTransponder(self, tp):
1018                 if tp[3] in range (4) and tp[4] in range (11):
1019                         pol_list = ['H','V','L','R']
1020                         fec_list = ['Auto','1/2','2/3','3/4','5/6','7/8','8/9','3/5','4/5','9/10','None']
1021                         return str(tp[1] / 1000) + " " + pol_list[tp[3]] + " " + str(tp[2] / 1000) + " " + fec_list[tp[4]]
1022                 return _("Invalid transponder data")
1023
1024         def compareTransponders(self, tp, compare):
1025                 frequencyTolerance = 2000 #2 MHz
1026                 symbolRateTolerance = 10
1027                 return abs(tp[1] - compare[1]) <= frequencyTolerance and abs(tp[2] - compare[2]) <= symbolRateTolerance and tp[3] == compare[3] and (not tp[4] or tp[4] == compare[4])
1028
1029         def predefinedTerrTranspondersList(self):
1030                 default = None
1031                 list = []
1032                 compare = [2, self.scan_ter.frequency.value*1000]
1033                 i = 0
1034                 index_to_scan = int(self.scan_nims.value)
1035                 channels = supportedChannels(index_to_scan)
1036                 region = self.terrestrial_nims_regions[index_to_scan].value
1037                 tps = nimmanager.getTranspondersTerrestrial(region)
1038                 for tp in tps:
1039                         if tp[0] == 2: #TERRESTRIAL
1040                                 channel = ''
1041                                 if channels:
1042                                         channel = _(' (Channel %s)') % (getChannelNumber(tp[1], index_to_scan))
1043                                 if default is None and self.compareTerrTransponders(tp, compare):
1044                                         default = str(i)
1045                                 list.append((str(i), '%s MHz %s' % (str(tp[1] / 1000000), channel)))
1046                                 i += 1
1047                                 print "channel", channel
1048                 self.TerrestrialTransponders = ConfigSelection(choices = list, default = default)
1049                 return default
1050
1051         def compareTerrTransponders(self, tp, compare):
1052                 frequencyTolerance = 1000000 #1 MHz
1053                 return abs(tp[1] - compare[1]) <= frequencyTolerance
1054
1055         def getTerrestrialRegionsList(self, index_to_scan = None):
1056                 default = None
1057                 list = []
1058                 if index_to_scan is None:
1059                         index_to_scan = int(self.scan_nims.value)
1060                 defaultRegionForNIM = nimmanager.getTerrestrialDescription(index_to_scan)
1061                 for r in nimmanager.terrestrialsList:
1062                         if default is None and r[0] == defaultRegionForNIM:
1063                                 default = r[0]
1064                         list.append((r[0], r[0][:46]))
1065                 return ConfigSelection(choices = list, default = default)
1066
1067         def predefinedCabTranspondersList(self):
1068                 default = None
1069                 list = []
1070                 # 0 transponder type, 1 freq, 2 sym, 3 mod, 4 fec, 5 inv, 6 sys
1071                 compare = [1, self.scan_cab.frequency.value*1000, self.scan_cab.symbolrate.value*1000, self.scan_cab.modulation.value, self.scan_cab.fec.value, self.scan_cab.inversion.value, self.scan_cab.system.value]
1072                 i = 0
1073                 index_to_scan = int(self.scan_nims.value)
1074                 tps = nimmanager.getTranspondersCable(index_to_scan)
1075                 for tp in tps:
1076                         if tp[0] == 1: #CABLE
1077                                 if default is None and self.compareCabTransponders(tp, compare):
1078                                         default = str(i)
1079                                 list.append((str(i), self.humanReadableCabTransponder(tp)))
1080                                 i += 1
1081                 self.CableTransponders = ConfigSelection(choices = list, default = default)
1082                 return default
1083
1084         def humanReadableCabTransponder(self, tp):
1085                 if tp[3] in range (6) and (tp[4] in range (10) or tp[4] == 15):
1086                         mod_list = ['Auto', '16-QAM','32-QAM','64-QAM','128-QAM', '256-QAM']
1087                         fec_list = {0:"Auto", 1:'1/2', 2:'2/3', 3:'3/4', 4:'5/6', 5:'7/8', 6:'8/9', 7:'3/5', 8:'4/5', 9:'9/10', 15:'None'}
1088                         print str(tp[1]/1000) + " MHz " + fec_list[tp[4]] + " " + str(tp[2]/1000) + " " + mod_list[tp[3]]
1089                         return str(tp[1]/1000) + " MHz " + fec_list[tp[4]] + " " + str(tp[2]/1000) + " " + mod_list[tp[3]]
1090                 return _("Invalid transponder data")
1091
1092         def compareCabTransponders(self, tp, compare):
1093                 frequencyTolerance = 1000000 #1 MHz
1094                 symbolRateTolerance = 10
1095                 return abs(tp[1] - compare[1]) <= frequencyTolerance and abs(tp[2] - compare[2]) <= symbolRateTolerance and tp[3] == compare[3] and (not tp[4] or tp[4] == compare[4])
1096
1097         def startScan(self, tlist, flags, feid, networkid = 0):
1098                 if len(tlist):
1099                         # flags |= eComponentScan.scanSearchBAT
1100                         if self.finished_cb:
1101                                 self.session.openWithCallback(self.finished_cb, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags, "networkid": networkid}])
1102                         else:
1103                                 self.session.openWithCallback(self.startScanCallback, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags, "networkid": networkid}])
1104                 else:
1105                         if self.finished_cb:
1106                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1107                         else:
1108                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1109
1110         def startScanCallback(self, answer):
1111                 if answer:
1112                         self.doCloseRecursive()
1113
1114         def keyCancel(self):
1115                 self.session.nav.playService(self.session.postScanService)
1116                 for x in self["config"].list:
1117                         x[1].cancel()
1118                 self.close()
1119
1120         def doCloseRecursive(self):
1121                 self.session.nav.playService(self.session.postScanService)
1122                 self.closeRecursive()
1123
1124 class ScanSimple(ConfigListScreen, Screen, CableTransponderSearchSupport):
1125         def getNetworksForNim(self, nim):
1126                 if nim.isCompatible("DVB-S"):
1127                         networks = nimmanager.getSatListForNim(nim.slot)
1128                 elif not nim.empty:
1129                         networks = [ nim.type ] # "DVB-C" or "DVB-T". TODO: seperate networks for different C/T tuners, if we want to support that.
1130                 else:
1131                         # empty tuners provide no networks.
1132                         networks = [ ]
1133                 return networks
1134
1135         def __init__(self, session):
1136                 Screen.__init__(self, session)
1137
1138                 self["actions"] = ActionMap(["SetupActions", "MenuActions"],
1139                 {
1140                         "ok": self.keyGo,
1141                         "save": self.keyGo,
1142                         "cancel": self.keyCancel,
1143                         "menu": self.doCloseRecursive,
1144                 }, -2)
1145
1146                 self.session.postScanService = session.nav.getCurrentlyPlayingServiceOrGroup()
1147
1148                 self.list = []
1149                 tlist = []
1150
1151                 known_networks = [ ]
1152                 nims_to_scan = [ ]
1153                 self.finished_cb = None
1154
1155                 for nim in nimmanager.nim_slots:
1156                         # collect networks provided by this tuner
1157
1158                         need_scan = False
1159                         networks = self.getNetworksForNim(nim)
1160
1161                         print "nim %d provides" % nim.slot, networks
1162                         print "known:", known_networks
1163
1164                         # we only need to scan on the first tuner which provides a network.
1165                         # this gives the first tuner for each network priority for scanning.
1166                         for x in networks:
1167                                 if x not in known_networks:
1168                                         need_scan = True
1169                                         print x, "not in ", known_networks
1170                                         known_networks.append(x)
1171
1172                         # don't offer to scan nims if nothing is connected
1173                         if not nimmanager.somethingConnected(nim.slot):
1174                                 need_scan = False
1175
1176                         if need_scan:
1177                                 nims_to_scan.append(nim)
1178
1179                 # we save the config elements to use them on keyGo
1180                 self.nim_enable = [ ]
1181
1182                 if len(nims_to_scan):
1183                         self.scan_networkScan = ConfigYesNo(default = True)
1184                         self.scan_clearallservices = ConfigSelection(default = "yes", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
1185                         self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
1186                         self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
1187
1188                         for nim in nims_to_scan:
1189                                 nimconfig = ConfigYesNo(default = True)
1190                                 nimconfig.nim_index = nim.slot
1191                                 self.nim_enable.append(nimconfig)
1192                                 self.list.append(getConfigListEntry(_("Scan ") + nim.slot_name + " (" + nim.friendly_type + ")", nimconfig))
1193
1194                 ConfigListScreen.__init__(self, self.list)
1195                 self["header"] = Label(_("Automatic scan"))
1196                 self["footer"] = Label(_("Press OK to scan"))
1197
1198         def runAsync(self, finished_cb):
1199                 self.finished_cb = finished_cb
1200                 self.keyGo()
1201
1202         def keyGo(self):
1203                 InfoBarInstance = InfoBar.instance
1204                 if InfoBarInstance:
1205                         InfoBarInstance.checkTimeshiftRunning(self.keyGoCheckTimeshiftCallback)
1206                 else:
1207                         self.keyGoCheckTimeshiftCallback(True)
1208
1209         def keyGoCheckTimeshiftCallback(self, answer):
1210                 if answer:
1211                         self.scanList = []
1212                         self.known_networks = set()
1213                         self.nim_iter=0
1214                         self.buildTransponderList()
1215
1216         def buildTransponderList(self): # this method is called multiple times because of asynchronous stuff
1217                 APPEND_NOW = 0
1218                 SEARCH_CABLE_TRANSPONDERS = 1
1219                 action = APPEND_NOW
1220
1221                 n = self.nim_iter < len(self.nim_enable) and self.nim_enable[self.nim_iter] or None
1222                 self.nim_iter += 1
1223                 if n:
1224                         if n.value: # check if nim is enabled
1225                                 flags = 0
1226                                 nim = nimmanager.nim_slots[n.nim_index]
1227                                 networks = set(self.getNetworksForNim(nim))
1228                                 networkid = 0
1229
1230                                 # don't scan anything twice
1231                                 networks.discard(self.known_networks)
1232
1233                                 tlist = [ ]
1234                                 if nim.isCompatible("DVB-S"):
1235                                         # get initial transponders for each satellite to be scanned
1236                                         for sat in networks:
1237                                                 getInitialTransponderList(tlist, sat[0])
1238                                 elif nim.isCompatible("DVB-C"):
1239                                         if config.Nims[nim.slot].cable.scan_type.value == "provider":
1240                                                 getInitialCableTransponderList(tlist, nim.slot)
1241                                         else:
1242                                                 action = SEARCH_CABLE_TRANSPONDERS
1243                                                 networkid = config.Nims[nim.slot].cable.scan_networkid.value
1244                                 elif nim.isCompatible("DVB-T"):
1245                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(nim.slot))
1246                                 else:
1247                                         assert False
1248
1249                                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
1250                                 tmp = self.scan_clearallservices.value
1251                                 if tmp == "yes":
1252                                         flags |= eComponentScan.scanRemoveServices
1253                                 elif tmp == "yes_hold_feeds":
1254                                         flags |= eComponentScan.scanRemoveServices
1255                                         flags |= eComponentScan.scanDontRemoveFeeds
1256
1257                                 if action == APPEND_NOW:
1258                                         self.scanList.append({"transponders": tlist, "feid": nim.slot, "flags": flags})
1259                                 elif action == SEARCH_CABLE_TRANSPONDERS:
1260                                         self.flags = flags
1261                                         self.feid = nim.slot
1262                                         self.networkid = networkid
1263                                         self.startCableTransponderSearch(nim.slot)
1264                                         return
1265                                 else:
1266                                         assert False
1267
1268                         self.buildTransponderList() # recursive call of this function !!!
1269                         return
1270                 # when we are here, then the recursion is finished and all enabled nims are checked
1271                 # so we now start the real transponder scan
1272                 self.startScan(self.scanList)
1273
1274         def startScan(self, scanList):
1275                 if len(scanList):
1276                         if self.finished_cb:
1277                                 self.session.openWithCallback(self.finished_cb, ServiceScan, scanList = scanList)
1278                         else:
1279                                 self.session.open(ServiceScan, scanList = scanList)
1280                 else:
1281                         if self.finished_cb:
1282                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1283                         else:
1284                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1285
1286         def setCableTransponderSearchResult(self, tlist):
1287                 if tlist is not None:
1288                         self.scanList.append({"transponders": tlist, "feid": self.feid, "flags": self.flags})
1289
1290         def cableTransponderSearchFinished(self):
1291                 self.buildTransponderList()
1292
1293         def keyCancel(self):
1294                 self.session.nav.playService(self.session.postScanService)
1295                 self.close()
1296
1297         def doCloseRecursive(self):
1298                 self.session.nav.playService(self.session.postScanService)
1299                 self.closeRecursive()
1300
1301         def Satexists(self, tlist, pos):
1302                 for x in tlist:
1303                         if x == pos:
1304                                 return 1
1305                 return 0