Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
PREFIX = /usr
APP_ROOT = $(DESTDIR)$(PREFIX)/share/ibus-bogo
IBUS_ROOT = $(DESTDIR)$(PREFIX)/share/ibus
PYTHON = $(shell which python3)

all:


run:
python3 ibus_engine/main.py
${PYTHON} ibus_engine/main.py

install:
# TODO: More fine-grain copying
Expand All @@ -15,9 +16,9 @@ install:
mkdir --parent $(IBUS_ROOT)/component/
cp ibus_engine/data/bogo.xml $(IBUS_ROOT)/component/
sed -i \
-e "s|@EXEC_PATH@|python3 $(APP_ROOT)/ibus_engine/main.py|g" \
-e "s|@EXEC_PATH@|${PYTHON} $(APP_ROOT)/ibus_engine/main.py|g" \
-e "s|@ICON_PATH@|${APP_ROOT}/ibus_engine/data/ibus-bogo-dev.svg|g" \
-e "s|@SETUP_PATH@|python3 ${APP_ROOT}/gui/controller.py|g" \
-e "s|@SETUP_PATH@|${PYTHON} ${APP_ROOT}/gui/controller.py|g" \
$(IBUS_ROOT)/component/bogo.xml


Expand Down
3 changes: 2 additions & 1 deletion ibus_engine/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"lxterminal",
"konsole",
"geany",
"skype"
"skype",
"__nan",
],
"typo-correction-level": 2,
"typo-correction-threshold": 1
Expand Down
29 changes: 6 additions & 23 deletions ibus_engine/ibus_engine.py
Original file line number Diff line number Diff line change
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 Expand Up @@ -168,8 +148,11 @@ def find_focused_executable(self):
"awk '/_NET_WM_PID\(CARDINAL\)/{print $NF}'",
shell=True).decode().strip()

self.focused_exe = os.path.realpath(
"/proc/{0}/exe".format(focused_pid))
if focused_pid:
self.focused_exe = os.path.realpath(
"/proc/{0}/exe".format(focused_pid))
else:
self.focused_exe = '__nan'

logger.debug("%s focused", self.focused_exe)

Expand Down
21 changes: 20 additions & 1 deletion ibus_engine/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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 @@ -35,9 +36,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 @@ -90,6 +94,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 @@ -116,7 +135,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