Exemple #1
0
    def __init__(self, exec_by_ibus):
        engine_name = "bogo"
        long_engine_name = "BoGo"
        author = "BoGo Development Team <*****@*****.**>"
        description = "ibus-bogo for IBus"
        version = "0.4"
        license = "GPLv3"

        self.component = \
            IBus.Component.new("org.freedesktop.IBus.BoGo",
                               description,
                               version,
                               license,
                               author,
                               "https://github.com/BoGoEngine/ibus-bogo",
                               "/usr/bin/exec",
                               "ibus-bogo")

        engine = IBus.EngineDesc(
            name=engine_name,
            longname=long_engine_name,
            description=description,
            language="vi",
            license=license,
            author=author,
            icon=current_path + "/data/ibus-bogo-dev.svg",
            # icon = "ibus-bogo",
            layout="default")

        self.component.add_engine(engine)
        self.mainloop = GObject.MainLoop()
        self.bus = IBus.Bus()
        self.bus.connect("disconnected", self.bus_disconnected_cb)

        self.engine_count = 0
        self.factory = IBus.Factory.new(self.bus.get_connection())
        self.factory.connect("create-engine", self.create_engine)

        CONFIG_DIR = os.path.expanduser("~/.config/ibus-bogo/")
        self.config = Config()
        self.abbr_expander = AbbreviationExpander(config=self.config)
        self.abbr_expander.watch_file(CONFIG_DIR + "/abbr_rules.json")

        if exec_by_ibus:
            self.bus.request_name("org.freedesktop.IBus.BoGo", 0)
        else:
            self.bus.register_component(self.component)
            self.bus.set_global_engine_async("bogo", -1, None, None, None)
        custom_broker = enchant.Broker()
        custom_broker.set_param('enchant.myspell.dictionary.path', DICT_PATH)

        spellchecker = enchant.DictWithPWL('vi_VN_telex',
                                           pwl=PWL_PATH,
                                           broker=custom_broker)

        # FIXME: Catch enchant.errors.DictNotFoundError exception here.
        english_spellchecker = enchant.Dict('en_US')

        self.auto_corrector = AutoCorrector(self.config, spellchecker,
                                            english_spellchecker)
Exemple #2
0
    def __init__(self, exec_by_ibus):
        engine_name = "bogo"
        long_engine_name = "BoGo"
        author = "BoGo Development Team <*****@*****.**>"
        description = "ibus-bogo for IBus"
        version = "0.4"
        license = "GPLv3"

        self.component = \
            IBus.Component.new("org.freedesktop.IBus.BoGo",
                               description,
                               version,
                               license,
                               author,
                               "https://github.com/BoGoEngine/ibus-bogo",
                               "/usr/bin/exec",
                               "ibus-bogo")

        engine = IBus.EngineDesc(name=engine_name,
                                 longname=long_engine_name,
                                 description=description,
                                 language="vi",
                                 license=license,
                                 author=author,
                                 icon=current_path + "/data/ibus-bogo-dev.svg",
                                 # icon = "ibus-bogo",
                                 layout="default")

        self.component.add_engine(engine)
        self.mainloop = GObject.MainLoop()
        self.bus = IBus.Bus()
        self.bus.connect("disconnected", self.bus_disconnected_cb)

        self.engine_count = 0
        self.factory = IBus.Factory.new(self.bus.get_connection())
        self.factory.connect("create-engine", self.create_engine)

        CONFIG_DIR = os.path.expanduser("~/.config/ibus-bogo/")
        self.config = Config()
        self.abbr_expander = AbbreviationExpander(config=self.config)
        self.abbr_expander.watch_file(CONFIG_DIR + "/abbr_rules.json")
        self.icon = TrayIcon()

        if exec_by_ibus:
            self.bus.request_name("org.freedesktop.IBus.BoGo", 0)
        else:
            self.bus.register_component(self.component)
            self.bus.set_global_engine_async(
                "bogo", -1, None, None, None)
Exemple #3
0
    def setup(self):
        config = {
            "input-method": "telex",
            "output-charset": "utf-8",
            "skip-non-vietnamese": True,
            "auto-capitalize-abbreviations": False,
            "input-method-definition": {
                "a": "a^",
                "o": "o^",
                "e": "e^",
                "w": ["u*", "o*", "a+", "<ư"],
                "d": "d-",
                "f": "\\",
                "s": "/",
                "r": "?",
                "x": "~",
                "j": ".",
                "]": "<ư",
                "[": "<ơ",
                "}": "<Ư",
                "{": "<Ơ"
            },
        }

        self.eng = BaseBackend(
            config=config,
            abbr_expander=AbbreviationExpander(config),
            auto_corrector=None)
Exemple #4
0
    def __init__(self, exec_by_ibus):
        engine_name = "bogo"
        long_engine_name = "BoGo"
        author = "BoGo Development Team <*****@*****.**>"
        description = "ibus-bogo for IBus"
        version = "0.4"
        license = "GPLv3"

        self.component = \
            IBus.Component.new("org.freedesktop.IBus.BoGo",
                               description,
                               version,
                               license,
                               author,
                               "https://github.com/BoGoEngine/ibus-bogo",
                               "/usr/bin/exec",
                               "ibus-bogo")

        engine = IBus.EngineDesc(name=engine_name,
                                 longname=long_engine_name,
                                 description=description,
                                 language="vi",
                                 license=license,
                                 author=author,
                                 icon=current_path + "/data/ibus-bogo-dev.svg",
                                 # icon = "ibus-bogo",
                                 layout="default")

        self.component.add_engine(engine)
        self.mainloop = GObject.MainLoop()
        self.bus = IBus.Bus()
        self.bus.connect("disconnected", self.bus_disconnected_cb)

        self.engine_count = 0
        self.factory = IBus.Factory.new(self.bus.get_connection())
        self.factory.connect("create-engine", self.create_engine)

        CONFIG_DIR = os.path.expanduser("~/.config/ibus-bogo/")
        self.config = Config()
        self.abbr_expander = AbbreviationExpander(config=self.config)
        self.abbr_expander.watch_file(CONFIG_DIR + "/abbr_rules.json")

        if exec_by_ibus:
            self.bus.request_name("org.freedesktop.IBus.BoGo", 0)
        else:
            self.bus.register_component(self.component)
            self.bus.set_global_engine_async(
                "bogo", -1, None, None, None)
        custom_broker = enchant.Broker()
        custom_broker.set_param(
            'enchant.myspell.dictionary.path',
            DICT_PATH)

        spellchecker = enchant.DictWithPWL(
            'vi_VN_telex',
            pwl=PWL_PATH,
            broker=custom_broker)

        # FIXME: Catch enchant.errors.DictNotFoundError exception here.
        english_spellchecker = enchant.Dict('en_US')

        self.auto_corrector = AutoCorrector(
            self.config, spellchecker, english_spellchecker)
Exemple #5
0
class IMApp:

    def __init__(self, exec_by_ibus):
        engine_name = "bogo"
        long_engine_name = "BoGo"
        author = "BoGo Development Team <*****@*****.**>"
        description = "ibus-bogo for IBus"
        version = "0.4"
        license = "GPLv3"

        self.component = \
            IBus.Component.new("org.freedesktop.IBus.BoGo",
                               description,
                               version,
                               license,
                               author,
                               "https://github.com/BoGoEngine/ibus-bogo",
                               "/usr/bin/exec",
                               "ibus-bogo")

        engine = IBus.EngineDesc(name=engine_name,
                                 longname=long_engine_name,
                                 description=description,
                                 language="vi",
                                 license=license,
                                 author=author,
                                 icon=current_path + "/data/ibus-bogo-dev.svg",
                                 # icon = "ibus-bogo",
                                 layout="default")

        self.component.add_engine(engine)
        self.mainloop = GObject.MainLoop()
        self.bus = IBus.Bus()
        self.bus.connect("disconnected", self.bus_disconnected_cb)

        self.engine_count = 0
        self.factory = IBus.Factory.new(self.bus.get_connection())
        self.factory.connect("create-engine", self.create_engine)

        CONFIG_DIR = os.path.expanduser("~/.config/ibus-bogo/")
        self.config = Config()
        self.abbr_expander = AbbreviationExpander(config=self.config)
        self.abbr_expander.watch_file(CONFIG_DIR + "/abbr_rules.json")

        if exec_by_ibus:
            self.bus.request_name("org.freedesktop.IBus.BoGo", 0)
        else:
            self.bus.register_component(self.component)
            self.bus.set_global_engine_async(
                "bogo", -1, None, None, None)
        custom_broker = enchant.Broker()
        custom_broker.set_param(
            'enchant.myspell.dictionary.path',
            DICT_PATH)

        spellchecker = enchant.DictWithPWL(
            'vi_VN_telex',
            pwl=PWL_PATH,
            broker=custom_broker)

        # FIXME: Catch enchant.errors.DictNotFoundError exception here.
        english_spellchecker = enchant.Dict('en_US')

        self.auto_corrector = AutoCorrector(
            self.config, spellchecker, english_spellchecker)

    def create_engine(self, factory, engine_name):
        if engine_name == "bogo":
            dbus_path = "/org/freedesktop/IBus/Engine/%d" % self.engine_count

            # It looks like the GObject's new_with_type constructor also
            # calls __init__ but without arguments so there will be error
            # messages like this:
            #
            # TypeError: __init__() missing 1 required positional argument
            #
            # We will ignore that message by temporarily redirect stderr
            # to /dev/null

            f = open('/dev/null', 'w')
            stderr = sys.stderr
            sys.stderr = f

            engine = Engine.new_with_type(GObject.type_from_name("EngineBoGo"),
                                          "bogo-python",
                                          dbus_path,
                                          self.bus.get_connection())

            sys.stderr = stderr
            f.close()

            Engine.__init__(engine, self.config, self.abbr_expander, self.auto_corrector)

            self.engine_count += 1
            return engine

    def run(self):
        self.mainloop.run()

    def bus_disconnected_cb(self, bus):
        self.mainloop.quit()
 def setup(self):
     self.config = {"auto-capitalize-expansion": False}
     self.abbr = AbbreviationExpander(config=self.config)
class TestAbbreviationExpander():
    def setup(self):
        self.config = {"auto-capitalize-expansion": False}
        self.abbr = AbbreviationExpander(config=self.config)

    def tear_down(self):
        # Delete the test file
        pass

    def test_no_rule(self):
        eq_(self.abbr.expand("lorem ipsum"), "lorem ipsum")

    def test_simple_rule(self):
        self.abbr.add_rule("a", "abc")
        eq_(self.abbr.expand("a"), "abc")

    @attr('skip-travis')
    def test_watch_file_content(self):
        import tempfile

        f = tempfile.NamedTemporaryFile(mode="w")
        f.write('{}')
        f.file.flush()

        loop = GObject.MainLoop()

        def mainloop():
            self.abbr.watch_file(f.name)
            loop.run()

        threading.Thread(target=mainloop).start()

        time.sleep(2)

        f.file.seek(0)
        f.write('{"a" : "abc"}')
        f.file.flush()

        time.sleep(2)

        try:
            eq_(self.abbr.expand("a"), "abc")
        finally:
            loop.quit()

        f.close()

    def test_auto_capitalization(self):
        self.abbr.add_rule("tm", "thay mat")

        eq_(self.abbr.expand("tm"), "thay mat")
        eq_(self.abbr.expand("Tm"), "Tm")
        eq_(self.abbr.expand("TM"), "TM")

        self.config["auto-capitalize-expansion"] = True

        eq_(self.abbr.expand("tm"), "thay mat")
        eq_(self.abbr.expand("Tm"), "Thay mat")
        eq_(self.abbr.expand("TM"), "THAY MAT")
Exemple #8
0
class IMApp:

    def __init__(self, exec_by_ibus):
        engine_name = "bogo"
        long_engine_name = "BoGo"
        author = "BoGo Development Team <*****@*****.**>"
        description = "ibus-bogo for IBus"
        version = "0.4"
        license = "GPLv3"

        self.component = \
            IBus.Component.new("org.freedesktop.IBus.BoGo",
                               description,
                               version,
                               license,
                               author,
                               "https://github.com/BoGoEngine/ibus-bogo",
                               "/usr/bin/exec",
                               "ibus-bogo")

        engine = IBus.EngineDesc(name=engine_name,
                                 longname=long_engine_name,
                                 description=description,
                                 language="vi",
                                 license=license,
                                 author=author,
                                 icon=current_path + "/data/ibus-bogo-dev.svg",
                                 # icon = "ibus-bogo",
                                 layout="default")

        self.component.add_engine(engine)
        self.mainloop = GObject.MainLoop()
        self.bus = IBus.Bus()
        self.bus.connect("disconnected", self.bus_disconnected_cb)

        self.engine_count = 0
        self.factory = IBus.Factory.new(self.bus.get_connection())
        self.factory.connect("create-engine", self.create_engine)

        CONFIG_DIR = os.path.expanduser("~/.config/ibus-bogo/")
        self.config = Config()
        self.abbr_expander = AbbreviationExpander(config=self.config)
        self.abbr_expander.watch_file(CONFIG_DIR + "/abbr_rules.json")
        self.icon = TrayIcon()

        if exec_by_ibus:
            self.bus.request_name("org.freedesktop.IBus.BoGo", 0)
        else:
            self.bus.register_component(self.component)
            self.bus.set_global_engine_async(
                "bogo", -1, None, None, None)

    def create_engine(self, factory, engine_name):
        if engine_name == "bogo":
            dbus_path = "/org/freedesktop/IBus/Engine/%d" % self.engine_count

            # It looks like the GObject's new_with_type constructor also
            # calls __init__ but without arguments so there will be error
            # messages like this:
            #
            # TypeError: __init__() missing 1 required positional argument
            #
            # We will ignore that message by temporarily redirect stderr
            # to /dev/null

            f = open('/dev/null', 'w')
            stderr = sys.stderr
            sys.stderr = f

            engine = Engine.new_with_type(GObject.type_from_name("EngineBoGo"),
                                          "bogo-python",
                                          dbus_path,
                                          self.bus.get_connection())

            sys.stderr = stderr
            f.close()

            Engine.__init__(engine, self.config, self.abbr_expander, self.icon)

            self.engine_count += 1
            return engine

    def run(self):
        self.mainloop.run()

    def bus_disconnected_cb(self, bus):
        self.mainloop.quit()
class TestAbbreviationExpander():

    def setup(self):
        self.config = {
            "auto-capitalize-expansion": False
        }
        self.abbr = AbbreviationExpander(config=self.config)

    def tear_down(self):
        # Delete the test file
        pass

    def test_no_rule(self):
        eq_(self.abbr.expand("lorem ipsum"), "lorem ipsum")

    def test_simple_rule(self):
        self.abbr.add_rule("a", "abc")
        eq_(self.abbr.expand("a"), "abc")

    @attr('skip-travis')
    def test_watch_file_content(self):
        import tempfile

        f = tempfile.NamedTemporaryFile(mode="w")
        f.write('{}')
        f.file.flush()

        loop = GObject.MainLoop()

        def mainloop():
            self.abbr.watch_file(f.name)
            loop.run()

        threading.Thread(target=mainloop).start()

        time.sleep(2)

        f.file.seek(0)
        f.write('{"a" : "abc"}')
        f.file.flush()

        time.sleep(2)

        try:
            eq_(self.abbr.expand("a"), "abc")
        finally:
            loop.quit()

        f.close()

    def test_auto_capitalization(self):
        self.abbr.add_rule("tm", "thay mat")

        eq_(self.abbr.expand("tm"), "thay mat")
        eq_(self.abbr.expand("Tm"), "Tm")
        eq_(self.abbr.expand("TM"), "TM")

        self.config["auto-capitalize-expansion"] = True

        eq_(self.abbr.expand("tm"), "thay mat")
        eq_(self.abbr.expand("Tm"), "Thay mat")
        eq_(self.abbr.expand("TM"), "THAY MAT")
 def setup(self):
     self.config = {
         "auto-capitalize-expansion": False
     }
     self.abbr = AbbreviationExpander(config=self.config)