avoid future redundant code by moving functionality for tuner status display to a...
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Tue, 4 Apr 2006 09:24:39 +0000 (09:24 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Tue, 4 Apr 2006 09:24:39 +0000 (09:24 +0000)
lib/python/Components/Makefile.am
lib/python/Components/TunerInfo.py [new file with mode: 0644]
lib/python/Components/__init__.py
lib/python/Screens/InfoBarGenerics.py

index 94a8c06..8f43cae 100644 (file)
@@ -13,6 +13,6 @@ install_PYTHON = \
        BlinkingPixmap.py Pixmap.py ConditionalWidget.py Slider.py LanguageList.py \
        PluginList.py PluginComponent.py RecordingConfig.py About.py UsageConfig.py \
        FIFOList.py ServiceEventTracker.py Input.py TimerSanityCheck.py FileList.py \
        BlinkingPixmap.py Pixmap.py ConditionalWidget.py Slider.py LanguageList.py \
        PluginList.py PluginComponent.py RecordingConfig.py About.py UsageConfig.py \
        FIFOList.py ServiceEventTracker.py Input.py TimerSanityCheck.py FileList.py \
-       MultiContent.py MediaPlayer.py
+       MultiContent.py MediaPlayer.py TunerInfo.py
 
 
 
 
diff --git a/lib/python/Components/TunerInfo.py b/lib/python/Components/TunerInfo.py
new file mode 100644 (file)
index 0000000..e22ce46
--- /dev/null
@@ -0,0 +1,83 @@
+from GUIComponent import GUIComponent
+
+from enigma import eLabel, eSlider, iFrontendStatusInformation
+
+from math import log
+
+class TunerInfo(GUIComponent):
+       SNR_PERCENTAGE = 0
+       AGC_PERCENTAGE = 1
+       BER_VALUE = 2
+       SNR_BAR = 3
+       AGC_BAR = 4
+       BER_BAR = 5
+       def __init__(self, type, servicefkt):
+               GUIComponent.__init__(self)
+               self.instance = None
+               self.message = None
+               self.value = None
+               
+               self.servicefkt = servicefkt
+               self.type = type
+               self.update()
+       
+       def setText(self, text):
+               self.message = text
+               if self.instance:
+                       self.instance.setText(self.message)
+       
+       def setValue(self, value):
+               self.value = value
+               if self.instance:
+                       self.instance.setValue(self.value)              
+                       
+       def calc(self,val):
+               if not val:
+                       return 0
+               if val < 2500:
+                       return (long)(log(val)/log(2))
+               return val*100/65535
+       
+       def update(self):
+               service = self.servicefkt()
+               value = 0
+               if service is not None:
+                       feinfo = service.frontendStatusInfo()
+                       if feinfo is not None:
+                               if self.type == self.SNR_PERCENTAGE or self.type == self.SNR_BAR:
+                                       value = feinfo.getFrontendInfo(iFrontendStatusInformation.signalPower) * 100 / 65536
+                               elif self.type == self.AGC_PERCENTAGE or self.type == self.AGC_BAR:
+                                       value = feinfo.getFrontendInfo(iFrontendStatusInformation.signalQuality) * 100 / 65536
+                               elif self.type == self.BER_VALUE or self.type == self.BER_BAR:
+                                       value = feinfo.getFrontendInfo(iFrontendStatusInformation.bitErrorRate)
+               
+               if self.type == self.SNR_PERCENTAGE or self.type == self.AGC_PERCENTAGE:
+                       self.setText("%d%%" % (value))
+               elif self.type == self.BER_VALUE:
+                       self.setText("%d" % (value))
+               elif self.type == self.SNR_BAR or self.type == self.AGC_BAR:
+                       self.setValue(value)
+               elif self.type == self.BER_BAR:
+                       self.setValue(self.calc(value))
+
+       def createWidget(self, parent):
+               if self.SNR_PERCENTAGE <= self.type <= self.BER_VALUE:
+                       return eLabel(parent)
+               elif self.SNR_BAR <= self.type <= self.BER_BAR:
+                       self.g = eSlider(parent)
+                       self.g.setRange(0, 100)
+                       return self.g
+               
+       def GUIcreate(self, parent):
+               self.instance = self.createWidget(parent)
+               if self.message is not None:
+                       self.instance.setText(self.message)
+               elif self.value is not None:
+                       self.instance.setValue(self.value)      
+
+       def GUIdelete(self):
+               self.removeWidget(self.instance)
+               self.instance = None
+       
+       def removeWidget(self, instance):
+               pass
\ No newline at end of file
index 1b148d7..b6ad939 100644 (file)
@@ -7,4 +7,4 @@ __all__ = ["ActionMap", "Button", "Clock", "ConfigList", "EventInfo",
        "InputDevice",  "ServicePosition", "IPAddress", "VariableIP", "IPGateway",
        "IPNameserver", "Network", "RFmon", "DiskInfo", "NimManager", "TimerEntry",
        "Lcd", "EpgList" "ScrollLabel", "Timezones", "HelpMenuList", "TimerSanityCheck",
        "InputDevice",  "ServicePosition", "IPAddress", "VariableIP", "IPGateway",
        "IPNameserver", "Network", "RFmon", "DiskInfo", "NimManager", "TimerEntry",
        "Lcd", "EpgList" "ScrollLabel", "Timezones", "HelpMenuList", "TimerSanityCheck",
-       "FileList", "MultiContent" ]
+       "FileList", "MultiContent", "TunerInfo" ]
index f8b185f..358ef44 100644 (file)
@@ -16,6 +16,7 @@ from Components.ServiceName import ServiceName
 from Components.config import config, configElement, ConfigSubsection, configSequence, configElementBoolean
 from Components.config import configfile, configsequencearg
 from Components.TimerList import TimerEntryComponent
 from Components.config import config, configElement, ConfigSubsection, configSequence, configElementBoolean
 from Components.config import configfile, configsequencearg
 from Components.TimerList import TimerEntryComponent
+from Components.TunerInfo import TunerInfo
 
 from EpgSelection import EPGSelection
 from Plugins.Plugin import PluginDescriptor
 
 from EpgSelection import EPGSelection
 from Plugins.Plugin import PluginDescriptor
@@ -429,49 +430,30 @@ class InfoBarEPG:
                        self.epglist[1]=tmp
                        setEvent(self.epglist[0])
 
                        self.epglist[1]=tmp
                        setEvent(self.epglist[0])
 
-from math import log
-
 class InfoBarTuner:
        """provides a snr/agc/ber display"""
        def __init__(self):
                self["snr"] = Label()
                self["agc"] = Label()
                self["ber"] = Label()
 class InfoBarTuner:
        """provides a snr/agc/ber display"""
        def __init__(self):
                self["snr"] = Label()
                self["agc"] = Label()
                self["ber"] = Label()
-               self["snr_percent"] = Label()
-               self["agc_percent"] = Label()
-               self["ber_count"] = Label()
-               self["snr_progress"] = ProgressBar()
-               self["agc_progress"] = ProgressBar()
-               self["ber_progress"] = ProgressBar()
+               self["snr_percent"] = TunerInfo(TunerInfo.SNR_PERCENTAGE, self.session.nav.getCurrentService)
+               self["agc_percent"] = TunerInfo(TunerInfo.AGC_PERCENTAGE, self.session.nav.getCurrentService)
+               self["ber_count"] = TunerInfo(TunerInfo.BER_VALUE, self.session.nav.getCurrentService)
+               self["snr_progress"] = TunerInfo(TunerInfo.SNR_BAR, self.session.nav.getCurrentService)
+               self["agc_progress"] = TunerInfo(TunerInfo.AGC_BAR, self.session.nav.getCurrentService)
+               self["ber_progress"] = TunerInfo(TunerInfo.BER_BAR, self.session.nav.getCurrentService)
                self.timer = eTimer()
                self.timer.timeout.get().append(self.updateTunerInfo)
                self.timer.start(1000)
 
                self.timer = eTimer()
                self.timer.timeout.get().append(self.updateTunerInfo)
                self.timer.start(1000)
 
-       def calc(self,val):
-               if not val:
-                       return 0
-               if val < 2500:
-                       return (long)(log(val)/log(2))
-               return val*100/65535
-
        def updateTunerInfo(self):
                if self.instance.isVisible():
        def updateTunerInfo(self):
                if self.instance.isVisible():
-                       service = self.session.nav.getCurrentService()
-                       snr=0
-                       agc=0
-                       ber=0
-                       if service is not None:
-                               feinfo = service.frontendStatusInfo()
-                               if feinfo is not None:
-                                       ber=feinfo.getFrontendInfo(iFrontendStatusInformation.bitErrorRate)
-                                       snr=feinfo.getFrontendInfo(iFrontendStatusInformation.signalPower)*100/65536
-                                       agc=feinfo.getFrontendInfo(iFrontendStatusInformation.signalQuality)*100/65536
-                       self["snr_percent"].setText("%d%%"%(snr))
-                       self["agc_percent"].setText("%d%%"%(agc))
-                       self["ber_count"].setText("%d"%(ber))
-                       self["snr_progress"].setValue(snr)
-                       self["agc_progress"].setValue(agc)
-                       self["ber_progress"].setValue(self.calc(ber))
+                       self["snr_percent"].update()
+                       self["agc_percent"].update()
+                       self["ber_count"].update()
+                       self["snr_progress"].update()
+                       self["agc_progress"].update()
+                       self["ber_progress"].update()
 
 class InfoBarEvent:
        """provides a current/next event info display"""
 
 class InfoBarEvent:
        """provides a current/next event info display"""