1 from GUIComponent import GUIComponent
3 from enigma import eLabel, eSlider, iFrontendInformation
7 class TunerInfo(GUIComponent):
22 def __init__(self, type, servicefkt = None, frontendfkt = None, statusDict = None):
23 GUIComponent.__init__(self)
27 self.servicefkt = servicefkt
28 self.frontendfkt = frontendfkt
29 self.statusDict = statusDict
33 def setText(self, text):
36 self.instance.setText(self.message)
38 def setValue(self, value):
41 self.instance.setValue(self.value)
47 return (long)(log(val)/log(2))
51 if self.type == self.SNR_DB:
52 value = self.getValue(self.SNR_DB)
53 elif self.type == self.SNR_PERCENTAGE or self.type == self.SNR_BAR:
54 value = self.getValue(self.SNR) * 100 / 65536
55 elif self.type == self.AGC_PERCENTAGE or self.type == self.AGC_BAR:
56 value = self.getValue(self.AGC) * 100 / 65536
57 elif self.type == self.BER_VALUE or self.type == self.BER_BAR:
58 value = self.getValue(self.BER)
59 elif self.type == self.LOCK_STATE:
60 value = self.getValue(self.LOCK)
62 if self.type == self.SNR_DB:
63 if value != 0x12345678:
64 self.setText("%3.02f dB" % (value / 100.0))
67 elif self.type == self.SNR_PERCENTAGE or self.type == self.AGC_PERCENTAGE:
68 self.setText("%d%%" % (value))
69 elif self.type == self.BER_VALUE:
70 self.setText("%d" % (value))
71 elif self.type == self.SNR_BAR or self.type == self.AGC_BAR:
73 elif self.type == self.BER_BAR:
74 self.setValue(self.calc(value))
75 elif self.type == self.LOCK_STATE:
77 self.setText(_("locked"))
79 self.setText(_("not locked"))
81 def getValue(self, what):
83 if what == self.SNR_DB:
84 return self.statusDict.get("tuner_signal_quality_db", 0x12345678)
85 elif what == self.SNR:
86 return self.statusDict.get("tuner_signal_quality", 0)
87 elif what == self.AGC:
88 return self.statusDict.get("tuner_signal_power", 0)
89 elif what == self.BER:
90 return self.statusDict.get("tuner_bit_error_rate", 0)
91 elif what == self.LOCK:
92 return self.statusDict.get("tuner_locked", 0)
94 service = self.servicefkt()
95 if service is not None:
96 feinfo = service.frontendInfo()
97 if feinfo is not None:
98 if what == self.SNR_DB:
99 return feinfo.getFrontendInfo(iFrontendInformation.signalQualitydB)
100 elif what == self.SNR:
101 return feinfo.getFrontendInfo(iFrontendInformation.signalQuality)
102 elif what == self.AGC:
103 return feinfo.getFrontendInfo(iFrontendInformation.signalPower)
104 elif what == self.BER:
105 return feinfo.getFrontendInfo(iFrontendInformation.bitErrorRate)
106 elif what == self.LOCK:
107 return feinfo.getFrontendInfo(iFrontendInformation.lockState)
108 elif self.frontendfkt:
109 frontend = self.frontendfkt()
111 if what == self.SNR_DB:
112 return frontend.readFrontendData(iFrontendInformation.signalQualitydB)
113 elif what == self.SNR:
114 return frontend.readFrontendData(iFrontendInformation.signalQuality)
115 elif what == self.AGC:
116 return frontend.readFrontendData(iFrontendInformation.signalPower)
117 elif what == self.BER:
118 return frontend.readFrontendData(iFrontendInformation.bitErrorRate)
119 elif what == self.LOCK:
120 return frontend.readFrontendData(iFrontendInformation.lockState)
123 def createWidget(self, parent):
124 if self.SNR_PERCENTAGE <= self.type <= self.BER_VALUE or self.type == self.LOCK_STATE:
125 return eLabel(parent)
126 elif self.SNR_BAR <= self.type <= self.BER_BAR:
127 self.g = eSlider(parent)
128 self.g.setRange(0, 100)
131 def postWidgetCreate(self, instance):
132 if self.message is not None:
133 instance.setText(self.message)
134 elif self.value is not None:
135 instance.setValue(self.value)