Пример #1
0
    def setup(self):
        self.engine = Mock()
        self.config = {"skip-non-vietnamese": True}
        self.abbr_expander = Mock()
        self.auto_corrector = Mock()

        self.backend = PreeditBackend(engine=self.engine,
                                      config=self.config,
                                      abbr_expander=self.abbr_expander,
                                      auto_corrector=self.auto_corrector)
Пример #2
0
    def __init__(self, config, abbr_expander, icon):
        super().__init__()

        self.config = config
        self.icon = icon
        self.ui_delegate = UiDelegate(engine=self)

        self.preedit_backend = PreeditBackend(engine=self,
                                              config=config,
                                              abbr_expander=abbr_expander)

        self.surrounding_text_backend = SurroundingTextBackend(
            engine=self, config=config, abbr_expander=abbr_expander)

        self.backend = self.preedit_backend

        # Create a new thread to detect mouse clicks
        # mouse_detector = MouseDetector.get_instance()
        # mouse_detector.add_mouse_click_listener(self.reset)

        self.caps = 0

        self.vietnameseMode = True

        self.reset()
Пример #3
0
    def setup(self):
        self.engine = Mock()
        self.config = {
            "skip-non-vietnamese": True
        }
        self.abbr_expander = Mock()
        self.auto_corrector = Mock()

        self.backend = PreeditBackend(
            engine=self.engine,
            config=self.config,
            abbr_expander=self.abbr_expander,
            auto_corrector=self.auto_corrector)
Пример #4
0
    def __init__(self, config, abbr_expander, auto_corrector):
        super().__init__()

        self.caps = 0
        self.vietnameseMode = True

        self.config = config
        self.ui_delegate = UiDelegate(engine=self)

        self.preedit_backend = PreeditBackend(engine=self,
                                              config=config,
                                              abbr_expander=abbr_expander,
                                              auto_corrector=auto_corrector)

        self.surrounding_text_backend = SurroundingTextBackend(
            engine=self,
            config=config,
            abbr_expander=abbr_expander,
            auto_corrector=auto_corrector)

        # The preedit backend is the default
        self.backend = self.preedit_backend
        self.reset()
Пример #5
0
    def __init__(self, config, abbr_expander):
        super().__init__()

        self.caps = 0
        self.vietnameseMode = True

        self.config = config
        self.ui_delegate = UiDelegate(engine=self)

        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')

        auto_corrector = AutoCorrector(config, spellchecker,
                                       english_spellchecker)

        self.preedit_backend = PreeditBackend(engine=self,
                                              config=config,
                                              abbr_expander=abbr_expander,
                                              auto_corrector=auto_corrector)

        self.surrounding_text_backend = SurroundingTextBackend(
            engine=self,
            config=config,
            abbr_expander=abbr_expander,
            auto_corrector=auto_corrector)

        # The preedit backend is the default
        self.backend = self.preedit_backend
        self.reset()
Пример #6
0
class TestPreeditBackend():

    def setup(self):
        self.engine = Mock()
        self.config = {
            "skip-non-vietnamese": True
        }
        self.abbr_expander = Mock()
        self.auto_corrector = Mock()

        self.backend = PreeditBackend(
            engine=self.engine,
            config=self.config,
            abbr_expander=self.abbr_expander,
            auto_corrector=self.auto_corrector)

    def test_update_composition_preedit(self):
        """
        update_composition() should use preedit.
        """
        string = "blah"
        self.engine.update_preedit_text_with_mode = Mock()

        self.backend.update_composition(string)

        self.engine.update_preedit_text_with_mode.assert_called_once()
        args = self.engine.update_preedit_text_with_mode.call_args[1]

        eq_(args["text"].text, string)

    def test_commit_last_correction(self):
        """
        Should commit the last string correction preedit text
        on the next normal key press.
        """
        corrected_string = "ba"
        key = "a"

        self.backend.history.append({
            "type": "string-correction",
            "editing-string": corrected_string,
            "raw-string": "bah"
        })

        self.config["input-method-definition"] = {}
        self.config["input-method"] = "aoe"

        self.backend.commit_composition = Mock()
        self.backend.update_composition = Mock()

        self.backend.process_key_event(ord(key), 0)

        self.backend.commit_composition.assert_called_once_with(
            corrected_string)
        self.backend.update_composition.assert_called_once_with(
            string=key, raw_string=key)

    def test_backspace_preedit(self):
        """
        If there is a preedit showing then it should update the preedit
        with one less character, else it should yield a hard backspace.
        """
        self.backend.update_composition = Mock()
        self.backend.reset = Mock()

        self.backend.history.append({
            "type": "update-composition",
            "editing-string": "a",
            "raw-string": "a"
        })

        result = self.backend.on_special_key_pressed(IBus.BackSpace)

        eq_(result, True)
        self.backend.update_composition.assert_called_once_with("")
Пример #7
0
class TestPreeditBackend():
    def setup(self):
        self.engine = Mock()
        self.config = {"skip-non-vietnamese": True}
        self.abbr_expander = Mock()
        self.auto_corrector = Mock()

        self.backend = PreeditBackend(engine=self.engine,
                                      config=self.config,
                                      abbr_expander=self.abbr_expander,
                                      auto_corrector=self.auto_corrector)

    def test_update_composition_preedit(self):
        """
        update_composition() should use preedit.
        """
        string = "blah"
        self.engine.update_preedit_text_with_mode = Mock()

        self.backend.update_composition(string)

        self.engine.update_preedit_text_with_mode.assert_called_once()
        args = self.engine.update_preedit_text_with_mode.call_args[1]

        eq_(args["text"].text, string)

    def test_commit_last_correction(self):
        """
        Should commit the last string correction preedit text
        on the next normal key press.
        """
        corrected_string = "ba"
        key = "a"

        self.backend.history.append({
            "type": "string-correction",
            "editing-string": corrected_string,
            "raw-string": "bah"
        })

        self.config["input-method-definition"] = {}
        self.config["input-method"] = "aoe"

        self.backend.commit_composition = Mock()
        self.backend.update_composition = Mock()

        self.backend.process_key_event(ord(key), 0)

        self.backend.commit_composition.assert_called_once_with(
            corrected_string)
        self.backend.update_composition.assert_called_once_with(string=key,
                                                                raw_string=key)

    def test_backspace_preedit(self):
        """
        If there is a preedit showing then it should update the preedit
        with one less character, else it should yield a hard backspace.
        """
        self.backend.update_composition = Mock()
        self.backend.reset = Mock()

        self.backend.history.append({
            "type": "update-composition",
            "editing-string": "a",
            "raw-string": "a"
        })

        result = self.backend.on_special_key_pressed(IBus.BackSpace)

        eq_(result, True)
        self.backend.update_composition.assert_called_once_with("")