Last active
June 11, 2019 16:44
-
-
Save lidaobing/407dfeae98a88114e60679a81c154cd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/wrapper/ibus/setup/main.py b/wrapper/ibus/setup/main.py | |
index e20a3a5..396c514 100644 | |
--- a/wrapper/ibus/setup/main.py | |
+++ b/wrapper/ibus/setup/main.py | |
@@ -39,10 +39,12 @@ import os | |
from os import path | |
try: | |
import gtk | |
+ import glib | |
except ImportError: | |
from gi import require_version as gi_require_version | |
gi_require_version('Gtk', '3.0') | |
from gi.repository import Gtk as gtk | |
+ from gi.repository import GLib as glib | |
try: | |
import ibus | |
except ImportError: | |
@@ -63,25 +65,33 @@ class Logger: | |
def pr(message): | |
print >> sys.stderr, message | |
+ | |
class Option(object): | |
"""Option serves as an interface of ibus.config | |
it is used to synchronize the configuration with setting on user interface | |
""" | |
config = ibus.Bus().get_config() | |
+ __wrappers = { | |
+ type(True): glib.Variant.new_boolean, | |
+ type(1): glib.Variant.new_int32, | |
+ type('str'): glib.Variant.new_string, | |
+ type([]): glib.Variant.new_strv, | |
+ } | |
def __init__(self, name, default): | |
self.name = name | |
self.default = default | |
+ self.__wrap = self.__wrappers[type(self.default)] | |
def read(self): | |
section, key = self.__get_config_name() | |
- return self.config.get_value(section, key, self.default) | |
+ wrapped = self.config.get_value(section, key) | |
+ return self.default if wrapped is None else wrapped.unpack() | |
def write(self, v): | |
section, key = self.__get_config_name() | |
- return self.config.set_value(section, key, type(self.default)(v)) | |
- | |
+ return self.config.set_value(section, key, self.__wrap(v)) | |
def __get_config_name(self): | |
keys = self.name.rsplit(SEPARATOR ,1) |
gtk will introduce this require version
On Wed, Jun 12, 2019 at 00:00 Boyuan Yang ***@***.***> wrote:
I guess we also need to add gi_require_version('GLib', '2.0') before
importing it from gi.repository.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/407dfeae98a88114e60679a81c154cd1?email_source=notifications&email_token=AAAGXCIVPDY6GNSPUKSLDS3PZ7DYPA5CNFSM4HW73AVKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFTPYM#gistcomment-2940806>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAGXCJNEZZPQ6APKNDU53TPZ7DYPANCNFSM4HW73AVA>
.
--
Sent from Gmail Mobile
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess we also need to add
gi_require_version('GLib', '2.0')
before importing it from gi.repository.