7f6bf31e681de8e67431a5e90d64b92d3a64ebc8
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / ServiceStopScreen.py
1 from Screens.MessageBox import MessageBox
2
3 class ServiceStopScreen:
4         def __init__(self):
5                 try:
6                         self.session
7                 except:
8                         print "[ServiceStopScreen] ERROR: no self.session set"
9                 self.oldref = None
10                 self.onClose.append(self.__onClose)
11
12         def pipAvailable(self):
13                 # pip isn't available in every state of e2
14                 try:
15                         self.session.pipshown
16                         pipavailable = True
17                 except:
18                         pipavailable = False
19                 return pipavailable
20
21         def stopService(self):
22                 self.oldref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
23                 self.session.nav.stopService()
24                 if self.pipAvailable():
25                         if self.session.pipshown: # try to disable pip
26                                 if hasattr(self.session, 'infobar'):
27                                         if self.session.infobar.servicelist and self.session.infobar.servicelist.dopipzap:
28                                                 self.session.infobar.servicelist.togglePipzap()
29                                 if hasattr(self.session, 'pip'):
30                                         del self.session.pip
31                                 self.session.pipshown = False
32
33         def __onClose(self):
34                 self.session.nav.playService(self.oldref)
35
36         def restoreService(self, msg = _("Zap back to previously tuned service?")):
37                 if self.oldref:
38                         self.session.openWithCallback(self.restartPrevService, MessageBox, msg, MessageBox.TYPE_YESNO)
39                 else:
40                         self.restartPrevService(False)
41
42         def restartPrevService(self, yesno):
43                 if not yesno:
44                         self.oldref=None
45                 self.close()