Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
create only one auto_corrector for all engine
Browse files Browse the repository at this point in the history
  • Loading branch information
ntcong committed Apr 2, 2015
1 parent a411b88 commit f22346f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
22 changes: 1 addition & 21 deletions ibus_engine/ibus_engine.py
Expand Up @@ -26,25 +26,21 @@
import os
import subprocess
import logging
import enchant

#from mouse_detector import MouseDetector
from ui import UiDelegate
from preedit_backend import PreeditBackend
from surrounding_text_backend import SurroundingTextBackend
from auto_corrector import AutoCorrector

logger = logging.getLogger(__name__)

ENGINE_PATH = os.path.dirname(__file__)
DICT_PATH = ENGINE_PATH + '/data'
PWL_PATH = os.path.expanduser('~/.config/ibus-bogo/spelling-blacklist.txt')


class Engine(IBus.Engine):
__gtype_name__ = 'EngineBoGo'

def __init__(self, config, abbr_expander):
def __init__(self, config, abbr_expander, auto_corrector):
super().__init__()

self.caps = 0
Expand All @@ -53,22 +49,6 @@ def __init__(self, config, abbr_expander):
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,
Expand Down
21 changes: 20 additions & 1 deletion ibus_engine/main.py
Expand Up @@ -29,6 +29,7 @@
import locale
import logging
import argparse
import enchant

ENGINE_PATH = os.path.dirname(__file__) + "/"
sys.path.append(os.path.abspath(ENGINE_PATH + ".."))
Expand All @@ -37,9 +38,12 @@
from ibus_engine import Engine
from config import Config
from abbr import AbbreviationExpander
from auto_corrector import AutoCorrector


current_path = os.path.dirname(os.path.abspath(__file__))
DICT_PATH = ENGINE_PATH + '/data'
PWL_PATH = os.path.expanduser('~/.config/ibus-bogo/spelling-blacklist.txt')


class IMApp:
Expand Down Expand Up @@ -92,6 +96,21 @@ def __init__(self, exec_by_ibus):
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":
Expand All @@ -118,7 +137,7 @@ def create_engine(self, factory, engine_name):
sys.stderr = stderr
f.close()

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

self.engine_count += 1
return engine
Expand Down

0 comments on commit f22346f

Please sign in to comment.