Exposed a global context.get_bus() method to allow plugins to send events to the main bus
This commit is contained in:
parent
9052e18f9c
commit
e5e1270380
2 changed files with 15 additions and 3 deletions
|
@ -9,6 +9,9 @@ backends = {}
|
|||
# Map: plugin_name -> plugin_instance
|
||||
plugins = {}
|
||||
|
||||
# Reference to the main application bus
|
||||
main_bus = None
|
||||
|
||||
def register_backends(bus=None, global_scope=False, **kwargs):
|
||||
""" Initialize the backend objects based on the configuration and returns
|
||||
a name -> backend_instance map.
|
||||
|
@ -19,6 +22,10 @@ def register_backends(bus=None, global_scope=False, **kwargs):
|
|||
kwargs -- Any additional key-value parameters required to initialize the backends
|
||||
"""
|
||||
|
||||
global main_bus
|
||||
if bus:
|
||||
main_bus = bus
|
||||
|
||||
if global_scope:
|
||||
global backends
|
||||
else:
|
||||
|
@ -84,6 +91,10 @@ def get_plugin(plugin_name, reload=False):
|
|||
plugins[plugin_name] = plugin
|
||||
return plugin
|
||||
|
||||
def get_bus():
|
||||
global main_bus
|
||||
return main_bus
|
||||
|
||||
def register_plugin(name, plugin, **kwargs):
|
||||
""" Registers a plugin instance by name """
|
||||
global plugins
|
||||
|
|
|
@ -10,6 +10,7 @@ from bs4 import BeautifulSoup
|
|||
from dbus.exceptions import DBusException
|
||||
from omxplayer import OMXPlayer
|
||||
|
||||
from platypush.context import get_bus
|
||||
from platypush.plugins.media import PlayerState
|
||||
from platypush.message.response import Response
|
||||
from platypush.message.event.video import VideoPlayEvent, VideoPauseEvent, \
|
||||
|
@ -158,17 +159,17 @@ class VideoOmxplayerPlugin(Plugin):
|
|||
|
||||
def on_play(self):
|
||||
def _f(player):
|
||||
self.bus.post(VideoPlayEvent(video=self.player.get_source()))
|
||||
get_bus().post(VideoPlayEvent(video=self.player.get_source()))
|
||||
return _f
|
||||
|
||||
def on_pause(self):
|
||||
def _f(player):
|
||||
self.bus.post(VideoPauseEvent(video=self.player.get_source()))
|
||||
get_bus().post(VideoPauseEvent(video=self.player.get_source()))
|
||||
return _f
|
||||
|
||||
def on_stop(self):
|
||||
def _f(player):
|
||||
self.bus.post(VideoStopEvent())
|
||||
get_bus().post(VideoStopEvent())
|
||||
return _f
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue