refs bug #429
[enigma2.git] / lib / python / Components / Renderer / Picon.py
index 117e08d..5ae43ed 100644 (file)
@@ -3,21 +3,28 @@
 ##
 from Renderer import Renderer
 from enigma import ePixmap
-from Tools.Directories import pathExists, fileExists, SCOPE_SKIN_IMAGE, resolveFilename
-
-from time import time
+from Tools.Directories import fileExists, SCOPE_SKIN_IMAGE, SCOPE_CURRENT_SKIN, resolveFilename
 
 class Picon(Renderer):
-       visible = True
-       pngname = ""
-       nameCache = { }
-       searchPaths = ['/etc/picon/',
-                               '/media/cf/picon/',
-                               '/media/usb/picon/',
-                               '/media/hdd/picon/']
+       searchPaths = ('/usr/share/enigma2/%s/',
+                               '/media/cf/%s/',
+                               '/media/usb/%s/')
 
        def __init__(self):
                Renderer.__init__(self)
+               self.path = "picon"
+               self.nameCache = { }
+               self.pngname = ""
+
+       def applySkin(self, desktop, parent):
+               attribs = [ ]
+               for (attrib, value) in self.skinAttributes:
+                       if attrib == "path":
+                               self.path = value
+                       else:
+                               attribs.append((attrib,value))
+               self.skinAttributes = attribs
+               return Renderer.applySkin(self, desktop, parent)
 
        GUI_WIDGET = ePixmap
 
@@ -26,46 +33,33 @@ class Picon(Renderer):
                        pngname = ""
                        if what[0] != self.CHANGED_CLEAR:
                                sname = self.source.text
+                               # strip all after last :
+                               pos = sname.rfind(':')
+                               if pos != -1:
+                                       sname = sname[:pos].rstrip(':').replace(':','_')
                                pngname = self.nameCache.get(sname, "")
                                if pngname == "":
-                                       pngname = self.findPicon(self.source.text)
-                                       if pngname == "":
-                                               self.nameCache[sname] = pngname
-                                       else:
+                                       pngname = self.findPicon(sname)
+                                       if pngname != "":
                                                self.nameCache[sname] = pngname
                        if pngname == "": # no picon for service found
                                pngname = self.nameCache.get("default", "")
                                if pngname == "": # no default yet in cache..
                                        pngname = self.findPicon("picon_default")
-                                       self.nameCache[sname] = pngname
-                                       if pngname == "": # Fallback to enigma2 logo
-                                               pngname = resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/enigma2.png")
+                                       if pngname == "":
+                                               tmp = resolveFilename(SCOPE_CURRENT_SKIN, "picon_default.png")
+                                               if fileExists(tmp):
+                                                       pngname = tmp
+                                               else:
+                                                       pngname = resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/picon_default.png")
                                        self.nameCache["default"] = pngname
-                       if pngname != "":
-                               if self.pngname != pngname:
-                                       self.instance.setPixmapFromFile(pngname)
-                                       if not self.visible:
-                                               self.instance.show()
-                                               self.visible=True
-                       elif self.visible:
-                               self.instance.hide()
-                               self.visible = False
-                       self.pngname = pngname
+                       if self.pngname != pngname:
+                               self.instance.setPixmapFromFile(pngname)
+                               self.pngname = pngname
 
        def findPicon(self, serviceName):
                for path in self.searchPaths:
-                       if pathExists(path):
-                               png = self.findFile(path, serviceName)
-                               if png != "":
-                                       return png
+                       pngname = (path % self.path) + serviceName + ".png"
+                       if fileExists(pngname):
+                               return pngname
                return ""
-
-       def findFile(self, path, serviceName):
-               pngname = path + serviceName + ".png"
-               if fileExists(pngname):
-                       return pngname
-               else:
-                       for i in range(len(serviceName), 1, -1):
-                               if fileExists(path + serviceName[0:i] + ".png"):
-                                       return path + serviceName[0:i] + ".png"
-                       return ""