move Satfinder and Positioner Plugin to Menu -> Setup -> Service Searching
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Wed, 1 Nov 2006 08:28:56 +0000 (08:28 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Wed, 1 Nov 2006 08:28:56 +0000 (08:28 +0000)
On close Satfinder/Positioner Setup ask the user to rezap to service before
Satfinder/Positioner Setup

lib/python/Plugins/SystemPlugins/PositionerSetup/plugin.py
lib/python/Plugins/SystemPlugins/Satfinder/plugin.py

index e2c07ae..e09359e 100644 (file)
@@ -46,17 +46,24 @@ class PositionerSetup(Screen):
        def __init__(self, session, feid):
                self.skin = PositionerSetup.skin
                Screen.__init__(self, session)
-               
-               self.session.nav.stopService()
-               
                self.feid = feid
+               self.oldref = None
+               
+               if not self.openFrontend():
+                       self.oldref = session.nav.getCurrentlyPlayingServiceReference()
+                       session.nav.stopService() # try to disable foreground service
+                       if not self.openFrontend():
+                               if session.pipshown: # try to disable pip
+                                       session.pipshown = False
+                                       del session.pip
+                                       if not self.openFrontend():
+                                               self.frontend = None # in normal case this should not happen
+                                               self.getFrontend = None
                
                self.diseqc = Diseqc(self.feid)
-               self.tuner = Tuner(self.diseqc.getFrontend())
+               self.tuner = Tuner(self.frontend)
                self.tuner.tune((0,0,0,0,0,0))
                
-               #self.session.nav.stopService()
-               
                self.createConfig()
                
                self.isMoving = False
@@ -79,13 +86,13 @@ class PositionerSetup(Screen):
                self["agc"] = Label()
                self["ber"] = Label()
                self["lock"] = Label()
-               self["snr_percentage"] = TunerInfo(TunerInfo.SNR_PERCENTAGE, frontendfkt = self.diseqc.getFrontend)
-               self["agc_percentage"] = TunerInfo(TunerInfo.AGC_PERCENTAGE, frontendfkt = self.diseqc.getFrontend)
-               self["ber_value"] = TunerInfo(TunerInfo.BER_VALUE, frontendfkt = self.diseqc.getFrontend)
-               self["snr_bar"] = TunerInfo(TunerInfo.SNR_BAR, frontendfkt = self.diseqc.getFrontend)
-               self["agc_bar"] = TunerInfo(TunerInfo.AGC_BAR, frontendfkt = self.diseqc.getFrontend)
-               self["ber_bar"] = TunerInfo(TunerInfo.BER_BAR, frontendfkt = self.diseqc.getFrontend)
-               self["lock_state"] = TunerInfo(TunerInfo.LOCK_STATE, frontendfkt = self.diseqc.getFrontend)
+               self["snr_percentage"] = TunerInfo(TunerInfo.SNR_PERCENTAGE, frontendfkt = self.getFrontend)
+               self["agc_percentage"] = TunerInfo(TunerInfo.AGC_PERCENTAGE, frontendfkt = self.getFrontend)
+               self["ber_value"] = TunerInfo(TunerInfo.BER_VALUE, frontendfkt = self.getFrontend)
+               self["snr_bar"] = TunerInfo(TunerInfo.SNR_BAR, frontendfkt = self.getFrontend)
+               self["agc_bar"] = TunerInfo(TunerInfo.AGC_BAR, frontendfkt = self.getFrontend)
+               self["ber_bar"] = TunerInfo(TunerInfo.BER_BAR, frontendfkt = self.getFrontend)
+               self["lock_state"] = TunerInfo(TunerInfo.LOCK_STATE, frontendfkt = self.getFrontend)
 
                self["frequency"] = Label()
                self["symbolrate"] = Label()
@@ -98,7 +105,7 @@ class PositionerSetup(Screen):
                self["actions"] = ActionMap(["DirectionActions", "OkCancelActions", "ColorActions"],
                {
                        "ok": self.go,
-                       "cancel": self.close,
+                       "cancel": self.keyCancel,
                        "up": self.up,
                        "down": self.down,
                        "left": self.left,
@@ -115,6 +122,39 @@ class PositionerSetup(Screen):
                self.statusTimer.timeout.get().append(self.updateStatus)
                self.statusTimer.start(50, False)
 
+       def restartPrevService(self, yesno):
+               if yesno:
+                       if self.frontend:
+                               self.frontend = None
+                               del self.raw_channel
+                       self.session.nav.playService(self.oldref)
+               self.close(None)
+       
+       def keyCancel(self):
+               if self.oldref:
+                       self.session.openWithCallback(self.restartPrevService, MessageBox, _("Zap back to service before positioner setup?"), MessageBox.TYPE_YESNO)
+               else:
+                       self.restartPrevService(False)
+
+       def getFrontend(self):
+               return self.frontend
+
+       def openFrontend(self):
+               res_mgr = eDVBResourceManagerPtr()
+               if eDVBResourceManager.getInstance(res_mgr) == 0:
+                       self.raw_channel = iDVBChannelPtr()
+                       if res_mgr.allocateRawChannel(self.raw_channel, self.feid) == 0:
+                               self.frontend = iDVBFrontendPtr()
+                               if self.raw_channel.getFrontend(self.frontend) == 0:
+                                       return True
+                               else:
+                                       print "getFrontend failed"
+                       else:
+                               print "getRawChannel failed"
+               else:
+                       print "getResourceManager instance failed"
+               return False
+
        def createConfig(self):
                self.positioner_tune = ConfigNothing()
                self.positioner_move = ConfigNothing()
@@ -239,7 +279,7 @@ class PositionerSetup(Screen):
                        self.diseqccommand("store", int(self.positioner_storage.value))
                elif entry == "limits":
                        self.diseqccommand("limitWest")
-       
+
        def yellowKey(self):
                entry = self.getCurrentConfigPath()
                if entry == "move":
@@ -260,7 +300,7 @@ class PositionerSetup(Screen):
                        self.diseqccommand("moveTo", int(self.positioner_storage.value))
                elif entry == "limits":
                        self.diseqccommand("limitEast")
-#      
+
        def blueKey(self):
                entry = self.getCurrentConfigPath()
                if entry == "move":
@@ -301,30 +341,13 @@ class PositionerSetup(Screen):
        def tune(self, transponder):
                if transponder is not None:
                        self.tuner.tune(transponder)
-                       
+
 class Diseqc:
-       def __init__(self, feid = 0):
-               self.ready = False
-               self.feid = feid
-               res_mgr = eDVBResourceManagerPtr()
-               if eDVBResourceManager.getInstance(res_mgr) == 0:
-                       self.raw_channel = iDVBChannelPtr()
-                       if res_mgr.allocateRawChannel(self.raw_channel, self.feid) == 0:
-                               self.frontend = iDVBFrontendPtr()
-                               if self.raw_channel.getFrontend(self.frontend) == 0:
-                                       self.ready = True
-                               else:
-                                       print "getFrontend failed"
-                       else:
-                               print "getRawChannel failed"
-               else:
-                       print "getResourceManager instance failed"
-       
-       def getFrontend(self):
-               return self.frontend
-               
+       def __init__(self, frontend):
+               self.frontend = frontend
+
        def command(self, what, param = 0):
-               if self.ready:
+               if self.frontend:
                        cmd = eDVBDiseqcCommand()
                        if what == "moveWest":
                                string = 'e03169' + ("%02x" % param)
@@ -344,7 +367,7 @@ class Diseqc:
                                string = 'e03167'
                        else:
                                string = 'e03160' #positioner stop
-
+                       
                        print "diseqc command:",
                        print string
                        cmd.setCommandString(string)
@@ -356,7 +379,7 @@ class Diseqc:
 class Tuner:
        def __init__(self, frontend):
                self.frontend = frontend
-               
+
        def tune(self, transponder):
                print "tuning to transponder with data", transponder
                parm = eDVBFrontendParametersSatellite()
@@ -371,13 +394,17 @@ class Tuner:
                feparm = eDVBFrontendParameters()
                feparm.setDVBS(parm, True)
                self.lastparm = feparm
-               self.frontend.tune(feparm)
-       
+               if self.frontend:
+                       self.frontend.tune(feparm)
+
        def retune(self):
-               self.frontend.tune(self.lastparm)
-       
+               if self.frontend:
+                       self.frontend.tune(self.lastparm)
+
        def getTransponderData(self):
-               return self.frontend.readTransponderData(True)
+               if self.frontend:
+                       return self.frontend.readTransponderData(True)
+               return None
 
 tuning = None
 
@@ -391,13 +418,11 @@ class TunerScreen(ScanSetup):
        def __init__(self, session, feid):
                self.feid = feid
                ScanSetup.__init__(self, session)
-
                self["introduction"].setText("")
-               
+
        def createSetup(self):
                self.typeOfTuningEntry = None
                self.satEntry = None
-
                self.list = []
                self.typeOfTuningEntry = getConfigListEntry(_('Tune'), tuning.type)
                self.list.append(self.typeOfTuningEntry)
@@ -494,7 +519,7 @@ class NimSelection(Screen):
                <screen position="140,165" size="400,100" title="select Slot">
                        <widget name="nimlist" position="20,10" size="360,75" />
                </screen>"""
-               
+
        def __init__(self, session):
                Screen.__init__(self, session)
 
@@ -535,5 +560,11 @@ def PositionerMain(session, **kwargs):
                        else:
                                session.open(MessageBox, _("No tuner is configured for use with a diseqc positioner!"), MessageBox.TYPE_ERROR)
 
+def PositionerSetupStart(menuid):
+       if menuid == "scan":
+               return [("Positioner setup", PositionerMain)]
+       else:
+               return []
+
 def Plugins(**kwargs):
-       return PluginDescriptor(name="Positioner setup", description="Setup your positioner", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=PositionerMain)
+       return PluginDescriptor(name="Positioner setup", description="Setup your positioner", where = PluginDescriptor.WHERE_SETUP, fnc=PositionerSetupStart)
index 40a6557..ac95b28 100644 (file)
@@ -89,10 +89,10 @@ class Satfinder(ScanSetup):
                                        if not self.openFrontend():
                                                self.frontend = None # in normal case this should not happen
                                                self.getFrontend = None
-
+               
                ScanSetup.__init__(self, session)
                self.tuner = Tuner(self.frontend)
-
+               
                self["snr"] = Label()
                self["agc"] = Label()
                self["ber"] = Label()
@@ -104,16 +104,16 @@ class Satfinder(ScanSetup):
                self["agc_bar"] = TunerInfo(TunerInfo.AGC_BAR, frontendfkt = self.getFrontend)
                self["ber_bar"] = TunerInfo(TunerInfo.BER_BAR, frontendfkt = self.getFrontend)
                self["lock_state"] = TunerInfo(TunerInfo.LOCK_STATE, frontendfkt = self.getFrontend)
-
+               
                self["introduction"].setText("")
                
                self.statusTimer = eTimer()
                self.statusTimer.timeout.get().append(self.updateStatus)
                self.statusTimer.start(50, False)
-
+               
                self.initcomplete = True
                self.session = session
-               
+
        def updateStatus(self):
                self["snr_percentage"].update()
                self["agc_percentage"].update()
@@ -126,7 +126,7 @@ class Satfinder(ScanSetup):
        def createSetup(self):
                self.typeOfTuningEntry = None
                self.satEntry = None
-
+               
                self.list = []
                self.typeOfTuningEntry = getConfigListEntry(_('Tune'), self.tuning_type)
                self.list.append(self.typeOfTuningEntry)
@@ -167,14 +167,13 @@ class Satfinder(ScanSetup):
                        self.tune(returnvalue)
 
        def createConfig(self, foo):
-
                self.tuning_transponder = None
                self.tuning_type = ConfigSelection(choices = [("manual_transponder", _("Manual transponder")), ("predefined_transponder", _("Predefined transponder"))])
                self.tuning_sat = getConfigSatlist(192, nimmanager.getSatListForNim(self.feid))
                ScanSetup.createConfig(self, None)
                
                self.updateSats()
-
+               
                self.tuning_type.addNotifier(self.retune, initial_call = False)
                self.tuning_sat.addNotifier(self.sat_changed, initial_call = False)
                self.scan_sat.frequency.addNotifier(self.retune, initial_call = False)
@@ -216,18 +215,24 @@ class Satfinder(ScanSetup):
                                list.append(str(x[1]) + "," + str(x[2]) + "," + pol + "," + fec)
                        self.tuning_transponder = ConfigSelection(choices = list)
                        self.tuning_transponder.addNotifier(self.retune, initial_call = False)
-       
+
        def keyGo(self):
                self.retune(self.tuning_type)
 
-       def keyCancel(self):
-               if self.oldref:
+       def restartPrevService(self, yesno):
+               if yesno:
                        if self.frontend:
                                self.frontend = None
                                del self.raw_channel
                        self.session.nav.playService(self.oldref)
                self.close(None)
-               
+
+       def keyCancel(self):
+               if self.oldref:
+                       self.session.openWithCallback(self.restartPrevService, MessageBox, _("Zap back to service before satfinder?"), MessageBox.TYPE_YESNO)
+               else:
+                       self.restartPrevService(False)
+
        def tune(self, transponder):
                if self.initcomplete:
                        if transponder is not None:
@@ -262,18 +267,21 @@ class NimSelection(Screen):
 def SatfinderMain(session, **kwargs):
        nimList = nimmanager.getNimListOfType(nimmanager.nimType["DVB-S"])
        if len(nimList) == 0:
-               session.open(MessageBox, _("No positioner capable frontend found."), MessageBox.TYPE_ERROR)
+               session.open(MessageBox, _("No satellite frontend found!!"), MessageBox.TYPE_ERROR)
        else:
                if session.nav.RecordTimer.isRecording():
-                       session.open(MessageBox, _("A recording is currently running. Please stop the recording before trying to configure the positioner."), MessageBox.TYPE_ERROR)
+                       session.open(MessageBox, _("A recording is currently running. Please stop the recording before trying to start the satfinder."), MessageBox.TYPE_ERROR)
                else:
                        if len(nimList) == 1:
                                session.open(Satfinder, nimList[0])
-                       elif len(nimList) > 1:
-                               session.open(NimSelection)
                        else:
-                               session.open(MessageBox, _("No tuner is configured for use with a diseqc positioner!"), MessageBox.TYPE_ERROR)
+                               session.open(NimSelection)
 
+def SatfinderStart(menuid):
+       if menuid == "scan":
+               return [("Satfinder", SatfinderMain)]
+       else:
+               return []
 
 def Plugins(**kwargs):
-       return PluginDescriptor(name="Satfinder", description="Helps setting up your dish", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=SatfinderMain)
+       return PluginDescriptor(name="Satfinder", description="Helps setting up your dish", where = PluginDescriptor.WHERE_SETUP, fnc=SatfinderStart)