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 __init__(self): self.__init_curses() self.__bus = IBus.Bus() self.__ic_path = self.__bus.create_input_context("DemoTerm") #self.__ic = IBus.InputContext(self.__bus, self.__ic_path, True) self.__ic = IBus.InputContext() self.__ic.set_capabilities(7) self.__ic.connect("commit-text", self.__commit_text_cb) self.__ic.connect("update-preedit-text", self.__update_preedit_text_cb) self.__ic.connect("show-preedit-text", self.__show_preedit_text_cb) self.__ic.connect("hide-preedit-text", self.__hide_preedit_text_cb) self.__ic.connect("update-auxiliary-text", self.__update_aux_text_cb) self.__ic.connect("show-auxiliary-text", self.__show_aux_text_cb) self.__ic.connect("hide-auxiliary-text", self.__hide_aux_text_cb) self.__ic.connect("update-lookup-table", self.__update_lookup_table_cb) self.__ic.connect("show-lookup-table", self.__show_lookup_table_cb) self.__ic.connect("hide-lookup-table", self.__hide_lookup_table_cb) GLib.io_add_watch(0, GLib.IO_IN, self.__stdin_cb) # GLib.timeout_add(500, self.__timeout_cb) # self.__master_fd, self.__slave_fd = os.openpty() # self.__run_shell() self.__is_invalidate = False self.__preedit = None self.__preedit_visible = False self.__aux_string = None self.__aux_string_visible = False self.__lookup_table = None self.__lookup_table_visible = False
def __init__(self, exec_by_ibus): engine_name = "replace-with-kanji-python" if exec_by_ibus else "replace-with-kanji-python (debug)" self.__component = IBus.Component.new( "org.freedesktop.IBus.ReplaceWithKanji", "Replace With Kanji Input Method", "0.8.0", "Apache", "Esrille Inc. <*****@*****.**>", "https://github.com/esrille/ibus-replace-with-kanji", "/usr/bin/exec", "ibus-replace-with-kanji") engine = IBus.EngineDesc.new("replace-with-kanji-python", engine_name, "Japanese Replace With Kanji", "ja", "Apache", "Esrille Inc. <*****@*****.**>", "", "us") self.__component.add_engine(engine) self.__mainloop = GLib.MainLoop() self.__bus = IBus.Bus() self.__bus.connect("disconnected", self.__bus_disconnected_cb) self.__factory = IBus.Factory.new(self.__bus.get_connection()) self.__factory.add_engine( "replace-with-kanji-python", GObject.type_from_name("EngineReplaceWithKanji")) if exec_by_ibus: self.__bus.request_name("org.freedesktop.IBus.ReplaceWithKanji", 0) else: self.__bus.register_component(self.__component) self.__bus.set_global_engine_async("replace-with-kanji-python", -1, None, None, None)
def __init__(self, exec_by_ibus): self.__mainloop = GObject.MainLoop() self.__bus = IBus.Bus() self.__bus.connect("disconnected", self.__bus_destroy_cb) self.__factory = factory.EngineFactory(self.__bus) self.destroied = False if exec_by_ibus: self.__bus.request_name("org.freedesktop.IBus.Sdim", 0) else: self.__component = IBus.Component("org.freedesktop.IBus.Sdim", "Sdim Component", "0.1.0", "GPL", "Yuwei Yu <*****@*****.**>") name = 'SDIM' longname = name description = 'Shadow Dance Input Method' language = 'zh' license = 'LGPL' author = 'Bao Haojun <*****@*****.**>' icon = icon_dir + "/sdim.png" if icon: icon = os.path.join(icon_dir, icon) if not os.access(icon, os.F_OK): icon = '' layout = 'us' self.__component.add_engine(name, longname, description, language, license, author, icon, layout) self.__bus.register_component(self.__component)
def register_ibus_engine(self) -> bool: self.__bus = IBus.Bus() if not self.__bus.is_connected(): self.fail('ibus-daemon is not running') return False self.__bus.get_connection().signal_subscribe( 'org.freedesktop.DBus', 'org.freedesktop.DBus', 'NameOwnerChanged', '/org/freedesktop/DBus', None, 0, self.__bus_signal_cb, self.__bus) self.__factory = IBus.Factory(object_path=IBus.PATH_FACTORY, connection=self.__bus.get_connection()) self.__factory.connect('create-engine', self.__create_engine_cb) self.__component = IBus.Component( name='org.freedesktop.IBus.TypingBooster.Test', description='Test Typing Booster Component', version='1.0', license='GPL', author=('Mike FABIAN <*****@*****.**>, ' + 'Anish Patil <*****@*****.**>'), homepage='http://mike-fabian.github.io/ibus-typing-booster', command_line='', textdomain='ibus-typing-booster') desc = IBus.EngineDesc( name='testTyping-booster', longname='Test Typing Booster', description='Test a completion input method to speedup typing.', language='t', license='GPL', author=('Mike FABIAN <*****@*****.**>, ' + 'Anish Patil <*****@*****.**>'), icon='', symbol='T') self.__component.add_engine(desc) self.__bus.register_component(self.__component) self.__bus.request_name('org.freedesktop.IBus.TypingBooster.Test', 0) return True
def __init__(self, exec_by_ibus): engine_name = "unicode-db-python" if exec_by_ibus else "unicode-db-python (debug)" self.__component = \ IBus.Component.new("org.freedesktop.IBus.UnicodeDb", "Unicode Db Input Method", "0.1.0", "GPL", "Daniel Sim <*****@*****.**>", "http://example.com", "/usr/bin/exec", "ibus-unicode-db") engine = IBus.EngineDesc.new("unicode-db-python", engine_name, "English Unicode Db", "en", "GPL", "Daniel Sim <*****@*****.**>", "", "us") self.__component.add_engine(engine) self.__mainloop = GLib.MainLoop() self.__bus = IBus.Bus() self.__bus.connect("disconnected", self.__bus_disconnected_cb) self.__factory = IBus.Factory.new(self.__bus.get_connection()) self.__factory.add_engine("unicode-db-python", GObject.type_from_name("EngineUnicodeDb")) if exec_by_ibus: self.__bus.request_name("org.freedesktop.IBus.UnicodeDb", 0) else: self.__bus.register_component(self.__component) self.__bus.set_global_engine_async( "unicode-db-python", -1, None, None, None)
def __init__(self, exec_by_ibus): engine_name = "uniemoji" if not exec_by_ibus: engine_name += " (debug)" global debug_on debug_on = True self.component = \ IBus.Component.new("org.freedesktop.IBus.UniEmoji", "Unicode emoji and symbols by name", "0.1.0", "GPL", "Lalo Martins <*****@*****.**>", "https://github.com/lalomartins/ibus-uniemoji", "/usr/bin/exec", "uniemoji") engine = IBus.EngineDesc.new("uniemoji", engine_name, "Unicode emoji and symbols by name", "", "GPL", "Lalo Martins <*****@*****.**>", "", "us") self.component.add_engine(engine) self.mainloop = GLib.MainLoop() self.bus = IBus.Bus() self.bus.connect("disconnected", self.bus_disconnected_cb) self.factory = IBus.Factory.new(self.bus.get_connection()) self.factory.add_engine("uniemoji", GObject.type_from_name("UniEmoji")) if exec_by_ibus: self.bus.request_name("org.freedesktop.IBus.UniEmoji", 0) else: self.bus.register_component(self.component) self.bus.set_global_engine_async("uniemoji", -1, None, None, None)
def __init__(self, exec_by_ibus): self.__id = 0 engine_name = "BoGo Engine" self.__component = \ IBus.Component.new("org.freedesktop.IBus.BoGoPython", "BoGo Engine for IBus", "0.2", "GPLv3", "Long T. Dam <*****@*****.**>", "https://github.com/BoGoEngine/ibus-bogo-python", "/usr/bin/exec", "ibus-bogo") engine = IBus.EngineDesc(name="bogo-python", longname=engine_name, description="BoGo Engine for IBus", language="vi", license="GPLv3", author="Long T. Dam <*****@*****.**>", icon=current_path + "/data/ibus-bogo.svg", layout="us") self.__component.add_engine(engine) self.__mainloop = GObject.MainLoop() self.__bus = IBus.Bus() self.__bus.connect("disconnected", self.__bus_disconnected_cb) self.__config = Config() self.__factory = IBus.Factory.new(self.__bus.get_connection()) self.__factory.add_engine("bogo-python", GObject.type_from_name("EngineBoGo")) if exec_by_ibus: self.__bus.request_name("org.freedesktop.IBus.BoGoPython", 0) else: self.__bus.register_component(self.__component) self.__bus.set_global_engine_async("bogo-python", -1, None, None, None)
def main(): options = get_options().parse_args() logging.basicConfig( level=logging.DEBUG if options.verbose else logging.WARNING, format='%(levelname) 7s %(name)s:%(lineno)s %(message)s', ) if options.raw: log.warning("Dictating with raw DeepSpeech output") global DEFAULT_PIPE DEFAULT_PIPE = os.path.join(RUN_DIR, 'events') global BUS, MAINLOOP mainloop = MAINLOOP = GLib.MainLoop() bus = BUS = IBus.Bus() def on_disconnected(bus): mainloop.quit() bus.connect('disconnected', on_disconnected) # TODO: we should be checking the result here, the sync method just times out # but the async one seems to work, just takes a while log.debug("Starting mainloop") GLib.idle_add(register_engine, bus, False) mainloop.run()
def __init__(self, exec_by_ibus): command_line = config.LIBEXECDIR + '/ibus-engine-anthy --ibus' self.__component = IBus.Component( name='org.freedesktop.IBus.Anthy', description='Anthy Component', version='0.1.0', license='GPL', author='Peng Huang <*****@*****.**>', homepage='https://github.com/ibus/ibus/wiki', command_line=command_line, textdomain='ibus-anthy') engine = IBus.EngineDesc(name='anthy', longname='Anthy', description='Anthy Input Method', language='ja', license='GPL', author='Peng Huang <*****@*****.**>', icon='ibus-anthy', layout=config.LAYOUT, symbol=config.SYMBOL_CHAR, rank=99) self.__component.add_engine(engine) self.__mainloop = GLib.MainLoop() self.__bus = IBus.Bus() self.__bus.connect('disconnected', self.__bus_disconnected_cb) self.__factory = factory.EngineFactory(self.__bus) if exec_by_ibus: self.__bus.request_name('org.freedesktop.IBus.Anthy', 0) else: self.__bus.register_component(self.__component)
def __init__(self, engine): self.__bus = IBus.Bus() self.__builder = Gtk.Builder() self.__builder.set_translation_domain(DOMAINNAME) self.__builder.add_from_file("ibus-libpinyin-preferences.ui") self.__dialog = self.__builder.get_object("dialog") self.__init_pages() if engine == "libpinyin": self.__config_namespace = "com.github.libpinyin.ibus-libpinyin.libpinyin" self.__config = Gio.Settings.new(self.__config_namespace) self.__init_general() self.__init_pinyin() self.__init_fuzzy() self.__init_dictionary() self.__init_user_data() self.__init_shortcut() self.__init_about() elif engine == "libbopomofo": self.__config_namespace = "com.github.libpinyin.ibus-libpinyin.libbopomofo" self.__config = Gio.Settings.new(self.__config_namespace) self.__init_general() self.__init_bopomofo() self.__init_fuzzy() self.__init_dictionary() #self.__init_user_data() self.__init_shortcut() self.__init_about() self.__convert_fuzzy_pinyin_to_bopomofo() else: print("Error: Unknown Engine") exit() self.__pages.set_current_page(0)
def __init__(self, exec_by_ibus): engine_name = "enchant python" if exec_by_ibus else "enchant python (debug)" self.__component = \ IBus.Component.new("org.freedesktop.IBus.EnchantPython", "Enchant Python Component", "0.1.0", "GPL", "Peng Huang <*****@*****.**>", "http://example.com", "/usr/bin/exec", "ibus-enchant") engine = IBus.EngineDesc.new("enchant-python", engine_name, "English Enchant", "en", "GPL", "Peng Huang <*****@*****.**>", "", "us") self.__component.add_engine(engine) self.__mainloop = GLib.MainLoop() self.__bus = IBus.Bus() self.__bus.connect("disconnected", self.__bus_disconnected_cb) self.__factory = IBus.Factory.new(self.__bus.get_connection()) self.__factory.add_engine("enchant-python", GObject.type_from_name("EngineEnchant")) if exec_by_ibus: self.__bus.request_name("org.freedesktop.IBus.EnchantPython", 0) else: self.__bus.register_component(self.__component) self.__bus.set_global_engine_async("enchant-python", -1, None, None, None)
def save(self, widget, data=None): pagenum = self.notebook.get_current_page() object = self.notebook.get_nth_page(pagenum) self.save_to_file("{}/{}/{}".format(data_dir, self.language, object.filename)) bus = IBus.Bus() bus.set_global_engine("braille")
def __init__(self): locale.setlocale(locale.LC_ALL, "") localedir = os.getenv("IBUS_LOCALEDIR") gettext.bindtextdomain("ibus-table", localedir) gettext.bind_textdomain_codeset("ibus-table", "UTF-8") self.__bus = IBus.Bus() self.__engine_name = None if options.engine_name: # If the engine name is specified on the command line, use that: self.__engine_name = options.engine_name else: # If the engine name is not specified on the command line, # try to get it from the environment. This is necessary # in gnome-shell on Fedora 18,19,20,... because the setup tool is # called without command line options there but the # environment variable IBUS_ENGINE_NAME is set: if 'IBUS_ENGINE_NAME' in os.environ: self.__engine_name = os.environ['IBUS_ENGINE_NAME'] else: self.__run_message_dialog( _("IBUS_ENGINE_NAME environment variable is not set."), Gtk.MessageType.WARNING) if self.__engine_name == None: self.__run_message_dialog( _("Cannot determine the engine name. Please use the --engine-name option." ), Gtk.MessageType.ERROR) sys.exit(1)
def __init__(self, exec_by_ibus: bool) -> None: engine_name = "deepspeech" if exec_by_ibus else "deepspeech (debug)" self.__component = IBus.Component.new( "org.freedesktop.IBus.DeepSpeech", "DeepSpeech Speech Recognition Component", "0.1.0", "GPL", "Mike Sheldon <*****@*****.**>", "https://github.com/Elleo/ibus-deepspeech", "/usr/bin/exec", "ibus-deepspeech", ) engine = IBus.EngineDesc.new( "deepspeech", engine_name, "English Speech Recognition (DeepSpeech)", "en", "GPL", "Mike Sheldon <*****@*****.**>", "", "us", ) self.__component.add_engine(engine) self.__mainloop = GLib.MainLoop() self.__bus = IBus.Bus() self.__bus.connect("disconnected", self.__bus_disconnected_cb) self.__factory = IBus.Factory.new(self.__bus.get_connection()) self.__factory.add_engine("deepspeech", GObject.type_from_name("EngineDeepSpeech")) if exec_by_ibus: self.__bus.request_name("org.freedesktop.IBus.DeepSpeech", 0) else: self.__bus.register_component(self.__component) self.__bus.set_global_engine_async("deepspeech", -1, None, None, None)
def __init__(self, exec_by_ibus): self._mainloop = GLib.MainLoop() self._bus = IBus.Bus() self._bus.connect("disconnected", self._bus_disconnected_cb) self._factory = IBus.Factory(self._bus) self._factory.add_engine("hiragana", GObject.type_from_name("EngineHiragana")) if exec_by_ibus: self._bus.request_name("org.freedesktop.IBus.Hiragana", 0) else: self._component = IBus.Component( name="org.freedesktop.IBus.Hiragana", description="Hiragana IME", version=package.get_version(), license="Apache", author="Esrille Inc. <*****@*****.**>", homepage="https://github.com/esrille/" + package.get_name(), textdomain=package.get_name()) engine = IBus.EngineDesc(name="hiragana", longname="Hiragana IME", description="Hiragana IME", language="ja", license="Apache", author="Esrille Inc. <*****@*****.**>", icon=package.get_name(), layout="default") self._component.add_engine(engine) self._bus.register_component(self._component) self._bus.set_global_engine_async("hiragana", -1, None, None, None)
def __init__(self, engine, parent=None): self.__bus = IBus.Bus() self.__config = self.__bus.get_config() self.__builder = Gtk.Builder() self.__builder.set_translation_domain("ibus-libzhuyin") self.__builder.add_from_file("ibus-libzhuyin-preferences.ui") self.__window = self.__builder.get_object("window") self.__init_pages() if engine == "zhuyin": self.__config_namespace = "engine/zhuyin" self.__values = dict( self.__config.get_values(self.__config_namespace)) self.__init_inputting() self.__init_keyboard() self.__init_fuzzy_zhuyin() self.__init_user_phrases() self.__init_about() self.__update_fuzzy_zhuyin() else: print("Error: Unknown Engine") exit() self.__pages.set_current_page(0) self.__window.connect("delete-event", Gtk.main_quit)
def get_ibus_bus(): """Get the ibus bus object, possibly starting the ibus daemon if it's not already running. :raises: **RuntimeError** in the case of ibus-daemon being unavailable. """ bus = IBus.Bus() if bus.is_connected(): return bus main_loop = GLib.MainLoop() timeout = 5 GLib.timeout_add_seconds(timeout, lambda *args: main_loop.quit()) bus.connect("connected", lambda *args: main_loop.quit()) os.spawnlp(os.P_NOWAIT, "ibus-daemon", "ibus-daemon", "--xim") main_loop.run() if not bus.is_connected(): raise RuntimeError("Could not start ibus-daemon after %d seconds." % (timeout)) return bus
def __init__(self): locale.setlocale(locale.LC_ALL, "") localedir = os.getenv("IBUS_LOCALEDIR") gettext.bindtextdomain("ibus-table", localedir) gettext.bind_textdomain_codeset("ibus-table", "UTF-8") self.__bus = IBus.Bus() self.__engine_name = None if _OPTIONS.engine_name: # If the engine name is specified on the command line, use that: self.__engine_name = _OPTIONS.engine_name else: # If the engine name is not specified on the command line, # try to get it from the environment. This is necessary # in gnome-shell on Fedora 18,19,20,... because the setup tool is # called without command line options there but the # environment variable IBUS_ENGINE_NAME is set: if 'IBUS_ENGINE_NAME' in os.environ: self.__engine_name = os.environ['IBUS_ENGINE_NAME'] else: self.__run_message_dialog( _("IBUS_ENGINE_NAME environment variable is not set."), Gtk.MessageType.WARNING) if self.__engine_name is None: self.__run_message_dialog( _("Cannot determine the engine name. Please use the --engine-name option."), Gtk.MessageType.ERROR) sys.exit(1) short_engine_name = re.sub( r'^table:', '', self.__engine_name).replace(" ", "_") self.__gsettings = Gio.Settings( schema='org.freedesktop.ibus.engine.table', path='/org/freedesktop/ibus/engine/table/%s/' %short_engine_name) self.__gsettings.connect('changed', self.on_gsettings_value_changed)
def restore(self, widget, data=None): try: os.remove("{}/isb.cfg".format(home_dir)) except: pass bus = IBus.Bus() bus.set_global_engine("sharada-braille") Gtk.main_quit()
def apply(self, widget, data=None): file = open("{}/isb.cfg".format(home_dir), "w") self.config.set('cfg', "checked_languages", str(','.join(self.checked_languages))) self.config.write(file) file.close() bus = IBus.Bus() bus.set_global_engine("sharada-braille") Gtk.main_quit()
def setUp(self): self.bus = IBus.Bus() self.db = tabsqlitedb.TabSqliteDb(user_db_file = ':memory:') self.engine = TypingBoosterEngine( self.bus, '/com/redhat/IBus/engines/table/typing_booster/engine/0', self.db, unit_test = True) self.backup_original_settings() self.set_default_settings()
def restore_engine(): global default_engine if default_engine == 'hiragana': return try: logger.info("restore_engine %s", default_engine) bus = IBus.Bus() bus.set_global_engine(default_engine) except Exception as e: logger.error(str(e))
def __init__(self): self.__lk_engine = LekhaneeEngine() #self.__lk_engine.set_im(self) self.__component = IBus.Component.new_from_file("lekhanee.xml") self.__mainloop = GLib.MainLoop() self.__bus = IBus.Bus() self.__bus.connect("disconnected", self.__bus_disconnected_cb) self.__factory = IBus.Factory.new(self.__bus.get_connection()) #self.__factory.add_engine("Lekhanee", GObject.type_from_name("Lekhanee")) self.__factory.add_engine("Lekhanee", self.__lk_engine) self.__bus.register_component(self.__component) self.__bus.set_global_engine_async("Lekhanee", -1, None, None, None)
def get_ibus_bus(): try: for i in range(10000): bus = IBus.Bus() if bus.is_connected() and bus.is_global_engine_enabled(): return bus bus.destroy() except Exception as e: logging.warning("Failed get bus") logging.warning(e) logging.warning("could not find connected IBus.Bus") return None
def save_all(self, widget, data=None): for pagenum in range(0, self.notebook.get_n_pages()): object = self.notebook.get_nth_page(pagenum) file = open( "{}/{}/{}".format(data_dir, self.language, object.filename), "w") for item in object.liststore: key, val = item file.write("{} {}\n".format(key, val)) file.close() bus = IBus.Bus() bus.set_global_engine("braille")
def check_engine(): global default_engine try: bus = IBus.Bus() engine = bus.get_global_engine() default_engine = engine.get_name() logger.info("check_engine %s", default_engine) if default_engine == 'hiragana': return bus.set_global_engine('hiragana') except Exception as e: logger.error(str(e))
def main(): mainloop = MAINLOOP = GLib.MainLoop() bus = BUS = IBus.Bus() def on_disconnected(bus): mainloop.quit() bus.connect('disconnected', on_disconnected) # TODO: we should be checking the result here, the sync method just times out # but the async one seems to work, just takes a while log.debug("Starting mainloop") mainloop.run()
def setUp(self): self.bus = IBus.Bus() # it doesn’t really matter which config file for which language is used self.db = tabsqlitedb.tabsqlitedb( config_filename ='../hunspell-tables/de_DE.conf', user_db_file = ':memory:') self.engine = TypingBoosterEngine( self.bus, '/com/redhat/IBus/engines/table/typing_booster_de_DE/engine/0', self.db, unit_test = True) self.backup_original_settings() self.set_default_settings()
def set_up(engine_name): global TABSQLITEDB global ENGINE bus = IBus.Bus() db_dir = '/usr/share/ibus-table/tables' db_file = os.path.join(db_dir, engine_name + '.db') TABSQLITEDB = tabsqlitedb.TabSqliteDb(filename=db_file, user_db=':memory:') ENGINE = TabEngine(bus, '/com/redhat/IBus/engines/table/%s/engine/0' % engine_name, TABSQLITEDB, unit_test=True) backup_original_settings() set_default_settings()