fix off-by-one error on the progress and fix vars in ToolExistsPrecondition
[enigma2.git] / lib / python / Components / ServicePosition.py
index cb4449210d0a04d942aaf00286a408908d5bd30a..985f884162e466e3fe06d00bef2192c938b35345 100644 (file)
@@ -1,16 +1,18 @@
 from PerServiceDisplay import PerServiceDisplay, PerServiceBase
-from enigma import eTimer, iPlayableService, iSeekableServicePtr, ePositionGauge
+from Components.GUIComponent import GUIComponent
+from enigma import eTimer, iPlayableService, ePositionGauge
 import time
 
-class ServicePosition(PerServiceDisplay):
+class ServicePosition(PerServiceDisplay, object):
        TYPE_LENGTH = 0,
        TYPE_POSITION = 1,
        TYPE_REMAINING = 2,
        TYPE_RELATIVE = 3
        
        def __init__(self, navcore, type):
+               object.__init__(self)
                self.updateTimer = eTimer()
-               self.updateTimer.timeout.get().append(self.update)
+               self.updateTimer.callback.append(self.update)
                PerServiceDisplay.__init__(self, navcore,
                        {
                                iPlayableService.evStart: self.newService,
@@ -65,8 +67,11 @@ class ServicePosition(PerServiceDisplay):
                                l = self.get(self.TYPE_POSITION)
                                if l != -1:
                                        l += self.relative_base
-                                       t = time.localtime(l)
-                                       timestr = "%2d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
+                                       try:
+                                               t = time.localtime(l)
+                                               timestr = "%2d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
+                                       except ValueError:
+                                               timestr = ""
                                else:
                                        timestr = ""
 
@@ -81,8 +86,9 @@ class ServicePosition(PerServiceDisplay):
                self.updateTimer.stop()
                self.setText("");
 
-class ServicePositionGauge(PerServiceBase):
+class ServicePositionGauge(PerServiceBase, GUIComponent):
        def __init__(self, navcore):
+               GUIComponent.__init__(self)
                PerServiceBase.__init__(self, navcore,
                        {
                                iPlayableService.evStart: self.newService,
@@ -90,6 +96,7 @@ class ServicePositionGauge(PerServiceBase):
                                iPlayableService.evCuesheetChanged: self.newCuesheet
                        })
                self.instance = None
+               self.__seek_position = 0
 
        def newService(self):
                if self.get() is None:  
@@ -102,7 +109,7 @@ class ServicePositionGauge(PerServiceBase):
                service = self.navcore.getCurrentService()
                seek = service and service.seek()
                if seek is None:
-                       return None
+                       return (0, 0)
 
                len = seek.getLength()
                pos = seek.getPlayPosition()
@@ -127,6 +134,7 @@ class ServicePositionGauge(PerServiceBase):
        
        def postWidgetCreate(self, instance):
                self.newService()
+               self.setSeekPosition(self.__seek_position)
        
        def newCuesheet(self):
                service = self.navcore.getCurrentService()
@@ -134,3 +142,25 @@ class ServicePositionGauge(PerServiceBase):
                cutlist = (cue and cue.getCutList()) or [ ]
                if self.instance is not None:
                        self.instance.setInOutList(cutlist)
+
+       def getSeekEnable(self):
+               return self.__seek_enable
+       
+       def setSeekEnable(self, val):
+               self.__seek_enable = val
+               if self.instance is not None:
+                       self.instance.enableSeekPointer(val)
+
+       seek_pointer_enabled = property(getSeekEnable, setSeekEnable)
+
+       def getSeekPosition(self):
+               return self.__seek_position
+       
+       def setSeekPosition(self, pos):
+               print "set seek position:", pos
+               self.__seek_position = pos
+               if self.instance is not None:
+                       print "set instance."
+                       self.instance.setSeekPosition(pos)
+       
+       seek_pointer_position = property(getSeekPosition, setSeekPosition)