diff options
author | glasseyes <dglassey@gmail.com> | 2019-01-04 01:25:29 +0700 |
---|---|---|
committer | glasseyes <dglassey@gmail.com> | 2019-01-04 01:25:29 +0700 |
commit | ec738875379be57f0bffaa336c68ac6189eff2df (patch) | |
tree | 3d184bc45dbf1998470f92726fe3313419a05157 | |
parent | 303a0a1b57807056f3655a60c9991c9e4b6dfcf9 (diff) |
New upstream version 11.0.101
-rw-r--r-- | PKG-INFO | 2 | ||||
-rw-r--r-- | keyman_config.egg-info/PKG-INFO | 2 | ||||
-rw-r--r-- | keyman_config.egg-info/SOURCES.txt | 2 | ||||
-rw-r--r-- | keyman_config/get_info.py | 35 | ||||
-rw-r--r-- | keyman_config/ibus_util.py | 99 | ||||
-rw-r--r-- | keyman_config/version.py | 4 |
6 files changed, 140 insertions, 4 deletions
@@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: keyman_config -Version: 10.99.69 +Version: 11.0.101 Summary: Keyman for Linux configuration Home-page: http://www.keyman.com/ Author: Daniel Glassey diff --git a/keyman_config.egg-info/PKG-INFO b/keyman_config.egg-info/PKG-INFO index e5244d8..82298d3 100644 --- a/keyman_config.egg-info/PKG-INFO +++ b/keyman_config.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: keyman-config -Version: 10.99.69 +Version: 11.0.101 Summary: Keyman for Linux configuration Home-page: http://www.keyman.com/ Author: Daniel Glassey diff --git a/keyman_config.egg-info/SOURCES.txt b/keyman_config.egg-info/SOURCES.txt index 5a0961b..19b9330 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 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) diff --git a/keyman_config/version.py b/keyman_config/version.py index 71d3cdc..7900ceb 100644 --- a/keyman_config/version.py +++ b/keyman_config/version.py @@ -4,5 +4,5 @@ # 1) we don't load dependencies by storing it in __init__.py # 2) we can import it in setup.py for the same reason # 3) we can import it into your module module -__version__ = "10.99.69" -__majorversion__ = "11.0" +__version__ = "11.0.101" +__majorversion__ = "11.0.101" |