fix no more working service change after open audio track selection
[enigma2.git] / lib / python / Screens / InfoBarGenerics.py
index 1b56e43006f18fad39bc124647bca3d290a75f93..d15200710697fb7f7232aee22c2e1ddd3105215d 100644 (file)
@@ -342,8 +342,15 @@ class InfoBarSimpleEventView:
 class InfoBarEPG:
        """ EPG - Opens an EPG list when the showEPGList action fires """
        def __init__(self):
+               self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
+                       {
+                               iPlayableService.evUpdatedEventInfo: self.__evEventInfoChanged,
+                       })
+
+               self.is_now_next = False
                self.dlg_stack = [ ]
                self.bouquetSel = None
+               self.eventView = None
                self["EPGActions"] = HelpableActionMap(self, "InfobarEPGActions", 
                        {
                                "showEventInfo": (self.openEventView, _("show EPG...")),
@@ -397,10 +404,12 @@ class InfoBarEPG:
                closedScreen = self.dlg_stack.pop()
                if self.bouquetSel and closedScreen == self.bouquetSel:
                        self.bouquetSel = None
+               elif self.eventView and closedScreen == self.eventView:
+                       self.eventView = None
                if ret:
                        dlgs=len(self.dlg_stack)
-                       assert dlgs>0
-                       self.dlg_stack[dlgs-1].close(dlgs > 1)
+                       if dlgs > 0:
+                               self.dlg_stack[dlgs-1].close(dlgs > 1)
 
        def openMultiServiceEPG(self, withCallback=True):
                bouquets = self.servicelist.getBouquetList()
@@ -424,27 +433,40 @@ class InfoBarEPG:
        def openSimilarList(self, eventid, refstr):
                self.session.open(EPGSelection, refstr, None, eventid)
 
-       def openEventView(self):
+       def getNowNext(self):
                self.epglist = [ ]
                service = self.session.nav.getCurrentService()
-               ref = self.session.nav.getCurrentlyPlayingServiceReference()
-               info = service.info()
-               ptr=info.getEvent(0)
+               info = service and service.info()
+               ptr = info and info.getEvent(0)
                if ptr:
                        self.epglist.append(ptr)
-               ptr=info.getEvent(1)
+               ptr = info and info.getEvent(1)
                if ptr:
                        self.epglist.append(ptr)
+
+       def __evEventInfoChanged(self):
+               if self.is_now_next and len(self.dlg_stack) == 1:
+                       self.getNowNext()
+                       assert self.eventView
+                       self.eventView.setEvent(self.epglist[0])
+
+       def openEventView(self):
+               ref = self.session.nav.getCurrentlyPlayingServiceReference()
+               self.getNowNext()
                if len(self.epglist) == 0:
+                       self.is_now_next = False
                        epg = eEPGCache.getInstance()
-                       ptr = epg.lookupEventTime(ref, -1)
+                       ptr = ref and ref.valid() and epg.lookupEventTime(ref, -1)
                        if ptr:
                                self.epglist.append(ptr)
                                ptr = epg.lookupEventTime(ref, ptr.getBeginTime(), +1)
                                if ptr:
                                        self.epglist.append(ptr)
+               else:
+                       self.is_now_next = True
                if len(self.epglist) > 0:
-                       self.dlg_stack.append(self.session.openWithCallback(self.closed, EventViewEPGSelect, self.epglist[0], ServiceReference(ref), self.eventViewCallback, self.openSingleServiceEPG, self.openMultiServiceEPG, self.openSimilarList))
+                       self.eventView = self.session.openWithCallback(self.closed, EventViewEPGSelect, self.epglist[0], ServiceReference(ref), self.eventViewCallback, self.openSingleServiceEPG, self.openMultiServiceEPG, self.openSimilarList)
+                       self.dlg_stack.append(self.eventView)
                else:
                        print "no epg for the service avail.. so we show multiepg instead of eventinfo"
                        self.openMultiServiceEPG(False)
@@ -983,6 +1005,8 @@ class InfoBarTimeshift:
                self.timeshift_enabled = False
                self.__seekableStatusChanged()
 
+from Screens.PiPSetup import PiPSetup
+
 class InfoBarExtensions:
        def __init__(self):
                self.pipshown = False
@@ -991,19 +1015,24 @@ class InfoBarExtensions:
                        {
                                "extensions": (self.extensions, "Extensions..."),
                        })
-                       
+
+       PIPON = 0
+       PIPOFF = 1
+       MOVEPIP = 2
+
        def extensions(self):
                list = []
                if self.pipshown == False:
-                       list.append((_("Activate Picture in Picture"), "pipon"))
+                       list.append((_("Activate Picture in Picture"), self.PIPON))
                elif self.pipshown == True:
-                       list.append((_("Disable Picture in Picture"), "pipoff"))
+                       list.append((_("Disable Picture in Picture"), self.PIPOFF))
+                       list.append((_("Move Picture in Picture"), self.MOVEPIP))
                self.session.openWithCallback(self.extensionCallback, ChoiceBox, title=_("Please choose an extension..."), list = list)
 
        def extensionCallback(self, answer):
                if answer is not None:
-                       if answer[1] == "pipon":
-                               self.session.nav.stopService()
+                       if answer[1] == self.PIPON:
+#                              self.session.nav.stopService()
                                self.pip = self.session.instantiateDialog(PictureInPicture)
                                #self.pip.show()
                                
@@ -1015,12 +1044,14 @@ class InfoBarExtensions:
                                else:
                                        self.pipservice = None
                                        del self.pip
-       
-                       elif answer[1] == "pipoff":
+                               self.session.nav.playService(newservice)
+                       elif answer[1] == self.PIPOFF:
                                #self.pip.hide()
                                self.pipservice = None
                                del self.pip
                                self.pipshown = False
+                       elif answer[1] == self.MOVEPIP:
+                               self.session.open(PiPSetup, pip = self.pip)
 
 from RecordTimer import parseEvent
 
@@ -1194,6 +1225,7 @@ class InfoBarAudioSelection:
        def audioSelected(self, audio):
                if audio is not None:
                        self.audio.selectTrack(audio[1])
+               del self.audio
 
 class InfoBarSubserviceSelection:
        def __init__(self):