add support for channellogos (picons)
[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 from time import time
9
10 class Picon(Renderer):
11         visible = True
12         pngname = ""
13         nameCache = { }
14         searchPaths = ['/etc/picon/',
15                                 '/media/cf/picon/',
16                                 '/media/usb/picon/',
17                                 '/media/hdd/picon/']
18
19         def __init__(self):
20                 Renderer.__init__(self)
21
22         GUI_WIDGET = ePixmap
23
24         def changed(self, what):
25                 if self.instance:
26                         pngname = ""
27                         if what[0] != self.CHANGED_CLEAR:
28                                 sname = self.source.text
29                                 pngname = self.nameCache.get(sname, "")
30                                 if pngname == "":
31                                         pngname = self.findPicon(self.source.text)
32                                         if pngname == "":
33                                                 self.nameCache[sname] = pngname
34                                         else:
35                                                 self.nameCache[sname] = pngname
36                         if pngname == "": # no picon for service found
37                                 pngname = self.nameCache.get("default", "")
38                                 if pngname == "": # no default yet in cache..
39                                         pngname = self.findPicon("picon_default")
40                                         self.nameCache[sname] = pngname
41                                         if pngname == "": # Fallback to enigma2 logo
42                                                 pngname = resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/enigma2.png")
43                                         self.nameCache["default"] = pngname
44                         if pngname != "":
45                                 if self.pngname != pngname:
46                                         self.instance.setPixmapFromFile(pngname)
47                                         if not self.visible:
48                                                 self.instance.show()
49                                                 self.visible=True
50                         elif self.visible:
51                                 self.instance.hide()
52                                 self.visible = False
53                         self.pngname = pngname
54
55         def findPicon(self, serviceName):
56                 for path in self.searchPaths:
57                         if pathExists(path):
58                                 png = self.findFile(path, serviceName)
59                                 if png != "":
60                                         return png
61                 return ""
62
63         def findFile(self, path, serviceName):
64                 pngname = path + serviceName + ".png"
65                 if fileExists(pngname):
66                         return pngname
67                 else:
68                         for i in range(len(serviceName), 1, -1):
69                                 if fileExists(path + serviceName[0:i] + ".png"):
70                                         return path + serviceName[0:i] + ".png"
71                         return ""