2 from Plugins.Plugin import PluginDescriptor
4 from Components.PluginComponent import plugins
5 from Tools.BoundFunction import boundFunction
6 from Screens.InfoBarGenerics import InfoBarPlugins, InfoBarMoviePlayerSummarySupport
7 from Screens.ChannelSelection import ChannelSelection
8 from Screens.InfoBar import InfoBar, MoviePlayer
15 # This plugin consists of 4 "steps" which serve their own purpose and if combined allow access to both the service list and plugins requiring the service list from within the movie player.
16 # Each of these steps are enclosed in their own sections and their purpose is explained.
18 # Step 1: change way used to determine if plugins requiring service list should be shown
19 # Base implementation uses isinstance(self, InfoBarChannelSelection) which we do not want (to implement) for various reasons.
20 # Instead we we check for the instance variable "servicelist".
22 # Additionally, we inject our "fake" plugin only if the (original?) movie player is running.
24 # Doing so should not affect behavior if plugin is disabled, though we still overwrite these functions to make things easier to manage internally.
25 def InfoBarPlugins_getPluginList(self, *args, **kwargs):
27 showSlistPlugins = hasattr(self, 'servicelist')
28 for p in plugins.getPlugins(where = PluginDescriptor.WHERE_EXTENSIONSMENU):
29 args = inspect.getargspec(p.__call__)[0]
30 if len(args) == 1 or len(args) == 2 and showSlistPlugins:
31 l.append(((boundFunction(self.getPluginName, p.name), boundFunction(self.runPlugin, p), lambda: True), None, p.name))
32 # this is the/a movie player, add our fake plugin
33 if isinstance(self, InfoBarMoviePlayerSummarySupport):
34 l.append(((boundFunction(self.getPluginName, "EPG"), boundFunction(self.runPlugin, entry), lambda: True), None, "EPG"))
35 l.sort(key = lambda e: e[2]) # sort by name
37 def InfoBarPlugins_runPlugin(self, plugin, *args, **kwargs):
38 if hasattr(self, 'servicelist'):
39 plugin(session = self.session, servicelist = self.servicelist)
41 plugin(session = self.session)
42 InfoBarPlugins.getPluginList = InfoBarPlugins_getPluginList
43 InfoBarPlugins.runPlugin = InfoBarPlugins_runPlugin
45 # Step 2: Overwrite some ChannelSelection code to be able to interject channel selection
46 # TODO: right now we only block channel selection, this can be improved by allowing to switch channels
48 # Doing so should not affect behavior if plugin is disabled, though we still overwrite these functions to make things easier to manage internally.
49 baseChannelSelection_channelSelected = None
50 def ChannelSelection_channelSelected(self, *args, **kwargs):
51 if hasattr(self, 'secretMovieMode') and self.secretMovieMode:
52 # XXX: better would be to invoke the movie player quit handler and eventually (if not canceled) zap
54 baseChannelSelection_channelSelected(self, *args, **kwargs)
55 baseChannelSelection_channelSelected = ChannelSelection.channelSelected
56 ChannelSelection.channelSelected = ChannelSelection_channelSelected
58 baseChannelSelection_close = None
59 def ChannelSelection_close(self, *args, **kwargs):
60 if hasattr(self, 'secretMovieMode') and self.secretMovieMode != MODE_MOVIEPLAYER:
61 self.secretMovieMode = MODE_OFF
62 baseChannelSelection_close(self, *args, **kwargs)
63 baseChannelSelection_close = ChannelSelection.close
64 ChannelSelection.close = ChannelSelection_close
66 baseChannelSelection_zap = None
67 def ChannelSelection_zap(self, *args, **kwargs):
68 if hasattr(self, 'secretMovieMode') and self.secretMovieMode:
69 # XXX: better would be to invoke the movie player quit handler and eventually (if not canceled) zap
71 baseChannelSelection_zap(self, *args, **kwargs)
72 baseChannelSelection_zap = ChannelSelection.zap
73 ChannelSelection.zap = ChannelSelection_zap
75 # Step 3: Plugin which allows access to service list from extension menu (and possibly later on from plugin menu)
76 # Absolutely no effect on its own.
77 def entry(session = None, servicelist = None):
78 # XXX: session.current_dialog is the movie player (or infobar if ran from "regular" extension menu)
79 if not session: return
81 servicelist = InfoBar.instance.servicelist
82 if hasattr(servicelist, 'secretMovieMode') and servicelist.secretMovieMode != MODE_MOVIEPLAYER:
83 servicelist.secretMovieMode = MODE_ON
84 session.execDialog(servicelist)
86 # Step 4: Modify standard movie player to keep a reference to the service list (taken from the info bar)
87 # Basically no effect on its own.
88 baseMoviePlayer___init__ = None
89 def MoviePlayer___init__(self, *args, **kwargs):
90 baseMoviePlayer___init__(self, *args, **kwargs)
91 self.servicelist = InfoBar.instance.servicelist
92 self.servicelist.secretMovieMode = MODE_MOVIEPLAYER
93 baseMoviePlayer___init__ = MoviePlayer.__init__
94 MoviePlayer.__init__ = MoviePlayer___init__
96 baseMoviePlayer_close = None
97 def MoviePlayer_close(self, *args, **kwargs):
98 self.servicelist.secretMovieMode = MODE_OFF
99 baseMoviePlayer_close(self, *args, **kwargs)
100 baseMoviePlayer_close = MoviePlayer.close
101 MoviePlayer.close = MoviePlayer_close
104 def autostart(reason, **kwargs):
106 pass # TODO: anything to do here?
108 def Plugins(**kwargs):
111 where = PluginDescriptor.WHERE_AUTOSTART,