use servicereferences instead of servicename as picon filenames
[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(self.source.text)
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                                         self.nameCache[sname] = pngname
40                                         if pngname == "": # Fallback to enigma2 logo
41                                                 pngname = resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/enigma2.png")
42                                         self.nameCache["default"] = pngname
43                         if self.pngname != pngname:
44                                 self.instance.setPixmapFromFile(pngname)
45                                 self.pngname = pngname
46
47         def findPicon(self, serviceName):
48                 for path in self.searchPaths:
49                         pngname = path + serviceName + ".png"
50                         if fileExists(pngname):
51                                 return pngname
52                 return ""