diff options
author | fujiwarat <takao.fujiwara1@gmail.com> | 2012-10-26 10:22:44 +0900 |
---|---|---|
committer | fujiwarat <takao.fujiwara1@gmail.com> | 2012-10-26 10:22:44 +0900 |
commit | 4183ae6407274e6b6e70623aaa531f55f1c6b130 (patch) | |
tree | cf5cf68d2a26085a9cafd9736d838000dd4bc44b /setup | |
parent | aa669840d3084489f5e9613c184600565dff9825 (diff) | |
download | ibus-anthy-4183ae6407274e6b6e70623aaa531f55f1c6b130.tar.gz |
Fixed kana table customizations. (#1403)
Diffstat (limited to 'setup')
-rw-r--r-- | setup/anthyprefs.py.in | 540 | ||||
-rw-r--r-- | setup/main.py | 20 |
2 files changed, 348 insertions, 212 deletions
diff --git a/setup/anthyprefs.py.in b/setup/anthyprefs.py.in index 3135d93..995b794 100644 --- a/setup/anthyprefs.py.in +++ b/setup/anthyprefs.py.in @@ -33,6 +33,7 @@ __all__ = ['AnthyPrefs'] class AnthyPrefs(Prefs): _prefix = 'engine/anthy' + _char_to_config_key = None def __init__(self, bus=None, config=None): super(AnthyPrefs, self).__init__(bus, config) @@ -75,6 +76,48 @@ class AnthyPrefs(Prefs): def get_version(self): return '@VERSION@' + # Convert typing sequences to gsettings key. + # E.g. 'largea-bracketleft' to 'A[' + def typing_from_config_key(self, gkeys): + retval = '' + for key in gkeys.split('-'): + if key in _supported_gsettings_key_chars: + retval += key + continue + try: + ch = _config_key_to_char[key] + except KeyError: + print >> sys.stderr, 'Not supported key in gsettings', gkeys + retval = '' + break + retval += ch + return retval + + # Convert typing sequences to gsettings key. + # E.g. 'A[' to 'largea-bracketleft' + def typing_to_config_key(self, typing): + retval = '' + if self._char_to_config_key == None: + self._char_to_config_key = {} + for _key, _ch in _config_key_to_char.items(): + self._char_to_config_key[_ch] = _key + for ch in typing: + if ch in _supported_gsettings_key_chars: + if retval != '': + retval += '-' + retval += ch + continue + try: + key = self._char_to_config_key[ch] + except KeyError: + print >> sys.stderr, 'Not supported key in gsettings', typing + retval = '' + break + if retval != '': + retval += '-' + retval += key + return retval + # Sad! dict.keys() doesn't return the saved order. # locale.strcoll() also just returns the Unicode code point. # Unicode order is wrong in Japanese large 'a' and small 'a'. @@ -146,6 +189,83 @@ _japanese_ordered_list = [ 'ヴゃ', 'ヴぃぇ', 'ヴゅ', 'ヴょ', ] +# http://git.gnome.org/browse/glib/tree/gio/glib-compile-schemas.c#n765 +# gsettings supports keys named by "abcdefghijklmnopqrstuvwxyz0123456789-" +# and ibus-anthy uses '-' as the delimiter. +_supported_gsettings_key_chars = "abcdefghijklmnopqrstuvwxyz0123456789" + +_config_key_to_char = { + # no modifiers keys + 'minus' : '-', + 'asciicircum' : '^', + 'at' : '@', + 'bracketleft' : '[', + 'semicolon' : ';', + 'colon' : ':', + 'bracketright' : ']', + 'comma' : ',', + 'period' : '.', + 'slash' : '/', + 'backslash' : '\\', + + # shift modifiered keys + 'exclam' : '!', + 'quotedbl' : '"', + 'numbersign' : '#', + 'dollar' : '$', + 'percent' : '%', + 'ampersand' : '&', + 'apostrophe' : '\'', + 'parenleft' : '(', + 'parenright' : ')', + 'asciitilde' : '~', + 'equal' : '=', + 'bar' : '|', + + 'largeq' : 'Q', + 'largew' : 'W', + 'largee' : 'E', + 'larger' : 'R', + 'larget' : 'T', + 'largey' : 'Y', + 'largeu' : 'U', + 'largei' : 'I', + 'largeo' : 'O', + 'largep' : 'P', + 'grave' : '`', + + 'braceleft' : '{', + + 'largea' : 'A', + 'larges' : 'S', + 'larged' : 'D', + 'largef' : 'F', + 'largeg' : 'G', + 'largeh' : 'H', + 'largej' : 'J', + 'largek' : 'K', + 'largel' : 'L', + 'plus' : '+', + 'asterisk' : '*', + + 'braceright' : '}', + + 'largez' : 'Z', + 'largex' : 'X', + 'largec' : 'C', + 'largev' : 'V', + 'largeb' : 'B', + 'largen' : 'N', + 'largem' : 'M', + 'less' : '<', + 'greater' : '>', + + 'question' : '?', + 'underscore' : '_', + + 'yen' : '¥', +} + _cmd_keys = [ 'on_off', 'circle_input_mode', @@ -550,224 +670,224 @@ _config = { 'kana_typing_rule/jp': { # no modifiers keys - '1' : 'ぬ', - '2' : 'ふ', - '3' : 'あ', - '4' : 'う', - '5' : 'え', - '6' : 'お', - '7' : 'や', - '8' : 'ゆ', - '9' : 'よ', - '0' : 'わ', - '-' : 'ほ', - '^' : 'へ', - - 'q' : 'た', - 'w' : 'て', - 'e' : 'い', - 'r' : 'す', - 't' : 'か', - 'y' : 'ん', - 'u' : 'な', - 'i' : 'に', - 'o' : 'ら', - 'p' : 'せ', - '@' : '゛', - '[' : '゜', - - 'a' : 'ち', - 's' : 'と', - 'd' : 'し', - 'f' : 'は', - 'g' : 'き', - 'h' : 'く', - 'j' : 'ま', - 'k' : 'の', - 'l' : 'り', - ';' : 'れ', - ':' : 'け', - ']' : 'む', - - 'z' : 'つ', - 'x' : 'さ', - 'c' : 'そ', - 'v' : 'ひ', - 'b' : 'こ', - 'n' : 'み', - 'm' : 'も', - ',' : 'ね', - '.' : 'る', - '/' : 'め', - # '\\' : 'ー', - '\\' : 'ろ', + '1' : 'ぬ', + '2' : 'ふ', + '3' : 'あ', + '4' : 'う', + '5' : 'え', + '6' : 'お', + '7' : 'や', + '8' : 'ゆ', + '9' : 'よ', + '0' : 'わ', + 'minus' : 'ほ', + 'asciicircum' : 'へ', + + 'q' : 'た', + 'w' : 'て', + 'e' : 'い', + 'r' : 'す', + 't' : 'か', + 'y' : 'ん', + 'u' : 'な', + 'i' : 'に', + 'o' : 'ら', + 'p' : 'せ', + 'at' : '゛', + 'bracketleft' : '゜', + + 'a' : 'ち', + 's' : 'と', + 'd' : 'し', + 'f' : 'は', + 'g' : 'き', + 'h' : 'く', + 'j' : 'ま', + 'k' : 'の', + 'l' : 'り', + 'semicolon' : 'れ', + 'colon' : 'け', + 'bracketright' : 'む', + + 'z' : 'つ', + 'x' : 'さ', + 'c' : 'そ', + 'v' : 'ひ', + 'b' : 'こ', + 'n' : 'み', + 'm' : 'も', + 'comma' : 'ね', + 'period' : 'る', + 'slash' : 'め', + # 'backslash' : 'ー', + 'backslash' : 'ろ', # shift modifiered keys - '!' : 'ぬ', - '"' : 'ふ', - '#' : 'ぁ', - '$' : 'ぅ', - '%' : 'ぇ', - '&' : 'ぉ', - '\'' : 'ゃ', - '(' : 'ゅ', - ')' : 'ょ', - '~' : 'を', - '=' : 'ゑ', - '|' : 'ー', - - 'Q' : 'た', - 'W' : 'て', - 'E' : 'ぃ', - 'R' : 'す', - 'T' : 'ヵ', - 'Y' : 'ん', - 'U' : 'な', - 'I' : 'に', - 'O' : 'ら', - 'P' : 'せ', - '`' : '゛', - - '{' : '「', - - 'A' : 'ち', - 'S' : 'と', - 'D' : 'し', - 'F' : 'ゎ', - 'G' : 'き', - 'H' : 'く', - 'J' : 'ま', - 'K' : 'の', - 'L' : 'り', - '+' : 'れ', - '*' : 'ヶ', - - '}' : '」', - - 'Z' : 'っ', - 'X' : 'さ', - 'C' : 'そ', - 'V' : 'ゐ', - 'B' : 'こ', - 'M' : 'も', - 'N' : 'み', - '<' : '、', - '>' : '。', - - '?' : '・', - '_' : 'ろ', - - '¥' : 'ー', + 'exclam' : 'ぬ', + 'quotedbl' : 'ふ', + 'numbersign' : 'ぁ', + 'dollar' : 'ぅ', + 'percent' : 'ぇ', + 'ampersand' : 'ぉ', + 'apostrophe' : 'ゃ', + 'parenleft' : 'ゅ', + 'parenright' : 'ょ', + 'asciitilde' : 'を', + 'equal' : 'ゑ', + 'bar' : 'ー', + + 'largeq' : 'た', + 'largew' : 'て', + 'largee' : 'ぃ', + 'larger' : 'す', + 'larget' : 'ヵ', + 'largey' : 'ん', + 'largeu' : 'な', + 'largei' : 'に', + 'largeo' : 'ら', + 'largep' : 'せ', + 'grave' : '゛', + + 'braceleft' : '「', + + 'largea' : 'ち', + 'larges' : 'と', + 'larged' : 'し', + 'largef' : 'ゎ', + 'largeg' : 'き', + 'largeh' : 'く', + 'largej' : 'ま', + 'largek' : 'の', + 'largel' : 'り', + 'plus' : 'れ', + 'asterisk' : 'ヶ', + + 'braceright' : '」', + + 'largez' : 'っ', + 'largex' : 'さ', + 'largec' : 'そ', + 'largev' : 'ゐ', + 'largeb' : 'こ', + 'largen' : 'み', + 'largem' : 'も', + 'less' : '、', + 'greater' : '。', + + 'question' : '・', + 'underscore' : 'ろ', + + 'yen' : 'ー', }, 'kana_typing_rule/us': { # no modifiers keys - '`' : 'ろ', - '1' : 'ぬ', - '2' : 'ふ', - '3' : 'あ', - '4' : 'う', - '5' : 'え', - '6' : 'お', - '7' : 'や', - '8' : 'ゆ', - '9' : 'よ', - '0' : 'わ', - '-' : 'ほ', - '=' : 'へ', - - 'q' : 'た', - 'w' : 'て', - 'e' : 'い', - 'r' : 'す', - 't' : 'か', - 'y' : 'ん', - 'u' : 'な', - 'i' : 'に', - 'o' : 'ら', - 'p' : 'せ', - '[' : '゛', - ']' : '゜', - # '\\' : 'ー', - '\\' : 'む', - - 'a' : 'ち', - 's' : 'と', - 'd' : 'し', - 'f' : 'は', - 'g' : 'き', - 'h' : 'く', - 'j' : 'ま', - 'k' : 'の', - 'l' : 'り', - ';' : 'れ', - '\'' : 'け', - - 'z' : 'つ', - 'x' : 'さ', - 'c' : 'そ', - 'v' : 'ひ', - 'b' : 'こ', - 'n' : 'み', - 'm' : 'も', - ',' : 'ね', - '.' : 'る', - '/' : 'め', + 'grave' : 'ろ', + '1' : 'ぬ', + '2' : 'ふ', + '3' : 'あ', + '4' : 'う', + '5' : 'え', + '6' : 'お', + '7' : 'や', + '8' : 'ゆ', + '9' : 'よ', + '0' : 'わ', + 'minus' : 'ほ', + 'equal' : 'へ', + + 'q' : 'た', + 'w' : 'て', + 'e' : 'い', + 'r' : 'す', + 't' : 'か', + 'y' : 'ん', + 'u' : 'な', + 'i' : 'に', + 'o' : 'ら', + 'p' : 'せ', + 'bracketleft' : '゛', + 'bracketright' : '゜', + # 'backslash' : 'ー', + 'backslash' : 'む', + + 'a' : 'ち', + 's' : 'と', + 'd' : 'し', + 'f' : 'は', + 'g' : 'き', + 'h' : 'く', + 'j' : 'ま', + 'k' : 'の', + 'l' : 'り', + 'semicolon' : 'れ', + 'apostrophe' : 'け', + + 'z' : 'つ', + 'x' : 'さ', + 'c' : 'そ', + 'v' : 'ひ', + 'b' : 'こ', + 'n' : 'み', + 'm' : 'も', + 'comma' : 'ね', + 'period' : 'る', + 'slash' : 'め', # shift modifiered keys - '~' : 'ろ', - '!' : 'ぬ', - '@' : 'ふ', - '#' : 'ぁ', - '$' : 'ぅ', - '%' : 'ぇ', - '^' : 'ぉ', - '&' : 'ゃ', - '*' : 'ゅ', - '(' : 'ょ', - ')' : 'を', - '_' : 'ー', - '+' : 'ゑ', - - 'Q' : 'た', - 'W' : 'て', - 'E' : 'ぃ', - 'R' : 'す', - 'T' : 'ヵ', - 'Y' : 'ん', - 'U' : 'な', - 'I' : 'に', - 'O' : 'ら', - 'P' : 'せ', - '{' : '「', - - '}' : '」', - - '|' : 'む', - - 'A' : 'ち', - 'S' : 'と', - 'D' : 'し', - 'F' : 'ゎ', - 'G' : 'き', - 'H' : 'く', - 'J' : 'ま', - 'K' : 'の', - 'L' : 'り', - ':' : 'れ', - '"' : 'ヶ', - - 'Z' : 'っ', - 'X' : 'さ', - 'C' : 'そ', - 'V' : 'ゐ', - 'B' : 'こ', - 'M' : 'も', - 'N' : 'み', - '<' : '、', - '>' : '。', - - '?' : '・', + 'asciitilde' : 'ろ', + 'exclam' : 'ぬ', + 'at' : 'ふ', + 'numbersign' : 'ぁ', + 'dollar' : 'ぅ', + 'percent' : 'ぇ', + 'asciicircum' : 'ぉ', + 'ampersand' : 'ゃ', + 'asterisk' : 'ゅ', + 'parenleft' : 'ょ', + 'parenright' : 'を', + 'underscore' : 'ー', + 'plus' : 'ゑ', + + 'largeq' : 'た', + 'largew' : 'て', + 'largee' : 'ぃ', + 'larger' : 'す', + 'larget' : 'ヵ', + 'largey' : 'ん', + 'largeu' : 'な', + 'largei' : 'に', + 'largeo' : 'ら', + 'largep' : 'せ', + 'braceleft' : '「', + + 'braceright' : '」', + + 'bar' : 'む', + + 'largea' : 'ち', + 'larges' : 'と', + 'larged' : 'し', + 'largef' : 'ゎ', + 'largeg' : 'き', + 'largeh' : 'く', + 'largej' : 'ま', + 'largek' : 'の', + 'largel' : 'り', + 'colon' : 'れ', + 'quotedbl' : 'ヶ', + + 'largez' : 'っ', + 'largex' : 'さ', + 'largec' : 'そ', + 'largev' : 'ゐ', + 'largeb' : 'こ', + 'largen' : 'み', + 'largem' : 'も', + 'less' : '、', + 'greater' : '。', + + 'question' : '・', }, 'thumb': { 'keyboard_layout_mode': True, diff --git a/setup/main.py b/setup/main.py index c26ca56..837d334 100644 --- a/setup/main.py +++ b/setup/main.py @@ -351,15 +351,21 @@ class AnthySetup(object): for key in prefs.keys(section): key = prefs.str(key) value = prefs.get_value(section, key) + ch = prefs.typing_from_config_key(key) + if ch == '': + continue # config.set_value(key, None) is not supported. if value != None and value != '': - rule[key] = prefs.str(value) + rule[ch] = prefs.str(value) for key in prefs.get_value(section_base, 'newkeys'): key = prefs.str(key) value = self.prefs.get_value_direct(section, key) + ch = prefs.typing_from_config_key(key) + if ch == '': + continue # config.set_value(key, None) is not supported. if value != None and value != '': - rule[key] = prefs.str(value) + rule[ch] = prefs.str(value) for key, value in sorted(rule.items(), \ cmp = self.__japanese_tuple_sort): ls.append(['kana', key, value]) @@ -1191,6 +1197,11 @@ class AnthySetup(object): if section_base == None: self.__run_message_dialog(_("Your custom key is not assigned in any sections. Maybe a bug.")) return + if type == 'kana': + gkey = prefs.typing_to_config_key(key) + if gkey == '': + return + key = gkey section = section_base + '/' + method if key not in prefs.keys(section): # ibus does not support gconf_client_all_entries(). @@ -1233,6 +1244,11 @@ class AnthySetup(object): return section = section_base + '/' + method newkeys = prefs.get_value(section_base, 'newkeys') + if type == 'kana': + gkey = prefs.typing_to_config_key(key) + if gkey == '': + return + key = gkey if key in newkeys: newkeys.remove(key) prefs.set_value(section_base, 'newkeys', newkeys) |