/
PiconUni.py
123 lines (114 loc) · 3.92 KB
/
PiconUni.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# PiconUni
# Copyright (c) 2boom 2012-16
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# 26.09.2012 added search mountpoints
# 25.06.2013 added resize picon
# 26.11.2013 code optimization
# 02.12.2013 added compatibility with CaidInfo2 (SatName)
# 18.12.2013 added picon miltipath
# 27.12.2013 added picon reference
# 27.01.2014 added noscale parameter (noscale="0" is default, scale picon is on)
# 28.01.2014 code otimization
# 02.04.2014 added iptv ref code
# 17.04.2014 added path in plugin dir...
# 02.07.2014 small fix reference
# 09.01.2015 redesign code
# 02.05.2015 add path uuid device
# 08.05.2016 add 5001, 5002 stream id
# 16.11.2018 fix search Paths (by Sirius, thx Taapat)
from Components.Renderer.Renderer import Renderer
from enigma import ePixmap
from Tools.Directories import resolveFilename ,SCOPE_SKIN_IMAGE, SCOPE_CURRENT_SKIN, SCOPE_PLUGINS
import os
searchPaths = []
def initPiconPaths():
global searchPaths
if os.path.exists('/proc/mounts'):
for line in open('/proc/mounts'):
if '/dev/sd' in line or '/dev/disk/by-uuid/' in line or '/dev/mmc' in line:
piconPath = line.split()[1].replace('\\040', ' ') + '/%s/'
searchPaths.append(piconPath)
searchPaths.append('/usr/share/enigma2/%s/')
searchPaths.append('/usr/lib/enigma2/python/Plugins/%s/')
class PiconUni(Renderer):
__module__ = __name__
def __init__(self):
Renderer.__init__(self)
self.path = 'piconUni'
self.scale = '0'
self.nameCache = {}
self.pngname = ''
def applySkin(self, desktop, parent):
attribs = []
for (attrib, value,) in self.skinAttributes:
if attrib == 'path':
self.path = value
elif attrib == 'noscale':
self.scale = value
else:
attribs.append((attrib, value))
self.skinAttributes = attribs
return Renderer.applySkin(self, desktop, parent)
GUI_WIDGET = ePixmap
def changed(self, what):
if self.instance:
pngname = ''
if not what[0] is self.CHANGED_CLEAR:
sname = self.source.text
sname = sname.upper().replace('.', '').replace('\xc2\xb0', '')
print sname
if not sname.startswith('1'):
sname = sname.replace('4097', '1', 1).replace('5001', '1', 1).replace('5002', '1', 1)
if ':' in sname:
sname = '_'.join(sname.split(':')[:10])
pngname = self.nameCache.get(sname, '')
if pngname is '':
pngname = self.findPicon(sname)
if not pngname is '':
self.nameCache[sname] = pngname
if pngname is '':
pngname = self.nameCache.get('default', '')
if pngname is '':
pngname = self.findPicon('picon_default')
if pngname is '':
tmp = resolveFilename(SCOPE_CURRENT_SKIN, 'picon_default.png')
if os.path.exists(tmp):
pngname = tmp
else:
pngname = resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/picon_default.png')
self.nameCache['default'] = pngname
if not self.pngname is pngname:
if self.scale is '0':
if pngname:
self.instance.setScale(1)
self.instance.setPixmapFromFile(pngname)
self.instance.show()
else:
self.instance.hide()
else:
if pngname:
self.instance.setPixmapFromFile(pngname)
self.pngname = pngname
def findPicon(self, serviceName):
global searchPaths
pathtmp = self.path.split(',')
for path in searchPaths:
for dirName in pathtmp:
pngname = (path % dirName) + serviceName + '.png'
if os.path.exists(pngname):
return pngname
return ''
initPiconPaths()