Commit e61f3513 authored by Mathieu Bridon's avatar Mathieu Bridon

Stop bundling pycanberra

It came to my attention that pycanberra is LGPLv2 only, while IBus
Cangjie is LGPLv3+.

The mix of the two, bundled together might be problematic, so to avoid
any issue, dropping our copy of pycanberra is the easiest way out.

The code was already handling errors to play sound anyway (no sound
would be played, so let's generalize that to the case where pycanberra
is just not available.
parent 8a6dca08
......@@ -69,7 +69,6 @@ ibus_cangjie_PYTHON = \
src/__init__.py \
src/config.py \
src/engine.py \
src/pycanberra.py \
$(NULL)
ibus_cangjiedir = $(pythondir)/ibus_cangjie
nodist_ibus_cangjie_PYTHON = src/config.py
......
......@@ -42,14 +42,21 @@ To use this engine, you will need the following:
- pycangjie
-> https://github.com/bochecha/pycangjie
- pycanberra
Not needed currently as we bundle it. More details at the end of this
document.
-> https://github.com/psykoyiko/pycanberra
- the Python 3 GObject bindings
-> https://live.gnome.org/PyGObject
- pycanberra (optional)
This is needed to play event sounds, especially to give feedback to the
user on incorrect inputs.
-> https://github.com/psykoyiko/pycanberra
Note that we require a Python 3 version of pycanberra, as can be found
in this (yet-unmerged) pull request:
-> https://github.com/psykoyiko/pycanberra/pull/2
IBus Cangjie will fail gracefully if pycanberra is not available though,
and just won't play any sound.
Legal
=====
......@@ -58,19 +65,3 @@ License (LGPL) version 3 or any later version.
We won't ask you to sign a copyright assignment or any other long and tedious
legal document, so just send us your patches!
pycanberra
==========
ibus-cangjie requires pycanberra to play event sounds.
However, pycanberra hasn't been ported to Python 3 yet:
https://github.com/psykoyiko/pycanberra/pull/2
To avoid being blocked, we are currently bundling it in ibus-cangjie.
It is a temporary solution, though, which should be resolved as soon as
possible.
pycanberra is under the LGPL license, you can get it from there:
https://github.com/psykoyiko/pycanberra/blob/master/COPYING
......@@ -27,9 +27,8 @@ from gi.repository import IBus
try:
import pycanberra
except ImportError:
# Fall back on the bundled version, until upstream ports to Python 3:
# https://github.com/psykoyiko/pycanberra/pull/2
from . import pycanberra
# Too bad, the user won't get sound feedback on errors
pass
import cangjie
......@@ -386,10 +385,10 @@ class Engine(IBus.Engine):
def play_error_bell(self):
"""Play an error sound, to notify the user of invalid input."""
if not hasattr(self, "canberra"):
self.canberra = pycanberra.Canberra()
try:
if not hasattr(self, "canberra"):
self.canberra = pycanberra.Canberra()
self.canberra.play(1, pycanberra.CA_PROP_EVENT_ID, "dialog-error",
pycanberra.CA_PROP_MEDIA_ROLE, "error", None)
except:
......
This diff is collapsed.
#!@PYTHON_BIN@
import os
import sys
import unittest
......@@ -118,10 +119,10 @@ sys.modules["gi.repository.IBus"].PropList = MockPropList
try:
import pycanberra
sys.modules["pycanberra"].Canberra = MockCanberra
os.environ["IBUS_CANGJIE_TESTS_HAVE_PYCANBERRA"] = "true"
except ImportError:
# Fall back on the bundled version, until upstream ports to Python 3:
# https://github.com/psykoyiko/pycanberra/pull/2
sys.modules["src.pycanberra"].Canberra = MockCanberra
# Let the tests know that they shouldn't try pycanberra
os.environ["IBUS_CANGJIE_TESTS_HAVE_PYCANBERRA"] = "false"
# -- Load and run our unit tests ---------------------------------------------
......
import os
import unittest
from gi.repository import IBus
......@@ -73,14 +74,18 @@ class CangjieTestCase(unittest.TestCase):
self.assertEqual(len(self.engine._mock_auxiliary_text), 5)
self.assertEqual(len(self.engine._mock_committed_text), 0)
self.assertEqual(self.engine.lookuptable.get_number_of_candidates(), 0)
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
if os.environ["IBUS_CANGJIE_TESTS_HAVE_PYCANBERRA"] == "true":
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
# And once more
self.engine.do_process_key_event(IBus.a, 0, 0)
self.assertEqual(len(self.engine._mock_auxiliary_text), 5)
self.assertEqual(len(self.engine._mock_committed_text), 0)
self.assertEqual(self.engine.lookuptable.get_number_of_candidates(), 0)
self.assertEqual(len(self.engine.canberra._mock_played_events), 2)
if os.environ["IBUS_CANGJIE_TESTS_HAVE_PYCANBERRA"] == "true":
self.assertEqual(len(self.engine.canberra._mock_played_events), 2)
def test_inexistent_combination(self):
self.engine.do_process_key_event(IBus.z, 0, 0)
......@@ -93,7 +98,9 @@ class CangjieTestCase(unittest.TestCase):
self.assertEqual(len(self.engine._mock_auxiliary_text), 5)
self.assertEqual(len(self.engine._mock_committed_text), 0)
self.assertEqual(self.engine.lookuptable.get_number_of_candidates(), 0)
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
if os.environ["IBUS_CANGJIE_TESTS_HAVE_PYCANBERRA"] == "true":
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
def test_wildcard(self):
self.engine.do_process_key_event(IBus.d, 0, 0)
......@@ -126,7 +133,9 @@ class CangjieTestCase(unittest.TestCase):
self.assertEqual(len(self.engine._mock_auxiliary_text), 2)
self.assertEqual(len(self.engine._mock_committed_text), 0)
self.assertEqual(self.engine.lookuptable.get_number_of_candidates(), 0)
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
if os.environ["IBUS_CANGJIE_TESTS_HAVE_PYCANBERRA"] == "true":
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
def test_backspace(self):
self.engine.do_process_key_event(IBus.a, 0, 0)
......@@ -194,7 +203,9 @@ class CangjieTestCase(unittest.TestCase):
self.engine.do_process_key_event(IBus.z, 0, 0)
self.engine.do_process_key_event(IBus.space, 0, 0)
self.assertEqual(len(self.engine._mock_auxiliary_text), 2)
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
if os.environ["IBUS_CANGJIE_TESTS_HAVE_PYCANBERRA"] == "true":
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
# Now go on inputting
self.engine.do_process_key_event(IBus.z, 0, 0)
......@@ -211,7 +222,9 @@ class CangjieTestCase(unittest.TestCase):
self.engine.do_process_key_event(IBus.z, 0, 0)
self.engine.do_process_key_event(IBus.space, 0, 0)
self.assertEqual(len(self.engine._mock_auxiliary_text), 5)
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
if os.environ["IBUS_CANGJIE_TESTS_HAVE_PYCANBERRA"] == "true":
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
# Now go on inputting
self.engine.do_process_key_event(IBus.z, 0, 0)
......
import os
import unittest
from gi.repository import IBus
......@@ -75,7 +76,9 @@ class QuickTestCase(unittest.TestCase):
self.assertEqual(len(self.engine._mock_auxiliary_text), 2)
self.assertEqual(len(self.engine._mock_committed_text), 0)
self.assertEqual(self.engine.lookuptable.get_number_of_candidates(), 0)
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
if os.environ["IBUS_CANGJIE_TESTS_HAVE_PYCANBERRA"] == "true":
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
def test_nowildcard(self):
self.engine.do_process_key_event(IBus.d, 0, 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment