search default picon png first in currently used skin directory before
[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 fileExists, SCOPE_SKIN_IMAGE, SCOPE_CURRENT_SKIN, resolveFilename
7
8 class Picon(Renderer):
9         searchPaths = ['/usr/share/enigma2/%s/',
10                                 '/media/cf/%s/',
11                                 '/media/usb/%s/']
12
13         def __init__(self):
14                 Renderer.__init__(self)
15                 self.path = "picon"
16                 self.nameCache = { }
17                 self.pngname = ""
18
19         def applySkin(self, desktop):
20                 attribs = [ ]
21                 for (attrib, value) in self.skinAttributes:
22                         if attrib == "path":
23                                 self.path = value
24                         else:
25                                 attribs.append((attrib,value))
26                 self.skinAttributes = attribs
27                 return Renderer.applySkin(self, desktop)
28
29         GUI_WIDGET = ePixmap
30
31         def changed(self, what):
32                 if self.instance:
33                         pngname = ""
34                         if what[0] != self.CHANGED_CLEAR:
35                                 sname = self.source.text
36                                 # strip all after last :
37                                 pos = sname.rfind(':')
38                                 if pos != -1:
39                                         sname = sname[:pos].rstrip(':').replace(':','_')
40                                 pngname = self.nameCache.get(sname, "")
41                                 if pngname == "":
42                                         pngname = self.findPicon(sname)
43                                         if pngname != "":
44                                                 self.nameCache[sname] = pngname
45                         if pngname == "": # no picon for service found
46                                 pngname = self.nameCache.get("default", "")
47                                 if pngname == "": # no default yet in cache..
48                                         pngname = self.findPicon("picon_default")
49                                         if pngname == "":
50                                                 tmp = resolveFilename(SCOPE_CURRENT_SKIN, "picon_default.png")
51                                                 if fileExists(tmp):
52                                                         pngname = tmp
53                                                 else:
54                                                         pngname = resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/picon_default.png")
55                                         self.nameCache["default"] = pngname
56                         if self.pngname != pngname:
57                                 self.instance.setPixmapFromFile(pngname)
58                                 self.pngname = pngname
59
60         def findPicon(self, serviceName):
61                 for path in self.searchPaths:
62                         pngname = (path % self.path) + serviceName + ".png"
63                         if fileExists(pngname):
64                                 return pngname
65                 return ""