Components/Converter: add ValueToPixmap converter to convert a given path or language...
authorMladen Horvat <acid-burn@opendreambox.org>
Mon, 18 Apr 2011 17:39:59 +0000 (19:39 +0200)
committerMladen Horvat <acid-burn@opendreambox.org>
Mon, 18 Apr 2011 17:39:59 +0000 (19:39 +0200)
lib/python/Components/Converter/Makefile.am
lib/python/Components/Converter/ValueToPixmap.py [new file with mode: 0644]

index 3b6fd3e..b73f6d5 100644 (file)
@@ -6,4 +6,4 @@ install_PYTHON = \
        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 ProgressToText.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 ProgressToText.py \
-       Combine.py SensorToText.py
+       Combine.py SensorToText.py ValueToPixmap.py
diff --git a/lib/python/Components/Converter/ValueToPixmap.py b/lib/python/Components/Converter/ValueToPixmap.py
new file mode 100644 (file)
index 0000000..2ab695a
--- /dev/null
@@ -0,0 +1,40 @@
+from Components.Converter.Converter import Converter
+from Components.Element import cached, ElementError
+from Tools.Directories import fileExists, SCOPE_SKIN_IMAGE, SCOPE_CURRENT_SKIN, resolveFilename
+from Tools.LoadPixmap import LoadPixmap
+
+
+class ValueToPixmap(Converter, object):
+       LANGUAGE_CODE = 0
+       PATH = 1
+       
+       def __init__(self, type):
+               Converter.__init__(self, type)
+               if type == "LanguageCode":
+                       self.type = self.LANGUAGE_CODE
+               elif type == "Path":
+                       self.type = self.PATH
+               else:
+                       raise ElementError("'%s' is not <LanguageCode|Path> for ValueToPixmap converter" % type)
+
+       @cached
+       def getPixmap(self):
+               if self.source:
+                       val = self.source.text
+                       if val in (None, ""):
+                               return None
+               if self.type == self.PATH:
+                       return LoadPixmap(val)
+               if self.type == self.LANGUAGE_CODE:
+                       png = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "countries/" + val[3:].lower() + ".png"))
+                       if png == None:
+                               png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "countries/missing.png"))
+                       return png
+               return None                     
+       
+       pixmap = property(getPixmap)
+
+       def changed(self, what):
+               if what[0] != self.CHANGED_SPECIFIC or what[1] == self.type:
+                       Converter.changed(self, what)
+