enigma2 20131001 (master) -> 20131112 (master)
[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 re import compile
8
9 class Picon(Renderer):
10         searchPaths = (eEnv.resolve('${datadir}/enigma2/%s/'),
11                                 '/media/cf/%s/',
12                                 '/media/usb/%s/')
13
14         def __init__(self):
15                 Renderer.__init__(self)
16                 self.path = "picon"
17                 self.nameCache = { }
18                 self.pngname = ""
19                 self.partnerbox = compile('1:0:[0-9a-fA-F]+:[1-9a-fA-F]+[0-9a-fA-F]*:[1-9a-fA-F]+[0-9a-fA-F]*:[1-9a-fA-F]+[0-9a-fA-F]*:[1-9a-fA-F]+[0-9a-fA-F]*:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:http')
20
21         def applySkin(self, desktop, parent):
22                 attribs = [ ]
23                 for (attrib, value) in self.skinAttributes:
24                         if attrib == "path":
25                                 self.path = value
26                         else:
27                                 attribs.append((attrib,value))
28                 self.skinAttributes = attribs
29                 return Renderer.applySkin(self, desktop, parent)
30
31         GUI_WIDGET = ePixmap
32
33         def changed(self, what):
34                 if self.instance:
35                         pngname = ""
36                         if what[0] != self.CHANGED_CLEAR:
37                                 sname = self.source.text
38                                 pos = sname.rfind(':')
39                                 pos2 = sname.rfind(':', 0, pos)
40                                 if pos - pos2 == 1 or self.partnerbox.match(sname) is not None:
41                                         sname = sname[:pos2].replace(':', '_')
42                                 else:
43                                         sname = sname[:pos].replace(':', '_')
44                                 pngname = self.nameCache.get(sname, "")
45                                 if pngname == "":
46                                         pngname = self.findPicon(sname)
47                                         if pngname != "":
48                                                 self.nameCache[sname] = pngname
49                         if pngname == "": # no picon for service found
50                                 pngname = self.nameCache.get("default", "")
51                                 if pngname == "": # no default yet in cache..
52                                         pngname = self.findPicon("picon_default")
53                                         if pngname == "":
54                                                 tmp = resolveFilename(SCOPE_CURRENT_SKIN, "picon_default.png")
55                                                 if fileExists(tmp):
56                                                         pngname = tmp
57                                                 else:
58                                                         pngname = resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/picon_default.png")
59                                         self.nameCache["default"] = pngname
60                         if self.pngname != pngname:
61                                 self.instance.setPixmapFromFile(pngname)
62                                 self.pngname = pngname
63
64         def findPicon(self, serviceName):
65                 for path in self.searchPaths:
66                         pngname = (path % self.path) + serviceName + ".png"
67                         if fileExists(pngname):
68                                 return pngname
69                 return ""