use steps in startwizard
[enigma2.git] / lib / python / Components / ServiceScan.py
1 from enigma import eComponentScan, eDVBFrontendParametersSatellite, eDVBFrontendParametersCable, eDVBFrontendParametersTerrestrial
2
3 class ServiceScan:
4         
5         Idle = 1
6         Running = 2
7         Done = 3
8         Error = 4
9         
10         Errors = { 
11                 0: "error starting scanning",
12                 1: "error while scanning",
13                 2: "no resource manager",
14                 3: "no channel list"
15                 }
16         
17         def scanStatusChanged(self):
18                 if self.state == self.Running:
19                         self.progressbar.setValue(self.scan.getProgress())
20                         if self.scan.isDone():
21                                 errcode = self.scan.getError()
22                                 
23                                 if errcode == 0:
24                                         self.state = self.Done
25                                 else:
26                                         self.state = self.Error
27                                         self.errorcode = errcode
28                         else:
29                                 self.text.setText(_("scan in progress - %d %% done!\n%d services found!") % (self.scan.getProgress(), self.scan.getNumServices()))
30                 
31                 if self.state == self.Done:
32                         self.text.setText(_("scan done!"))
33                 
34                 if self.state == self.Error:
35                         self.text.setText(_("ERROR - failed to scan (%s)!") % (self.Errors[self.errorcode]) )
36         
37         def __init__(self, progressbar, text, transponders, feid, flags):
38                 self.progressbar = progressbar
39                 self.text = text
40                 self.scan = eComponentScan()
41                 self.state = self.Idle
42                 self.feid = feid
43                 self.flags = flags
44                 self.scanStatusChanged()
45                 
46 #               if 1:
47 #                       parm = eDVBFrontendParametersSatellite()
48 #
49 #                       parm.frequency = 11817000
50 #                       parm.symbol_rate = 27500000
51 #                       parm.polarisation = 1 # eDVBFrontendParametersSatellite.Polarisation.Vertical
52 #                       parm.fec = 3 # eDVBFrontendParametersSatellite.FEC.f3_4;
53 #                       parm.inversion = 1 #eDVBFrontendParametersSatellite.Inversion.Off;
54 #                       parm.orbital_position = 192
55 #                       self.scan.addInitial(parm)
56 #               else:
57 #                               # until we have a terrestrial.xml:
58 #                       for x in [490000000, 530000000, 546000000, 570000000, 626000000]:
59 #                               parm = eDVBFrontendParametersTerrestrial()
60 #                               parm.frequency = x
61 #                               parm.inversion = 2  # eDVBFrontendParametersTerrestrial.Inversion.Unknown;
62 #                               parm.bandwidth = 0  #eDVBFrontendParametersTerrestrial.Bandwidth.Bw8MHz;
63 #                               parm.code_rate_HP = parm.code_rate_LP = 6 #eDVBFrontendParametersTerrestrial.FEC.fAuto;
64 #                               parm.modulation = 1 #eDVBFrontendParametersTerrestrial.Modulation.QAM16;
65 #                               parm.transmission_mode = 1 # eDVBFrontendParametersTerrestrial.TransmissionMode.TM8k;
66 #                               parm.guard_interval = 0 # eDVBFrontendParametersTerrestrial.GuardInterval.GI_1_32;
67 #                               parm.hierarchy = 0 #eDVBFrontendParametersTerrestrial.Hierarchy.HNone;
68 #                               self.scan.addInitial(parm)
69                 
70                 for x in transponders:
71                         self.scan.addInitial(x)
72                 
73                 #self.scan.addInitial(parm)
74                 
75         def execBegin(self):
76                 self.scan.statusChanged.get().append(self.scanStatusChanged)
77                 self.state = self.Running
78                 err = self.scan.start(self.feid, self.flags)
79                 if err:
80                         self.state = self.Error
81                         self.errorcode = 0
82
83                 self.scanStatusChanged()
84         
85         def execEnd(self):
86                 self.scan.statusChanged.get().remove(self.scanStatusChanged)
87                 if not self.isDone():
88                         print "*** warning *** scan was not finished!"
89                 
90                 del self.scan
91
92         def isDone(self):
93                 print "state is %d " % (self.state)
94                 return self.state == self.Done or self.state == self.Error