From 57a19540443f56791752f66e06a390bc72539996 Mon Sep 17 00:00:00 2001 From: CongNT3 Date: Mon, 15 Sep 2014 09:38:32 +0700 Subject: [PATCH 1/4] use absolute path for python3 in ibus exec --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9821fff..f7417be 100644 --- a/Makefile +++ b/Makefile @@ -15,9 +15,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@|`which python3` $(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@|`which python3` ${APP_ROOT}/gui/controller.py|g" \ $(IBUS_ROOT)/component/bogo.xml From 6ec03bf54d3b6aa4002495b739e052586b120595 Mon Sep 17 00:00:00 2001 From: CongNT3 Date: Mon, 15 Sep 2014 09:38:32 +0700 Subject: [PATCH 2/4] python path: use dollar shell instead of backtick --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f7417be..dd66880 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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@|`which 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@|`which python3` ${APP_ROOT}/gui/controller.py|g" \ + -e "s|@SETUP_PATH@|${PYTHON} ${APP_ROOT}/gui/controller.py|g" \ $(IBUS_ROOT)/component/bogo.xml From ade6c992145ae547c9c7d694e2e76ff81af0e89c Mon Sep 17 00:00:00 2001 From: CongNT3 Date: Tue, 16 Sep 2014 13:42:09 +0700 Subject: [PATCH 3/4] create only one auto_corrector for all engine --- ibus_engine/ibus_engine.py | 22 +--------------------- ibus_engine/main.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/ibus_engine/ibus_engine.py b/ibus_engine/ibus_engine.py index 670cc63..35121e0 100644 --- a/ibus_engine/ibus_engine.py +++ b/ibus_engine/ibus_engine.py @@ -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 @@ -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, diff --git a/ibus_engine/main.py b/ibus_engine/main.py index 5301f83..967bcf7 100644 --- a/ibus_engine/main.py +++ b/ibus_engine/main.py @@ -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 + "..")) @@ -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: @@ -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": @@ -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 From 109ce4472e1538eddee1bd1179ba74a109ff752c Mon Sep 17 00:00:00 2001 From: CongNT3 Date: Mon, 26 Jan 2015 09:28:54 +0700 Subject: [PATCH 4/4] blacklist by default if xprop can't get windows id --- ibus_engine/base_config.py | 3 ++- ibus_engine/ibus_engine.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ibus_engine/base_config.py b/ibus_engine/base_config.py index bcda482..8325f67 100644 --- a/ibus_engine/base_config.py +++ b/ibus_engine/base_config.py @@ -45,7 +45,8 @@ "lxterminal", "konsole", "geany", - "skype" + "skype", + "__nan", ], "typo-correction-level": 2, "typo-correction-threshold": 1 diff --git a/ibus_engine/ibus_engine.py b/ibus_engine/ibus_engine.py index 35121e0..f0cb5f0 100644 --- a/ibus_engine/ibus_engine.py +++ b/ibus_engine/ibus_engine.py @@ -148,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)