Форум сайта python.su
Здравствуйте
Уважаемые помогите пожалуйста подправить два файла CaidDisplay.py и RendCaids.py
/usr/lib/enigma2/python/Components/Converter/CaidDisplay.py
from Components.Converter.Converter import Converter
from enigma import iServiceInformation, iPlayableService
from Components.Element import cached
from Poll import Poll
class CaidDisplay(Poll, Converter, object):
def __init__(self, type):
Poll.__init__(self)
Converter.__init__(self, type)
self.type = type
self.systemCaids = {
"26" : "BiSS",
"01" : "SEC",
"06" : "IRD",
"17" : "BET",
"05" : "VIA",
"18" : "NAG",
"09" : "NDS",
"0B" : "CON",
"0D" : "CRW",
"4A" : "DRE" }
self.poll_interval = 2000
self.poll_enabled = True
@cached
def get_caidlist(self):
caidlist = {}
service = self.source.service
if service:
info = service and service.info()
if info:
caids = info.getInfoObject(iServiceInformation.sCAIDs)
if caids:
for cs in self.systemCaids:
caidlist[cs] = (self.systemCaids.get(cs),0)
for caid in caids:
c = "%x" % int(caid)
if len(c) == 3:
c = "0%s" % c
c = c[:2].upper()
if self.systemCaids.has_key(c):
caidlist[c] = (self.systemCaids.get(c),1)
ecm_info = self.ecmfile()
if ecm_info:
emu_caid = ecm_info.get("caid", "")
if emu_caid and emu_caid != "0x000":
c = emu_caid.lstrip("0x")
if len(c) == 3:
c = "0%s" % c
c = c[:2].upper()
caidlist[c] = (self.systemCaids.get(c),2)
return caidlist
getCaidlist = property(get_caidlist)
@cached
def getText(self):
textvalue = ""
service = self.source.service
if service:
info = service and service.info()
if info:
if info.getInfoObject(iServiceInformation.sCAIDs):
ecm_info = self.ecmfile()
if ecm_info:
# caid
caid = ecm_info.get("caid", "")
caid = caid.lstrip("0x")
caid = caid.upper()
caid = caid.zfill(4)
caid = "CAID: %s" % caid
# hops
hops = ecm_info.get("hops", None)
hops = "HOPS: %s" % hops
# ecm time
ecm_time = ecm_info.get("ecm time", None)
if ecm_time:
if "msec" in ecm_time:
ecm_time = "ECM: %s " % ecm_time
else:
ecm_time = "ECM: %s s" % ecm_time
# address
address = ecm_info.get("address", "")
# source
using = ecm_info.get("using", "")
if using:
if using == "emu":
textvalue = "(EMU) %s - %s" % (caid, ecm_time)
elif using == "CCcam-s2s":
textvalue = "(NET) %s - %s - %s - %s" % (caid, address, hops, ecm_time)
else:
textvalue = "%s - %s - %s - %s" % (caid, address, hops, ecm_time)
else:
# mgcamd
source = ecm_info.get("source", None)
if source:
if source == "emu":
textvalue = "(EMU) %s" % (caid)
else:
textvalue = "%s - %s - %s" % (caid, source, ecm_time)
# oscam
oscsource = ecm_info.get("from", None)
if oscsource:
textvalue = "%s - %s - %s - %s" % (caid, oscsource, hops, ecm_time)
# gbox
decode = ecm_info.get("decode", None)
if decode:
if decode == "Internal":
textvalue = "(EMU) %s" % (caid)
else:
textvalue = "%s - %s" % (caid, decode)
return textvalue
text = property(getText)
def ecmfile(self):
ecm = None
info = {}
service = self.source.service
if service:
frontendInfo = service.frontendInfo()
if frontendInfo:
try:
ecmpath = "/tmp/ecm%s.info" % frontendInfo.getAll(False).get("tuner_number")
ecm = open(ecmpath, "rb").readlines()
except:
try:
ecm = open("/tmp/ecm.info", "rb").readlines()
except: pass
if ecm:
for line in ecm:
x = line.lower().find("msec")
if x != -1:
info["ecm time"] = line[0:x+4]
else:
item = line.split(":", 1)
if len(item) > 1:
info[item[0].strip().lower()] = item[1].strip()
else:
if not info.has_key("caid"):
x = line.lower().find("caid")
if x != -1:
y = line.find(",")
if y != -1:
info["caid"] = line[x+5:y]
return info
def changed(self, what):
if (what[0] == self.CHANGED_SPECIFIC and what[1] == iPlayableService.evUpdatedInfo) or what[0] == self.CHANGED_POLL:
Converter.changed(self, what)
from Renderer import Renderer
from enigma import eCanvas, eRect, gFont
from skin import parseColor, parseFont
class RendCaids(Renderer):
GUI_WIDGET = eCanvas
def __init__(self):
Renderer.__init__(self)
self.backgroundColor = parseColor("#ff000000")
self.nocColor = parseColor("#00aaaaaa")
self.emmColor = parseColor("#00aaaaaa")
self.ecmColor = parseColor("#0056c856")
self.font = gFont("Regular", 20)
def pull_updates(self):
if self.instance is None:
return
self.instance.clear(self.backgroundColor)
caidlist = self.source.getCaidlist
if caidlist is None:
return
self.draw(caidlist)
def draw(self, caidlist):
offset = 0
pointSize = self.font.pointSize
for key in caidlist:
if caidlist[key][0]:
if caidlist[key][1] == 0:
foregroundColor = self.nocColor
elif caidlist[key][1] == 1:
foregroundColor = self.emmColor
else:
foregroundColor = self.ecmColor
length = len(caidlist[key][0]) * (pointSize)
self.instance.writeText(eRect(offset, 0, length, pointSize), foregroundColor, self.backgroundColor, self.font, caidlist[key][0], 2)
offset = offset + length
def changed(self, what):
self.pull_updates()
def applySkin(self, desktop, parent):
attribs = [ ]
from enigma import eSize
def parseSize(str):
x, y = str.split(',')
return eSize(int(x), int(y))
for (attrib, value) in self.skinAttributes:
if attrib == "size":
self.instance.setSize(parseSize(value))
attribs.append((attrib,value))
elif attrib == "nocColor":
self.nocColor = parseColor(value)
elif attrib == "emmColor":
self.emmColor = parseColor(value)
elif attrib == "ecmColor":
self.ecmColor = parseColor(value)
elif attrib == "font":
self.font = parseFont(value, ((1,1),(1,1)))
elif attrib == "backgroundColor":
self.backgroundColor = parseColor(value)
self.instance.clear(self.backgroundColor)
attribs.append((attrib,value))
else:
attribs.append((attrib,value))
self.skinAttributes = attribs
return Renderer.applySkin(self, desktop, parent)
<widget source="session.CurrentService" render="RendCaids" backgroundColor="transparent2" ecmColor="green" emmColor="yellow" font="Regular;14" nocColor="grey" position="630,589" size="437,16" transparent="1" zPosition="10" alphatest="blend">
<convert type="CaidDisplay">Default</convert>
</widget>
Отредактировано (Янв. 2, 2012 17:48:13)
Офлайн