summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorfujiwarat <takao.fujiwara1@gmail.com>2017-12-28 20:48:32 +0900
committerfujiwarat <takao.fujiwara1@gmail.com>2017-12-28 20:48:32 +0900
commit89f8ddf86f417ed3074532e7b66f5eabc9595984 (patch)
tree7c74356b963fd56a88ce4a2e74759612c424a93a /engine
parentae039c727a89c8a27d5224adafb656a37d345d22 (diff)
downloadibus-anthy-89f8ddf86f417ed3074532e7b66f5eabc9595984.tar.gz
Migrated DConf to GSettings for python2
Diffstat (limited to 'engine')
-rw-r--r--engine/python2/Makefile.am5
-rw-r--r--engine/python2/_config.py.in5
-rw-r--r--engine/python2/engine.py277
-rw-r--r--engine/python2/factory.py19
-rw-r--r--engine/python2/jastring.py20
-rw-r--r--engine/python2/kana.py56
-rw-r--r--engine/python2/romaji.py32
-rw-r--r--engine/python2/thumb.py86
-rw-r--r--engine/python3/engine.py1
9 files changed, 184 insertions, 317 deletions
diff --git a/engine/python2/Makefile.am b/engine/python2/Makefile.am
index 47a7574..ec9cdd6 100644
--- a/engine/python2/Makefile.am
+++ b/engine/python2/Makefile.am
@@ -3,8 +3,8 @@
# ibus-anthy - The Anthy engine for IBus
#
# Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2010-2016 Takao Fujiwara <takao.fujiwara1@gmail.com>
-# Copyright (c) 2007-2016 Red Hat, Inc.
+# Copyright (c) 2010-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2007-2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -102,6 +102,7 @@ _config.py: _config.py.in
-e "s|\@LAYOUT\@|$(LAYOUT)|g" \
-e "s|\@SYMBOL_CHAR_INT\@|$(SYMBOL_CHAR_INT)|g" \
-e "s|\@ICON_PREFERENCE\@|$(ICON_PREFERENCE)|g" \
+ -e "s|\@VERSION\@|$(VERSION)|g" \
$< > $@
test:
diff --git a/engine/python2/_config.py.in b/engine/python2/_config.py.in
index d78d182..f7eff10 100644
--- a/engine/python2/_config.py.in
+++ b/engine/python2/_config.py.in
@@ -4,8 +4,8 @@
# ibus-anthy - The Anthy engine for IBus
#
# Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2010-2016 Takao Fujiwara <takao.fujiwara1@gmail.com>
-# Copyright (c) 2007-2016 Red Hat, Inc.
+# Copyright (c) 2010-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2007-2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -27,4 +27,5 @@ LOCALEDIR = '@datadir@/locale'
LAYOUT = '@LAYOUT@'
SYMBOL_CHAR = unichr(@SYMBOL_CHAR_INT@)
ICON_PREFERENCE = '@ICON_PREFERENCE@'
+VERSION = '@VERSION@'
DEBUG = False
diff --git a/engine/python2/engine.py b/engine/python2/engine.py
index 44d6ad1..1dc937c 100644
--- a/engine/python2/engine.py
+++ b/engine/python2/engine.py
@@ -156,7 +156,7 @@ class Engine(IBus.EngineSimple):
# cursor_pos=0,
# cursor_visible=True,
# round=True)
- size = self.__prefs.get_value('common', 'page_size')
+ size = self.__prefs.get_value('common', 'page-size')
self.__lookup_table = IBus.LookupTable.new(page_size=size,
cursor_pos=0,
cursor_visible=True,
@@ -178,10 +178,6 @@ class Engine(IBus.EngineSimple):
# use reset to init values
self.__reset()
- ibus_config = bus.get_config()
- if ibus_config != None:
- ibus_config.connect('value-changed',
- self.__config_value_changed_cb)
def __ibus_check_version(self, v):
major = IBus.MAJOR_VERSION
@@ -279,7 +275,7 @@ class Engine(IBus.EngineSimple):
# the engine keeps the class method in the memory.
Engine.__input_mode = INPUT_MODE_HIRAGANA
Engine.__input_mode = self.__prefs.get_value('common',
- 'input_mode')
+ 'input-mode')
if not self.__prefs.get_value('common', 'show-input-mode'):
return
@@ -372,7 +368,7 @@ class Engine(IBus.EngineSimple):
if Engine.__typing_mode == None:
Engine.__typing_mode = jastring.TYPING_MODE_ROMAJI
Engine.__typing_mode = self.__prefs.get_value('common',
- 'typing_method')
+ 'typing-method')
if not self.__prefs.get_value('common', 'show-typing-method'):
return
@@ -440,7 +436,7 @@ class Engine(IBus.EngineSimple):
if Engine.__segment_mode == None:
Engine.__segment_mode = SEGMENT_DEFAULT
Engine.__segment_mode = self.__prefs.get_value('common',
- 'conversion_segment_mode')
+ 'conversion-segment-mode')
if not self.__prefs.get_value('common', 'show-segment-mode'):
return
@@ -520,8 +516,8 @@ class Engine(IBus.EngineSimple):
if not self.__prefs.get_value('common', 'show-dict-mode'):
return
- short_label = self.__prefs.get_value('dict/file/embedded',
- 'short_label')
+ dicts = self.__prefs.get_value('dict', 'list')
+ short_label = dicts['embedded'].short_label
label = _("%(description)s (%(symbol)s)") % \
{ 'description' : _("Dictionary mode"), 'symbol' : short_label }
dict_mode_prop = IBus.Property(key=u'DictMode',
@@ -537,8 +533,7 @@ class Engine(IBus.EngineSimple):
self.__prop_dict[u'DictMode'] = dict_mode_prop
props = IBus.PropList()
- long_label = self.__prefs.get_value('dict/file/embedded',
- 'long_label')
+ long_label = dicts['embedded'].long_label
props.append(IBus.Property(key=u'DictMode.embedded',
prop_type=IBus.PropType.RADIO,
# if long_label is UTF-8
@@ -549,15 +544,24 @@ class Engine(IBus.EngineSimple):
visible=True,
state=IBus.PropState.UNCHECKED,
sub_props=None))
- for file in self.__prefs.get_value('dict', 'files'):
- if not self.__link_dict_file(file):
- continue
- id = self.__get_dict_id_from_file(file)
- section = 'dict/file/' + id
- if not self.__prefs.get_value(section, 'single'):
- continue
+ order = self.__prefs.get_value('dict', 'order')
+ if len(order) == 0:
+ order = list(self.__prefs.get_value('dict', 'files').keys())
+ files = self.__prefs.get_value('dict', 'files')
+ dicts = self.__prefs.get_value('dict', 'list')
+ for id in order:
+ dict_item = dicts[id]
+ is_cont = False
+ for file in files[id]:
+ if not self.__link_dict_file(dict_item, file):
+ is_cont = True
+ break
+ if is_cont:
+ continue
+ if not dict_item.single:
+ continue
key = 'DictMode.' + id
- long_label = self.__prefs.get_value(section, 'long_label')
+ long_label = dict_item.long_label
# ibus-config 'value-changed' signal updated dict/files but
# not dict/file/new yet.
@@ -565,8 +569,7 @@ class Engine(IBus.EngineSimple):
continue
# if long_label is UTF-8
- if 'is_system' in self.__prefs.keys(section) and \
- self.__prefs.get_value(section, 'is_system'):
+ if dict_item.is_system:
uni_long_label = UN(_(long_label))
else:
uni_long_label = UN(long_label)
@@ -607,8 +610,8 @@ class Engine(IBus.EngineSimple):
if not self.__prefs.get_value('common', 'show-dict-config'):
return
- admin_command = self.__prefs.get_value('common', 'dict_admin_command')
- icon_path = self.__prefs.get_value('common', 'dict_config_icon')
+ admin_command = self.__prefs.get_value('common', 'dict-admin-command')
+ icon_path = self.__prefs.get_value('common', 'dict-config-icon')
if not path.exists(admin_command[0]):
return
@@ -670,20 +673,28 @@ class Engine(IBus.EngineSimple):
return clipboard_text
def __get_single_dict_files(self):
+ order = self.__prefs.get_value('dict', 'order')
+ if len(order) == 0:
+ order = list(self.__prefs.get_value('dict', 'files').keys())
files = self.__prefs.get_value('dict', 'files')
+ dicts = self.__prefs.get_value('dict', 'list')
single_files = []
- for file in files:
- if not path.exists(file):
- continue
- id = self.__get_dict_id_from_file(file)
- section = 'dict/file/' + id
- if self.__prefs.get_value(section, 'single'):
- single_files.append(file)
+ for id in order:
+ for file in files[id]:
+ if not path.exists(file):
+ continue
+ dict_item = dicts[id]
+ if dict_item.single:
+ single_files.append(file)
return single_files
def __remove_dict_files(self):
- for file in self.__prefs.get_value('dict', 'files'):
- self.__remove_dict_file(file)
+ dicts = self.__prefs.get_value('dict', 'list')
+ files = self.__prefs.get_value('dict', 'files')
+ for id in files.keys():
+ dict_item = dicts[id]
+ for file in files[id]:
+ self.__remove_dict_file(dict_item, file)
def update_preedit(self, string, attrs, cursor_pos, visible):
text = IBus.Text.new_from_string(string)
@@ -695,7 +706,7 @@ class Engine(IBus.EngineSimple):
attr.get_start_index(),
attr.get_end_index())
i += 1
- mode = self.__prefs.get_value('common', 'behavior_on_focus_out')
+ mode = self.__prefs.get_value('common', 'behavior-on-focus-out')
if self.__has_update_preedit_text_with_mode and mode == 1:
self.update_preedit_text_with_mode(text,
cursor_pos, visible,
@@ -1016,8 +1027,8 @@ class Engine(IBus.EngineSimple):
self.__context.do_set_personality(str(dict_name))
prop = self.__prop_dict[u'DictMode']
- section = 'dict/file/' + id
- symbol = self.__prefs.get_value(section, 'short_label')
+ dicts = self.__prefs.get_value('dict', 'list')
+ symbol = dicts[id].short_label
label = _("%(description)s (%(symbol)s)") % \
{ 'description' : _("Dictionary mode"), 'symbol' : symbol }
prop.set_symbol(IBus.Text.new_from_string(symbol))
@@ -1033,19 +1044,19 @@ class Engine(IBus.EngineSimple):
def do_focus_in(self):
self.register_properties(self.__prop_list)
self.__refresh_typing_mode_property()
- mode = self.__prefs.get_value('common', 'behavior_on_focus_out')
+ mode = self.__prefs.get_value('common', 'behavior-on-focus-out')
if mode == 2:
self.__update_input_chars()
# self.__reset()
# self.__invalidate()
- size = self.__prefs.get_value('common', 'page_size')
+ size = self.__prefs.get_value('common', 'page-size')
if size != self.__lookup_table.get_page_size():
self.__lookup_table.set_page_size(size)
def do_focus_out(self):
if self.__has_input_purpose:
self.__input_purpose = 0
- mode = self.__prefs.get_value('common', 'behavior_on_focus_out')
+ mode = self.__prefs.get_value('common', 'behavior-on-focus-out')
if mode == 0 or mode == 1:
self.__reset()
self.__invalidate()
@@ -1646,11 +1657,12 @@ class Engine(IBus.EngineSimple):
#=======================================================================
@classmethod
- def CONFIG_RELOADED(cls, bus):
+ def CONFIG_RELOADED(cls):
if config.DEBUG:
print 'RELOADED'
if not cls.__prefs:
- cls.__prefs = AnthyPrefs(bus)
+ cls.__prefs = AnthyPrefs()
+ cls.__prefs.connect('changed', cls.CONFIG_VALUE_CHANGED)
cls._init_prefs()
cls.__keybind = cls._mk_keybind()
@@ -1658,70 +1670,45 @@ class Engine(IBus.EngineSimple):
jastring.JaString.SET_PREFS(cls.__prefs)
@classmethod
- def CONFIG_VALUE_CHANGED(cls, bus, section, name, variant):
+ def CONFIG_VALUE_CHANGED(cls, prefs, section, key, variant):
if config.DEBUG:
- print 'VALUE_CHAMGED =', section, name, variant
-
- if not section.startswith('engine/anthy'):
- # This value is used for IBus.config.set_value only.
- return
-
- # The key was deleted by dconf.
- # test case: update /desktop/ibus/engine/anthy/thumb/ls
- # and reset the key with dconf direclty.
- if variant.get_type_string() == '()':
- cls.__prefs.undo_item(section, name)
- return
-
- value = cls.__prefs.variant_to_value(variant)
- base_sec = section[len(cls.__prefs._prefix) + 1:]
- sec = cls._get_shortcut_type()
- if base_sec == sec:
- cmd = '_Engine__cmd_' + name
- old = cls.__prefs.get_value(sec, name)
- value = value if value != [''] else []
- for s in set(old).difference(value):
- cls.__keybind.get(cls._s_to_key(s), []).remove(cmd)
-
- keys = cls.__prefs.keys(sec)
- for s in set(value).difference(old):
- cls.__keybind.setdefault(cls._s_to_key(s), []).append(cmd)
- cls.__keybind.get(cls._s_to_key(s)).sort(
- lambda a, b: cmp(keys.index(a[13:]), keys.index(b[13:])))
-
- cls.__prefs.set_value(sec, name, value)
- elif base_sec == 'common':
- cls.__prefs.set_value(base_sec, name, value)
- if name == 'shortcut_type':
+ print('VALUE_CHAMGED =', section, key, variant)
+ if section == 'shortcut':
+ cls.__keybind = cls._mk_keybind()
+ elif section == 'common':
+ if key == 'shortcut-type':
cls.__keybind = cls._mk_keybind()
- if name == 'latin_with_shift':
+ elif key == 'latin-with-shift':
+ value = prefs.get_value(section, key)
cls.__latin_with_shift = value
- jastring.JaString.RESET(cls.__prefs, base_sec, name, value)
- elif base_sec.startswith('kana_typing_rule'):
- jastring.JaString.RESET(cls.__prefs, base_sec, name, value)
+ jastring.JaString.RESET(cls.__prefs, section, key, value)
+ elif section == 'kana-typing-rule':
+ value = prefs.get_value(section, key)
+ jastring.JaString.RESET(cls.__prefs, section, key, value)
@classmethod
def _init_prefs(cls):
prefs = cls.__prefs
- value = prefs.get_value('common', 'latin_with_shift')
+ value = prefs.get_value('common', 'latin-with-shift')
cls.__latin_with_shift = value
@classmethod
def _mk_keybind(cls):
keybind = {}
sec = cls._get_shortcut_type()
- for k in cls.__prefs.keys(sec):
+ shortcuts = cls.__prefs.get_value('shortcut', sec)
+ for k in shortcuts.keys():
cmd = '_Engine__cmd_' + k
- for s in cls.__prefs.get_value(sec, k):
+ for s in shortcuts[k]:
keybind.setdefault(cls._s_to_key(s), []).append(cmd)
return keybind
@classmethod
def _get_shortcut_type(cls):
try:
- t = 'shortcut/' + cls.__prefs.get_value('common', 'shortcut_type')
+ t = cls.__prefs.get_value('common', 'shortcut-type')
except:
- t = 'shortcut/default'
+ t = 'default'
return t
@classmethod
@@ -1787,9 +1774,9 @@ class Engine(IBus.EngineSimple):
self._MM = self._SS = 0
ret = self.__on_key_common(ord(keyval))
if (keyval in
- UN(self.__prefs.get_value('common', 'trigger_periods'))):
+ UN(self.__prefs.get_value('common', 'trigger-periods'))):
behavior = self.__prefs.get_value('common',
- 'behavior_on_period')
+ 'behavior-on-period')
if behavior == 1:
return self.__cmd_convert(keyval, state)
elif behavior == 2:
@@ -1828,7 +1815,7 @@ class Engine(IBus.EngineSimple):
IBus.ModifierType.RELEASE_MASK)
if keyval in KP_Table and self.__prefs.get_value('common',
- 'ten_key_mode'):
+ 'ten-key-mode'):
keyval = KP_Table[keyval]
if state & IBus.ModifierType.RELEASE_MASK:
@@ -1924,7 +1911,7 @@ class Engine(IBus.EngineSimple):
return False
if keyval in KP_Table and self.__prefs.get_value('common',
- 'ten_key_mode'):
+ 'ten-key-mode'):
keyval = KP_Table[keyval]
key = self._mk_key(keyval, state)
@@ -1958,9 +1945,9 @@ class Engine(IBus.EngineSimple):
ret = self.__on_key_common(keyval, state)
if (Engine.__input_mode != INPUT_MODE_LATIN and
unichr(keyval) in
- UN(self.__prefs.get_value('common', 'trigger_periods'))):
+ UN(self.__prefs.get_value('common', 'trigger-periods'))):
behavior = self.__prefs.get_value('common',
- 'behavior_on_period')
+ 'behavior-on-period')
if behavior == 1:
return self.__cmd_convert(keyval, state)
elif behavior == 2:
@@ -2020,7 +2007,7 @@ class Engine(IBus.EngineSimple):
def __get_dict_id_from_file(self, file):
return self.__get_quoted_id(file)
- def __link_dict_file_with_id(self, file, id, link_mode):
+ def __link_dict_file_with_mode(self, id, file, link_mode):
if id == None:
return
if link_mode == LINK_DICT_EMBEDDED:
@@ -2051,7 +2038,7 @@ class Engine(IBus.EngineSimple):
if backup_dir != None:
os.chdir(backup_dir)
- def __remove_dict_file_with_id(self, file, id, link_mode):
+ def __remove_dict_file_with_mode(self, id, file, link_mode):
if id == None:
return
if link_mode == LINK_DICT_EMBEDDED:
@@ -2073,97 +2060,23 @@ class Engine(IBus.EngineSimple):
if backup_dir != None:
os.chdir(backup_dir)
- def __link_dict_file(self, file):
+ def __link_dict_file(self, dict_item, file):
if not path.exists(file):
printerr(file + ' does not exist')
return False
- id = self.__get_dict_id_from_file(file)
- section = 'dict/file/' + id
- if section not in self.__prefs.sections():
- self.__fetch_dict_values(section)
- if self.__prefs.get_value(section, 'embed'):
- self.__link_dict_file_with_id(file, id, LINK_DICT_EMBEDDED)
- if self.__prefs.get_value(section, 'single'):
- self.__link_dict_file_with_id(file, id, LINK_DICT_SINGLE)
+ id = dict_item.id
+ if dict_item.embed:
+ self.__link_dict_file_with_mode(id, file, LINK_DICT_EMBEDDED)
+ if dict_item.single:
+ self.__link_dict_file_with_mode(id, file, LINK_DICT_SINGLE)
return True
- def __remove_dict_file(self, file):
- id = self.__get_dict_id_from_file(file)
- section = 'dict/file/' + id
- if section not in self.__prefs.sections():
- self.__fetch_dict_values(section)
- if self.__prefs.get_value(section, 'embed'):
- self.__remove_dict_file_with_id(file, id, LINK_DICT_EMBEDDED)
- if self.__prefs.get_value(section, 'single'):
- self.__remove_dict_file_with_id(file, id, LINK_DICT_SINGLE)
-
- def __set_dict_files_value(self, base_sec, name, value):
- if name == 'files':
- str_list = []
- for file in value:
- str_list.append(self.__prefs.str(file))
- old_files = self.__prefs.get_value(base_sec, name)
- for file in old_files:
- if file in str_list:
- continue
- self.__remove_dict_file(file)
- for file in str_list:
- if file in old_files:
- continue
- self.__link_dict_file(file)
- self.__prefs.set_value(base_sec, name, str_list)
- else:
- self.__prefs.set_value(base_sec, name, value)
-
- def __fetch_dict_values(self, section):
- self.__prefs.set_new_section(section)
- self.__prefs.set_new_key(section, 'short_label')
- self.__prefs.set_no_key_warning(True)
- self.__prefs.fetch_item(section, 'short_label')
- self.__prefs.set_new_key(section, 'long_label')
- self.__prefs.fetch_item(section, 'long_label')
- self.__prefs.set_new_key(section, 'embed')
- self.__prefs.fetch_item(section, 'embed')
- self.__prefs.set_new_key(section, 'single')
- self.__prefs.fetch_item(section, 'single')
- self.__prefs.set_new_key(section, 'reverse')
- self.__prefs.fetch_item(section, 'reverse')
- self.__prefs.set_no_key_warning(False)
-
- def __config_value_changed_cb(self, ibus_config, section, name, variant):
- if config.DEBUG:
- print 'VALUE_CHAMGED =', section, name, variant
-
- if not section.startswith('engine/anthy'):
- # This value is used for IBus.config.set_value only.
- return
-
- # The key was deleted by dconf.
- # test case: update /desktop/ibus/engine/anthy/thumb/ls
- # and reset the key with dconf direclty.
- if variant.get_type_string() == '()':
- self.__prefs.undo_item(section, name)
- return
-
- value = self.__prefs.variant_to_value(variant)
- base_sec = section[len(self.__prefs._prefix) + 1:]
- sec = self._get_shortcut_type()
-
- if base_sec == 'thumb':
- self.__prefs.set_value(base_sec, name, value)
- self._reset_thumb()
- elif base_sec == 'dict':
- self.__set_dict_files_value(base_sec, name, value)
- self.__set_dict_mode_props(self.__prop_list, True)
- elif base_sec.startswith('dict/file/'):
- if base_sec not in self.__prefs.sections():
- self.__fetch_dict_values(base_sec)
- self.__prefs.set_value(base_sec, name, value)
- self.__set_dict_mode_props(self.__prop_list, True)
- elif base_sec:
- self.__prefs.set_value(base_sec, name, value)
- else:
- self.__prefs.set_value(section, name, value)
+ def __remove_dict_file(self, dict_item, file):
+ id = dict_item.id
+ if dict_item.embed:
+ self.__remove_dict_file_with_mode(id, file, LINK_DICT_EMBEDDED)
+ if dict_item.single:
+ self.__remove_dict_file_with_mode(id, file, LINK_DICT_SINGLE)
#mod_keys
def __set_input_mode(self, mode):
@@ -2294,7 +2207,7 @@ class Engine(IBus.EngineSimple):
def __cmd_insert_space(self, keyval, state):
if Engine.__input_mode == INPUT_MODE_LATIN:
return False
- if (self.__prefs.get_value('common', 'half_width_space') or
+ if (self.__prefs.get_value('common', 'half-width-space') or
Engine.__input_mode == INPUT_MODE_HALF_WIDTH_KATAKANA):
return self.__cmd_insert_half_space(keyval, state)
else:
@@ -2303,7 +2216,7 @@ class Engine(IBus.EngineSimple):
def __cmd_insert_alternate_space(self, keyval, state):
if Engine.__input_mode == INPUT_MODE_LATIN:
return False
- if (self.__prefs.get_value('common', 'half_width_space') or
+ if (self.__prefs.get_value('common', 'half-width-space') or
Engine.__input_mode == INPUT_MODE_HALF_WIDTH_KATAKANA):
return self.__cmd_insert_wide_space(keyval, state)
else:
@@ -2901,11 +2814,11 @@ class Engine(IBus.EngineSimple):
return True
def __start_dict_admin(self):
- command = self.__prefs.get_value('common', 'dict_admin_command')
+ command = self.__prefs.get_value('common', 'dict-admin-command')
os.spawnl(os.P_NOWAIT, *command)
def __start_add_word(self):
- command = self.__prefs.get_value('common', 'add_word_command')
+ command = self.__prefs.get_value('common', 'add-word-command')
os.spawnl(os.P_NOWAIT, *command)
def __start_setup(self):
diff --git a/engine/python2/factory.py b/engine/python2/factory.py
index 8aec2b2..b7b1e89 100644
--- a/engine/python2/factory.py
+++ b/engine/python2/factory.py
@@ -4,8 +4,8 @@
# ibus-anthy - The Anthy engine for IBus
#
# Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2010-2016 Takao Fujiwara <takao.fujiwara1@gmail.com>
-# Copyright (c) 2007-2016 Red Hat, Inc.
+# Copyright (c) 2010-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2007-2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -44,19 +44,11 @@ class EngineFactory(IBus.Factory):
def __init__(self, bus):
self.__bus = bus
- engine.Engine.CONFIG_RELOADED(bus)
+ engine.Engine.CONFIG_RELOADED()
super(EngineFactory, self).__init__(object_path=IBus.PATH_FACTORY,
connection=bus.get_connection())
self.__id = 0
- self.__config = self.__bus.get_config()
-
- if self.__config != None:
- self.__config.connect('value-changed',
- self.__config_value_changed_cb)
- else:
- print >> sys.stderr, \
- 'ibus-config is not running or bus address is not correct.'
bus.get_connection().signal_subscribe('org.freedesktop.DBus',
'org.freedesktop.DBus',
@@ -74,11 +66,8 @@ class EngineFactory(IBus.Factory):
return super(EngineFactory, self).do_create_engine(engine_name)
- def __config_value_changed_cb(self, config, section, name, value):
- engine.Engine.CONFIG_VALUE_CHANGED(self.__bus, section, name, value)
-
def __name_owner_changed_cb(self, connection, sender_name, object_path,
interface_name, signal_name, parameters,
user_data):
if signal_name == 'NameOwnerChanged':
- engine.Engine.CONFIG_RELOADED(self.__bus)
+ engine.Engine.CONFIG_RELOADED()
diff --git a/engine/python2/jastring.py b/engine/python2/jastring.py
index aeb7e6e..26b7b74 100644
--- a/engine/python2/jastring.py
+++ b/engine/python2/jastring.py
@@ -4,8 +4,8 @@
# ibus-anthy - The Anthy engine for IBus
#
# Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2010-2013 Takao Fujiwara <takao.fujiwara1@gmail.com>
-# Copyright (c) 2007-2013 Red Hat, Inc.
+# Copyright (c) 2010-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2007-2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -78,13 +78,13 @@ class JaString:
cls._prefs = prefs
@classmethod
- def RESET(cls, prefs, section, name, value):
+ def RESET(cls, prefs, section, key, value):
cls._prefs = prefs
- if section.startswith('kana_typing_rule'):
+ if section == 'kana-typing-rule':
mode = TYPING_MODE_KANA
- kana.KanaSegment.RESET(prefs, section, name, value)
+ kana.KanaSegment.RESET(prefs, section, key, value)
cls._init_mode(mode)
- if section == 'common' and name == 'latin_with_shift':
+ if section == 'common' and key == 'latin-with-shift':
romaji.RomajiSegment.SET_LATIN_WITH_SHIFT(value)
def set_shift(self, shift):
@@ -241,10 +241,10 @@ class JaString:
self.__cursor = self.__cursor + 1
def _chk_text(self, s):
- period = self._prefs.get_value('common', 'period_style')
- symbol = self._prefs.get_value('common', 'symbol_style')
- half_symbol = self._prefs.get_value('common', 'half_width_symbol')
- half_number = self._prefs.get_value('common', 'half_width_number')
+ period = self._prefs.get_value('common', 'period-style')
+ symbol = self._prefs.get_value('common', 'symbol-style')
+ half_symbol = self._prefs.get_value('common', 'half-width-symbol')
+ half_number = self._prefs.get_value('common', 'half-width-number')
ret = ''
for c in s:
c = c if not period else PeriodTable.get(c, c)
diff --git a/engine/python2/kana.py b/engine/python2/kana.py
index c85a199..9027571 100644
--- a/engine/python2/kana.py
+++ b/engine/python2/kana.py
@@ -4,8 +4,8 @@
# ibus-anthy - The Anthy engine for IBus
#
# Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2010-2013 Takao Fujiwara <takao.fujiwara1@gmail.com>
-# Copyright (c) 2007-2013 Red Hat, Inc.
+# Copyright (c) 2010-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2007-2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -30,8 +30,9 @@ _UNFINISHED_HIRAGANA = set(u'かきくけこさしすせそたちつてとはひ
class KanaSegment(segment.Segment):
_prefs = None
- _kana_typing_rule_section = None
+ _kana_typing_rule_method = None
_kana_voiced_consonant_rule = None
+ _kana_voiced_consonant_dict = None
def __init__(self, enchars=u'', jachars=u''):
if not jachars:
@@ -42,24 +43,25 @@ class KanaSegment(segment.Segment):
def INIT_KANA_TYPING_RULE(cls, prefs):
cls._prefs = prefs
if prefs == None:
- cls._kana_typing_rule_section = None
+ cls._kana_typing_rule_method = None
return
- if cls._kana_typing_rule_section == None:
+ if cls._kana_typing_rule_method == None:
cls._init_kana_typing_method()
if cls._kana_voiced_consonant_rule == None and \
- cls._kana_typing_rule_section != None:
+ cls._kana_typing_rule_method != None:
cls._init_kana_voiced_consonant_rule()
@classmethod
def _init_kana_typing_method(cls, method=None):
prefs = cls._prefs
if method == None:
- method = prefs.get_value('kana_typing_rule', 'method')
+ method = prefs.get_value('kana-typing-rule', 'method')
if method == None:
method = 'jp'
- cls._kana_typing_rule_section = 'kana_typing_rule/' + method
- if cls._kana_typing_rule_section not in prefs.sections():
- cls._kana_typing_rule_section = None
+ cls._kana_typing_rule_method = method
+ keymap = prefs.get_value('kana-typing-rule', 'list')
+ if cls._kana_typing_rule_method not in keymap.keys():
+ cls._kana_typing_rule_method = None
@classmethod
def _init_kana_voiced_consonant_rule(cls):
@@ -70,9 +72,10 @@ class KanaSegment(segment.Segment):
# If the customized table provides U+309b with other chars,
# it needs to be detected dynamically.
cls._kana_voiced_consonant_rule = {}
- section = cls._kana_typing_rule_section
- for gkey in prefs.keys(section):
- value = prefs.get_value(section, gkey)
+ method = cls._kana_typing_rule_method
+ keymap = prefs.get_value('kana-typing-rule', 'list')[method]
+ for gkey in keymap.keys():
+ value = keymap[gkey]
key = prefs.typing_from_config_key(gkey)
if key == '':
continue
@@ -88,37 +91,26 @@ class KanaSegment(segment.Segment):
cls._kana_voiced_consonant_rule[rule] = voiced
@classmethod
- def RESET(cls, prefs, section, name, value):
+ def RESET(cls, prefs, section, key, value):
cls._prefs = prefs
- if section == 'kana_typing_rule' and name == 'method' and \
- value != None:
- cls._kana_typing_rule_section = None
- cls._kana_voiced_consonant_rule = None
- cls._init_kana_typing_method(value)
- elif section.startswith('kana_typing_rule/'):
- # Probably it's better to restart ibus by manual
- # instead of saving the emitted values from config.
+ if section == 'kana-typing-rule' and value != None:
+ cls._kana_typing_rule_method = None
cls._kana_voiced_consonant_rule = None
+ cls.INIT_KANA_TYPING_RULE(prefs)
def __get_kana_typing_rule(self, enchars, retval=None):
prefs = self._prefs
value = None
- section = self._kana_typing_rule_section
- if section != None:
+ method = self._kana_typing_rule_method
+ if method != None:
# Need to send Unicode to typing_to_config_key instead of UTF-8
# not to separate U+A5
gkey = prefs.typing_to_config_key(enchars)
if gkey == '':
return None
enchars = gkey
- if enchars in prefs.keys(section):
- value = prefs.unicode(prefs.str(prefs.get_value(section, enchars)))
- else:
- prefs.set_no_key_warning(True)
- value = prefs.get_value_direct(section, enchars)
- prefs.set_no_key_warning(False)
- if value != None:
- value = prefs.unicode(prefs.str(value))
+ keymap = prefs.get_value('kana-typing-rule', 'list')[method]
+ value = prefs.unicode(keymap.get(enchars))
if value == '':
value = None
if value == None:
diff --git a/engine/python2/romaji.py b/engine/python2/romaji.py
index 48167c6..333d438 100644
--- a/engine/python2/romaji.py
+++ b/engine/python2/romaji.py
@@ -4,8 +4,8 @@
# ibus-anthy - The Anthy engine for IBus
#
# Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2010-2013 Takao Fujiwara <takao.fujiwara1@gmail.com>
-# Copyright (c) 2007-2013 Red Hat, Inc.
+# Copyright (c) 2010-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2007-2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@ def romaji_correction_rule_get(k, d):
class RomajiSegment(segment.Segment):
_prefs = None
- _romaji_typing_rule_section = None
+ _romaji_typing_rule_method = None
_latin_with_shift = True
_shift_mode = False
@@ -59,14 +59,15 @@ class RomajiSegment(segment.Segment):
def INIT_ROMAJI_TYPING_RULE(cls, prefs):
cls._prefs = prefs
if prefs == None:
- cls._romaji_typing_rule_section = None
+ cls._romaji_typing_rule_method = None
return
- method = prefs.get_value('romaji_typing_rule', 'method')
+ method = prefs.get_value('romaji-typing-rule', 'method')
if method == None:
method = 'default'
- cls._romaji_typing_rule_section = 'romaji_typing_rule/' + method
- if cls._romaji_typing_rule_section not in prefs.sections():
- cls._romaji_typing_rule_section = None
+ cls._romaji_typing_rule_method = method
+ keymap = prefs.get_value('romaji-typing-rule', 'list')
+ if cls._romaji_typing_rule_method not in keymap.keys():
+ cls._romaji_typing_rule_method = None
@classmethod
def SET_LATIN_WITH_SHIFT(cls, latin_with_shift):
@@ -76,22 +77,15 @@ class RomajiSegment(segment.Segment):
def __get_romaji_typing_rule(self, enchars, retval=None):
prefs = self._prefs
value = None
- section = self._romaji_typing_rule_section
- if section != None:
+ method = self._romaji_typing_rule_method
+ if method != None:
# Need to send Unicode to typing_to_config_key instead of UTF-8
# not to separate U+A5
gkey = prefs.typing_to_config_key(enchars)
if gkey == '':
return None
- if gkey in prefs.keys(section):
- value = prefs.unicode(prefs.str(
- prefs.get_value(section, gkey)))
- else:
- prefs.set_no_key_warning(True)
- value = prefs.get_value_direct(section, gkey)
- prefs.set_no_key_warning(False)
- if value != None:
- value = prefs.unicode(prefs.str(value))
+ keymap = prefs.get_value('romaji-typing-rule', 'list')[method]
+ value = prefs.unicode(keymap.get(gkey))
if value == '':
value = None
if value == None:
diff --git a/engine/python2/thumb.py b/engine/python2/thumb.py
index 6cb6980..7073aa2 100644
--- a/engine/python2/thumb.py
+++ b/engine/python2/thumb.py
@@ -5,8 +5,8 @@
#
# Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
# Copyright (c) 2009 Hideaki ABE <abe.sendai@gmail.com>
-# Copyright (c) 2010-2016 Takao Fujiwara <takao.fujiwara1@gmail.com>
-# Copyright (c) 2007-2016 Red Hat, Inc.
+# Copyright (c) 2010-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2007-2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -231,8 +231,7 @@ class ThumbShiftKeyboard:
self.__layout = 0
self.__fmv_extension = 2
self.__handakuten = False
- self.__thumb_typing_rule_section_base = None
- self.__thumb_typing_rule_section = None
+ self.__thumb_typing_rule_method = None
self.__init_thumb_typing_rule()
self.__init_layout_table()
if self.__prefs != None:
@@ -242,34 +241,27 @@ class ThumbShiftKeyboard:
def __init_thumb_typing_rule(self):
prefs = self.__prefs
if prefs == None:
- self.__thumb_typing_rule_section = None
+ self.__thumb_typing_rule_method = None
return
- method = prefs.get_value('thumb_typing_rule', 'method')
+ method = prefs.get_value('thumb-typing-rule', 'method')
if method == None:
method = _THUMB_BASIC_METHOD
- self.__thumb_typing_rule_section_base = 'thumb_typing_rule'
- self.__thumb_typing_rule_section = \
- self.__thumb_typing_rule_section_base + '/' + method
- if self.__thumb_typing_rule_section not in prefs.sections():
- self.__thumb_typing_rule_section = None
+ self.__thumb_typing_rule_method = method
+ keymap = prefs.get_value('thumb-typing-rule', 'list')
+ if self.__thumb_typing_rule_method not in keymap.keys():
+ self.__thumb_typing_rule_method = None
def __init_layout_table(self):
if self.__table != {}:
self.__table.clear()
if self.__r_table != {}:
self.__r_table.clear()
- section_base = self.__thumb_typing_rule_section_base
- section = self.__thumb_typing_rule_section
- if section != None:
+ method = self.__thumb_typing_rule_method
+ if method != None:
prefs = self.__prefs
- for k in prefs.keys(section):
- value = prefs.get_value(section, k)
- ch = prefs.typing_from_config_key(k)
- if ch == '':
- continue
- self.__set_bus_table(ch, value)
- for k in prefs.get_value(section_base, 'newkeys'):
- value = prefs.get_value_direct(section, k)
+ keymap = prefs.get_value('thumb-typing-rule', 'list')[method]
+ for k in keymap.keys():
+ value = keymap.get(k)
ch = prefs.typing_from_config_key(k)
if ch == '':
continue
@@ -313,19 +305,12 @@ class ThumbShiftKeyboard:
sub_table = f_table
if method == None or sub_table == None:
return
- section_base = self.__thumb_typing_rule_section_base
- section = self.__thumb_typing_rule_section
- sub_section = section_base + '/' + method
- if section != None:
+ method = self.__thumb_typing_rule_method
+ if method != None:
prefs = self.__prefs
- for k in prefs.keys(sub_section):
- value = prefs.get_value(sub_section, k)
- ch = prefs.typing_from_config_key(k)
- if ch == '':
- continue
- self.__set_bus_table(ch, value)
- for k in prefs.get_value(section_base, method + '_newkeys'):
- value = prefs.get_value_direct(sub_section, k)
+ keymap = prefs.get_value('thumb-typing-rule', 'list')[method]
+ for k in keymap.keys():
+ value = keymap.get(k)
ch = prefs.typing_from_config_key(k)
if ch == '':
continue
@@ -460,15 +445,15 @@ class ThumbShiftKeyboard:
return layout
def __reset_layout_and_handakuten(self):
- mode = self.__prefs.get_value('thumb', 'keyboard_layout_mode')
+ mode = self.__prefs.get_value('thumb', 'keyboard-layout-mode')
layout = 0
if mode == 1:
layout = self.__get_xkb_layout()
else:
- layout = self.__prefs.get_value('thumb', 'keyboard_layout')
+ layout = self.__prefs.get_value('thumb', 'keyboard-layout')
self.set_layout(layout)
- fmv_extension = self.__prefs.get_value('thumb', 'fmv_extension')
+ fmv_extension = self.__prefs.get_value('thumb', 'fmv-extension')
self.set_fmv_extension(fmv_extension)
handakuten = self.__prefs.get_value('thumb', 'handakuten')
self.set_handakuten(handakuten)
@@ -585,32 +570,25 @@ class ThumbShiftSegment(segment.Segment):
if prefs == None:
cls._thumb_typing_rule_section = None
return
- method = prefs.get_value('thumb_typing_rule', 'method')
+ method = prefs.get_value('thumb-typing-rule', 'method')
if method == None:
method = _THUMB_BASIC_METHOD
- cls._thumb_typing_rule_section_base = 'thumb_typing_rule'
- cls._thumb_typing_rule_section = \
- cls._thumb_typing_rule_section_base + '/' + method
- if cls._thumb_typing_rule_section not in prefs.sections():
- cls._thumb_typing_rule_section = None
+ cls._thumb_typing_rule_method = method
+ keymap = prefs.get_value('thumb-typing-rule', 'list')
+ if cls._thumb_typing_rule_method not in keymap.keys():
+ cls._thumb_typing_rule_method = None
cls._init_layout_table()
@classmethod
def _init_layout_table(cls):
if cls._r_table != {}:
cls._r_table.clear()
- section_base = cls._thumb_typing_rule_section_base
- section = cls._thumb_typing_rule_section
- if section != None:
+ method = cls._thumb_typing_rule_method
+ if method != None:
prefs = cls._prefs
- for k in prefs.keys(section):
- value = prefs.get_value(section, k)
- ch = prefs.typing_from_config_key(k)
- if ch == '':
- continue
- cls._set_bus_table(ch, value)
- for k in prefs.get_value(section_base, 'newkeys'):
- value = prefs.get_value_direct(section, k)
+ keymap = prefs.get_value('thumb-typing-rule', 'list')[method]
+ for k in keymap.keys():
+ value = keymap.get(k)
ch = prefs.typing_from_config_key(k)
if ch == '':
continue
diff --git a/engine/python3/engine.py b/engine/python3/engine.py
index f150a9f..bb84d3d 100644
--- a/engine/python3/engine.py
+++ b/engine/python3/engine.py
@@ -1681,7 +1681,6 @@ class Engine(IBus.EngineSimple):
value = prefs.get_value(section, key)
jastring.JaString.RESET(cls.__prefs, section, key, value)
-
@classmethod
def _init_prefs(cls):
prefs = cls.__prefs