swap key and value
[enigma2.git] / lib / python / Screens / InfoBar.py
1 from Tools.Profile import profile, profile_final
2
3 from Screen import Screen
4
5 profile("LOAD:enigma")
6 from enigma import iPlayableService
7
8 profile("LOAD:ChannelSelectionRadio")
9 from Screens.ChannelSelection import ChannelSelectionRadio
10 profile("LOAD:MovieSelection")
11 from Screens.MovieSelection import MovieSelection
12 profile("LOAD:ChoiceBox")
13 from Screens.ChoiceBox import ChoiceBox
14
15 profile("LOAD:InfoBarGenerics")
16 from Screens.InfoBarGenerics import InfoBarShowHide, \
17         InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarRdsDecoder, \
18         InfoBarEPG, InfoBarSeek, InfoBarInstantRecord, \
19         InfoBarAudioSelection, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, \
20         InfoBarSubserviceSelection, InfoBarShowMovies, InfoBarTimeshift,  \
21         InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView, \
22         InfoBarSummarySupport, InfoBarMoviePlayerSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions, \
23         InfoBarSubtitleSupport, InfoBarPiP, InfoBarPlugins, InfoBarSleepTimer, InfoBarServiceErrorPopupSupport
24
25 profile("LOAD:InitBar_Components")
26 from Components.ActionMap import HelpableActionMap
27 from Components.config import config
28 from Components.ServiceEventTracker import ServiceEventTracker, InfoBarBase
29
30 profile("LOAD:HelpableScreen")
31 from Screens.HelpMenu import HelpableScreen
32
33 class InfoBar(InfoBarBase, InfoBarShowHide,
34         InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder,
35         InfoBarInstantRecord, InfoBarAudioSelection, 
36         HelpableScreen, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish,
37         InfoBarSubserviceSelection, InfoBarTimeshift, InfoBarSeek,
38         InfoBarSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions,
39         InfoBarPiP, InfoBarPlugins, InfoBarSubtitleSupport, InfoBarSleepTimer, InfoBarServiceErrorPopupSupport,
40         Screen):
41         
42         ALLOW_SUSPEND = True
43
44         def __init__(self, session):
45                 Screen.__init__(self, session)
46                 self["actions"] = HelpableActionMap(self, "InfobarActions",
47                         {
48                                 "showMovies": (self.showMovies, _("Play recorded movies...")),
49                                 "showRadio": (self.showRadio, _("Show the radio player...")),
50                                 "showTv": (self.showTv, _("Show the tv player...")),
51                         }, prio=2)
52                 
53                 for x in HelpableScreen, \
54                                 InfoBarBase, InfoBarShowHide, \
55                                 InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder, \
56                                 InfoBarInstantRecord, InfoBarAudioSelection, \
57                                 InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarSubserviceSelection, \
58                                 InfoBarTimeshift, InfoBarSeek, InfoBarSummarySupport, InfoBarTimeshiftState, \
59                                 InfoBarTeletextPlugin, InfoBarExtensions, InfoBarPiP, InfoBarSubtitleSupport, InfoBarSleepTimer, \
60                                 InfoBarPlugins, InfoBarServiceErrorPopupSupport:
61                         x.__init__(self)
62
63                 self.helpList.append((self["actions"], "InfobarActions", [("showMovies", _("view recordings..."))]))
64                 self.helpList.append((self["actions"], "InfobarActions", [("showRadio", _("hear radio..."))]))
65
66                 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
67                         {
68                                 iPlayableService.evUpdatedEventInfo: self.__eventInfoChanged
69                         })
70
71                 self.current_begin_time=0
72
73         def __eventInfoChanged(self):
74                 if self.execing:
75                         service = self.session.nav.getCurrentService()
76                         old_begin_time = self.current_begin_time
77                         info = service and service.info()
78                         ptr = info and info.getEvent(0)
79                         self.current_begin_time = ptr and ptr.getBeginTime() or 0
80                         if config.usage.show_infobar_on_event_change.value:
81                                 if old_begin_time and old_begin_time != self.current_begin_time:
82                                         self.doShow()
83
84         def __checkServiceStarted(self):
85                 self.__serviceStarted(True)
86                 self.onExecBegin.remove(self.__checkServiceStarted)
87
88         def serviceStarted(self):  #override from InfoBarShowHide
89                 new = self.servicelist.newServicePlayed()
90                 if self.execing:
91                         InfoBarShowHide.serviceStarted(self)
92                         self.current_begin_time=0
93                 elif not self.__checkServiceStarted in self.onShown and new:
94                         self.onShown.append(self.__checkServiceStarted)
95
96         def __checkServiceStarted(self):
97                 self.serviceStarted()
98                 self.onShown.remove(self.__checkServiceStarted)
99
100         def showTv(self):
101                 self.showTvChannelList(True)
102
103         def showRadio(self):
104                 if config.usage.e1like_radio_mode.value:
105                         self.showRadioChannelList(True)
106                 else:
107                         self.rds_display.hide() # in InfoBarRdsDecoder
108                         self.session.openWithCallback(self.ChannelSelectionRadioClosed, ChannelSelectionRadio, self)
109
110         def ChannelSelectionRadioClosed(self, *arg):
111                 self.rds_display.show()  # in InfoBarRdsDecoder
112
113         def showMovies(self):
114                 self.session.openWithCallback(self.movieSelected, MovieSelection)
115
116         def movieSelected(self, service):
117                 if service is not None:
118                         self.session.open(MoviePlayer, service)
119
120 class MoviePlayer(InfoBarBase, InfoBarShowHide, \
121                 InfoBarMenu, \
122                 InfoBarSeek, InfoBarShowMovies, InfoBarAudioSelection, HelpableScreen, InfoBarNotifications,
123                 InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView,
124                 InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, Screen, InfoBarTeletextPlugin,
125                 InfoBarServiceErrorPopupSupport):
126
127         ENABLE_RESUME_SUPPORT = True
128         ALLOW_SUSPEND = True
129                 
130         def __init__(self, session, service):
131                 Screen.__init__(self, session)
132                 
133                 self["actions"] = HelpableActionMap(self, "MoviePlayerActions",
134                         {
135                                 "leavePlayer": (self.leavePlayer, _("leave movie player..."))
136                         })
137                 
138                 for x in HelpableScreen, InfoBarShowHide, InfoBarMenu, \
139                                 InfoBarBase, InfoBarSeek, InfoBarShowMovies, \
140                                 InfoBarAudioSelection, InfoBarNotifications, InfoBarSimpleEventView, \
141                                 InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, \
142                                 InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, \
143                                 InfoBarTeletextPlugin, InfoBarServiceErrorPopupSupport:
144                         x.__init__(self)
145
146                 self.lastservice = self.session.nav.getCurrentlyPlayingServiceReference()
147                 self.session.nav.playService(service)
148                 self.returning = False
149
150         def leavePlayer(self):
151                 self.is_closing = True
152
153                 if config.usage.on_movie_stop.value == "ask":
154                         list = []
155                         list.append((_("Yes"), "quit"))
156                         if config.usage.setup_level.index >= 2: # expert+
157                                 list.append((_("Yes, returning to movie list"), "movielist"))
158                         list.append((_("No"), "continue"))
159                         if config.usage.setup_level.index >= 2: # expert+
160                                 list.append((_("No, but restart from begin"), "restart"))
161                         self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
162                 else:
163                         self.leavePlayerConfirmed([True, config.usage.on_movie_stop.value])
164
165         def leavePlayerConfirmed(self, answer):
166                 answer = answer and answer[1]
167                 if answer == "quit":
168                         self.session.nav.playService(self.lastservice)
169                         config.movielist.last_videodir.cancel()
170                         self.close()
171                 elif answer == "movielist":
172                         ref = self.session.nav.getCurrentlyPlayingServiceReference()
173                         self.returning = True
174                         self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
175                         self.session.nav.playService(self.lastservice)
176                 elif answer == "restart":
177                         self.doSeek(0)
178
179         def doEofInternal(self, playing):
180                 if not self.execing:
181                         return
182                 if not playing :
183                         return
184                 self.is_closing = True
185                 if config.usage.on_movie_eof.value == "ask":
186                         list = []
187                         list.append((_("Yes"), "quit"))
188                         if config.usage.setup_level.index >= 2: # expert+
189                                 list.append((_("Yes, returning to movie list"), "movielist"))
190                         list.append((_("No"), "continue"))
191                         if config.usage.setup_level.index >= 2: # expert+
192                                 list.append((_("No, but restart from begin"), "restart"))
193                         self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
194                 else:
195                         self.leavePlayerConfirmed([True, config.usage.on_movie_eof.value])
196
197         def showMovies(self):
198                 ref = self.session.nav.getCurrentlyPlayingServiceReference()
199                 self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
200
201         def movieSelected(self, service):
202                 if service is not None:
203                         self.is_closing = False
204                         self.session.nav.playService(service)
205                         self.returning = False
206                 elif self.returning:
207                         self.close()