yet another small fix
[enigma2.git] / lib / python / Components / Renderer / Picon.py
1 ##
2 ## Picon renderer by Gruffy .. some speedups by Ghost
3 ##
4 from Renderer import Renderer
5 from enigma import ePixmap
6 from Tools.Directories import pathExists, fileExists, SCOPE_SKIN_IMAGE, resolveFilename
7
8 class Picon(Renderer):
9         pngname = ""
10         nameCache = { }
11         searchPaths = ['/etc/picon/',
12                                 '/media/cf/picon/',
13                                 '/media/usb/picon/',
14                                 '/media/hdd/picon/']
15
16         def __init__(self):
17                 Renderer.__init__(self)
18
19         GUI_WIDGET = ePixmap
20
21         def changed(self, what):
22                 if self.instance:
23                         pngname = ""
24                         if what[0] != self.CHANGED_CLEAR:
25                                 sname = self.source.text
26                                 # strip all after last :
27                                 pos = sname.rfind(':')
28                                 if pos != -1:
29                                         sname = sname[:pos].rstrip(':')
30                                 pngname = self.nameCache.get(sname, "")
31                                 if pngname == "":
32                                         pngname = self.findPicon(sname)
33                                         if pngname != "":
34                                                 self.nameCache[sname] = pngname
35                         if pngname == "": # no picon for service found
36                                 pngname = self.nameCache.get("default", "")
37                                 if pngname == "": # no default yet in cache..
38                                         pngname = self.findPicon("picon_default")
39                                         if pngname == "": # Fallback to enigma2 logo
40                                                 pngname = resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/enigma2.png")
41                                         self.nameCache["default"] = pngname
42                         if self.pngname != pngname:
43                                 self.instance.setPixmapFromFile(pngname)
44                                 self.pngname = pngname
45
46         def findPicon(self, serviceName):
47                 for path in self.searchPaths:
48                         pngname = path + serviceName + ".png"
49                         if fileExists(pngname):
50                                 return pngname
51                 return ""