dont show display contrast setting in display setup when a oled is detected
[enigma2.git] / lib / python / Components / ServicePosition.py
index 349ee392a5b27c9cb596a4cf9c25d0097d0e09e9..6f7082d545c661958fa98b1c318523b8270c9055 100644 (file)
@@ -1,14 +1,16 @@
-from PerServiceDisplay import *
-from enigma import eTimer
+from PerServiceDisplay import PerServiceDisplay, PerServiceBase
+from Components.GUIComponent import GUIComponent
+from enigma import eTimer, iPlayableService, ePositionGauge
+import time
 
-from enigma import iPlayableService, iSeekableServicePtr, ePositionGauge
-
-class ServicePosition(PerServiceDisplay):
+class ServicePosition(PerServiceDisplay, object):
        TYPE_LENGTH = 0,
        TYPE_POSITION = 1,
-       TYPE_REMAINING = 2
+       TYPE_REMAINING = 2,
+       TYPE_RELATIVE = 3
        
        def __init__(self, navcore, type):
+               object.__init__(self)
                self.updateTimer = eTimer()
                self.updateTimer.timeout.get().append(self.update)
                PerServiceDisplay.__init__(self, navcore,
@@ -17,6 +19,7 @@ class ServicePosition(PerServiceDisplay):
                                iPlayableService.evEnd: self.stopEvent
                        })
                self.type = type
+               self.relative_base = 0
 #              self.setType(type)
 
        def newService(self):
@@ -28,6 +31,9 @@ class ServicePosition(PerServiceDisplay):
                self.updateTimer.start(500)
                self.update()
        
+       def setRelative(self, rel):
+               self.relative_base = rel
+       
        def get(self, what):
                service = self.navcore.getCurrentService()
                seek = service and service.seek()
@@ -48,14 +54,29 @@ class ServicePosition(PerServiceDisplay):
                        seek = service.seek()
 
                if seek is not None:
-                       if self.type == self.TYPE_LENGTH:
-                               l = self.get(self.TYPE_LENGTH)
-                       elif self.type == self.TYPE_POSITION:
-                               l = self.get(self.TYPE_POSITION)
-                       elif self.type == self.TYPE_REMAINING:
-                               l = self.get(self.TYPE_LENGTH) - self.get(self.TYPE_POSITION)
+                       if self.type != self.TYPE_RELATIVE:
+                               if self.type == self.TYPE_LENGTH:
+                                       l = self.get(self.TYPE_LENGTH)
+                               elif self.type == self.TYPE_POSITION:
+                                       l = self.get(self.TYPE_POSITION)
+                               elif self.type == self.TYPE_REMAINING:
+                                       l = self.get(self.TYPE_LENGTH) - self.get(self.TYPE_POSITION)
                        
-                       self.setText("%d:%02d" % (l/60, l%60))
+                               self.setText("%d:%02d" % (l/60, l%60))
+                       else:
+                               l = self.get(self.TYPE_POSITION)
+                               if l != -1:
+                                       l += self.relative_base
+                                       try:
+                                               t = time.localtime(l)
+                                               timestr = "%2d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
+                                       except ValueError:
+                                               timestr = ""
+                               else:
+                                       timestr = ""
+
+                               self.setText(timestr)
+                               
                        self.updateTimer.start(500)
                else:
                        self.updateTimer.start(10000)
@@ -65,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,
@@ -74,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:  
@@ -86,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()
@@ -107,16 +130,37 @@ class ServicePositionGauge(PerServiceBase):
        def stopEvent(self):
                self.disablePolling()
 
-       def GUIcreate(self, parent):
-               self.instance = ePositionGauge(parent)
+       GUI_WIDGET = ePositionGauge
+       
+       def postWidgetCreate(self, instance):
                self.newService()
+               self.setSeekPosition(self.__seek_position)
        
-       def GUIdelete(self):
-               self.instance = None
-
        def newCuesheet(self):
                service = self.navcore.getCurrentService()
                cue = service and service.cueSheet()
                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)