From 53c3eeb8f77c2d175707d95a5c948df40679a5e8 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Mon, 11 Sep 2017 17:44:17 +0300 Subject: [PATCH] Sound plugins using pycanberra and gst-python --- setup.py | 3 +++ src/plugins/sound_canberra.py | 21 +++++++++++++++++++++ src/plugins/sound_gstreamer.py | 14 ++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/plugins/sound_canberra.py create mode 100644 src/plugins/sound_gstreamer.py diff --git a/setup.py b/setup.py index cf6bd9d2..dc803931 100644 --- a/setup.py +++ b/setup.py @@ -304,6 +304,9 @@ if __name__ == "__main__": '[gir, notify2]' ], 'bitmessage.notification.sound': [ + 'theme.canberra = pybitmessage.plugins.sound_canberra', + 'file.gstreamer = pybitmessage.plugins.sound_gstreamer' + '[gir]', 'file.fallback = pybitmessage.plugins.sound_playfile' '[sound]' ], diff --git a/src/plugins/sound_canberra.py b/src/plugins/sound_canberra.py new file mode 100644 index 00000000..094901ed --- /dev/null +++ b/src/plugins/sound_canberra.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +from pybitmessage.bitmessageqt import sound + +import pycanberra + +_canberra = pycanberra.Canberra() + +_theme = { + sound.SOUND_UNKNOWN: 'message-new-email', + sound.SOUND_CONNECTED: 'network-connectivity-established', + sound.SOUND_DISCONNECTED: 'network-connectivity-lost', + sound.SOUND_CONNECTION_GREEN: 'network-connectivity-established' +} + + +def connect_plugin(category, label=None): + try: + _canberra.play(0, pycanberra.CA_PROP_EVENT_ID, _theme[category], None) + except (KeyError, pycanberra.CanberraException): + pass diff --git a/src/plugins/sound_gstreamer.py b/src/plugins/sound_gstreamer.py new file mode 100644 index 00000000..062da3f9 --- /dev/null +++ b/src/plugins/sound_gstreamer.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +import gi +gi.require_version('Gst', '1.0') +from gi.repository import Gst # noqa: E402 + +Gst.init(None) +_player = Gst.ElementFactory.make("playbin", "player") + + +def connect_plugin(sound_file): + _player.set_state(Gst.State.NULL) + _player.set_property("uri", "file://" + sound_file) + _player.set_state(Gst.State.PLAYING)