intial checkin of mediadownload.
[vuplus_dvbapp-plugin] / mediadownloader / src / VariableProgressSource.py
1 from Components.Sources.Source import Source
2
3 class VariableProgressSource(Source):
4         """Source to feed Progress Renderer from HTTPProgressDownloader"""
5
6         def __init__(self):
7                 # Initialize and invalidate
8                 Source.__init__(self)
9                 self.invalidate()
10
11         def invalidate(self):
12                 # Invalidate
13                 self.range = None
14                 self.value = 0
15                 self.factor = 1
16                 self.changed((self.CHANGED_CLEAR, ))
17
18         def writeValues(self, pos, max):
19                 # Increase Factor as long as range is too big
20                 if self.range > 5000000:
21                         self.factor *= 500
22                         self.range /= 500
23
24                 # Only save range if not None
25                 if max is not None:
26                         self.range = max / self.factor
27
28                 # Save pos
29                 self.value = pos / self.factor          
30
31                 # Trigger change
32                 self.changed((self.CHANGED_ALL, ))