add 'progress' source, 'progress to text' converter
authorFelix Domke <tmbinc@elitedvb.net>
Mon, 14 Apr 2008 23:27:01 +0000 (23:27 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Mon, 14 Apr 2008 23:27:01 +0000 (23:27 +0000)
lib/python/Components/Converter/Makefile.am
lib/python/Components/Converter/ProgressToText.py [new file with mode: 0644]
lib/python/Components/Sources/Makefile.am
lib/python/Components/Sources/Progress.py [new file with mode: 0644]

index 0fff9c8d5eb36c9ee2f3bf126084475bbb0a9315..331a6dc0f10cdd425baaf6aeec4ab8d7b17f4675 100644 (file)
@@ -5,5 +5,4 @@ install_PYTHON = \
        Poll.py RemainingToText.py StringList.py ServiceName.py FrontendInfo.py ServiceInfo.py \
        ConditionalShowHide.py ServicePosition.py ValueRange.py RdsInfo.py Streaming.py \
        StaticMultiList.py ServiceTime.py MovieInfo.py MenuEntryCompare.py StringListSelection.py \
        Poll.py RemainingToText.py StringList.py ServiceName.py FrontendInfo.py ServiceInfo.py \
        ConditionalShowHide.py ServicePosition.py ValueRange.py RdsInfo.py Streaming.py \
        StaticMultiList.py ServiceTime.py MovieInfo.py MenuEntryCompare.py StringListSelection.py \
-       ValueBitTest.py TunerInfo.py ConfigEntryTest.py TemplatedMultiContent.py
-
+       ValueBitTest.py TunerInfo.py ConfigEntryTest.py TemplatedMultiContent.py ProgressToText.py
\ No newline at end of file
diff --git a/lib/python/Components/Converter/ProgressToText.py b/lib/python/Components/Converter/ProgressToText.py
new file mode 100644 (file)
index 0000000..0ad3a88
--- /dev/null
@@ -0,0 +1,22 @@
+from Components.Converter.Converter import Converter
+from Components.Element import cached
+
+class ProgressToText(Converter, object):
+       def __init__(self, type):
+               Converter.__init__(self, type)
+               self.in_percent = "InPercent" in type.split(',')
+
+       @cached
+       def getText(self):
+               r = self.source.range
+               v = self.source.value
+
+               if self.in_percent:
+                       if r:
+                               return "%d %%" % (v * 100 / r)
+                       else:
+                               return None
+               else:
+                       return "%d / %d" % (v, r)
+
+       text = property(getText)
index 5ac636c8eb6bc195798cc3d4c6c49d727438b851..d04013ff5aedd37b21c840945456523d05632b59 100644 (file)
@@ -4,4 +4,4 @@ install_PYTHON = \
        __init__.py Clock.py EventInfo.py Source.py List.py CurrentService.py \
        FrontendStatus.py Boolean.py Config.py ServiceList.py RdsDecoder.py StreamService.py \
        StaticText.py CanvasSource.py ServiceEvent.py Event.py FrontendInfo.py TunerInfo.py \
        __init__.py Clock.py EventInfo.py Source.py List.py CurrentService.py \
        FrontendStatus.py Boolean.py Config.py ServiceList.py RdsDecoder.py StreamService.py \
        StaticText.py CanvasSource.py ServiceEvent.py Event.py FrontendInfo.py TunerInfo.py \
-       RecordState.py
+       RecordState.py Progress.py
diff --git a/lib/python/Components/Sources/Progress.py b/lib/python/Components/Sources/Progress.py
new file mode 100644 (file)
index 0000000..b96065b
--- /dev/null
@@ -0,0 +1,16 @@
+from Source import Source
+
+class Progress(Source):
+       def __init__(self, value = 0, range = 100):
+               Source.__init__(self)
+               self.__value = value
+               self.range = range
+
+       def getValue(self):
+               return self.__value
+
+       def setValue(self, value):
+               self.__value = value
+               self.changed((self.CHANGED_ALL,))
+
+       value = property(getValue, setValue)