allow styleable TemplatedMultiContent lists
[enigma2.git] / lib / python / Components / Converter / ServicePosition.py
index 7621bb178ecb72472b8820e2bb4b0af345df2887..d7a55daea47ce81cc5f1bb4b04f8fcc7461ed5e1 100644 (file)
@@ -4,14 +4,28 @@ from enigma import iPlayableService
 from Components.Element import cached
 
 class ServicePosition(Converter, Poll, object):
-       TYPE_LENGTH = 0,
-       TYPE_POSITION = 1,
-       TYPE_REMAINING = 2,
+       TYPE_LENGTH = 0
+       TYPE_POSITION = 1
+       TYPE_REMAINING = 2
        TYPE_GAUGE = 3
 
        def __init__(self, type):
                Poll.__init__(self)
                Converter.__init__(self, type)
+
+               args = type.split(',')
+               type = args.pop(0)
+
+               self.negate = 'Negate' in args
+               self.detailed = 'Detailed' in args
+               self.showHours = 'ShowHours' in args
+               self.showNoSeconds = 'ShowNoSeconds' in args
+
+               if self.detailed:
+                       self.poll_interval = 100
+               else:
+                       self.poll_interval = 500
+
                if type == "Length":
                        self.type = self.TYPE_LENGTH
                elif type == "Position":
@@ -20,8 +34,9 @@ class ServicePosition(Converter, Poll, object):
                        self.type = self.TYPE_REMAINING
                elif type == "Gauge":
                        self.type = self.TYPE_GAUGE
+               else:
+                       raise "type must be {Length|Position|Remaining|Gauge} with optional arguments {Negate|Detailed|ShowHours|NoSeconds}"
 
-               self.poll_interval = 500
                self.poll_enabled = self.type != self.TYPE_LENGTH
 
        def getSeek(self):
@@ -67,7 +82,10 @@ class ServicePosition(Converter, Poll, object):
                        elif self.type == self.TYPE_REMAINING:
                                l = self.length - self.position
 
-                       l /= 90000
+                       if not self.detailed:
+                               l /= 90000
+
+                       if self.negate: l = -l
 
                        if l > 0:
                                sign = ""
@@ -75,12 +93,39 @@ class ServicePosition(Converter, Poll, object):
                                l = -l
                                sign = "-"
 
-                       return sign + "%d:%02d" % (l/60, l%60)
+                       if not self.detailed:
+                               if self.showHours:
+                                       if self.showNoSeconds:
+                                               return sign + "%d:%02d" % (l/3600, l%3600/60)
+                                       else:
+                                               return sign + "%d:%02d:%02d" % (l/3600, l%3600/60, l%60)
+                               else:
+                                       if self.showNoSeconds:
+                                               return sign + "%d" % (l/60)
+                                       else:
+                                               return sign + "%d:%02d" % (l/60, l%60)
+                       else:
+                               if self.showHours:
+                                       return sign + "%d:%02d:%02d:%03d" % ((l/3600/90000), (l/90000)%3600/60, (l/90000)%60, (l%90000)/90)
+                               else:
+                                       return sign + "%d:%02d:%03d" % ((l/60/90000), (l/90000)%60, (l%90000)/90)
+
+       # range/value are for the Progress renderer
+       range = 10000
+
+       @cached
+       def getValue(self):
+               pos = self.position
+               len = self.length
+               if pos is None or len is None or len <= 0:
+                       return None
+               return pos * 10000 / len
 
        position = property(getPosition)
        length = property(getLength)
        cutlist = property(getCutlist)
        text = property(getText)
+       value = property(getValue)
 
        def changed(self, what):
                cutlist_refresh = what[0] != self.CHANGED_SPECIFIC or what[1] in [iPlayableService.evCuesheetChanged]