set default standby-brightness to 0
[enigma2.git] / lib / python / Components / ServiceScan.py
1 from enigma import eComponentScan
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):
38                 self.progressbar = progressbar
39                 self.text = text
40                 self.scan = eComponentScan()
41                 self.state = self.Idle
42                 self.scanStatusChanged()
43                 
44         def execBegin(self):
45                 self.scan.statusChanged.get().append(self.scanStatusChanged)
46                 self.state = self.Running
47                 err = self.scan.start()
48                 if err:
49                         self.state = self.Error
50                         self.errorcode = 0
51
52                 self.scanStatusChanged()
53         
54         def execEnd(self):
55                 self.scan.statusChanged.get().remove(self.scanStatusChanged)
56                 if not self.isDone():
57                         print "*** warning *** scan was not finished!"
58
59         def isDone(self):
60                 print "state is %d " % (self.state)
61                 return self.state == self.Done or self.state == self.Error
62