4.3.0r12
[enigma2.git] / usr / lib / enigma2 / 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, eEnv
6 from Tools.Directories import fileExists, SCOPE_SKIN_IMAGE, SCOPE_CURRENT_SKIN, resolveFilename
7 from Tools.PiconResolver import PiconResolver
8
9 class Picon(Renderer):
10         searchPaths = (eEnv.resolve('${datadir}/enigma2/%s/'),)
11
12         def __init__(self):
13                 Renderer.__init__(self)
14                 self.path = "picon"
15                 self.nameCache = { }
16                 self.pngname = ""
17
18         def applySkin(self, desktop, parent):
19                 attribs = [ ]
20                 for (attrib, value) in self.skinAttributes:
21                         if attrib == "path":
22                                 self.path = value
23                         else:
24                                 attribs.append((attrib,value))
25                 self.skinAttributes = attribs
26                 return Renderer.applySkin(self, desktop, parent)
27
28         GUI_WIDGET = ePixmap
29
30         def postWidgetCreate(self, instance):
31                 instance.setScale(1)
32                 instance.setDefaultAnimationEnabled(self.source.isAnimated)
33
34         def changed(self, what):
35                 if self.instance:
36                         if what[0] == self.CHANGED_ANIMATED:
37                                 self.instance.setDefaultAnimationEnabled(self.source.isAnimated)
38                                 return
39                         pngname = ""
40                         sname = self.source.text
41                         if what[0] != self.CHANGED_CLEAR:
42                                 pngname = PiconResolver.getPngName(sname, self.nameCache, self.findPicon)
43                         if pngname == "": # no picon for service found, resolve skin default picon
44                                 tmp = resolveFilename(SCOPE_CURRENT_SKIN, "picon_default.png")
45                                 if fileExists(tmp):
46                                         pngname = tmp
47                                 else:
48                                         pngname = resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/picon_default.png")
49                                 self.nameCache["default"] = pngname
50
51                         if self.pngname != pngname:
52                                 self.instance.setPixmapFromFile(pngname)
53                                 self.pngname = pngname
54
55         def findPicon(self, serviceName):
56                 for path in self.searchPaths:
57                         pngname = (path % self.path) + serviceName + ".png"
58                         if fileExists(pngname):
59                                 return pngname
60                 return ""