diff options
author | Daniel Glassey <wdg@debian.org> | 2018-12-22 21:56:13 +0700 |
---|---|---|
committer | Daniel Glassey <wdg@debian.org> | 2018-12-22 21:56:13 +0700 |
commit | 7c57e621d2acc6b84c2df04fe576dc9acd7556a2 (patch) | |
tree | 79d2fd0fbc01608b7197915f785a692d9f53b4ca | |
parent | 61cba6361f8777e65bab989c663f62a7bf51a836 (diff) |
missing_filesarchive/debian/10.99.69-2
Gbp-Pq: Name missing_files.patch
-rw-r--r-- | keyman_config.egg-info/SOURCES.txt | 4 | ||||
-rw-r--r-- | keyman_config/get_info.py | 35 | ||||
-rw-r--r-- | keyman_config/ibus_util.py | 99 |
3 files changed, 137 insertions, 1 deletions
diff --git a/keyman_config.egg-info/SOURCES.txt b/keyman_config.egg-info/SOURCES.txt index 5a0961b..d644591 100644 --- a/keyman_config.egg-info/SOURCES.txt +++ b/keyman_config.egg-info/SOURCES.txt @@ -17,7 +17,9 @@ keyman_config/accelerators.py keyman_config/check_mime_type.py keyman_config/convertico.py keyman_config/downloadkeyboard.py +keyman_config/get_info.py keyman_config/get_kmp.py +keyman_config/ibus_util.py keyman_config/install_kmp.py keyman_config/install_window.py keyman_config/keyboard_details.py @@ -37,4 +39,4 @@ keyman_config/icons/cross20.png keyman_config/icons/defaultpackage.gif keyman_config/icons/expand20.png keyman_config/icons/help20.png -keyman_config/icons/icon_kmp.png
\ No newline at end of file +keyman_config/icons/icon_kmp.png diff --git a/keyman_config/get_info.py b/keyman_config/get_info.py new file mode 100644 index 0000000..c1bc1be --- /dev/null +++ b/keyman_config/get_info.py @@ -0,0 +1,35 @@ +#!/usr/bin/python3 + +import os +import threading +from keyman_config.install_kmp import process_keyboard_data +from keyman_config.kmpmetadata import parsemetadata + +class GetInfo(object): + """ Get information about kmp packages and keyboards + The run() method will be started and it will run in the background. + """ + + def __init__(self, kmp_list): + """ Constructor + :type kmp_list: list + :param kmp_list: List of keyboards to get info for + """ + self.kmp_list = kmp_list + + thread = threading.Thread(target=self.run, args=()) + thread.daemon = True # Daemonize thread + thread.start() # Start the execution + + def run(self): + """ Method that gets info for installed kmp that were installed manually + rather then from the download window. + """ + for kmp in self.kmp_list: + packageDir = os.path.join(kmp['areapath'], kmp['packageID']) + process_keyboard_data(kmp['packageID'], packageDir) + info, system, options, keyboards, files = parsemetadata(packageDir, "kmp.json") + if keyboards: + for kb in keyboards: + if kb['id'] != kmp['packageID']: + process_keyboard_data(kb['id'], packageDir)
\ No newline at end of file diff --git a/keyman_config/ibus_util.py b/keyman_config/ibus_util.py new file mode 100644 index 0000000..9108656 --- /dev/null +++ b/keyman_config/ibus_util.py @@ -0,0 +1,99 @@ +#!/usr/bin/python3 + +import gi +import logging +import subprocess + +gi.require_version('IBus', '1.0') +from gi.repository import IBus, Gio + +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 install_to_ibus(bus, keyboard_id): + try: + # keyboard_id = "%s:%s" % (lang, kmx_file) + # logging.debug("getting bus") + # bus = IBus.Bus() + logging.debug("installing to ibus") + ibus_settings = Gio.Settings.new("org.freedesktop.ibus.general") + preload_engines = ibus_settings.get_strv("preload-engines") + logging.debug(preload_engines) + if keyboard_id not in preload_engines: + preload_engines.append(keyboard_id) + logging.debug(preload_engines) + ibus_settings.set_strv("preload-engines", preload_engines) + bus.preload_engines(preload_engines) + except Exception as e: + logging.warning("Failed to set up install %s to IBus", keyboard_id) + logging.warning(e) + +def uninstall_from_ibus(bus, keyboard_id): +# need to uninstall for all installed langs + try: + # logging.debug("getting bus") + # bus = IBus.Bus() + ibus_settings = Gio.Settings.new("org.freedesktop.ibus.general") + preload_engines = ibus_settings.get_strv("preload-engines") + logging.debug(preload_engines) + if keyboard_id in preload_engines: + preload_engines.remove(keyboard_id) + logging.debug(preload_engines) + ibus_settings.set_strv("preload-engines", preload_engines) + bus.preload_engines(preload_engines) + except Exception as e: + logging.warning("Failed to uninstall keyboard %s", keyboard_id) + logging.warning(e) + +def restart_ibus_subp(): + logging.info("restarting IBus by subprocess") + subprocess.run(["ibus", "restart"]) + +def restart_ibus(bus=None): + try: + if not bus: + bus = get_ibus_bus() + logging.info("restarting IBus") + bus.exit(True) + bus.destroy() + except Exception as e: + logging.warning("Failed to restart IBus") + logging.warning(e) + +def bus_has_engine(bus, name): + engines = bus.get_engines_by_names([name]) + return len(engines) + +def get_current_engine(bus): + try: + contextname = bus.current_input_context() + ic = IBus.InputContext.get_input_context(contextname, bus.get_connection()) + engine = ic.get_engine() + if engine: + return engine.get_name() + except Exception as e: + logging.warning("Failed to get current engine") + logging.warning(e) + + +def change_to_keyboard(bus, keyboard_id): + try: + contextname = bus.current_input_context() + ic = IBus.InputContext.get_input_context(contextname, bus.get_connection()) + if bus_has_engine(bus, name) <= 0: + logging.warning("Could not find engine %s"%name) + else: + ic.set_engine(name) + except Exception as e: + logging.warning("Failed to change keyboard") + logging.warning(e) |