allow styleable TemplatedMultiContent lists
[enigma2.git] / lib / python / Components / Converter / RemainingToText.py
1 from Components.Converter.Converter import Converter
2 from Components.Element import cached
3
4 class RemainingToText(Converter, object):
5         DEFAULT = 0
6         WITH_SECONDS = 1
7         NO_SECONDS = 2
8
9         def __init__(self, type):
10                 Converter.__init__(self, type)
11                 if type == "WithSeconds":
12                         self.type = self.WITH_SECONDS
13                 elif type == "NoSeconds":
14                         self.type = self.NO_SECONDS
15                 else:
16                         self.type = self.DEFAULT
17
18         @cached
19         def getText(self):
20                 time = self.source.time
21                 if time is None:
22                         return ""
23
24                 (duration, remaining) = self.source.time
25
26                 if self.type == self.WITH_SECONDS:
27                         if remaining is not None:
28                                 return "%d:%02d:%02d" % (remaining / 3600, (remaining / 60) - ((remaining / 3600) * 60), remaining % 60)
29                         else:
30                                 return "%02d:%02d:%02d" % (duration / 3600, (duration / 60) - ((duration / 3600) * 60), duration % 60)
31                 elif self.type == self.NO_SECONDS:
32                         if remaining is not None:
33                                 return "+%d:%02d" % (remaining / 3600, (remaining / 60) - ((remaining / 3600) * 60))
34                         else:
35                                 return "%02d:%02d" % (duration / 3600, (duration / 60) - ((duration / 3600) * 60))
36                 elif self.type == self.DEFAULT:
37                         if remaining is not None:
38                                 return "+%d min" % (remaining / 60)
39                         else:
40                                 return "%d min" % (duration / 60)
41                 else:
42                         return "???"
43
44         text = property(getText)