virtualzap/src/plugin.py: ignore additional arguments to zap function
[vuplus_dvbapp-plugin] / virtualzap / src / plugin.py
index 435ef1e..7fe9138 100644 (file)
@@ -45,7 +45,7 @@ from Screens.PictureInPicture import PictureInPicture
 
 InfoBarShowHideINIT = None
 
-from Components.config import config, ConfigSubsection, ConfigSelection, ConfigYesNo, getConfigListEntry, configfile, ConfigPosition
+from Components.config import config, ConfigSubsection, ConfigSelection, ConfigYesNo, getConfigListEntry, configfile, ConfigPosition, ConfigText, ConfigInteger
 from Components.ConfigList import ConfigList, ConfigListScreen
 
 # for localized messages
@@ -55,6 +55,10 @@ config.plugins.virtualzap = ConfigSubsection()
 config.plugins.virtualzap.mode = ConfigSelection(default="0", choices = [("0", _("as plugin in extended bar")),("1", _("with long OK press")), ("2", _("with exit button"))])
 config.plugins.virtualzap.usepip = ConfigYesNo(default = True)
 config.plugins.virtualzap.showpipininfobar = ConfigYesNo(default = True)
+config.plugins.virtualzap.saveLastService = ConfigYesNo(default = False)
+config.plugins.virtualzap.curref = ConfigText()
+config.plugins.virtualzap.curbouquet = ConfigText()
+config.plugins.virtualzap.exittimer =  ConfigInteger(0,limits = (0, 20))
 
 def autostart(reason, **kwargs):
        if config.plugins.virtualzap.mode.value != "0":
@@ -254,11 +258,13 @@ class VirtualZap(Screen):
                        "cancel": self.closing,\r
                        "right": self.nextService,\r
                        "left": self.prevService,
-                       "nextBouquet": self.nextBouquet,
-                       "prevBouquet": self.prevBouquet,
+                       "nextBouquet": self.showFavourites,
+                       "prevBouquet": self.openServiceList,
                        "showEPGList": self.openEventView,
                        "blue": self.standardPiP,
                        "yellow": self.switchAndStandardPiP,
+                       "down": self.switchChannelDown,
+                       "up": self.switchChannelUp,
                },-2)
                self["actions2"] = NumberActionMap(["NumberActions"],
                {
@@ -289,13 +295,46 @@ class VirtualZap(Screen):
                        self["video"] = Label()
                # this is the servicelist from ChannelSelectionBase
                self.servicelist = servicelist
-               # needed, because if we won't zap, we habe to go back to the current bouquet and service
+               # save orig. method of zap in servicelist
+               self.servicelist_orig_zap = self.servicelist.zap 
+               # when displaying ChannelSelection, do not zap when pressing "ok", so new method is needed      
+               self.servicelist.zap = self.servicelist_overwrite_zap
+               # overwrite the actionmap of ChannelSelection
+               self.servicelist["actions"] = ActionMap(["OkCancelActions"],
+                       {
+                               "cancel": self.cancelChannelSelection,
+                               "ok": self.servicelist.channelSelected,
+                       })
+               # temp. vars, needed when pressing cancel in ChannelSelection
+               self.curSelectedRef = None
+               self.curSelectedBouquet = None
+               # needed, because if we won't zap, we have to go back to the current bouquet and service
                self.curRef = ServiceReference(self.servicelist.getCurrentSelection())
                self.curBouquet = self.servicelist.getRoot()
+               # start with last used service
+               if config.plugins.virtualzap.saveLastService.value:
+                       # get service and bouquet ref
+                       ref = eServiceReference(config.plugins.virtualzap.curref.value)
+                       bouquet = eServiceReference(config.plugins.virtualzap.curbouquet.value)
+                       if ref.valid() and bouquet.valid():
+                               # select bouquet and ref in servicelist
+                               self.setServicelistSelection(bouquet, ref)
+               # prepare exitTimer
+               self.exitTimer = eTimer()
+               self.exitTimer.timeout.get().append(self.standardPiP)
+               # reverse changes of ChannelSelection when closing plugin
+               self.onClose.append(self.__onClose)
 
        def onLayoutReady(self):
                self.updateInfos()
 
+       def resetExitTimer(self):
+               # if enabled, run exit timer
+               if config.plugins.virtualzap.exittimer.value != 0:
+                       if self.exitTimer.isActive():
+                               self.exitTimer.stop()
+                       self.exitTimer.start(config.plugins.virtualzap.exittimer.value * 1000)
+
        def nextService(self):
                # get next service
                if self.servicelist.inBouquet():
@@ -358,6 +397,7 @@ class VirtualZap(Screen):
 \r
 \r
        def updateInfos(self):
+               self.resetExitTimer()
                # update data\r
                current = ServiceReference(self.servicelist.getCurrentSelection())
                self["NowChannel"].setText(current.getServiceName())
@@ -398,6 +438,9 @@ class VirtualZap(Screen):
                self.session.open(EPGSelection, current.ref)
 
        def openEventView(self):
+               # stop exitTimer
+               if self.exitTimer.isActive():
+                       self.exitTimer.stop()
                # show EPG Event
                epglist = [ ]
                self.epglist = epglist
@@ -410,7 +453,11 @@ class VirtualZap(Screen):
                if evt:
                        epglist.append(evt)
                if epglist:
-                       self.session.open(EventViewEPGSelect, epglist[0], service, self.eventViewCallback, self.openSingleServiceEPG, self.openMultiServiceEPG, self.openSimilarList)
+                       self.session.openWithCallback(self.EventViewEPGSelectCallBack, EventViewEPGSelect, epglist[0], service, self.eventViewCallback, self.openSingleServiceEPG, self.openMultiServiceEPG, self.openSimilarList)
+
+       def EventViewEPGSelectCallBack(self):
+               # if enabled, start ExitTimer
+               self.resetExitTimer()
 
        def eventViewCallback(self, setEvent, setService, val):
                epglist = self.epglist
@@ -431,14 +478,16 @@ class VirtualZap(Screen):
                # we need to select the old service with bouquet
                if self.servicelist.getRoot() != bouquet: #already in correct bouquet?
                        self.servicelist.clearPath()
-                       if self.servicelist.bouquet_root != bouquet:
-                               self.servicelist.enterPath(self.servicelist.bouquet_root)
+                       self.servicelist.enterPath(self.servicelist.bouquet_root)
                        self.servicelist.enterPath(bouquet)
                self.servicelist.setCurrentSelection(service) #select the service in servicelist
 
        def closing(self):
                if self.pipAvailable:
                        self.pipservice = None
+               # save last used service and bouqet ref
+               self.saveLastService(self.servicelist.getCurrentSelection().toString(), self.servicelist.getRoot().toString())
+               # select running service in servicelist again
                self.setServicelistSelection(self.curBouquet, self.curRef.ref)
                self.close()\r
                        \r
@@ -447,7 +496,9 @@ class VirtualZap(Screen):
                if self.pipAvailable:
                        self.pipservice = None
                # play selected service and close virtualzap
-               self.servicelist.zap()\r
+               self.servicelist_orig_zap()
+               # save last used service and bouqet ref
+               self.saveLastService(self.curRef.ref.toString(), self.curBouquet.toString())
                self.close()
 
        def standardPiP(self):
@@ -457,7 +508,10 @@ class VirtualZap(Screen):
                self.pipservice = None
                # save current selected service for standard PiP
                service = ServiceReference(self.servicelist.getCurrentSelection()).ref
-               servicePath = self.servicelist.getCurrentServicePath() # same bug as in channelselection 
+               servicePath = self.servicelist.getCurrentServicePath() # same bug as in channelselection
+               # save last used service and bouqet ref
+               self.saveLastService(self.servicelist.getCurrentSelection().toString(), self.servicelist.getRoot().toString())
+               # select running service in servicelist
                self.setServicelistSelection(self.curBouquet, self.curRef.ref)
                # close VZ and start standard PiP
                self.close(service, servicePath)
@@ -468,10 +522,22 @@ class VirtualZap(Screen):
                self.pipservice = None
                # save current selected servicePath for standard PiP
                servicePath = self.servicelist.getCurrentServicePath()
+               # save last used service and bouqet ref
+               self.saveLastService(self.curRef.ref.toString(), self.curBouquet.toString())
                # play selected service
-               self.servicelist.zap()
+               self.servicelist_orig_zap()
                # close VZ and start standard PiP
                self.close(self.curRef.ref, servicePath)
+
+       def saveLastService(self, ref, bouquet):
+               if config.plugins.virtualzap.saveLastService.value:
+                       # save last VZ service
+                       config.plugins.virtualzap.curref.value = ref
+                       config.plugins.virtualzap.curbouquet.value = bouquet
+                       config.plugins.virtualzap.save()
+               # stop exitTimer
+               if self.exitTimer.isActive():
+                       self.exitTimer.stop()
 \r
        def CheckItNow(self):\r
                self.CheckForEPG.stop()\r
@@ -540,7 +606,7 @@ class VirtualZap(Screen):
                if self.pipAvailable:
                        self.pipservice = None
                # zap and set new values for the new reference and bouquet
-               self.servicelist.zap()
+               self.servicelist_orig_zap()
                self.curRef = ServiceReference(self.servicelist.getCurrentSelection())
                self.curBouquet = self.servicelist.getRoot()
                # select old values in servicelist
@@ -548,10 +614,81 @@ class VirtualZap(Screen):
                # play old service in PiP
                self.updateInfos()
 
+       # ChannelSelection Support
+       def prepareChannelSelectionDisplay(self):
+               # stop exitTimer
+               if self.exitTimer.isActive():
+                       self.exitTimer.stop()
+               # turn off PiP
+               if self.pipAvailable:
+                       self.pipservice = None
+               # save current ref and bouquet ( for cancel )
+               self.curSelectedRef = eServiceReference(self.servicelist.getCurrentSelection().toString())
+               self.curSelectedBouquet = self.servicelist.getRoot()
+
+       def cancelChannelSelection(self):
+               # select service and bouquet selected before started ChannelSelection
+               if self.servicelist.revertMode is None:
+                       ref = self.curSelectedRef
+                       bouquet = self.curSelectedBouquet
+                       if ref.valid() and bouquet.valid():
+                               # select bouquet and ref in servicelist
+                               self.setServicelistSelection(bouquet, ref)
+               # close ChannelSelection
+               self.servicelist.revertMode = None
+               self.servicelist.asciiOff()
+               self.servicelist.close(None)
+
+               # clean up
+               self.curSelectedRef = None
+               self.curSelectedBouquet = None
+               # display VZ data
+               self.servicelist_overwrite_zap()
+
+       def switchChannelDown(self):
+               self.prepareChannelSelectionDisplay()
+               self.servicelist.moveDown()
+               # show ChannelSelection
+               self.session.execDialog(self.servicelist)
+
+       def switchChannelUp(self):
+               self.prepareChannelSelectionDisplay()
+               self.servicelist.moveUp()
+               # show ChannelSelection
+               self.session.execDialog(self.servicelist)
+
+       def showFavourites(self):
+               self.prepareChannelSelectionDisplay()
+               self.servicelist.showFavourites()
+               # show ChannelSelection
+               self.session.execDialog(self.servicelist)
+
+       def openServiceList(self):
+               self.prepareChannelSelectionDisplay()
+               # show ChannelSelection
+               self.session.execDialog(self.servicelist)
+
+       def servicelist_overwrite_zap(self, *args, **kwargs):
+               # we do not really want to zap to the service, just display data for VZ
+               self.currentPiP = ""
+               if self.isPlayable():
+                       self.updateInfos()
+
+       def __onClose(self):
+               # reverse changes of ChannelSelection 
+               self.servicelist.zap = self.servicelist_orig_zap
+               self.servicelist["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
+                       {
+                               "cancel": self.servicelist.cancel,
+                               "ok": self.servicelist.channelSelected,
+                               "keyRadio": self.servicelist.setModeRadio,
+                               "keyTV": self.servicelist.setModeTv,
+                       })
+
 class VirtualZapConfig(Screen, ConfigListScreen):
 
        skin = """
-               <screen position="center,center" size="560,130" title="Virtual Zap Config" >
+               <screen position="center,center" size="560,180" title="Virtual Zap Config" >
                        <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
                        <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
                        <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
@@ -570,6 +707,8 @@ class VirtualZapConfig(Screen, ConfigListScreen):
                if SystemInfo.get("NumVideoDecoders", 1) > 1:
                        self.list.append(getConfigListEntry(_("Use PiP"), config.plugins.virtualzap.usepip))
                        self.list.append(getConfigListEntry(_("Show PiP in Infobar"), config.plugins.virtualzap.showpipininfobar))
+                       self.list.append(getConfigListEntry(_("Start standard PiP after x secs (0 = disabled)"), config.plugins.virtualzap.exittimer))
+               self.list.append(getConfigListEntry(_("Remember last service"), config.plugins.virtualzap.saveLastService))
                ConfigListScreen.__init__(self, self.list, session)
                self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
                {