diff options
author | fujiwarat <takao.fujiwara1@gmail.com> | 2010-10-15 13:04:19 +0900 |
---|---|---|
committer | fujiwarat <takao.fujiwara1@gmail.com> | 2010-10-15 13:04:19 +0900 |
commit | ddaf0a50acde55db87ff007c92ced28be1550cfd (patch) | |
tree | 50553c7412b99f506a4413b5c76ee2d961608096 | |
parent | db8a7878f30d5dc528487063403db8757b934986 (diff) | |
download | ibus-anthy-ddaf0a50acde55db87ff007c92ced28be1550cfd.tar.gz |
Added custom key table.
-rw-r--r-- | engine/jastring.py | 3 | ||||
-rw-r--r-- | engine/kana.py | 38 | ||||
-rw-r--r-- | engine/romaji.py | 43 | ||||
-rw-r--r-- | engine/tables.py | 4 | ||||
-rw-r--r-- | engine/thumb.py | 176 | ||||
-rw-r--r-- | setup/anthyprefs.py.in | 558 | ||||
-rw-r--r-- | setup/main.py | 377 | ||||
-rw-r--r-- | setup/setup.glade | 513 |
8 files changed, 1628 insertions, 84 deletions
diff --git a/engine/jastring.py b/engine/jastring.py index 7aa2ff2..78c281d 100644 --- a/engine/jastring.py +++ b/engine/jastring.py @@ -51,6 +51,9 @@ class JaString: def __init__(self, mode=TYPING_MODE_ROMAJI): self.__mode = mode self.reset() + romaji.RomajiSegment._init_romaji_typing_rule(self._prefs) + kana.KanaSegment._init_kana_typing_rule(self._prefs) + thumb.ThumbShiftSegment._init_thumb_typing_rule(self._prefs) def reset(self): self.__cursor = 0 diff --git a/engine/kana.py b/engine/kana.py index 4932a6c..c7731bd 100644 --- a/engine/kana.py +++ b/engine/kana.py @@ -27,12 +27,42 @@ import segment _UNFINISHED_HIRAGANA = set(u"かきくけこさしすせそたちつてとはひふへほ") class KanaSegment(segment.Segment): + _prefs = None + _kana_typing_rule_section = None def __init__(self, enchars=u"", jachars=u""): if not jachars: - jachars = kana_typing_rule.get(enchars, u"") + jachars = self.__get_kana_typing_rule(enchars, u"") super(KanaSegment, self).__init__(enchars, jachars) + @classmethod + def _init_kana_typing_rule(cls, prefs): + cls._prefs = prefs + if prefs == None: + cls._kana_typing_rule_section = None + return + method = prefs.get_value('kana_typing_rule', 'method') + if method == None: + method = 'default' + 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 + + def __get_kana_typing_rule(self, enchars, retval=None): + prefs = self._prefs + value = None + section = self._kana_typing_rule_section + if section != None: + if enchars in prefs.keys(section): + value = prefs.get_value(section, enchars) + if value == '': + value = None + if value == None: + value = retval + else: + value = kana_typing_rule_static.get(enchars, retval) + return value + def is_finished(self): return not (self._jachars in _UNFINISHED_HIRAGANA) @@ -48,7 +78,7 @@ class KanaSegment(segment.Segment): return [] return [KanaSegment(enchar)] self._enchars = self._enchars + enchar - self._jachars = kana_typing_rule.get(self._enchars, u"") + self._jachars = self.__get_kana_typing_rule(self._enchars, u"") return [] def prepend(self, enchar): @@ -56,7 +86,7 @@ class KanaSegment(segment.Segment): return [] if self._enchars == u"": self._enchars = enchar - self._jachars = kana_typing_rule.get(self._enchars, u"") + self._jachars = self.__get_kana_typing_rule(self._enchars, u"") return [] return [KanaSegment(enchar)] @@ -68,4 +98,4 @@ class KanaSegment(segment.Segment): enchars = list(self._enchars) del enchars[index] self._enchars = u"".join(enchars) - self._jachars = kana_typing_rule.get(self._enchars, u"") + self._jachars = self.__get_kana_typing_rule(self._enchars, u"") diff --git a/engine/romaji.py b/engine/romaji.py index 3deb8f9..6db6e82 100644 --- a/engine/romaji.py +++ b/engine/romaji.py @@ -28,13 +28,44 @@ def romaji_correction_rule_get(k, d): return (u'ん', k[1:2]) if k[0:1] == u'n' and not k[1:2] in u"aiueony'" else d class RomajiSegment(segment.Segment): + _prefs = None + _romaji_typing_rule_section = None + def __init__(self, enchars=u"", jachars=u"", shift=False): if not jachars and not shift: - jachars = romaji_typing_rule.get(enchars, None) + jachars = self.__get_romaji_typing_rule(enchars, None) if jachars == None: jachars = symbol_rule.get(enchars, u"") super(RomajiSegment, self).__init__(enchars, jachars) + @classmethod + def _init_romaji_typing_rule(cls, prefs): + cls._prefs = prefs + if prefs == None: + cls._romaji_typing_rule_section = None + return + 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 + + def __get_romaji_typing_rule(self, enchars, retval=None): + prefs = self._prefs + value = None + section = self._romaji_typing_rule_section + if section != None: + if enchars in prefs.keys(section): + value = prefs.get_value(section, enchars) + if value == '': + value = None + if value == None: + value = retval + else: + value = romaji_typing_rule_static.get(enchars, retval) + return value + def is_finished(self): return self._jachars != u"" @@ -49,7 +80,7 @@ class RomajiSegment(segment.Segment): self._enchars = text return [] - jachars = romaji_typing_rule.get(text, None) + jachars = self.__get_romaji_typing_rule(text, None) if jachars == None: jachars = symbol_rule.get(text, None) if jachars: @@ -73,7 +104,7 @@ class RomajiSegment(segment.Segment): for i in range(-min(4, len(text)), 0): enchars = text[i:] - jachars = romaji_typing_rule.get(enchars, None) + jachars = self.__get_romaji_typing_rule(enchars, None) if jachars == None: jachars = symbol_rule.get(enchars, None) if jachars: @@ -113,7 +144,7 @@ class RomajiSegment(segment.Segment): self._enchars = text return [] - jachars = romaji_typing_rule.get(text, None) + jachars = self.__get_romaji_typing_rule(text, None) if jachars == None: jachars = symbol_rule.get(text, None) if jachars: @@ -135,7 +166,7 @@ class RomajiSegment(segment.Segment): for i in range(min(4, len(text)), 0, -1): enchars = text[:i] - jachars = romaji_typing_rule.get(enchars, None) + jachars = self.__get_romaji_typing_rule(enchars, None) if jachars == None: jachars = symbol_rule.get(enchars, None) if jachars: @@ -169,7 +200,7 @@ class RomajiSegment(segment.Segment): enchars = list(self._enchars) del enchars[index] self._enchars = u"".join(enchars) - jachars = romaji_typing_rule.get(self._enchars, None) + jachars = self.__get_romaji_typing_rule(self._enchars, None) if jachars == None: jachars = symbol_rule.get(self._enchars, u"") self._jachars = jachars diff --git a/engine/tables.py b/engine/tables.py index a86a26a..1daf88d 100644 --- a/engine/tables.py +++ b/engine/tables.py @@ -21,7 +21,7 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # string, result, cont -romaji_typing_rule = { +romaji_typing_rule_static = { u"-" : u"ー", u"a" : u"あ", u"i" : u"い", @@ -363,7 +363,7 @@ romaji_utf8_rule = { } # a port of 101kana.sty from scim-anthy -kana_typing_rule = { +kana_typing_rule_static = { # no modifiers keys u"1" : u"ぬ", u"2" : u"ふ", diff --git a/engine/thumb.py b/engine/thumb.py index 8c4baff..c4d01c0 100644 --- a/engine/thumb.py +++ b/engine/thumb.py @@ -35,8 +35,9 @@ try: except ImportError: get_default_root_window = lambda : None +_THUMB_BASIC_METHOD = 'base' -_table = { +_table_static = { 'q': [u'。', u'', u'ぁ'], 'w': [u'か', u'が', u'え'], 'e': [u'た', u'だ', u'り'], @@ -87,7 +88,7 @@ _table = { '\\': [u'¥', u'', u''], } -_nicola_j_table = { +_nicola_j_table_static = { ':': [u':', u'', u''], '@': [u'、', u'', u''], '[': [u'゛', u'゜', u''], @@ -97,7 +98,7 @@ _nicola_j_table = { '0': [u'0', u'', u''], } -_nicola_a_table = { +_nicola_a_table_static = { ':': [u':', u'', u''], '@': [u'@', u'', u''], '[': [u'、', u'', u''], @@ -107,7 +108,7 @@ _nicola_a_table = { '0': [u'0', u')', u''], } -_nicola_f_table = { +_nicola_f_table_static = { ':': [u'、', u'', u''], '@': [u'@', u'', u''], '[': [u'゛', u'゜', u''], @@ -117,28 +118,28 @@ _nicola_f_table = { '0': [u'0', u'', u''], } -_kb231_j_fmv_table = { +_kb231_j_fmv_table_static = { '3': [u'3', u'', u'~'], '0': [u'0', u'『', u''], '-': [u'-', u'』', u''], '=': [u'=', u'', u''], } -_kb231_a_fmv_table = { +_kb231_a_fmv_table_static = { '3': [u'3', u'', u'~'], '0': [u'0', u')', u''], '-': [u'-', u'『', u''], '=': [u'=', u'』', u''], } -_kb231_f_fmv_table = { +_kb231_f_fmv_table_static = { '3': [u'3', u'', u'~'], '0': [u'0', u'『', u''], '-': [u'-', u'』', u''], '=': [u'=', u'', u''], } -_kb611_j_fmv_table = { +_kb611_j_fmv_table_static = { '`': [u'‘', u'', u''], '^': [u'々', u'£', u''], ':': [u':', u'', u''], @@ -149,7 +150,7 @@ _kb611_j_fmv_table = { '\\': [u'¥', u'¦', u''], } -_kb611_a_fmv_table = { +_kb611_a_fmv_table_static = { '`': [u'々', u'', u'£'], ':': [u':', u'', u''], '@': [u'@', u'', u''], @@ -158,7 +159,7 @@ _kb611_a_fmv_table = { '\\': [u'¥', u'¦', u''], } -_kb611_f_fmv_table = { +_kb611_f_fmv_table_static = { '`': [u'‘', u'', u''], '^': [u'々', u'£', u''], ':': [u'、', u'¢', u''], @@ -176,13 +177,13 @@ _shift_table = { '>': u'ぽ', } -table = {} -r_table = {} +table_static = {} +r_table_static = {} -for k in _table.keys(): - table[ord(k)] = _table[k] - for c in _table[k]: - r_table[c] = k +for k in _table_static.keys(): + table_static[ord(k)] = _table_static[k] + for c in _table_static[k]: + r_table_static[c] = k kana_voiced_consonant_rule = { u"か゛" : u"が", @@ -217,8 +218,8 @@ _UNFINISHED_HIRAGANA = set(u"かきくけこさしすせそたちつてとはひ class ThumbShiftKeyboard: def __init__(self, prefs=None): self.__prefs = prefs - self.__table = table - self.__r_table = r_table + self.__table = table_static + self.__r_table = r_table_static self.__shift_table = {} self.__ls = 0 self.__rs = 0 @@ -227,54 +228,109 @@ class ThumbShiftKeyboard: self.__layout = 0 self.__fmv_extension = 2 self.__handakuten = False + self.__thumb_typing_rule_section = None + self.__init_thumb_typing_rule() if self.__prefs != None: self.reset() self.__reset_shift_table(False) + def __init_thumb_typing_rule(self): + prefs = self.__prefs + if prefs == None: + self.__thumb_typing_rule_section = None + return + method = prefs.get_value('thumb_typing_rule', 'method') + if method == None: + method = _THUMB_BASIC_METHOD + self.__thumb_typing_rule_section = 'thumb_typing_rule/' + method + if self.__thumb_typing_rule_section not in prefs.sections(): + self.__thumb_typing_rule_section = None + def __init_layout_table(self): if self.__table != {}: self.__table.clear() if self.__r_table != {}: self.__r_table.clear() - for k in _table.keys(): - self.__table[ord(k)] = _table[k] - for c in _table[k]: - self.__r_table[c] = k - - def __reset_layout_table(self, init, j_table, a_table, f_table): + section = self.__thumb_typing_rule_section + if section != None: + prefs = self.__prefs + for k in prefs.keys(section): + value = prefs.get_value(section, k) + if len(value) == 3 and value[0] == '' and \ + value[1] == '' and value[2] == '': + continue + self.__table[ord(k)] = value + for c in value: + self.__r_table[c] = k + else: + for k in _table.keys(): + self.__table[ord(k)] = _table_static[k] + for c in _table_static[k]: + self.__r_table[c] = k + + def __reset_layout_table(self, init, + j_table_label, j_table, + a_table_label, a_table, + f_table_label, f_table): if init: self.__init_layout_table() + method = None sub_table = None if self.__layout == 0: + method = j_table_label sub_table = j_table elif self.__layout == 1: + method = a_table_label sub_table = a_table elif self.__layout == 2: + method = f_table_label sub_table = f_table - if sub_table == None: + if method == None or sub_table == None: return - for k in sub_table.keys(): - self.__table[ord(unicode(k))] = sub_table[k] - for c in sub_table[k]: - self.__r_table[c] = k + base_section = self.__thumb_typing_rule_section + sub_section = 'thumb_typing_rule/' + method + if base_section != None: + prefs = self.__prefs + for k in prefs.keys(sub_section): + value = prefs.get_value(sub_section, k) + if len(value) == 3 and value[0] == '' and \ + value[1] == '' and value[2] == '': + continue + self.__table[ord(k)] = value + for c in value: + self.__r_table[c] = k + else: + for k in sub_table.keys(): + self.__table[ord(unicode(k))] = sub_table[k] + for c in sub_table[k]: + self.__r_table[c] = k def __reset_extension_table(self, init): self.__reset_layout_table(init, - _nicola_j_table, - _nicola_a_table, - _nicola_f_table) + "nicola_j_table", + _nicola_j_table_static, + "nicola_a_table", + _nicola_a_table_static, + "nicola_f_table", + _nicola_f_table_static) if self.__fmv_extension == 0: return if self.__fmv_extension >= 1: self.__reset_layout_table(False, - _kb231_j_fmv_table, - _kb231_a_fmv_table, - _kb231_f_fmv_table) + "kb231_j_fmv_table", + _kb231_j_fmv_table_static, + "kb231_a_fmv_table", + _kb231_a_fmv_table_static, + "kb231_f_fmv_table", + _kb231_f_fmv_table_static) if self.__fmv_extension >= 2: self.__reset_layout_table(False, - _kb611_j_fmv_table, - _kb611_a_fmv_table, - _kb611_f_fmv_table) + "kb611_j_fmv_table", + _kb611_j_fmv_table_static, + "kb611_a_fmv_table", + _kb611_a_fmv_table_static, + "kb611_f_fmv_table", + _kb611_f_fmv_table_static) def __reset_shift_table(self, init): self.__reset_extension_table(init) @@ -417,16 +473,52 @@ class ThumbShiftKeyboard: class ThumbShiftSegment(segment.Segment): - + _prefs = None + _thumb_typing_rule_section = None + _r_table = {} + def __init__(self, enchars=u"", jachars=u""): if not jachars: if u'!' <= enchars <= u'~': jachars = segment.unichar_half_to_full(enchars) else: jachars = enchars - enchars = r_table.get(jachars, u'') + enchars = self._r_table.get(jachars, u'') super(ThumbShiftSegment, self).__init__(enchars, jachars) + @classmethod + def _init_thumb_typing_rule(cls, prefs): + cls._prefs = prefs + if prefs == None: + cls._thumb_typing_rule_section = None + return + method = prefs.get_value('thumb_typing_rule', 'method') + if method == None: + method = _THUMB_BASIC_METHOD + cls._thumb_typing_rule_section = 'thumb_typing_rule/' + method + if cls._thumb_typing_rule_section not in prefs.sections(): + cls._thumb_typing_rule_section = None + cls._init_layout_table() + + @classmethod + def _init_layout_table(cls): + if cls._r_table != {}: + cls._r_table.clear() + section = cls._thumb_typing_rule_section + if section != None: + prefs = cls._prefs + for k in prefs.keys(section): + value = prefs.get_value(section, k) + if len(value) == 3 and value[0] == '' and \ + value[1] == '' and value[2] == '': + continue + for c in value: + cls._r_table[c] = k + else: + for k in _table.keys(): + for c in _table_static[k]: + cls._r_table[c] = k + def is_finished(self): return not (self._jachars in _UNFINISHED_HIRAGANA) @@ -436,7 +528,7 @@ class ThumbShiftSegment(segment.Segment): text = self._jachars + enchar jachars = kana_voiced_consonant_rule.get(text, None) if jachars: - self._enchars = self._enchars + r_table.get(enchar, u'') + self._enchars = self._enchars + self._r_table.get(enchar, u'') self._jachars = jachars return [] return [ThumbShiftSegment(enchar)] @@ -449,7 +541,7 @@ class ThumbShiftSegment(segment.Segment): self._enchars = enchar self._jachars = segment.unichar_half_to_full(enchars) else: - self._enchars = r_table.get(enchar, u'') + self._enchars = self._r_table.get(enchar, u'') self._jachars = enchar return [] return [ThumbShiftSegment(enchar)] diff --git a/setup/anthyprefs.py.in b/setup/anthyprefs.py.in index 8fb5586..1c825d7 100644 --- a/setup/anthyprefs.py.in +++ b/setup/anthyprefs.py.in @@ -75,6 +75,70 @@ class AnthyPrefs(Prefs): return _cmd_keys return self.default[section].keys() + def get_japanese_ordered_list(self): + return _japanese_ordered_list + +# 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'. +# The workaround is to save the order here... +_japanese_ordered_list = [ + "あ", "い", "う", "え", "お", + "ぁ", "ぃ", "ぅ", "ぇ", "ぉ", + "いぇ", + "うぁ", "うぃ", "うぅ", "うぇ", "うぉ", + "か", "き", "く", "け", "こ", + "ゕ", "ゖ", "ヵ", "ヶ", + "が", "ぎ", "ぐ", "げ", "ご", + "きゃ", "きぃ", "きゅ", "きぇ", "きょ", + "くぁ", + "ぎゃ", "ぎぃ", "ぎゅ", "ぎぇ", "ぎょ", + "ぐぁ", + "さ", "し", "す", "せ", "そ", + "ざ", "じ", "ず", "ぜ", "ぞ", + "しゃ", "しぃ", "しゅ", "しぇ", "しょ", + "じゃ", "じぃ", "じゅ", "じぇ", "じょ", + "た", "ち", "つ", "て", "と", + "だ", "ぢ", "づ", "で", "ど", + "っ", + "ちゃ", "ちぃ", "ちゅ", "ちぇ", "ちょ", + "ぢぃ", "ぢぇ", + "ぢゃ", "ぢゅ", "ぢょ", + "つぁ", "つぃ", "つぇ", "つぉ", + "てぃ", "てぇ", + "てゃ", "てゅ", "てょ", + "とぅ", + "でぃ", "でぇ", + "でゃ", "でゅ", "でょ", + "どぅ", + "な", "に", "ぬ", "ね", "の", + "にぃ", "にぇ", + "にゃ", "にゅ", "にょ", + "は", "ひ", "ふ", "へ", "ほ", + "ば", "び", "ぶ", "べ", "ぼ", + "ぱ", "ぴ", "ぷ", "ぺ", "ぽ", + "ひぃ", "ひぇ", + "ひゃ", "ひゅ", "ひょ", + "びぃ", "びぇ", + "びゃ", "びゅ", "びょ", + "ぴぃ", "ぴぇ", + "ぴゃ", "ぴゅ", "ぴょ", + "ふぁ", "ふぃ", "ふぇ", "ふぉ", + "ふゃ", "ふゅ", "ふょ", + "ま", "み", "む", "め", "も", + "みぃ", "みぇ", + "みゃ", "みゅ", "みょ", + "や", "ゆ", "よ", + "ゃ", "ゅ", "ょ", + "ら", "り", "る", "れ", "ろ", + "りぃ", "りぇ", + "りゃ", "りゅ", "りょ", + "わ", "を", "ん", + "ゎ", + "ゐ", "ゑ", + "ー", + "ヴぁ", "ヴぃ", "ヴ", "ヴぇ", "ヴぉ", +] _cmd_keys = [ "on_off", @@ -174,6 +238,364 @@ _config = { 'dict_config_icon': '@KASUMI_ICON_FILE@', }, + 'romaji_typing_rule': { + 'method': 'default', + }, + + 'romaji_typing_rule/default': { + "-": "ー", + "a" : "あ", + "i" : "い", + "u" : "う", + "e" : "え", + "o" : "お", + "xa" : "ぁ", + "xi" : "ぃ", + "xu" : "ぅ", + "xe" : "ぇ", + "xo" : "ぉ", + "la" : "ぁ", + "li" : "ぃ", + "lu" : "ぅ", + "le" : "ぇ", + "lo" : "ぉ", + "wha" : "うぁ", + "whi" : "うぃ", + "whe" : "うぇ", + "who" : "うぉ", + "va" : "ヴぁ", + "vi" : "ヴぃ", + "vu" : "ヴ", + "ve" : "ヴぇ", + "vo" : "ヴぉ", + "ka" : "か", + "ki" : "き", + "ku" : "く", + "ke" : "け", + "ko" : "こ", + "lka" : "ヵ", + "lke" : "ヶ", +# "xka" : "ゕ", + "xka" : "ヵ", +# "xke" : "ゖ", + "xke" : "ヶ", + "ga" : "が", + "gi" : "ぎ", + "gu" : "ぐ", + "ge" : "げ", + "go" : "ご", + "kya" : "きゃ", + "kyi" : "きぃ", + "kyu" : "きゅ", + "kye" : "きぇ", + "kyo" : "きょ", + "kwa" : "くぁ", + "gya" : "ぎゃ", + "gyi" : "ぎぃ", + "gyu" : "ぎゅ", + "gye" : "ぎぇ", + "gyo" : "ぎょ", + "gwa" : "ぐぁ", + "sa" : "さ", + "si" : "し", + "su" : "す", + "se" : "せ", + "so" : "そ", + "za" : "ざ", + "zi" : "じ", + "zu" : "ず", + "ze" : "ぜ", + "zo" : "ぞ", + "sya" : "しゃ", + "syi" : "しぃ", + "syu" : "しゅ", + "sye" : "しぇ", + "syo" : "しょ", + "sha" : "しゃ", + "shi" : "し", + "shu" : "しゅ", + "she" : "しぇ", + "sho" : "しょ", + "zya" : "じゃ", + "zyi" : "じぃ", + "zyu" : "じゅ", + "zye" : "じぇ", + "zyo" : "じょ", + "ja" : "じゃ", + "jya" : "じゃ", + "ji" : "じ", + "jyi" : "じぃ", + "ju" : "じゅ", + "jyu" : "じゅ", + "je" : "じぇ", + "jye" : "じぇ", + "jo" : "じょ", + "jyo" : "じょ", + "ta" : "た", + "ti" : "ち", + "tu" : "つ", + "tsu" : "つ", + "te" : "て", + "to" : "と", + "da" : "だ", + "di" : "ぢ", + "du" : "づ", + "de" : "で", + "do" : "ど", + "xtu" : "っ", + "xtsu" : "っ", + "ltu" : "っ", + "ltsu" : "っ", + "tya" : "ちゃ", + "tyi" : "ちぃ", + "tyu" : "ちゅ", + "tye" : "ちぇ", + "tyo" : "ちょ", + "cya" : "ちゃ", + "cyi" : "ちぃ", + "cyu" : "ちゅ", + "cye" : "ちぇ", + "cyo" : "ちょ", + "cha" : "ちゃ", + "chi" : "ち", + "chu" : "ちゅ", + "che" : "ちぇ", + "cho" : "ちょ", + "dya" : "ぢゃ", + "dyi" : "ぢぃ", + "dyu" : "ぢゅ", + "dye" : "ぢぇ", + "dyo" : "ぢょ", + "tsa" : "つぁ", + "tsi" : "つぃ", + "tse" : "つぇ", + "tso" : "つぉ", + "tha" : "てゃ", + "thi" : "てぃ", + "thu" : "てゅ", + "the" : "てぇ", + "tho" : "てょ", + "twu" : "とぅ", + "dha" : "でゃ", + "dhi" : "でぃ", + "dhu" : "でゅ", + "dhe" : "でぇ", + "dho" : "でょ", + "dwu" : "どぅ", + "na" : "な", + "ni" : "に", + "nu" : "ぬ", + "ne" : "ね", + "no" : "の", + "nya" : "にゃ", + "nyi" : "にぃ", + "nyu" : "にゅ", + "nye" : "にぇ", + "nyo" : "にょ", + "ha" : "は", + "hi" : "ひ", + "hu" : "ふ", + "he" : "へ", + "ho" : "ほ", + "ba" : "ば", + "bi" : "び", + "bu" : "ぶ", + "be" : "べ", + "bo" : "ぼ", + "pa" : "ぱ", + "pi" : "ぴ", + "pu" : "ぷ", + "pe" : "ぺ", + "po" : "ぽ", + "hya" : "ひゃ", + "hyi" : "ひぃ", + "hyu" : "ひゅ", + "hye" : "ひぇ", + "hyo" : "ひょ", + "bya" : "びゃ", + "byi" : "びぃ", + "byu" : "びゅ", + "bye" : "びぇ", + "byo" : "びょ", + "pya" : "ぴゃ", + "pyi" : "ぴぃ", + "pyu" : "ぴゅ", + "pye" : "ぴぇ", + "pyo" : "ぴょ", + "fa" : "ふぁ", + "fi" : "ふぃ", + "fu" : "ふ", + "fe" : "ふぇ", + "fo" : "ふぉ", + "fya" : "ふゃ", + "fyi" : "ふぃ", + "fyu" : "ふゅ", + "fye" : "ふぇ", + "fyo" : "ふょ", + "ma" : "ま", + "mi" : "み", + "mu" : "む", + "me" : "め", + "mo" : "も", + "mya" : "みゃ", + "myi" : "みぃ", + "myu" : "みゅ", + "mye" : "みぇ", + "myo" : "みょ", + "ya" : "や", + "yi" : "い", + "yu" : "ゆ", + "ye" : "いぇ", + "yo" : "よ", + "lya" : "ゃ", + "lyi" : "ぃ", + "lyu" : "ゅ", + "lye" : "ぇ", + "lyo" : "ょ", + "xya" : "ゃ", + "xyi" : "ぃ", + "xyu" : "ゅ", + "xye" : "ぇ", + "xyo" : "ょ", + "ra" : "ら", + "ri" : "り", + "ru" : "る", + "re" : "れ", + "ro" : "ろ", + "rya" : "りゃ", + "ryi" : "りぃ", + "ryu" : "りゅ", + "rye" : "りぇ", + "ryo" : "りょ", + "wa" : "わ", + "wi" : "うぃ", + "wu" : "う", + "we" : "うぇ", + "wo" : "を", + "lwa" : "ゎ", + "xwa" : "ゎ", + "n'" : "ん", + "nn" : "ん", + "wyi" : "ゐ", + "wye" : "ゑ", + }, + + 'kana_typing_rule': { + 'method': 'default', + }, + + 'kana_typing_rule/default': { + # 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" : "も", + "," : "ね", + "." : "る", + "/" : "め", + # "\\" : "ー", + "\\" : "ろ", + + # 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" : "み", + "<" : "、", + ">" : "。", + + "?" : "・", + "_" : "ろ", + + "¥" : "ー", + }, + 'thumb': { 'keyboard_layout_mode': True, 'keyboard_layout': 0, @@ -185,6 +607,142 @@ _config = { 't2': 75, }, + 'thumb_typing_rule': { + 'method': 'base', + }, + + 'thumb_typing_rule/base': { + 'q': [u'。', u'', u'ぁ'], + 'w': [u'か', u'が', u'え'], + 'e': [u'た', u'だ', u'り'], + 'r': [u'こ', u'ご', u'ゃ'], + 't': [u'さ', u'ざ', u'れ'], + + 'y': [u'ら', u'よ', u'ぱ'], + 'u': [u'ち', u'に', u'ぢ'], + 'i': [u'く', u'る', u'ぐ'], + 'o': [u'つ', u'ま', u'づ'], + 'p': [u',', u'ぇ', u'ぴ'], + '@': [u'、', u'', u''], + '[': [u'゛', u'゜', u''], + + 'a': [u'う', u'', u'を'], + 's': [u'し', u'じ', u'あ'], + 'd': [u'て', u'で', u'な'], + 'f': [u'け', u'げ', u'ゅ'], + 'g': [u'せ', u'ぜ', u'も'], + + 'h': [u'は', u'み', u'ば'], + 'j': [u'と', u'お', u'ど'], + 'k': [u'き', u'の', u'ぎ'], + 'l': [u'い', u'ょ', u'ぽ'], + ';': [u'ん', u'っ', u''], + + 'z': [u'.', u'', u'ぅ'], + 'x': [u'ひ', u'び', u'ー'], + 'c': [u'す', u'ず', u'ろ'], + 'v': [u'ふ', u'ぶ', u'や'], + 'b': [u'へ', u'べ', u'ぃ'], + + 'n': [u'め', u'ぬ', u'ぷ'], + 'm': [u'そ', u'ゆ', u'ぞ'], + ',': [u'ね', u'む', u'ぺ'], + '.': [u'ほ', u'わ', u'ぼ'], + '/': [u'・', u'ぉ', u''], + + '1': [u'1', u'', u'?'], + '2': [u'2', u'', u'/'], + '4': [u'4', u'', u'「'], + '5': [u'5', u'', u'」'], + + '6': [u'6', u'[', u''], + '7': [u'7', u']', u''], + '8': [u'8', u'(', u''], + '9': [u'9', u')', u''], + '\\': [u'¥', u'', u''], + }, + + 'thumb_typing_rule/nicola_j_table': { + ':': [u':', u'', u''], + '@': [u'、', u'', u''], + '[': [u'゛', u'゜', u''], + ']': [u'」', u'', u''], + '8': [u'8', u'(', u''], + '9': [u'9', u')', u''], + '0': [u'0', u'', u''], + }, + + 'thumb_typing_rule/nicola_a_table': { + ':': [u':', u'', u''], + '@': [u'@', u'', u''], + '[': [u'、', u'', u''], + ']': [u'゛', u'゜', u''], + '8': [u'8', u'', u''], + '9': [u'9', u'(', u''], + '0': [u'0', u')', u''], + }, + + 'thumb_typing_rule/nicola_f_table': { + ':': [u'、', u'', u''], + '@': [u'@', u'', u''], + '[': [u'゛', u'゜', u''], + ']': [u'」', u'', u''], + '8': [u'8', u'(', u''], + '9': [u'9', u')', u''], + '0': [u'0', u'', u''], + }, + + 'thumb_typing_rule/kb231_j_fmv_table': { + '3': [u'3', u'', u'~'], + '0': [u'0', u'『', u''], + '-': [u'-', u'』', u''], + '=': [u'=', u'', u''], + }, + + 'thumb_typing_rule/kb231_a_fmv_table': { + '3': [u'3', u'', u'~'], + '0': [u'0', u')', u''], + '-': [u'-', u'『', u''], + '=': [u'=', u'』', u''], + }, + + 'thumb_typing_rule/kb231_f_fmv_table': { + '3': [u'3', u'', u'~'], + '0': [u'0', u'『', u''], + '-': [u'-', u'』', u''], + '=': [u'=', u'', u''], + }, + + 'thumb_typing_rule/kb611_j_fmv_table': { + '`': [u'‘', u'', u''], + '^': [u'々', u'£', u''], + ':': [u':', u'', u''], + '@': [u'、', u'¢', u''], + '[': [u'゛', u'゜', u''], + # keysyms are same and keycodes depend on the platforms. + #'¥': [u'¥', u'¬', u''], + '\\': [u'¥', u'¦', u''], + }, + + 'thumb_typing_rule/kb611_a_fmv_table': { + '`': [u'々', u'', u'£'], + ':': [u':', u'', u''], + '@': [u'@', u'', u''], + '[': [u'、', u'¢', u''], + #'¥': [u'¥', u'¬', u''], + '\\': [u'¥', u'¦', u''], + }, + + 'thumb_typing_rule/kb611_f_fmv_table': { + '`': [u'‘', u'', u''], + '^': [u'々', u'£', u''], + ':': [u'、', u'¢', u''], + '@': [u'@', u'', u''], + '[': [u'゛', u'゜', u''], + #'¥': [u'¥', u'¬', u''], + '\\': [u'¥', u'¦', u''], + }, + 'dict': { 'anthy_zipcode': ['@ANTHY_ZIPCODE_FILE@'], 'ibus_symbol': ['@pkgdatadir@/dicts/symbol.t'], diff --git a/setup/main.py b/setup/main.py index af36484..e8b3a8f 100644 --- a/setup/main.py +++ b/setup/main.py @@ -45,6 +45,7 @@ class AnthySetup(object): self.__config = Bus().get_config() self.__thumb_kb_layout_mode = None self.__thumb_kb_layout = None + self.__japanese_ordered_dict = {} self.prefs = prefs = AnthyPrefs(None, self.__config) localedir = getenv("IBUS_LOCALEDIR") @@ -165,8 +166,17 @@ class AnthySetup(object): tv.set_model(ls) self.__append_dicts_in_model() + self.__init_japanese_sort() + xml.signal_autoconnect(self) + def __init_japanese_sort(self): + japanese_ordered_dict = {} + japanese_ordered_list = self.prefs.get_japanese_ordered_list() + for index, c in enumerate(japanese_ordered_list): + japanese_ordered_dict[c] = index + self.__japanese_ordered_dict = japanese_ordered_dict; + def __get_userhome(self): if 'HOME' not in environ: import pwd @@ -196,6 +206,233 @@ class AnthySetup(object): dlg.run() dlg.destroy() + def __japanese_tuple_sort(self, a, b): + if a[1] == b[1]: + return cmp(a[0], b[0]) + elif a[1] in self.__japanese_ordered_dict and \ + b[1] in self.__japanese_ordered_dict: + return self.__japanese_ordered_dict[a[1]] - \ + self.__japanese_ordered_dict[b[1]] + elif a[1] not in self.__japanese_ordered_dict and \ + b[1] in self.__japanese_ordered_dict: + return 1 + elif a[1] in self.__japanese_ordered_dict and \ + b[1] not in self.__japanese_ordered_dict: + return -1 + else: + return cmp(a[1], b[1]) + + def __japanese_thumb_sort(self, a, b): + return cmp(a[0], b[0]) + + def __get_romaji_treeview_custom_key_table(self, method): + prefs = self.prefs + rule = {} + ls = gtk.ListStore(str, str, str) + tv = self.xml.get_widget('treeview_custom_key_table') + section = 'romaji_typing_rule/' + str(method) + for key in prefs.keys(section): + key = str(key) + value = prefs.get_value(section, key) + # config.set_value(key, None) is not supported. + if value != None and value != '': + rule[key] = str(value) + for key, value in sorted(rule.items(), \ + cmp = self.__japanese_tuple_sort): + ls.append(['romaji', key, value]) + tv.append_column(gtk.TreeViewColumn(_(_("Input Chars")), + gtk.CellRendererText(), text=1)) + tv.append_column(gtk.TreeViewColumn(_(_("Output Chars")), + gtk.CellRendererText(), text=2)) + tv.set_model(ls) + return tv + + def __get_kana_treeview_custom_key_table(self, method): + prefs = self.prefs + rule = {} + ls = gtk.ListStore(str, str, str) + tv = self.xml.get_widget('treeview_custom_key_table') + section = 'kana_typing_rule/' + str(method) + for key in prefs.keys(section): + key = str(key) + value = prefs.get_value(section, key) + # config.set_value(key, None) is not supported. + if value != None and value != '': + rule[key] = str(value) + for key, value in sorted(rule.items(), \ + cmp = self.__japanese_tuple_sort): + ls.append(['kana', key, value]) + tv.append_column(gtk.TreeViewColumn(_(_("Input Chars")), + gtk.CellRendererText(), text=1)) + tv.append_column(gtk.TreeViewColumn(_(_("Output Chars")), + gtk.CellRendererText(), text=2)) + tv.set_model(ls) + return tv + + def __get_thumb_treeview_custom_key_table(self, method): + prefs = self.prefs + rule = {} + ls = gtk.ListStore(str, str, str, str, str) + tv = self.xml.get_widget('treeview_custom_key_table') + section = 'thumb_typing_rule/' + str(method) + for key in prefs.keys(section): + key = str(key) + value = prefs.get_value(section, key) + # config.set_value(key, None) is not supported. + if value != None and len(value) == 3 and \ + ((value[0] != None and value[0] != '') or \ + (value[1] != None and value[1] != '') or \ + (value[2] != None and value[2] != '')): + rule[key] = {} + rule[key][0] = str(value[0]) + rule[key][1] = str(value[1]) + rule[key][2] = str(value[2]) + for key, value in sorted(rule.items(), \ + cmp = self.__japanese_thumb_sort): + ls.append(['thumb', key, value[0], value[2], value[1]]) + tv.append_column(gtk.TreeViewColumn(_(_("Input")), + gtk.CellRendererText(), text=1)) + tv.append_column(gtk.TreeViewColumn(_(_("Single")), + gtk.CellRendererText(), text=2)) + tv.append_column(gtk.TreeViewColumn(_(_("Left")), + gtk.CellRendererText(), text=3)) + tv.append_column(gtk.TreeViewColumn(_(_("Right")), + gtk.CellRendererText(), text=4)) + tv.set_model(ls) + return tv + + def __show_dialog_custom_key_table_extention(self, mode): + hbox_combo = self.xml.get_widget('hbox_for_combobox_custom_key_table') + label_left = self.xml.get_widget('label_left_thumb_shift_custom_key') + entry_left = self.xml.get_widget('entry_left_thumb_shift_custom_key') + label_right = self.xml.get_widget('label_right_thumb_shift_custom_key') + entry_right = self.xml.get_widget('entry_right_thumb_shift_custom_key') + if mode == "thumb": + hbox_combo.show() + label_left.show() + entry_left.show() + label_right.show() + entry_right.show() + else: + hbox_combo.hide() + label_left.hide() + entry_left.hide() + label_right.hide() + entry_right.hide() + + def __connect_dialog_custom_key_table_buttons(self, mode): + tv = self.xml.get_widget('treeview_custom_key_table') + tv.get_selection().connect_after('changed', + self.on_selection_custom_key_table_changed, 0) + entry = self.xml.get_widget('entry_input_custom_key') + entry.connect('changed', self.on_entry_custom_key_changed, mode) + entry = self.xml.get_widget('entry_output_custom_key') + entry.connect('changed', self.on_entry_custom_key_changed, mode) + entry = self.xml.get_widget('entry_left_thumb_shift_custom_key') + entry.connect('changed', self.on_entry_custom_key_changed, mode) + entry = self.xml.get_widget('entry_right_thumb_shift_custom_key') + entry.connect('changed', self.on_entry_custom_key_changed, mode) + button = self.xml.get_widget('button_add_custom_key') + button.set_sensitive(False) + button.connect('clicked', self.on_btn_add_custom_key, mode) + button = self.xml.get_widget('button_remove_custom_key') + button.set_sensitive(False) + button.connect('clicked', self.on_btn_remove_custom_key, tv) + + def __disconnect_dialog_custom_key_table_buttons(self): + tv = self.xml.get_widget('treeview_custom_key_table') + combobox = self.xml.get_widget('combobox_custom_key_table') + if tv != None: + for column in tv.get_columns(): + tv.remove_column(column) + for child in tv.get_children(): + tv.remove(child) + entry = self.xml.get_widget('entry_input_custom_key') + entry.disconnect_by_func(self.on_entry_custom_key_changed) + entry.set_text('') + entry = self.xml.get_widget('entry_output_custom_key') + entry.disconnect_by_func(self.on_entry_custom_key_changed) + entry.set_text('') + entry = self.xml.get_widget('entry_left_thumb_shift_custom_key') + entry.disconnect_by_func(self.on_entry_custom_key_changed) + entry = self.xml.get_widget('entry_right_thumb_shift_custom_key') + entry.disconnect_by_func(self.on_entry_custom_key_changed) + button = self.xml.get_widget('button_add_custom_key') + button.disconnect_by_func(self.on_btn_add_custom_key) + button = self.xml.get_widget('button_remove_custom_key') + button.disconnect_by_func(self.on_btn_remove_custom_key) + combobox.clear() + combobox.disconnect_by_func(self.on_cb_custom_key_table_changed) + + def __run_dialog_custom_key_table(self, mode): + prefs = self.prefs + dlg = self.xml.get_widget('dialog_custom_key_table') + label = self.xml.get_widget('label_custom_key_table') + label_output = self.xml.get_widget('label_output_custom_key') + list_labels = [] + if mode == "romaji": + dlg.set_title(_("Customize Romaji Key Table")) + label.set_label(_("_Romaji Key Table")) + label_output.set_label(_("_Output Chars")) + list_labels = [["default", _("Default")]] + self.__show_dialog_custom_key_table_extention(mode) + elif mode == "kana": + dlg.set_title(_("Customize Kana Key Table")) + label.set_label(_("_Kana Key Table")) + label_output.set_label(_("_Output Chars")) + list_labels = [["default", _("Default")]] + self.__show_dialog_custom_key_table_extention(mode) + elif mode == "thumb": + dlg.set_title(_("Customize Thumb Shift Key Table")) + label.set_label(_("_Thumb Shift Key Table")) + label_output.set_label(_("Single _Output Chars")) + list_labels = [["base", _("Base")], + ["nicola_j_table", _("NICOLA-J key extension")], + ["nicola_a_table", _("NICOLA-A key extension")], + ["nicola_f_table", _("NICOLA-F key extension")], + ["kb231_j_fmv_table", _("FMV KB231-J key extension")], + ["kb231_a_fmv_table", _("FMV KB231-A key extension")], + ["kb231_f_fmv_table", _("FMV KB231-F key extension")], + ["kb611_j_fmv_table", _("FMV KB611-J key extension")], + ["kb611_a_fmv_table", _("FMV KB611-A key extension")], + ["kb611_f_fmv_table", _("FMV KB611-F key extension")], + ] + self.__show_dialog_custom_key_table_extention(mode) + ls = gtk.ListStore(str, str) + for s in list_labels: + ls.append([s[1], s[0]]) + renderer = gtk.CellRendererText() + combobox = self.xml.get_widget('combobox_custom_key_table') + combobox.pack_start(renderer, True) + combobox.add_attribute(renderer, "text", 0) + combobox.set_model(ls) + + tv = None + if mode == "romaji": + method = prefs.get_value('romaji_typing_rule', 'method') + if method == None: + method = 'default' + tv = self.__get_romaji_treeview_custom_key_table(method) + if mode == "kana": + method = prefs.get_value('kana_typing_rule', 'method') + if method == None: + method = 'default' + tv = self.__get_kana_treeview_custom_key_table(method) + if mode == "thumb": + method = prefs.get_value('thumb_typing_rule', 'method') + if method == None: + method = 'base' + tv = self.__get_thumb_treeview_custom_key_table(method) + + self.__connect_dialog_custom_key_table_buttons(mode) + combobox.set_active(0) + combobox.connect("changed", self.on_cb_custom_key_table_changed, mode) + + id = dlg.run() + dlg.hide() + + self.__disconnect_dialog_custom_key_table_buttons() + def __set_thumb_kb_label(self): if self.__thumb_kb_layout_mode == None or \ self.__thumb_kb_layout == None: @@ -475,6 +712,10 @@ class AnthySetup(object): for name in [['btn_default', 'btn_edit'], ['button5', 'button6']][id]: set_sensitive(name, flg) + def on_selection_custom_key_table_changed(self, widget, id): + button = self.xml.get_widget('button_remove_custom_key') + button.set_sensitive(True) + def on_main_delete(self, widget, event): self.on_btn_cancel_clicked(widget) return True @@ -515,6 +756,24 @@ class AnthySetup(object): self.prefs.set_value(section, key, widget.get_active()) self.xml.get_widget('btn_apply').set_sensitive(True) + def on_cb_custom_key_table_changed(self, widget, user_data): + tv = self.xml.get_widget('treeview_custom_key_table') + mode = user_data + id = widget.get_active() + model = widget.get_model() + method = model[id][1] + if tv != None: + for column in tv.get_columns(): + tv.remove_column(column) + for child in tv.get_children(): + tv.remove(child) + if mode == 'romaji': + tv = self.__get_romaji_treeview_custom_key_table(method) + elif mode == 'kana': + tv = self.__get_kana_treeview_custom_key_table(method) + elif mode == 'thumb': + tv = self.__get_thumb_treeview_custom_key_table(method) + def on_sb_changed(self, widget): section, key = self.__get_section_key(widget.name) self.prefs.set_value(section, key, widget.get_value_as_int()) @@ -557,6 +816,105 @@ class AnthySetup(object): ls.set(it, 1, new) self.xml.get_widget('btn_apply').set_sensitive(True) + def on_btn_romaji_custom_table_clicked(self, widget): + self.__run_dialog_custom_key_table("romaji") + + def on_btn_kana_custom_table_clicked(self, widget): + self.__run_dialog_custom_key_table("kana") + + def on_btn_thumb_custom_table_clicked(self, widget): + self.__run_dialog_custom_key_table("thumb") + + def on_btn_add_custom_key(self, widget, user_data): + prefs = self.prefs + input = self.xml.get_widget('entry_input_custom_key') + output = self.xml.get_widget('entry_output_custom_key') + left = self.xml.get_widget('entry_left_thumb_shift_custom_key') + right = self.xml.get_widget('entry_right_thumb_shift_custom_key') + model = self.xml.get_widget('treeview_custom_key_table').get_model() + combobox = self.xml.get_widget('combobox_custom_key_table') + id = combobox.get_active() + model_combobox = combobox.get_model() + method = model_combobox[id][1] + type = user_data + section = None + key = input.get_text() + value = output.get_text() + left_text = left.get_text() + right_text = right.get_text() + + if key == None: + self.__run_message_dialog(_("Please specify Input Chars")) + return + elif value == None: + self.__run_message_dialog(_("Please specify Output Chars")) + return + elif type == 'thumb' and left_text == None: + self.__run_message_dialog(_("Please specify Left Thumb Shift Chars")) + return + elif type == 'thumb' and right_text == None: + self.__run_message_dialog(_("Please specify Right Thumb Shift Chars")) + return + + if type == 'romaji': + section = 'romaji_typing_rule/' + method + model.append([type, key, value]) + elif type == 'kana': + section = 'kana_typing_rule/' + method + model.append([type, key, value]) + elif type == 'thumb': + section = 'thumb_typing_rule/' + method + model.append([type, key, value, left_text, right_text]) + if section == None: + self.__run_message_dialog(_("Your custom key is not assigned in any sections. Maybe a bug.")) + return + if section not in prefs.sections(): + prefs.set_new_section(section) + if key not in prefs.keys(section): + prefs.set_new_key(section, key) + if type != 'thumb': + prefs.set_value(section, key, value) + else: + prefs.set_value(section, key, [value, right_text, left_text]) + left.set_text('') + right.set_text('') + input.set_text('') + output.set_text('') + self.xml.get_widget('btn_apply').set_sensitive(True) + + def on_btn_remove_custom_key(self, widget, user_data): + prefs = self.prefs + combobox = self.xml.get_widget('combobox_custom_key_table') + id = combobox.get_active() + model_combobox = combobox.get_model() + method = model_combobox[id][1] + tv = user_data + l, i = tv.get_selection().get_selected() + type = l[i][0] + key = l[i][1] + section = None + if type == 'romaji': + section = 'romaji_typing_rule/' + method + elif type == 'kana': + section = 'kana_typing_rule/' + method + elif type == 'thumb': + section = 'thumb_typing_rule/' + method + if section == None: + self.__run_message_dialog(_("Your custom key is not assigned in any sections. Maybe a bug.")) + return + if section not in prefs.sections(): + prefs.set_new_section(section) + if key not in prefs.keys(section): + prefs.set_new_key(section, key) + # config.set_value(key, None) is not supported. + if type != 'thumb': + prefs.set_value(section, key, '') + else: + prefs.set_value(section, key, ['', '', '']) + l.remove(i) + widget.set_sensitive(False) + self.xml.get_widget('btn_apply').set_sensitive(True) + def on_btn_thumb_key_clicked(self, widget): if widget.name == 'thumb:button_ls': entry = 'thumb:ls' @@ -811,6 +1169,25 @@ class AnthySetup(object): widget.response(gtk.RESPONSE_OK) return True + def on_entry_custom_key_changed(self, widget, user_data): + mode = user_data + input = self.xml.get_widget('entry_input_custom_key') + output = self.xml.get_widget('entry_output_custom_key') + left = self.xml.get_widget('entry_left_thumb_shift_custom_key') + right = self.xml.get_widget('entry_right_thumb_shift_custom_key') + button = self.xml.get_widget('button_add_custom_key') + if mode != "thumb": + if input.get_text() != "" and output.get_text() != "": + button.set_sensitive(True) + else: + button.set_sensitive(False) + else: + if input.get_text() != "" and output.get_text() != "" and \ + left.get_text() != "" and right.get_text() != "": + button.set_sensitive(True) + else: + button.set_sensitive(False) + def on_entry_dict_command_changed(self, widget): if not widget.get_text(): return diff --git a/setup/setup.glade b/setup/setup.glade index b6ab96d..a09d606 100644 --- a/setup/setup.glade +++ b/setup/setup.glade @@ -38,7 +38,7 @@ <property name="column_spacing">8</property> <property name="row_spacing">4</property> <child> - <widget class="GtkLabel" id="label9"> + <widget class="GtkLabel" id="label101"> <property name="visible">True</property> <property name="xalign">0</property> <property name="label" translatable="yes">_Input Mode:</property> @@ -67,7 +67,7 @@ Wide Latin</property> </packing> </child> <child> - <widget class="GtkLabel" id="label21"> + <widget class="GtkLabel" id="label102"> <property name="visible">True</property> <property name="xalign">0</property> <property name="label" translatable="yes">_Typing Method:</property> @@ -98,7 +98,7 @@ Thumb shift</property> </packing> </child> <child> - <widget class="GtkLabel" id="label10"> + <widget class="GtkLabel" id="label103"> <property name="visible">True</property> <property name="xalign">0</property> <property name="label" translatable="yes">Conversion _Mode:</property> @@ -134,7 +134,7 @@ Immediate conversion (Single segment)</property> </widget> </child> <child> - <widget class="GtkLabel" id="label16"> + <widget class="GtkLabel" id="label151"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Initial Setting</b></property> <property name="use_markup">True</property> @@ -169,7 +169,7 @@ Immediate conversion (Single segment)</property> <property name="column_spacing">8</property> <property name="row_spacing">4</property> <child> - <widget class="GtkLabel" id="label12"> + <widget class="GtkLabel" id="label104"> <property name="visible">True</property> <property name="xalign">0</property> <property name="label" translatable="yes">_Period Style:</property> @@ -182,7 +182,7 @@ Immediate conversion (Single segment)</property> </packing> </child> <child> - <widget class="GtkLabel" id="label13"> + <widget class="GtkLabel" id="label105"> <property name="visible">True</property> <property name="xalign">0</property> <property name="label" translatable="yes">Symbo_l Style:</property> @@ -197,7 +197,7 @@ Immediate conversion (Single segment)</property> </packing> </child> <child> - <widget class="GtkLabel" id="label26"> + <widget class="GtkLabel" id="label106"> <property name="visible">True</property> <property name="xalign">0</property> <property name="label" translatable="yes">Numpad _Key Type:</property> @@ -260,7 +260,7 @@ Convert Characters </packing> </child> <child> - <widget class="GtkLabel" id="label24"> + <widget class="GtkLabel" id="label107"> <property name="visible">True</property> <property name="xalign">0</property> <property name="label" translatable="yes">_Behavior on Period:</property> @@ -275,7 +275,7 @@ Convert Characters </packing> </child> <child> - <widget class="GtkLabel" id="label23"> + <widget class="GtkLabel" id="label108"> <property name="visible">True</property> <property name="xalign">0</property> <property name="label" translatable="yes">Behavior on _Focus Out:</property> @@ -326,7 +326,7 @@ Hold </widget> </child> <child> - <widget class="GtkLabel" id="label17"> + <widget class="GtkLabel" id="label152"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Behavior</b></property> <property name="use_markup">True</property> @@ -381,7 +381,7 @@ Hold <property name="visible">True</property> <property name="spacing">8</property> <child> - <widget class="GtkLabel" id="label25"> + <widget class="GtkLabel" id="label109"> <property name="visible">True</property> <property name="xalign">0</property> <property name="label" translatable="yes">Candidate _Window Page Size:</property> @@ -452,7 +452,7 @@ Hold </widget> </child> <child> - <widget class="GtkLabel" id="label22"> + <widget class="GtkLabel" id="label153"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Other</b></property> <property name="use_markup">True</property> @@ -492,7 +492,7 @@ Hold <property name="visible">True</property> <property name="spacing">8</property> <child> - <widget class="GtkLabel" id="label6"> + <widget class="GtkLabel" id="label21"> <property name="visible">True</property> <property name="label" translatable="yes">_Shortcut Type:</property> <property name="use_underline">True</property> @@ -516,6 +516,8 @@ Wnn <signal name="changed" handler="on_shortcut_type_changed"/> </widget> <packing> + <property name="expand">False</property> + <property name="fill">False</property> <property name="position">1</property> </packing> </child> @@ -649,6 +651,185 @@ Wnn <property name="border_width">8</property> <property name="spacing">4</property> <child> + <widget class="GtkFrame" id="frame31"> + <property name="visible">True</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <child> + <widget class="GtkAlignment" id="alignment31"> + <property name="visible">True</property> + <property name="top_padding">0</property> + <property name="bottom_padding">8</property> + <property name="left_padding">12</property> + <child> + <widget class="GtkVBox" id="vbox31"> + <property name="visible">True</property> + <property name="border_width">4</property> + <property name="spacing">4</property> + <child> + <widget class="GtkTable" id="table31"> + <property name="visible">True</property> + <property name="n_rows">2</property> + <property name="n_columns">2</property> + <property name="column_spacing">8</property> + <property name="row_spacing">4</property> + <child> + <widget class="GtkLabel" id="label302"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Romaji Key Table:</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">romaji:button_custom_table</property> + </widget> + <packing> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkButton" id="romaji:button_custom_table"> + <property name="label">...</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="receives_default">False</property> + <property name="use_underline">True</property> + <signal name="clicked" handler="on_btn_romaji_custom_table_clicked"/> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="x_options">GTK_FILL</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + </widget> + </child> + </widget> + </child> + <child> + <widget class="GtkLabel" id="label301"> + <property name="visible">True</property> + <property name="label" translatable="yes"><b>Romaji</b></property> + <property name="use_markup">True</property> + </widget> + <packing> + <property name="type">label_item</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkFrame" id="frame32"> + <property name="visible">True</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <child> + <widget class="GtkAlignment" id="alignment32"> + <property name="visible">True</property> + <property name="top_padding">0</property> + <property name="bottom_padding">8</property> + <property name="left_padding">12</property> + <child> + <widget class="GtkVBox" id="vbox32"> + <property name="visible">True</property> + <property name="border_width">4</property> + <property name="spacing">4</property> + <child> + <widget class="GtkTable" id="table32"> + <property name="visible">True</property> + <property name="n_rows">2</property> + <property name="n_columns">2</property> + <property name="column_spacing">8</property> + <property name="row_spacing">4</property> + <child> + <widget class="GtkLabel" id="label312"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Kana Key Table:</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">kana:button_custom_table</property> + </widget> + <packing> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkButton" id="kana:button_custom_table"> + <property name="label">...</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="receives_default">False</property> + <property name="use_underline">True</property> + <signal name="clicked" handler="on_btn_kana_custom_table_clicked"/> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="x_options">GTK_FILL</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + </widget> + </child> + </widget> + </child> + <child> + <widget class="GtkLabel" id="label311"> + <property name="visible">True</property> + <property name="label" translatable="yes"><b>Kana</b></property> + <property name="use_markup">True</property> + </widget> + <packing> + <property name="type">label_item</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="position">2</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label3"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Typing Method</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">vbox3</property> + </widget> + <packing> + <property name="position">2</property> + <property name="tab_fill">False</property> + <property name="type">tab</property> + </packing> + </child> + <child> + <widget class="GtkVBox" id="vbox4"> + <property name="visible">True</property> + <property name="border_width">8</property> + <property name="spacing">4</property> + <child> <widget class="GtkFrame" id="frame4"> <property name="visible">True</property> <property name="label_xalign">0</property> @@ -662,7 +843,7 @@ Wnn <child> <widget class="GtkTable" id="table4"> <property name="visible">True</property> - <property name="n_rows">8</property> + <property name="n_rows">9</property> <property name="column_spacing">8</property> <property name="row_spacing">4</property> <child> @@ -703,6 +884,7 @@ Wnn <signal name="clicked" handler="on_btn_thumb_key_clicked"/> </widget> <packing> + <property name="x_options">GTK_FILL</property> <property name="left_attach">2</property> <property name="right_attach">3</property> </packing> @@ -742,6 +924,7 @@ Wnn <signal name="clicked" handler="on_btn_thumb_key_clicked"/> </widget> <packing> + <property name="x_options">GTK_FILL</property> <property name="left_attach">2</property> <property name="right_attach">3</property> <property name="top_attach">1</property> @@ -971,12 +1154,54 @@ FMV KB611 key extension</property> <property name="y_options"></property> </packing> </child> + <child> + <widget class="GtkTable" id="table6"> + <property name="visible">True</property> + <property name="n_rows">2</property> + <property name="n_columns">2</property> + <property name="column_spacing">8</property> + <property name="row_spacing">4</property> + <child> + <widget class="GtkLabel" id="label35"> + <property name="visible">True</property> + <property name="label" translatable="yes">Thumb _Shift Key Table:</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">thumb:button_custom_table</property> + </widget> + <packing> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkButton" id="thumb:button_custom_table"> + <property name="label">...</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="receives_default">False</property> + <property name="use_underline">True</property> + <signal name="clicked" handler="on_btn_thumb_custom_table_clicked"/> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="x_options">GTK_FILL</property> + </packing> + </child> + </widget> + <packing> + <property name="top_attach">8</property> + <property name="bottom_attach">9</property> + <property name="y_options"></property> + </packing> + </child> </widget> </child> </widget> </child> <child> - <widget class="GtkLabel" id="label35"> + <widget class="GtkLabel" id="label36"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Thumb Shift Layout</b></property> <property name="use_markup">True</property> @@ -994,24 +1219,24 @@ FMV KB611 key extension</property> </child> </widget> <packing> - <property name="position">2</property> + <property name="position">3</property> </packing> </child> <child> - <widget class="GtkLabel" id="label3"> + <widget class="GtkLabel" id="label4"> <property name="visible">True</property> <property name="label" translatable="yes">Thumb S_hift</property> <property name="use_underline">True</property> - <property name="mnemonic_widget">vbox3</property> + <property name="mnemonic_widget">vbox4</property> </widget> <packing> - <property name="position">2</property> + <property name="position">3</property> <property name="tab_fill">False</property> <property name="type">tab</property> </packing> </child> <child> - <widget class="GtkVBox" id="vbox4"> + <widget class="GtkVBox" id="vbox5"> <property name="visible">True</property> <property name="border_width">4</property> <property name="spacing">4</property> @@ -1026,12 +1251,12 @@ FMV KB611 key extension</property> <property name="top_padding">4</property> <property name="left_padding">0</property> <child> - <widget class="GtkVBox" id="vbox5"> + <widget class="GtkVBox" id="vbox51"> <property name="visible">True</property> <property name="border_width">4</property> <property name="spacing">4</property> <child> - <widget class="GtkTable" id="table6"> + <widget class="GtkTable" id="table7"> <property name="visible">True</property> <property name="n_rows">2</property> <property name="n_columns">3</property> @@ -1072,6 +1297,7 @@ FMV KB611 key extension</property> <signal name="clicked" handler="on_btn_dict_command_clicked"/> </widget> <packing> + <property name="x_options">GTK_FILL</property> <property name="left_attach">2</property> <property name="right_attach">3</property> </packing> @@ -1115,6 +1341,7 @@ FMV KB611 key extension</property> <signal name="clicked" handler="on_btn_dict_command_clicked"/> </widget> <packing> + <property name="x_options">GTK_FILL</property> <property name="left_attach">2</property> <property name="right_attach">3</property> <property name="top_attach">1</property> @@ -1159,7 +1386,7 @@ FMV KB611 key extension</property> <property name="top_padding">4</property> <property name="left_padding">0</property> <child> - <widget class="GtkVBox" id="vbox6"> + <widget class="GtkVBox" id="vbox52"> <property name="visible">True</property> <property name="border_width">4</property> <property name="spacing">4</property> @@ -1329,18 +1556,18 @@ FMV KB611 key extension</property> </child> </widget> <packing> - <property name="position">3</property> + <property name="position">4</property> </packing> </child> <child> - <widget class="GtkLabel" id="label4"> + <widget class="GtkLabel" id="label5"> <property name="visible">True</property> <property name="label" translatable="yes">Dictionar_y</property> <property name="use_underline">True</property> - <property name="mnemonic_widget">vbox4</property> + <property name="mnemonic_widget">vbox5</property> </widget> <packing> - <property name="position">3</property> + <property name="position">4</property> <property name="tab_fill">False</property> <property name="type">tab</property> </packing> @@ -1360,18 +1587,18 @@ URL : http://code.google.com/p/ibus/ <property name="ellipsize">start</property> </widget> <packing> - <property name="position">4</property> + <property name="position">5</property> </packing> </child> <child> - <widget class="GtkLabel" id="label5"> + <widget class="GtkLabel" id="label6"> <property name="visible">True</property> <property name="label" translatable="yes">Abo_ut</property> <property name="use_underline">True</property> <property name="mnemonic_widget">about</property> </widget> <packing> - <property name="position">4</property> + <property name="position">5</property> <property name="tab_fill">False</property> <property name="type">tab</property> </packing> @@ -1710,6 +1937,232 @@ URL : http://code.google.com/p/ibus/ </widget> </child> </widget> + <widget class="GtkDialog" id="dialog_custom_key_table"> + <property name="width_request">400</property> + <property name="height_request">470</property> + <property name="title"></property> + <property name="modal">True</property> + <property name="type_hint">dialog</property> + <child internal-child="vbox"> + <widget class="GtkVBox" id="dialog-vbox3"> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="spacing">6</property> + <child> + <widget class="GtkHBox" id="hbox_for_combobox_custom_key_table"> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="spacing">6</property> + <child> + <widget class="GtkLabel" id="label_custom_key_table"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label"></property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">combobox_custom_key_table</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkComboBox" id="combobox_custom_key_table"> + <property name="visible">True</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkHBox" id="hbox301"> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="spacing">6</property> + <child> + <widget class="GtkScrolledWindow" id="scrolledwindow301"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="border_width">1</property> + <property name="hscrollbar_policy">automatic</property> + <property name="vscrollbar_policy">automatic</property> + <property name="shadow_type">in</property> + <child> + <widget class="GtkTreeView" id="treeview_custom_key_table"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </widget> + </child> + </widget> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkVButtonBox" id="vbutton301"> + <property name="visible">True</property> + <property name="layout_style">start</property> + <property name="spacing">6</property> + <child> + <widget class="GtkLabel" id="label3001"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Input Chars</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">entry_input_custom_key</property> + </widget> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkEntry" id="entry_input_custom_key"> + <property name="visible">True</property> + <property name="width-chars">3</property> + </widget> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label_output_custom_key"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Output Chars</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">entry_output_custom_key</property> + </widget> + <packing> + <property name="position">2</property> + </packing> + </child> + <child> + <widget class="GtkEntry" id="entry_output_custom_key"> + <property name="visible">True</property> + <property name="width-chars">3</property> + </widget> + <packing> + <property name="position">3</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label_left_thumb_shift_custom_key"> + <property name="visible">False</property> + <property name="label" translatable="yes">_Left Thumb Shift</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">entry_left_thumb_shift_custom_key</property> + </widget> + <packing> + <property name="position">4</property> + </packing> + </child> + <child> + <widget class="GtkEntry" id="entry_left_thumb_shift_custom_key"> + <property name="visible">False</property> + <property name="width-chars">3</property> + </widget> + <packing> + <property name="position">5</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label_right_thumb_shift_custom_key"> + <property name="visible">False</property> + <property name="label" translatable="yes">_Right Thumb Shift</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">entry_right_thumb_shift_custom_key</property> + </widget> + <packing> + <property name="position">6</property> + </packing> + </child> + <child> + <widget class="GtkEntry" id="entry_right_thumb_shift_custom_key"> + <property name="visible">False</property> + <property name="width-chars">3</property> + </widget> + <packing> + <property name="position">7</property> + </packing> + </child> + <child> + <widget class="GtkButton" id="button_add_custom_key"> + <property name="visible">True</property> + <property name="label">gtk-add</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="receives_default">False</property> + <property name="use_stock">True</property> + </widget> + <packing> + <property name="position">8</property> + </packing> + </child> + <child> + <widget class="GtkButton" id="button_remove_custom_key"> + <property name="visible">True</property> + <property name="label">gtk-remove</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="receives_default">False</property> + <property name="use_stock">True</property> + </widget> + <packing> + <property name="position">9</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="position">1</property> + </packing> + </child> + <child internal-child="action_area"> + <widget class="GtkHButtonBox" id="dialog-action_area3"> + <property name="visible">True</property> + <property name="layout_style">end</property> + <child> + <widget class="GtkButton" id="closebutton301"> + <property name="visible">True</property> + <property name="label">gtk-close</property> + <property name="response_id">0</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="use_stock">True</property> + <property name="receives_default">True</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + </widget> + </child> + </widget> <widget class="GtkMessageDialog" id="quit_check"> <property name="border_width">5</property> <property name="resizable">False</property> |