1 from GUIComponent import GUIComponent
3 from enigma import eLabel, eSlider, iFrontendInformation
7 class TunerInfo(GUIComponent):
21 def __init__(self, type, servicefkt = None, frontendfkt = None, statusDict = None):
22 GUIComponent.__init__(self)
26 self.servicefkt = servicefkt
27 self.frontendfkt = frontendfkt
28 self.statusDict = statusDict
32 def setText(self, text):
35 self.instance.setText(self.message)
37 def setValue(self, value):
40 self.instance.setValue(self.value)
46 return (long)(log(val)/log(2))
50 if self.type == self.SNR_PERCENTAGE or self.type == self.SNR_BAR:
51 value = self.getValue(self.SNR) * 100 / 65536
52 elif self.type == self.AGC_PERCENTAGE or self.type == self.AGC_BAR:
53 value = self.getValue(self.AGC) * 100 / 65536
54 elif self.type == self.BER_VALUE or self.type == self.BER_BAR:
55 value = self.getValue(self.BER)
56 elif self.type == self.LOCK_STATE:
57 value = self.getValue(self.LOCK)
59 if self.type == self.SNR_PERCENTAGE or self.type == self.AGC_PERCENTAGE:
60 self.setText("%d%%" % (value))
61 elif self.type == self.BER_VALUE:
62 self.setText("%d" % (value))
63 elif self.type == self.SNR_BAR or self.type == self.AGC_BAR:
65 elif self.type == self.BER_BAR:
66 self.setValue(self.calc(value))
67 elif self.type == self.LOCK_STATE:
69 self.setText(_("locked"))
71 self.setText(_("not locked"))
73 def getValue(self, what):
76 return self.statusDict.get("tuner_signal_power", 0)
77 elif what == self.AGC:
78 return self.statusDict.get("tuner_signal_quality", 0)
79 elif what == self.BER:
80 return self.statusDict.get("tuner_bit_error_rate", 0)
81 elif what == self.LOCK:
82 return self.statusDict.get("tuner_locked", 0)
84 service = self.servicefkt()
85 if service is not None:
86 feinfo = service.frontendInfo()
87 if feinfo is not None:
89 return feinfo.getFrontendInfo(iFrontendInformation.signalPower)
90 elif what == self.AGC:
91 return feinfo.getFrontendInfo(iFrontendInformation.signalQuality)
92 elif what == self.BER:
93 return feinfo.getFrontendInfo(iFrontendInformation.bitErrorRate)
94 elif what == self.LOCK:
95 return feinfo.getFrontendInfo(iFrontendInformation.lockState)
96 elif self.frontendfkt:
97 frontend = self.frontendfkt()
100 return frontend.readFrontendData(iFrontendInformation.signalPower)
101 elif what == self.AGC:
102 return frontend.readFrontendData(iFrontendInformation.signalQuality)
103 elif what == self.BER:
104 return frontend.readFrontendData(iFrontendInformation.bitErrorRate)
105 elif what == self.LOCK:
106 return frontend.readFrontendData(iFrontendInformation.lockState)
109 def createWidget(self, parent):
110 if self.SNR_PERCENTAGE <= self.type <= self.BER_VALUE or self.type == self.LOCK_STATE:
111 return eLabel(parent)
112 elif self.SNR_BAR <= self.type <= self.BER_BAR:
113 self.g = eSlider(parent)
114 self.g.setRange(0, 100)
117 def postWidgetCreate(self, instance):
118 if self.message is not None:
119 instance.setText(self.message)
120 elif self.value is not None:
121 instance.setValue(self.value)