add service position converter
authorFelix Domke <tmbinc@elitedvb.net>
Mon, 10 Jul 2006 16:20:36 +0000 (16:20 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Mon, 10 Jul 2006 16:20:36 +0000 (16:20 +0000)
lib/python/Components/Converter/Makefile.am
lib/python/Components/Converter/ServicePosition.py [new file with mode: 0644]

index a84628a..a04b963 100644 (file)
@@ -3,4 +3,5 @@ installdir = $(LIBDIR)/enigma2/python/Components/Converter
 install_PYTHON = \
        __init__.py ClockToText.py Converter.py EventName.py StaticText.py EventTime.py \
        Poll.py RemainingToText.py StringList.py ServiceName.py FrontendInfo.py ServiceInfo.py \
-       ConditionalShowHide.py
+       ConditionalShowHide.py ServicePosition.py
+
diff --git a/lib/python/Components/Converter/ServicePosition.py b/lib/python/Components/Converter/ServicePosition.py
new file mode 100644 (file)
index 0000000..92c7b59
--- /dev/null
@@ -0,0 +1,80 @@
+from Converter import Converter
+from Poll import Poll
+from enigma import iPlayableService
+
+class ServicePosition(Converter, Poll, object):
+       TYPE_LENGTH = 0,
+       TYPE_POSITION = 1,
+       TYPE_REMAINING = 2,
+       TYPE_GAUGE = 3
+       
+       def __init__(self, type, *args, **kwargs):
+               Poll.__init__(self)
+               Converter.__init__(self)
+               if type == "Length":
+                       self.type = self.TYPE_LENGTH
+               elif type == "Position":
+                       self.type = self.TYPE_POSITION
+               elif type == "Remaining":
+                       self.type = self.TYPE_REMAINING
+               elif type == "Gauge":
+                       self.type = self.TYPE_GAUGE
+
+               self.poll_interval = 500
+               self.poll_enabled = self.type != self.TYPE_LENGTH
+       
+       def getSeek(self):
+               s = self.source.service
+               return s and s.seek()
+       
+       def getPosition(self):
+               seek = self.getSeek()
+               if seek is None:
+                       return None
+               pos = seek.getPlayPosition()
+               if pos[0]:
+                       return 0
+               return pos[1] / 90000
+       
+       def getLength(self):
+               seek = self.getSeek()
+               if seek is None:
+                       return None
+               length = seek.getLength()
+               if length[0]:
+                       return 0
+               return length[1] / 90000
+       
+       def getCutlist(self):
+               service = self.source.service
+               cue = service and service.cueSheet()
+               return cue and cue.getCutList()
+       
+       def getText(self):
+               seek = self.getSeek()
+               if seek is None:
+                       return ""
+               else:
+                       if self.type == self.TYPE_LENGTH:
+                               l = self.length
+                       elif self.type == self.TYPE_POSITION:
+                               l = self.position
+                       elif self.type == self.TYPE_REMAINING:
+                               l = self.length - self.position
+                       return "%d:%02d" % (l/60, l%60)
+
+       position = property(getPosition)
+       length = property(getLength)
+       cutlist = property(getCutlist)
+       text = property(getText)
+       
+       def changed(self, *args):
+               cutlist_refresh = len(args) and args[0] in [iPlayableService.evCuesheetChanged, iPlayableService.evStart, iPlayableService.evEnd]
+               time_refresh = not len(args) or args[0] in [iPlayableService.evStart, iPlayableService.evEnd]
+               
+               if cutlist_refresh:
+                       if self.type == self.TYPE_GAUGE:
+                               self.downstream_elements.cutlist_changed()
+
+               if time_refresh:
+                       self.downstream_elements.changed()