servicemp3.cpp: more simple/flexible streaming detection
[enigma2.git] / lib / python / Plugins / SystemPlugins / DiseqcTester / plugin.py
1 from Screens.Satconfig import NimSelection
2 from Screens.Screen import Screen
3 from Screens.TextBox import TextBox
4 from Screens.MessageBox import MessageBox
5
6 from Plugins.Plugin import PluginDescriptor
7
8 from Components.ActionMap import ActionMap, NumberActionMap
9 from Components.NimManager import nimmanager
10 from Components.ResourceManager import resourcemanager
11 from Components.Sources.FrontendStatus import FrontendStatus
12 from Components.TuneTest import TuneTest
13 from Components.Sources.List import List
14 from Components.Sources.Progress import Progress
15 from Components.Sources.StaticText import StaticText
16 from Components.ConfigList import ConfigListScreen
17 from Components.config import getConfigListEntry, ConfigSelection, ConfigYesNo
18 from Components.Harddisk import harddiskmanager
19
20 import random
21
22 # always use:
23 # setResultType(type)
24 # setResultParameter(parameter)
25 # getTextualResult()
26 class ResultParser:
27         def __init__(self):
28                 pass
29         
30         TYPE_BYORBPOS = 0
31         TYPE_BYINDEX = 1
32         TYPE_ALL = 2
33         def setResultType(self, type):
34                 self.type = type
35                 
36         def setResultParameter(self, parameter):
37                 if self.type == self.TYPE_BYORBPOS:
38                         self.orbpos = parameter
39                 elif self.type == self.TYPE_BYINDEX:
40                         self.index = parameter
41                         
42         def getTextualResultForIndex(self, index, logfulltransponders = False):
43                 text = ""
44                 text += "%s:\n" % self.getTextualIndexRepresentation(index)
45                 
46                 failed, successful = self.results[index]["failed"], self.results[index]["successful"]
47                 countfailed = len(failed)
48                 countsuccessful = len(successful)
49                 countall = countfailed + countsuccessful
50                 percentfailed = round(countfailed / float(countall + 0.0001) * 100)
51                 percentsuccessful = round(countsuccessful / float(countall + 0.0001) * 100)
52                 text += "Tested %d transponders\n%d (%d %%) transponders succeeded\n%d (%d %%) transponders failed\n" % (countall, countsuccessful, percentsuccessful, countfailed, percentfailed)
53                 reasons = {}
54                 completelist = []
55                 if countfailed > 0:
56                         for transponder in failed:
57                                 completelist.append({"transponder": transponder[0], "fedata": transponder[-1]})
58                                 reasons[transponder[2]] = reasons.get(transponder[2], [])
59                                 reasons[transponder[2]].append(transponder)
60                                 if transponder[2] == "pids_failed":
61                                         print transponder[2], "-", transponder[3]
62                                 
63                         text += "The %d unsuccessful tuning attempts failed for the following reasons:\n" % countfailed
64                         
65                         for reason in reasons.keys():
66                                 text += "%s: %d transponders failed\n" % (reason, len(reasons[reason]))
67                         
68                         for reason in reasons.keys():
69                                 text += "\n"
70                                 text += "%s previous planes:\n" % reason
71                                 for transponder in reasons[reason]:
72                                         if transponder[1] is not None:
73                                                 text += self.getTextualIndexRepresentation(self.getIndexForTransponder(transponder[1]))
74                                         else:
75                                                 text += "No transponder tuned"
76                                         text += " ==> " + self.getTextualIndexRepresentation(self.getIndexForTransponder(transponder[0]))
77                                         text += "\n"
78                                         if logfulltransponders:
79                                                 text += str(transponder[1])
80                                                 text += " ==> "
81                                                 text += str(transponder[0])
82                                                 text += "\n"
83                                         if reason == "pids_failed":
84                                                 text += "(tsid, onid): "
85                                                 text += str(transponder[3]['real'])
86                                                 text += "(read from sat) != "
87                                                 text += str(transponder[3]['expected'])
88                                                 text += "(read from file)"
89                                                 text += "\n"
90                                         text += "\n"
91                 if countsuccessful > 0:
92                         text += "\n"
93                         text += "Successfully tuned transponders' previous planes:\n" 
94                         for transponder in successful:
95                                 completelist.append({"transponder": transponder[0], "fedata": transponder[-1]})
96                                 if transponder[1] is not None:
97                                         text += self.getTextualIndexRepresentation(self.getIndexForTransponder(transponder[1]))
98                                 else:
99                                         text += "No transponder tuned"
100                                 text += " ==> " + self.getTextualIndexRepresentation(self.getIndexForTransponder(transponder[0]))
101                                 text += "\n"
102                 
103                 text += "------------------------------------------------\n"
104                 text += "complete transponderlist:\n"
105                 for entry in completelist:
106                         text += str(entry["transponder"]) + " -- " + str(entry["fedata"]) + "\n"
107                 return text
108
109         def getTextualResult(self):
110                 text = ""
111                 if self.type == self.TYPE_BYINDEX:
112                         text += self.getTextualResultForIndex(self.index)
113                 elif self.type == self.TYPE_BYORBPOS:
114                         for index in self.results.keys():
115                                 if index[2] == self.orbpos:
116                                         text += self.getTextualResultForIndex(index)
117                                         text += "\n-----------------------------------------------------\n"
118                 elif self.type == self.TYPE_ALL:
119                         orderedResults = {}
120                         for index in self.results.keys():
121                                 orbpos = index[2]
122                                 orderedResults[orbpos] = orderedResults.get(orbpos, [])
123                                 orderedResults[orbpos].append(index)
124                         ordered_orbpos = orderedResults.keys()
125                         ordered_orbpos.sort()
126                         for orbpos in ordered_orbpos:
127                                 text += "\n*****************************************\n"
128                                 text += "Orbital position %s:" % str(orbpos)
129                                 text += "\n*****************************************\n"
130                                 for index in orderedResults[orbpos]:
131                                         text += self.getTextualResultForIndex(index, logfulltransponders = True)
132                                         text += "\n-----------------------------------------------------\n"
133                         
134                                 
135                 return text
136
137 class DiseqcTester(Screen, TuneTest, ResultParser):
138         skin = """
139                 <screen position="90,100" size="520,400" title="DiSEqC Tester" >
140                 <!--ePixmap pixmap="skin_default/icons/dish_scan.png" position="5,25" zPosition="0" size="119,110" transparent="1" alphatest="on" />
141                 <widget source="Frontend" render="Label" position="190,10" zPosition="2" size="260,20" font="Regular;19" halign="center" valign="center" transparent="1">
142                         <convert type="FrontendInfo">SNRdB</convert>
143                 </widget>
144                 <eLabel name="snr" text="SNR:" position="120,35" size="60,22" font="Regular;21" halign="right" transparent="1" />
145                 <widget source="Frontend" render="Progress" position="190,35" size="260,20" pixmap="skin_default/bar_snr.png" borderWidth="2" borderColor="#cccccc">
146                         <convert type="FrontendInfo">SNR</convert>
147                 </widget>
148                 <widget source="Frontend" render="Label" position="460,35" size="60,22" font="Regular;21">
149                         <convert type="FrontendInfo">SNR</convert>
150                 </widget>
151                 <eLabel name="agc" text="AGC:" position="120,60" size="60,22" font="Regular;21" halign="right" transparent="1" />
152                 <widget source="Frontend" render="Progress" position="190,60" size="260,20" pixmap="skin_default/bar_snr.png" borderWidth="2" borderColor="#cccccc">
153                         <convert type="FrontendInfo">AGC</convert>
154                 </widget>
155                 <widget source="Frontend" render="Label" position="460,60" size="60,22" font="Regular;21">
156                         <convert type="FrontendInfo">AGC</convert>
157                 </widget>
158                 <eLabel name="ber" text="BER:" position="120,85" size="60,22" font="Regular;21" halign="right" transparent="1" />
159                 <widget source="Frontend" render="Progress" position="190,85" size="260,20" pixmap="skin_default/bar_ber.png" borderWidth="2" borderColor="#cccccc">
160                         <convert type="FrontendInfo">BER</convert>
161                 </widget>
162                 <widget source="Frontend" render="Label" position="460,85" size="60,22" font="Regular;21">
163                         <convert type="FrontendInfo">BER</convert>
164                 </widget>
165                 <eLabel name="lock" text="Lock:" position="120,115" size="60,22" font="Regular;21" halign="right" />
166                 <widget source="Frontend" render="Pixmap" pixmap="skin_default/icons/lock_on.png" position="190,110" zPosition="1" size="38,31" alphatest="on">
167                         <convert type="FrontendInfo">LOCK</convert>
168                         <convert type="ConditionalShowHide" />
169                 </widget>
170                 <widget source="Frontend" render="Pixmap" pixmap="skin_default/icons/lock_off.png" position="190,110" zPosition="1" size="38,31" alphatest="on">
171                         <convert type="FrontendInfo">LOCK</convert>
172                         <convert type="ConditionalShowHide">Invert</convert>
173                 </widget-->
174                 <widget source="progress_list" render="Listbox" position="0,0" size="510,150" scrollbarMode="showOnDemand">
175                         <convert type="TemplatedMultiContent">
176                                 {"template": [
177                                                 MultiContentEntryText(pos = (10, 0), size = (330, 25), flags = RT_HALIGN_LEFT, text = 1), # index 1 is the index name,
178                                                 MultiContentEntryText(pos = (330, 0), size = (150, 25), flags = RT_HALIGN_RIGHT, text = 2) # index 2 is the status,
179                                         ],
180                                  "fonts": [gFont("Regular", 20)],
181                                  "itemHeight": 25
182                                 }
183                         </convert>
184                 </widget>
185                 <eLabel name="overall_progress" text="Overall progress:" position="20,162" size="480,22" font="Regular;21" halign="center" transparent="1" />
186                 <widget source="overall_progress" render="Progress" position="20,192" size="480,20" borderWidth="2" backgroundColor="#254f7497" />
187                 <eLabel name="overall_progress" text="Progress:" position="20,222" size="480,22" font="Regular;21" halign="center" transparent="1" />
188                 <widget source="sub_progress" render="Progress" position="20,252" size="480,20" borderWidth="2" backgroundColor="#254f7497" />
189                 
190                 <eLabel name="" text="Failed:" position="20,282" size="140,22" font="Regular;21" halign="left" transparent="1" />
191                 <widget source="failed_counter" render="Label" position="160,282" size="100,20" font="Regular;21" />
192                 
193                 <eLabel name="" text="Succeeded:" position="20,312" size="140,22" font="Regular;21" halign="left" transparent="1" />
194                 <widget source="succeeded_counter" render="Label" position="160,312" size="100,20" font="Regular;21" />
195                 
196                 <eLabel name="" text="With errors:" position="20,342" size="140,22" font="Regular;21" halign="left" transparent="1" />
197                 <widget source="witherrors_counter" render="Label" position="160,342" size="100,20" font="Regular;21" />
198                 
199                 <eLabel name="" text="Not tested:" position="20,372" size="140,22" font="Regular;21" halign="left" transparent="1" />
200                 <widget source="untestable_counter" render="Label" position="160,372" size="100,20" font="Regular;21" />
201                 
202                 <widget source="CmdText" render="Label" position="300,282" size="180,200" font="Regular;21" />
203                 </screen>"""
204                 
205         TEST_TYPE_QUICK = 0
206         TEST_TYPE_RANDOM = 1
207         TEST_TYPE_COMPLETE = 2
208         def __init__(self, session, feid, test_type = TEST_TYPE_QUICK, loopsfailed = 3, loopssuccessful = 1, log = False):
209                 Screen.__init__(self, session)
210                 self.feid = feid
211                 self.test_type = test_type
212                 self.loopsfailed = loopsfailed
213                 self.loopssuccessful = loopssuccessful
214                 self.log = log
215                 
216                 self["actions"] = NumberActionMap(["SetupActions"],
217                 {
218                         "ok": self.select,
219                         "cancel": self.keyCancel,
220                 }, -2)
221                 
222                 TuneTest.__init__(self, feid, stopOnSuccess = self.loopssuccessful, stopOnError = self.loopsfailed)
223                 #self["Frontend"] = FrontendStatus(frontend_source = lambda : self.frontend, update_interval = 100)
224                 self["overall_progress"] = Progress()
225                 self["sub_progress"] = Progress()
226                 
227                 self["failed_counter"] = StaticText("0")
228                 self["succeeded_counter"] = StaticText("0")
229                 self["witherrors_counter"] = StaticText("0")
230                 self["untestable_counter"] = StaticText("0")
231                 
232                 self.list = []
233                 self["progress_list"] = List(self.list)
234                 self["progress_list"].onSelectionChanged.append(self.selectionChanged)
235                 
236                 self["CmdText"] = StaticText(_("Please wait while scanning is in progress..."))
237                                 
238                 self.indexlist = {}
239                 self.readTransponderList()
240                 
241                 self.running = False
242                 
243                 self.results = {}
244                 self.resultsstatus = {}
245                 
246                 self.onLayoutFinish.append(self.go)
247                 
248         def getProgressListComponent(self, index, status):
249                 return (index, self.getTextualIndexRepresentation(index), status)
250         
251         def clearProgressList(self):
252                 self.list = []
253                 self["progress_list"].list = self.list
254         
255         def addProgressListItem(self, index):
256                 if index in self.indexlist:
257                         for entry in self.list:
258                                 if entry[0] == index:
259                                         self.changeProgressListStatus(index, "working")
260                                         return
261                         self.list.append(self.getProgressListComponent(index, _("working")))
262                         self["progress_list"].list = self.list
263                         self["progress_list"].setIndex(len(self.list) - 1)
264
265         def changeProgressListStatus(self, index, status):
266                 self.newlist = []
267                 count = 0
268                 indexpos = 0
269                 for entry in self.list:
270                         if entry[0] == index:
271                                 self.newlist.append(self.getProgressListComponent(index, status))
272                                 indexpos = count
273                         else:
274                                 self.newlist.append(entry)
275                         count += 1
276                 self.list = self.newlist
277                 self["progress_list"].list = self.list
278                 self["progress_list"].setIndex(indexpos)
279
280         def readTransponderList(self):
281                 for sat in nimmanager.getSatListForNim(self.feid):
282                         for transponder in nimmanager.getTransponders(sat[0]):
283                                 #print transponder
284                                 mytransponder = (transponder[1] / 1000, transponder[2] / 1000, transponder[3], transponder[4], transponder[7], sat[0], transponder[5], transponder[6], transponder[8], transponder[9], transponder[10], transponder[11])
285                                 self.analyseTransponder(mytransponder)
286
287         def getIndexForTransponder(self, transponder):
288                 
289                 if transponder[0] < 11700:
290                         band = 1 # low
291                 else:
292                         band = 0 # high
293                 
294                 polarisation = transponder[2]
295                 
296                 sat = transponder[5]
297                 
298                 index = (band, polarisation, sat)
299                 return index
300
301         # sort the transponder into self.transponderlist
302         def analyseTransponder(self, transponder):
303                 index = self.getIndexForTransponder(transponder)
304                 if index not in self.indexlist:
305                         self.indexlist[index] = []
306                 self.indexlist[index].append(transponder)
307                 #print "self.indexlist:", self.indexlist
308         
309         # returns a string for the user representing a human readable output for index 
310         def getTextualIndexRepresentation(self, index):
311                 print "getTextualIndexRepresentation:", index
312                 text = ""
313                 
314                 text += nimmanager.getSatDescription(index[2]) + ", "
315                 
316                 if index[0] == 1:
317                         text += "Low Band, "
318                 else:
319                         text += "High Band, "
320                         
321                 if index[1] == 0:
322                         text += "H"
323                 else:
324                         text += "V"
325                 return text
326         
327         def fillTransponderList(self):
328                 self.clearTransponder()
329                 print "----------- fillTransponderList"
330                 print "index:", self.currentlyTestedIndex
331                 keys = self.indexlist.keys()
332                 if self.getContinueScanning():
333                         print "index:", self.getTextualIndexRepresentation(self.currentlyTestedIndex)
334                         for transponder in self.indexlist[self.currentlyTestedIndex]:
335                                 self.addTransponder(transponder)
336                         print "transponderList:", self.transponderlist
337                         return True
338                 else:
339                         return False
340                 
341         def progressCallback(self, progress):
342                 if progress[0] != self["sub_progress"].getRange():
343                         self["sub_progress"].setRange(progress[0])
344                 self["sub_progress"].setValue(progress[1])
345
346         # logic for scanning order of transponders
347         # on go getFirstIndex is called
348         def getFirstIndex(self):
349                 # TODO use other function to scan more randomly
350                 if self.test_type == self.TEST_TYPE_QUICK:
351                         self.myindex = 0
352                         keys = self.indexlist.keys()
353                         keys.sort(key = lambda a: a[2]) # sort by orbpos
354                         self["overall_progress"].setRange(len(keys))
355                         self["overall_progress"].setValue(self.myindex)
356                         return keys[0]
357                 elif self.test_type == self.TEST_TYPE_RANDOM:
358                         self.randomkeys = self.indexlist.keys()
359                         random.shuffle(self.randomkeys)
360                         self.myindex = 0
361                         self["overall_progress"].setRange(len(self.randomkeys))
362                         self["overall_progress"].setValue(self.myindex)
363                         return self.randomkeys[0]
364                 elif self.test_type == self.TEST_TYPE_COMPLETE:
365                         keys = self.indexlist.keys()
366                         print "keys:", keys
367                         successorindex = {}
368                         for index in keys:
369                                 successorindex[index] = []
370                                 for otherindex in keys:
371                                         if otherindex != index:
372                                                 successorindex[index].append(otherindex)
373                                 random.shuffle(successorindex[index])
374                         self.keylist = []
375                         stop = False
376                         currindex = None
377                         while not stop:
378                                 if currindex is None or len(successorindex[currindex]) == 0:
379                                         oldindex = currindex
380                                         for index in successorindex.keys():
381                                                 if len(successorindex[index]) > 0:
382                                                         currindex = index
383                                                         self.keylist.append(currindex)
384                                                         break
385                                         if currindex == oldindex:
386                                                 stop = True
387                                 else:
388                                         currindex = successorindex[currindex].pop()
389                                         self.keylist.append(currindex)
390                         print "self.keylist:", self.keylist
391                         self.myindex = 0
392                         self["overall_progress"].setRange(len(self.keylist))
393                         self["overall_progress"].setValue(self.myindex)
394                         return self.keylist[0]
395
396                                         
397         # after each index is finished, getNextIndex is called to get the next index to scan 
398         def getNextIndex(self):
399                 # TODO use other function to scan more randomly
400                 if self.test_type == self.TEST_TYPE_QUICK:
401                         self.myindex += 1
402                         keys = self.indexlist.keys()
403                         keys.sort(key = lambda a: a[2]) # sort by orbpos
404                         
405                         self["overall_progress"].setValue(self.myindex)
406                         if self.myindex < len(keys):
407                                 return keys[self.myindex]
408                         else:
409                                 return None
410                 elif self.test_type == self.TEST_TYPE_RANDOM:
411                         self.myindex += 1
412                         keys = self.randomkeys
413                         
414                         self["overall_progress"].setValue(self.myindex)
415                         if self.myindex < len(keys):
416                                 return keys[self.myindex]
417                         else:
418                                 return None
419                 elif self.test_type == self.TEST_TYPE_COMPLETE:
420                         self.myindex += 1
421                         keys = self.keylist
422                         
423                         self["overall_progress"].setValue(self.myindex)
424                         if self.myindex < len(keys):
425                                 return keys[self.myindex]
426                         else:
427                                 return None
428                                 
429         # after each index is finished and the next index is returned by getNextIndex
430         # the algorithm checks, if we should continue scanning
431         def getContinueScanning(self):
432                 if self.test_type == self.TEST_TYPE_QUICK or self.test_type == self.TEST_TYPE_RANDOM:
433                         return (self.myindex < len(self.indexlist.keys()))
434                 elif self.test_type == self.TEST_TYPE_COMPLETE:
435                         return (self.myindex < len(self.keylist))
436                 
437         def addResult(self, index, status, failedTune, successfullyTune):
438                 self.results[index] = self.results.get(index, {"failed": [], "successful": [], "status": None, "internalstatus": None})
439                 self.resultsstatus[status] = self.resultsstatus.get(status, [])
440
441                 oldstatus = self.results[index]["internalstatus"]
442                 if oldstatus is None:
443                         self.results[index]["status"] = status
444                 elif oldstatus == "successful":
445                         if status == "failed":
446                                 self.results[index]["status"] = "with_errors"
447                         elif status == "successful":
448                                 self.results[index]["status"] = oldstatus
449                         elif status == "with_errors":
450                                 self.results[index]["status"] = "with_errors"
451                         elif status == "not_tested":
452                                 self.results[index]["status"] = oldstatus
453                 elif oldstatus == "failed":
454                         if status == "failed":
455                                 self.results[index]["status"] = oldstatus
456                         elif status == "successful":
457                                 self.results[index]["status"] = "with_errors"
458                         elif status == "with_errors":
459                                 self.results[index]["status"] = "with_errors"
460                         elif status == "not_tested":
461                                 self.results[index]["status"] = oldstatus
462                 elif oldstatus == "with_errors":
463                         if status == "failed":
464                                 self.results[index]["status"] = oldstatus
465                         elif status == "successful":
466                                 self.results[index]["status"] = oldstatus
467                         elif status == "with_errors":
468                                 self.results[index]["status"] = oldstatus
469                         elif status == "not_tested":
470                                 self.results[index]["status"] = oldstatus
471                 elif oldstatus == "not_tested":
472                         self.results[index]["status"] = status
473                         
474                 if self.results[index]["status"] != "working":
475                         self.results[index]["internalstatus"] = self.results[index]["status"] 
476                 self.results[index]["failed"] = failedTune + self.results[index]["failed"]
477                 self.results[index]["successful"] = successfullyTune + self.results[index]["successful"]
478                 
479                 self.resultsstatus[status].append(index)
480         
481         def finishedChecking(self):
482                 print "finishedChecking"
483                 TuneTest.finishedChecking(self)
484
485                 if not self.results.has_key(self.currentlyTestedIndex):
486                         self.results[self.currentlyTestedIndex] = {"failed": [], "successful": [], "status": None, "internalstatus": None}
487                 
488                 if len(self.failedTune) > 0 and len(self.successfullyTune) > 0:
489                         self.changeProgressListStatus(self.currentlyTestedIndex, "with errors")
490                         self["witherrors_counter"].setText(str(int(self["witherrors_counter"].getText()) + 1))
491                         self.addResult(self.currentlyTestedIndex, "with_errors", self.failedTune, self.successfullyTune)
492                 elif len(self.failedTune) == 0 and len(self.successfullyTune) == 0:
493                         self.changeProgressListStatus(self.currentlyTestedIndex, "not tested")
494                         self["untestable_counter"].setText(str(int(self["untestable_counter"].getText()) + 1))
495                         self.addResult(self.currentlyTestedIndex, "untestable", self.failedTune, self.successfullyTune)
496                 elif len(self.failedTune) > 0:
497                         self.changeProgressListStatus(self.currentlyTestedIndex, "failed")
498                         #self["failed_counter"].setText(str(int(self["failed_counter"].getText()) + len(self.failedTune)))
499                         self["failed_counter"].setText(str(int(self["failed_counter"].getText()) + 1))
500                         self.addResult(self.currentlyTestedIndex, "failed", self.failedTune, self.successfullyTune)
501                 else:
502                         self.changeProgressListStatus(self.currentlyTestedIndex, "successful")
503                         #self["succeeded_counter"].setText(str(int(self["succeeded_counter"].getText()) + len(self.successfullyTune)))
504                         self["succeeded_counter"].setText(str(int(self["succeeded_counter"].getText()) + 1))
505                         self.addResult(self.currentlyTestedIndex, "successful", self.failedTune, self.successfullyTune)
506                         
507                         
508                 #self["failed_counter"].setText(str(int(self["failed_counter"].getText()) + len(self.failedTune)))
509                 #self["succeeded_counter"].setText(str(int(self["succeeded_counter"].getText()) + len(self.successfullyTune)))
510                 #if len(self.failedTune) == 0 and len(self.successfullyTune) == 0:
511                         #self["untestable_counter"].setText(str(int(self["untestable_counter"].getText()) + 1))
512                         
513                 self.currentlyTestedIndex = self.getNextIndex()
514                 self.addProgressListItem(self.currentlyTestedIndex)
515                 
516                 if self.fillTransponderList():
517                         self.run(checkPIDs = True)
518                 else:
519                         self.running = False
520                         self["progress_list"].setIndex(0)
521                         print "results:", self.results
522                         print "resultsstatus:", self.resultsstatus
523                         if self.log:
524                                 file = open("/media/hdd/diseqctester.log", "w")
525                                 self.setResultType(ResultParser.TYPE_ALL)
526                                 file.write(self.getTextualResult())
527                                 file.close()
528                                 self.session.open(MessageBox, text=_("The results have been written to %s.") % "/media/hdd/diseqctester.log", type = MessageBox.TYPE_INFO)
529
530         def go(self):
531                 self.running = True
532                 self["failed_counter"].setText("0")
533                 self["succeeded_counter"].setText("0")
534                 self["untestable_counter"].setText("0")
535                 self.currentlyTestedIndex = self.getFirstIndex()
536                 
537                 self.clearProgressList()
538                 self.addProgressListItem(self.currentlyTestedIndex)
539                 
540                 if self.fillTransponderList():
541                         self.run(True)
542
543         def keyCancel(self):
544                 self.close()
545                 
546         def select(self):
547                 print "selectedIndex:", self["progress_list"].getCurrent()[0]
548                 if not self.running:
549                         index = self["progress_list"].getCurrent()[0]
550                         #self.setResultType(ResultParser.TYPE_BYORBPOS)
551                         #self.setResultParameter(index[2])
552                         self.setResultType(ResultParser.TYPE_BYINDEX)
553                         self.setResultParameter(index)
554                         #self.setResultType(ResultParser.TYPE_ALL)
555                         self.session.open(TextBox, self.getTextualResult())
556         
557         def selectionChanged(self):
558                 print "selection changed"
559                 if len(self.list) > 0 and not self.running:
560                         self["CmdText"].setText(_("Press OK to get further details for %s") % str(self["progress_list"].getCurrent()[1]))
561
562 class DiseqcTesterTestTypeSelection(Screen, ConfigListScreen):
563
564         def __init__(self, session, feid):
565                 Screen.__init__(self, session)
566                 # for the skin: first try MediaPlayerSettings, then Setup, this allows individual skinning
567                 self.skinName = ["DiseqcTesterTestTypeSelection", "Setup" ]
568                 self.setup_title = _("DiSEqC-Tester settings")
569                 self.onChangedEntry = [ ]
570                 self.feid = feid
571                 
572                 self.list = []
573                 ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.changedEntry)
574                 
575                 self["actions"] = ActionMap(["SetupActions"],
576                         {
577                                 "cancel": self.keyCancel,
578                                 "save": self.keyOK,
579                                 "ok": self.keyOK,
580                         }, -2)
581
582                 self["key_red"] = StaticText(_("Cancel"))
583                 self["key_green"] = StaticText(_("OK"))
584                 
585                 self.createSetup()
586                 self.onLayoutFinish.append(self.layoutFinished)
587
588         def layoutFinished(self):
589                 self.setTitle(self.setup_title)
590
591         def createSetup(self):
592                 self.testtype = ConfigSelection(choices={"quick": _("Quick"), "random": _("Random"), "complete": _("Complete")}, default = "quick")
593                 self.testtypeEntry = getConfigListEntry(_("Test Type"), self.testtype)
594                 self.list.append(self.testtypeEntry)
595                 
596                 self.loopsfailed = ConfigSelection(choices={"-1": "Every known", "1": "1", "2": "2", "3": "3", "4": "4", "5": "5", "6": "6", "7": "7", "8": "8"}, default = "3")
597                 self.loopsfailedEntry = getConfigListEntry(_("Stop testing plane after # failed transponders"), self.loopsfailed)
598                 self.list.append(self.loopsfailedEntry)
599                 
600                 self.loopssuccessful = ConfigSelection(choices={"-1": "Every known", "1": "1", "2": "2", "3": "3", "4": "4", "5": "5", "6": "6", "7": "7", "8": "8"}, default = "1")
601                 self.loopssuccessfulEntry = getConfigListEntry(_("Stop testing plane after # successful transponders"), self.loopssuccessful)
602                 self.list.append(self.loopssuccessfulEntry)
603                 
604                 self.log = ConfigYesNo(False)
605                 if harddiskmanager.HDDCount() > 0:
606                         self.logEntry = getConfigListEntry(_("Log results to harddisk"), self.log)
607                         self.list.append(self.logEntry)
608                                         
609                 self["config"].list = self.list
610                 self["config"].l.setList(self.list)
611                 
612         def keyOK(self):
613                 print self.testtype.getValue()
614                 testtype = DiseqcTester.TEST_TYPE_QUICK
615                 if self.testtype.getValue() == "quick":
616                         testtype = DiseqcTester.TEST_TYPE_QUICK
617                 elif self.testtype.getValue() == "random":
618                         testtype = DiseqcTester.TEST_TYPE_RANDOM
619                 elif self.testtype.getValue() == "complete":
620                         testtype = DiseqcTester.TEST_TYPE_COMPLETE
621                 self.session.open(DiseqcTester, feid = self.feid, test_type = testtype, loopsfailed = int(self.loopsfailed.value), loopssuccessful = int(self.loopssuccessful.value), log = self.log.value)
622         
623         def keyCancel(self):
624                 self.close()
625
626         # for summary:
627         def changedEntry(self):
628                 for x in self.onChangedEntry:
629                         x()
630
631         def getCurrentEntry(self):
632                 return self["config"].getCurrent()[0]
633
634         def getCurrentValue(self):
635                 return str(self["config"].getCurrent()[1].getText())
636
637         def createSummary(self):
638                 from Screens.Setup import SetupSummary
639                 return SetupSummary
640
641 class DiseqcTesterNimSelection(NimSelection):
642         skin = """
643                 <screen position="160,123" size="400,330" title="Choose Tuner">
644                 <widget source="nimlist" render="Listbox" position="0,0" size="380,300" scrollbarMode="showOnDemand">
645                         <convert type="TemplatedMultiContent">
646                                 {"template": [
647                                                 MultiContentEntryText(pos = (10, 5), size = (360, 30), flags = RT_HALIGN_LEFT, text = 1), # index 1 is the nim name,
648                                                 MultiContentEntryText(pos = (50, 30), size = (320, 30), font = 1, flags = RT_HALIGN_LEFT, text = 2), # index 2 is a description of the nim settings,
649                                         ],
650                                  "fonts": [gFont("Regular", 20), gFont("Regular", 15)],
651                                  "itemHeight": 70
652                                 }
653                         </convert>
654                 </widget>
655         </screen>"""
656                 
657         def __init__(self, session, args = None):
658                 NimSelection.__init__(self, session)
659
660         def setResultClass(self):
661                 #self.resultclass = DiseqcTester
662                 self.resultclass = DiseqcTesterTestTypeSelection
663                 
664         def showNim(self, nim):
665                 nimConfig = nimmanager.getNimConfig(nim.slot)
666                 if nim.isCompatible("DVB-S"):
667                         if nimConfig.configMode.value in ("loopthrough", "equal", "satposdepends", "nothing"):
668                                 return False
669                         if nimConfig.configMode.value == "simple":
670                                 if nimConfig.diseqcMode.value == "positioner":
671                                         return True
672                         return True
673                 return False
674
675 def DiseqcTesterMain(session, **kwargs):
676         session.open(DiseqcTesterNimSelection)
677         
678 def autostart(reason, **kwargs):
679         resourcemanager.addResource("DiseqcTester", DiseqcTesterMain)
680
681 def Plugins(**kwargs):
682         return [ PluginDescriptor(name="DiSEqC Tester", description=_("Test DiSEqC settings"), where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=DiseqcTesterMain),
683                         PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, needsRestart = False, fnc = autostart)]