From ae039c727a89c8a27d5224adafb656a37d345d22 Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Fri, 15 Dec 2017 19:38:51 +0900 Subject: Migrated DConf to GSettings --- data/Makefile.am | 19 +- ...rg.freedesktop.ibus.engine.anthy.gschema.xml.in | 1111 ++++++++++++++++ engine/python3/Makefile.am | 5 +- engine/python3/_config.py.in | 5 +- engine/python3/engine.py | 277 ++-- engine/python3/factory.py | 19 +- engine/python3/jastring.py | 20 +- engine/python3/kana.py | 56 +- engine/python3/romaji.py | 29 +- engine/python3/thumb.py | 86 +- setup/python3/Makefile.am | 15 +- setup/python3/anthyprefs.py | 335 +++++ setup/python3/anthyprefs.py.in | 1361 -------------------- setup/python3/main.py | 602 ++++----- setup/python3/prefs.py | 444 ++++--- setup/python3/setup.ui | 134 +- 16 files changed, 2170 insertions(+), 2348 deletions(-) create mode 100644 data/org.freedesktop.ibus.engine.anthy.gschema.xml.in create mode 100644 setup/python3/anthyprefs.py delete mode 100644 setup/python3/anthyprefs.py.in diff --git a/data/Makefile.am b/data/Makefile.am index 89d5ee0..5d5747e 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -2,8 +2,8 @@ # # ibus-anthy - The Anthy engine for IBus # -# Copyright (c) 2010-2016 Takao Fujiwara -# Copyright (c) 2010-2016 Red Hat, Inc. +# Copyright (c) 2010-2017 Takao Fujiwara +# Copyright (c) 2010-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 @@ -36,11 +36,25 @@ appdata_DATA = $(appdata_in_files:.xml.in=.xml) appdatadir=$(datadir)/appdata @INTLTOOL_XML_RULE@ +schemas_in_files = org.freedesktop.ibus.engine.anthy.gschema.xml.in +schemas_DATA = $(schemas_in_files:.xml.in=.xml) +schemasdir = $(datadir)/glib-2.0/schemas + CLEANFILES = \ $(appdata_DATA) \ + $(schemas_DATA) \ emoji.t \ $(NULL) +$(schemas_DATA): $(schemas_in_files) + $(SED) -e "s|\@ANTHY_ZIPCODE_FILE\@|$(ANTHY_ZIPCODE_FILE)|g" \ + -e "s|\@KASUMI_EXEC_FILE\@|$(KASUMI_EXEC_FILE)|g" \ + -e "s|\@KASUMI_ICON_FILE\@|$(KASUMI_ICON_FILE)|g" \ + -e "s|\@ON_OFF_KEYS\@|$(ON_OFF_KEYS)|g" \ + -e "s|\@pkgdatadir\@|$(pkgdatadir)|g" \ + $< > $@ + + emoji.t: emoji-each.t emoji-emoji.t @echo "Generate $@"; \ $(SED) -e '/^#/d' $(srcdir)/emoji-emoji.t > emoji-emoji.t.$$$$; \ @@ -63,6 +77,7 @@ endif EXTRA_DIST = \ $(appdata_in_files) \ + $(schemas_in_files) \ emoji-each.t \ emoji-emoji.t \ era.t \ diff --git a/data/org.freedesktop.ibus.engine.anthy.gschema.xml.in b/data/org.freedesktop.ibus.engine.anthy.gschema.xml.in new file mode 100644 index 0000000..57436b3 --- /dev/null +++ b/data/org.freedesktop.ibus.engine.anthy.gschema.xml.in @@ -0,0 +1,1111 @@ + + + + + 0 + Input Mode + + + + 0 + Typing Mode + + + + 0 + Conversion Segment Mode + + + + true + Show Input Mode + + + + false + Show Typing Mode + + + + false + Show Segment Mode + + + + true + Show Dictionary Mode + + + + false + Show Dictionary Configuration + + + + true + Show Preferences + + + + 0 + Period Style + + + + 1 + Symbol Style + + + + 1 + Ten Key Mode + + + + 0 + Behavior on Focus out + + + + 0 + Behavior on Period + + + + ',.、。,.' + Trigger Periods + + + + 10 + Page Size + + + + false + Half Width Symbol + + + + false + Half Width Number + + + + false + Half Width Space + + + + true + Latin with Shift + + + + 'default' + Shortcut Type + + + + ['@KASUMI_EXEC_FILE@', 'kasumi'] + Dictionary Administration Command + + + + ['@KASUMI_EXEC_FILE@', 'kasumi', '-a'] + Add Word Command + + + + '@KASUMI_ICON_FILE@' + Dictionary configuration icon + + + + ['default', 'jp', 'us', + 'jp[ctrl:swapcaps]', 'us[ctrl:swapcaps]', + 'jp[ctrl:swapcaps,compose:rctrl]', + 'us[ctrl:swapcaps,compose:rctrl]', + 'jp[japan:kana_lock]', + 'jp[japan:nicola_f_bs]', + 'jp[japan:nicola_f_bs,ctrl:swapcaps]', + 'jp[japan:hztg_escape]', + 'jp[japan:hztg_escape,ctrl:swapcaps]' + ] + + Keyboard Layouts + + + + + + 'default' + Method + + + + + + { + 'default': <{ + 'minus' : <'ー'>, + 'a' : <'あ'>, + 'i' : <'い'>, + 'u' : <'う'>, + 'e' : <'え'>, + 'o' : <'お'>, + 'x-a' : <'ぁ'>, + 'x-i' : <'ぃ'>, + 'x-u' : <'ぅ'>, + 'x-e' : <'ぇ'>, + 'x-o' : <'ぉ'>, + 'l-a' : <'ぁ'>, + 'l-i' : <'ぃ'>, + 'l-u' : <'ぅ'>, + 'l-e' : <'ぇ'>, + 'l-o' : <'ぉ'>, + 'w-h-a' : <'うぁ'>, + 'w-h-i' : <'うぃ'>, + 'w-h-e' : <'うぇ'>, + 'w-h-o' : <'うぉ'>, + 'w-y-a' : <'うゃ'>, + 'w-y-u' : <'うゅ'>, + 'w-y-o' : <'うょ'>, + 'v-a' : <'ヴぁ'>, + 'v-i' : <'ヴぃ'>, + 'v-u' : <'ヴ'>, + 'v-e' : <'ヴぇ'>, + 'v-o' : <'ヴぉ'>, + 'v-y-a' : <'ヴゃ'>, + 'v-y-u' : <'ヴゅ'>, + 'v-y-e' : <'ヴぃぇ'>, + 'v-y-o' : <'ヴょ'>, + 'k-a' : <'か'>, + 'k-i' : <'き'>, + 'k-u' : <'く'>, + 'k-e' : <'け'>, + 'k-o' : <'こ'>, + 'l-k-a' : <'ヵ'>, + 'l-k-e' : <'ヶ'>, + + 'x-k-a' : <'ヵ'>, + + 'x-k-e' : <'ヶ'>, + 'g-a' : <'が'>, + 'g-i' : <'ぎ'>, + 'g-u' : <'ぐ'>, + 'g-e' : <'げ'>, + 'g-o' : <'ご'>, + 'k-y-a' : <'きゃ'>, + 'k-y-i' : <'きぃ'>, + 'k-y-u' : <'きゅ'>, + 'k-y-e' : <'きぇ'>, + 'k-y-o' : <'きょ'>, + 'k-w-a' : <'くぁ'>, + 'k-w-i' : <'くぃ'>, + 'k-w-u' : <'くぅ'>, + 'k-w-e' : <'くぇ'>, + 'k-w-o' : <'くぉ'>, + 'g-y-a' : <'ぎゃ'>, + 'g-y-i' : <'ぎぃ'>, + 'g-y-u' : <'ぎゅ'>, + 'g-y-e' : <'ぎぇ'>, + 'g-y-o' : <'ぎょ'>, + 'g-w-a' : <'ぐぁ'>, + 'g-w-i' : <'ぐぃ'>, + 'g-w-u' : <'ぐぅ'>, + 'g-w-e' : <'ぐぇ'>, + 'g-w-o' : <'ぐぉ'>, + 's-a' : <'さ'>, + 's-i' : <'し'>, + 's-u' : <'す'>, + 's-e' : <'せ'>, + 's-o' : <'そ'>, + 'z-a' : <'ざ'>, + 'z-i' : <'じ'>, + 'z-u' : <'ず'>, + 'z-e' : <'ぜ'>, + 'z-o' : <'ぞ'>, + 's-y-a' : <'しゃ'>, + 's-y-i' : <'しぃ'>, + 's-y-u' : <'しゅ'>, + 's-y-e' : <'しぇ'>, + 's-y-o' : <'しょ'>, + 's-h-a' : <'しゃ'>, + 's-h-i' : <'し'>, + 's-h-u' : <'しゅ'>, + 's-h-e' : <'しぇ'>, + 's-h-o' : <'しょ'>, + 'z-y-a' : <'じゃ'>, + 'z-y-i' : <'じぃ'>, + 'z-y-u' : <'じゅ'>, + 'z-y-e' : <'じぇ'>, + 'z-y-o' : <'じょ'>, + 'j-a' : <'じゃ'>, + 'j-y-a' : <'じゃ'>, + 'j-i' : <'じ'>, + 'j-y-i' : <'じぃ'>, + 'j-u' : <'じゅ'>, + 'j-y-u' : <'じゅ'>, + 'j-e' : <'じぇ'>, + 'j-y-e' : <'じぇ'>, + 'j-o' : <'じょ'>, + 'j-y-o' : <'じょ'>, + 's-w-i' : <'すぅぃ'>, + 's-w-e' : <'すぇ'>, + 'z-w-e' : <'ずぇ'>, + 't-a' : <'た'>, + 't-i' : <'ち'>, + 't-u' : <'つ'>, + 't-s-u' : <'つ'>, + 't-e' : <'て'>, + 't-o' : <'と'>, + 'd-a' : <'だ'>, + 'd-i' : <'ぢ'>, + 'd-u' : <'づ'>, + 'd-e' : <'で'>, + 'd-o' : <'ど'>, + 'x-t-u' : <'っ'>, + 'x-t-s-u' : <'っ'>, + 'l-t-u' : <'っ'>, + 'l-t-s-u' : <'っ'>, + 't-y-a' : <'ちゃ'>, + 't-y-i' : <'ちぃ'>, + 't-y-u' : <'ちゅ'>, + 't-y-e' : <'ちぇ'>, + 't-y-o' : <'ちょ'>, + 'c-y-a' : <'ちゃ'>, + 'c-y-i' : <'ちぃ'>, + 'c-y-u' : <'ちゅ'>, + 'c-y-e' : <'ちぇ'>, + 'c-y-o' : <'ちょ'>, + 'c-h-a' : <'ちゃ'>, + 'c-h-i' : <'ち'>, + 'c-h-u' : <'ちゅ'>, + 'c-h-e' : <'ちぇ'>, + 'c-h-o' : <'ちょ'>, + 'd-y-a' : <'ぢゃ'>, + 'd-y-i' : <'ぢぃ'>, + 'd-y-u' : <'ぢゅ'>, + 'd-y-e' : <'ぢぇ'>, + 'd-y-o' : <'ぢょ'>, + 't-s-a' : <'つぁ'>, + 't-s-i' : <'つぃ'>, + 't-s-e' : <'つぇ'>, + 't-s-o' : <'つぉ'>, + 't-s-y-a' : <'つゃ'>, + 't-s-y-u' : <'つゅ'>, + 't-s-y-e' : <'つぃぇ'>, + 't-s-y-o' : <'つょ'>, + 'd-z-a' : <'づぁ'>, + 'd-z-i' : <'づぃ'>, + 'd-z-u' : <'づ'>, + 'd-z-e' : <'づぇ'>, + 'd-z-o' : <'づぉ'>, + 'd-z-y-a' : <'づゃ'>, + 'd-z-y-u' : <'づゅ'>, + 'd-z-y-e' : <'づぃぇ'>, + 'd-z-y-o' : <'づょ'>, + 't-h-a' : <'てゃ'>, + 't-h-i' : <'てぃ'>, + 't-h-u' : <'てゅ'>, + 't-h-e' : <'てぇ'>, + 't-h-o' : <'てょ'>, + 't-w-u' : <'とぅ'>, + 'd-h-a' : <'でゃ'>, + 'd-h-i' : <'でぃ'>, + 'd-h-u' : <'でゅ'>, + 'd-h-e' : <'でぇ'>, + 'd-h-o' : <'でょ'>, + 'd-w-u' : <'どぅ'>, + 'n-a' : <'な'>, + 'n-i' : <'に'>, + 'n-u' : <'ぬ'>, + 'n-e' : <'ね'>, + 'n-o' : <'の'>, + 'n-y-a' : <'にゃ'>, + 'n-y-i' : <'にぃ'>, + 'n-y-u' : <'にゅ'>, + 'n-y-e' : <'にぇ'>, + 'n-y-o' : <'にょ'>, + 'h-a' : <'は'>, + 'h-i' : <'ひ'>, + 'h-u' : <'ふ'>, + 'h-e' : <'へ'>, + 'h-o' : <'ほ'>, + 'b-a' : <'ば'>, + 'b-i' : <'び'>, + 'b-u' : <'ぶ'>, + 'b-e' : <'べ'>, + 'b-o' : <'ぼ'>, + 'p-a' : <'ぱ'>, + 'p-i' : <'ぴ'>, + 'p-u' : <'ぷ'>, + 'p-e' : <'ぺ'>, + 'p-o' : <'ぽ'>, + 'h-y-a' : <'ひゃ'>, + 'h-y-i' : <'ひぃ'>, + 'h-y-u' : <'ひゅ'>, + 'h-y-e' : <'ひぇ'>, + 'h-y-o' : <'ひょ'>, + 'b-y-a' : <'びゃ'>, + 'b-y-i' : <'びぃ'>, + 'b-y-u' : <'びゅ'>, + 'b-y-e' : <'びぇ'>, + 'b-y-o' : <'びょ'>, + 'p-y-a' : <'ぴゃ'>, + 'p-y-i' : <'ぴぃ'>, + 'p-y-u' : <'ぴゅ'>, + 'p-y-e' : <'ぴぇ'>, + 'p-y-o' : <'ぴょ'>, + 'f-a' : <'ふぁ'>, + 'f-i' : <'ふぃ'>, + 'f-u' : <'ふ'>, + 'f-e' : <'ふぇ'>, + 'f-o' : <'ふぉ'>, + 'f-y-a' : <'ふゃ'>, + 'f-y-i' : <'ふぃ'>, + 'f-y-u' : <'ふゅ'>, + 'f-y-e' : <'ふぇ'>, + 'f-y-o' : <'ふょ'>, + 'b-w-a' : <'ぶぁ'>, + 'b-w-e' : <'ぶぇ'>, + 'b-w-o' : <'ぶぉ'>, + 'p-w-a' : <'ぷぁ'>, + 'p-w-e' : <'ぷぇ'>, + 'p-w-o' : <'ぷぉ'>, + 'm-a' : <'ま'>, + 'm-i' : <'み'>, + 'm-u' : <'む'>, + 'm-e' : <'め'>, + 'm-o' : <'も'>, + 'm-y-a' : <'みゃ'>, + 'm-y-i' : <'みぃ'>, + 'm-y-u' : <'みゅ'>, + 'm-y-e' : <'みぇ'>, + 'm-y-o' : <'みょ'>, + 'y-a' : <'や'>, + 'y-i' : <'い'>, + 'y-u' : <'ゆ'>, + 'y-e' : <'いぇ'>, + 'y-o' : <'よ'>, + 'l-y-a' : <'ゃ'>, + 'l-y-i' : <'ぃ'>, + 'l-y-u' : <'ゅ'>, + 'l-y-e' : <'ぇ'>, + 'l-y-o' : <'ょ'>, + 'x-y-a' : <'ゃ'>, + 'x-y-i' : <'ぃ'>, + 'x-y-u' : <'ゅ'>, + 'x-y-e' : <'ぇ'>, + 'x-y-o' : <'ょ'>, + 'r-a' : <'ら'>, + 'r-i' : <'り'>, + 'r-u' : <'る'>, + 'r-e' : <'れ'>, + 'r-o' : <'ろ'>, + 'r-y-a' : <'りゃ'>, + 'r-y-i' : <'りぃ'>, + 'r-y-u' : <'りゅ'>, + 'r-y-e' : <'りぇ'>, + 'r-y-o' : <'りょ'>, + 'w-a' : <'わ'>, + 'w-i' : <'うぃ'>, + 'w-u' : <'う'>, + 'w-e' : <'うぇ'>, + 'w-o' : <'を'>, + 'l-w-a' : <'ゎ'>, + 'x-w-a' : <'ゎ'>, + 'n-apostrophe' : <'ん'>, + 'n-n' : <'ん'>, + 'w-y-i' : <'ゐ'>, + 'w-y-e' : <'ゑ'> + }> + } + + List + + + + + + 'jp' + Method + + + + + { + 'jp': <{ + + '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' : <'ろ'>, + + + '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' : <'ー'> + }>, + 'us': <{ + + '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' : <'む'>, + + 'a' : <'ち'>, + 's' : <'と'>, + 'd' : <'し'>, + 'f' : <'は'>, + 'g' : <'き'>, + 'h' : <'く'>, + 'j' : <'ま'>, + 'k' : <'の'>, + 'l' : <'り'>, + 'semicolon' : <'れ'>, + 'apostrophe' : <'け'>, + + 'z' : <'つ'>, + 'x' : <'さ'>, + 'c' : <'そ'>, + 'v' : <'ひ'>, + 'b' : <'こ'>, + 'n' : <'み'>, + 'm' : <'も'>, + 'comma' : <'ね'>, + 'period' : <'る'>, + 'slash' : <'め'>, + + + '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' : <'・'> + }> + } + + List + + + + + + true + Keyboard Layout Mode + + + + 0 + Keyboard Layout + + + + 2 + FMV Extension + + + + false + FMV Extension + + + + 'Henkan' + Right S + + + + 'Muhenkan' + Left S + + + + 100 + T1 + + + + 75 + T2 + + + + + + 'base' + Method + + + + + { + 'base': <{ + 'q' : <['。', '', 'ぁ']>, + 'w' : <['か', 'が', 'え']>, + 'e' : <['た', 'だ', 'り']>, + 'r' : <['こ', 'ご', 'ゃ']>, + 't' : <['さ', 'ざ', 'れ']>, + + 'y' : <['ら', 'よ', 'ぱ']>, + 'u' : <['ち', 'に', 'ぢ']>, + 'i' : <['く', 'る', 'ぐ']>, + 'o' : <['つ', 'ま', 'づ']>, + 'p' : <[',', 'ぇ', 'ぴ']>, + 'at' : <['、', '', '']>, + 'bracketleft' : <['゛', '゜', '']>, + + 'a' : <['う', '', 'を']>, + 's' : <['し', 'じ', 'あ']>, + 'd' : <['て', 'で', 'な']>, + 'f' : <['け', 'げ', 'ゅ']>, + 'g' : <['せ', 'ぜ', 'も']>, + + 'h' : <['は', 'み', 'ば']>, + 'j' : <['と', 'お', 'ど']>, + 'k' : <['き', 'の', 'ぎ']>, + 'l' : <['い', 'ょ', 'ぽ']>, + 'semicolon' : <['ん', 'っ', '']>, + + 'z' : <['.', '', 'ぅ']>, + 'x' : <['ひ', 'び', 'ー']>, + 'c' : <['す', 'ず', 'ろ']>, + 'v' : <['ふ', 'ぶ', 'や']>, + 'b' : <['へ', 'べ', 'ぃ']>, + + 'n' : <['め', 'ぬ', 'ぷ']>, + 'm' : <['そ', 'ゆ', 'ぞ']>, + 'comma' : <['ね', 'む', 'ぺ']>, + 'period' : <['ほ', 'わ', 'ぼ']>, + 'slash' : <['・', 'ぉ', '']>, + + '1' : <['1', '', '?']>, + '2' : <['2', '', '/']>, + '4' : <['4', '', '「']>, + '5' : <['5', '', '」']>, + + '6' : <['6', '[', '']>, + '7' : <['7', ']', '']>, + '8' : <['8', '(', '']>, + '9' : <['9', ')', '']>, + 'backslash' : <['¥', '', '']> + }>, + 'nicola-j-table': <{ + 'colon' : <[':', '', '']>, + 'at' : <['、', '', '']>, + 'bracketleft' : <['゛', '゜', '']>, + 'bracketright' : <['」', '', '']>, + '8' : <['8', '(', '']>, + '9' : <['9', ')', '']>, + '0' : <['0', '', '']> + }>, + 'nicola-a-table': <{ + 'colon' : <[':', '', '']>, + 'at' : <['@', '', '']>, + 'bracketleft' : <['、', '', '']>, + 'bracketright' : <['゛', '゜', '']>, + '8' : <['8', '', '']>, + '9' : <['9', '(', '']>, + '0' : <['0', ')', '']> + }>, + 'nicola-f-table': <{ + 'colon' : <['、', '', '']>, + 'at' : <['@', '', '']>, + 'bracketleft' : <['゛', '゜', '']>, + 'bracketright' : <['」', '', '']>, + '8' : <['8', '(', '']>, + '9' : <['9', ')', '']>, + '0' : <['0', '', '']> + }>, + 'kb231-j-fmv-table': <{ + '3' : <['3', '', '~']>, + '0' : <['0', '『', '']>, + 'minus' : <['-', '』', '']>, + 'equal' : <['=', '', '']> + }>, + 'kb231-a-fmv-table': <{ + '3' : <['3', '', '~']>, + '0' : <['0', ')', '']>, + 'minus' : <['-', '『', '']>, + 'equal' : <['=', '』', '']> + }>, + 'kb231-f-fmv-table': <{ + '3' : <['3', '', '~']>, + '0' : <['0', '『', '']>, + 'minus' : <['-', '』', '']>, + 'equal' : <['=', '', '']> + }>, + 'kb611-j-fmv-table': <{ + 'grave' : <['‘', '', '']>, + 'asciicircum' : <['々', '£', '']>, + 'colon' : <[':', '', '']>, + 'at' : <['、', '¢', '']>, + 'bracketleft' : <['゛', '゜', '']>, + + + 'backslash' : <['¥', '¦', '']> + }>, + 'kb611-a-fmv-table': <{ + 'grave' : <['々', '', '£']>, + 'colon' : <[':', '', '']>, + 'at' : <['@', '', '']>, + 'bracketleft' : <['、', '¢', '']>, + + 'backslash' : <['¥', '¦', '']> + }>, + 'kb611-f-fmv-table': <{ + 'grave' : <['‘', '', '']>, + 'asciicircum' : <['々', '£', '']>, + 'colon' : <['、', '¢', '']>, + 'at' : <['@', '', '']>, + 'bracketleft' : <['゛', '゜', '']>, + + 'backslash' : <['¥', '¦', '']> + }> + } + + List + + + + + + + <('template', '', '', '', false, 300, false, true, false, 'utf-8')> + + Template Dictionary + + + + + + + [ + <('embedded', '般', 'General', '', true, 0, true, true, false, 'utf-8')>, + <('zipcode', '〒', 'Zip Code Conversion', '', true, -1, false, true, false, 'utf-8')>, + <('symbol', '記', 'Symbol', '', true, -1, true, false, false, 'utf-8')>, + <('oldchar', '旧', 'Old Character Style', '', true, -1, false, true, false, 'utf-8')>, + <('era', '年', 'Era', '', true, -1, false, true, false, 'utf-8')>, + <('emoji', '😊', 'Emoji', '', true, -1, false, true, false, 'utf-8')> + ] + + Lists + + + + + { + 'oldchar': <['@pkgdatadir@/dicts/oldchar.t']>, + 'era': <['@pkgdatadir@/dicts/era.t']>, + 'zipcode': <['@pkgdatadir@/dicts/zipcode.t']>, + 'symbol': <['@pkgdatadir@/dicts/symbol.t']>, + 'emoji': <['@pkgdatadir@/dicts/emoji.t']> + } + + Files + + + + [] + Order + + + + + + + { + 'on_off': <[@ON_OFF_KEYS@]>, + 'circle_input_mode': <['Ctrl+comma', 'Ctrl+less']>, + + 'circle_kana_mode': <['Ctrl+period', 'Ctrl+greater']>, + + 'circle_typing_method': <['Alt+Romaji', 'Ctrl+slash']>, + 'circle_dict_method': <['Alt+Henkan']>, + + 'insert_space': <['space']>, + 'insert_alternate_space': <['Shift+space']>, + 'backspace': <['BackSpace', 'Ctrl+H']>, + 'delete': <['Delete', 'Ctrl+D']>, + 'commit': <['Return', 'KP_Enter', 'Ctrl+J', 'Ctrl+M']>, + 'convert': <['space', 'KP_Space', 'Henkan']>, + 'predict': <['Tab', 'ISO_Left_Tab']>, + 'cancel': <['Escape', 'Ctrl+G']>, + 'reconvert': <['Shift+Henkan']>, + + 'move_caret_first': <['Ctrl+A', 'Home']>, + 'move_caret_last': <['Ctrl+E', 'End']>, + 'move_caret_forward': <['Right', 'Ctrl+F']>, + 'move_caret_backward': <['Left', 'Ctrl+B']>, + + 'select_first_segment': <['Ctrl+A', 'Home']>, + 'select_last_segment': <['Ctrl+E', 'End']>, + 'select_next_segment': <['Right', 'Ctrl+F']>, + 'select_prev_segment': <['Left', 'Ctrl+B']>, + 'shrink_segment': <['Shift+Left', 'Ctrl+I']>, + 'expand_segment': <['Shift+Right', 'Ctrl+O']>, + 'commit_first_segment': <['Shift+Down']>, + 'commit_selected_segment': <['Ctrl+Down']>, + + 'select_first_candidate': <['Home']>, + 'select_last_candidate': <['End']>, + 'select_next_candidate': <['space', 'KP_Space', 'Tab', 'ISO_Left_Tab', 'Henkan', 'Down', 'KP_Add', 'Ctrl+N']>, + 'select_prev_candidate': <['Shift+Tab', 'Shift+ISO_Left_Tab', 'Up', 'KP_Subtract', 'Ctrl+P']>, + 'candidates_page_up': <['Page_Up']>, + 'candidates_page_down': <['Page_Down', 'KP_Tab']>, + + 'select_candidates_1': <['1']>, + 'select_candidates_2': <['2']>, + 'select_candidates_3': <['3']>, + 'select_candidates_4': <['4']>, + 'select_candidates_5': <['5']>, + 'select_candidates_6': <['6']>, + 'select_candidates_7': <['7']>, + 'select_candidates_8': <['8']>, + 'select_candidates_9': <['9']>, + 'select_candidates_0': <['0']>, + + 'convert_to_char_type_forward': <['Muhenkan']>, + 'convert_to_hiragana': <['F6']>, + 'convert_to_katakana': <['F7']>, + 'convert_to_half': <['F8']>, + 'convert_to_half_katakana': <['Shift+F8']>, + 'convert_to_wide_latin': <['F9']>, + 'convert_to_latin': <['F10']>, + 'convert_to_hiragana_all': <['Shift+F6']>, + 'convert_to_katakana_all': <['Shift+F7']>, + 'convert_to_wide_latin_all': <['Shift+F9']>, + 'convert_to_latin_all': <['Shift+F10']>, + + 'dict_admin': <['F11']>, + 'add_word': <['F12']>, + + 'hiragana_for_latin_with_shift': <['Hiragana_Katakana']> + } + + Default + + + + + { + 'on_off': <['Henkan', 'Eisu_toggle', 'Zenkaku_Hankaku']>, + 'circle_input_mode': <['F10']>, + 'hiragana_mode': <['Hiragana_Katakana']>, + 'katakana_mode': <['Shift+Hiragana_Katakana']>, + 'circle_typing_method': <['Romaji', 'Alt+Romaji']>, + 'circle_dict_method': <['Alt+Henkan']>, + 'convert': <['space', 'Henkan', 'Shift+space', 'Shift+Henkan']>, + 'predict': <['Tab']>, + 'cancel': <['Escape', 'BackSpace', 'Ctrl+H', 'Ctrl+bracketleft']>, + 'commit': <['Return', 'Ctrl+M']>, + 'reconvert': <['Shift+Henkan']>, + + 'insert_space': <['space']>, + 'insert_alternate_space': <['Shift+space']>, + 'backspace': <['BackSpace', 'Ctrl+H']>, + 'delete': <['Delete', 'Ctrl+G']>, + + 'move_caret_backward': <['Left', 'Ctrl+K']>, + 'move_caret_forward': <['Right', 'Ctrl+L']>, + 'move_caret_first': <['Ctrl+Left']>, + 'move_caret_last': <['Ctrl+Right']>, + + 'select_prev_segment': <['Shift+Left']>, + 'select_next_segment': <['Shift+Right']>, + 'select_first_segment': <['Ctrl+Left']>, + 'select_last_segment': <['Ctrl+Right']>, + 'expand_segment': <['Right', 'Ctrl+L']>, + 'shrink_segment': <['Left', 'Ctrl+K']>, + 'commit_selected_segment': <['Down', 'Ctrl+N']>, + + 'candidates_page_up': <['Shift+Henkan', 'Page_Up']>, + 'candidates_page_down': <['Henkan', 'Page_Down']>, + 'select_next_candidate': <['space', 'Tab', 'Henkan', 'Shift+space', 'Shift+Henkan']>, + 'select_prev_candidate': <['Up']>, + + 'select_candidates_1': <['1']>, + 'select_candidates_2': <['2']>, + 'select_candidates_3': <['3']>, + 'select_candidates_4': <['4']>, + 'select_candidates_5': <['5']>, + 'select_candidates_6': <['6']>, + 'select_candidates_7': <['7']>, + 'select_candidates_8': <['8']>, + 'select_candidates_9': <['9']>, + 'select_candidates_0': <['0']>, + + 'convert_to_hiragana': <['F6', 'Ctrl+U']>, + 'convert_to_katakana': <['F7', 'Ctrl+I']>, + 'convert_to_half': <['F8', 'Ctrl+O']>, + 'convert_to_half_katakana': <['Shift+F8']>, + 'convert_to_wide_latin': <['F9', 'Ctrl+P']>, + 'convert_to_latin': <['F10', 'Ctrl+at']>, + 'convert_to_hiragana_all': <['Shift+F6']>, + 'convert_to_katakana_all': <['Shift+F7']>, + 'convert_to_wide_latin_all': <['Shift+F9']>, + 'convert_to_latin_all': <['Shift+F10']>, + + 'dict_admin': <['F11']>, + 'add_word': <['Ctrl+F7']>, + + 'hiragana_for_latin_with_shift': <['Ctrl+J']> + } + + ATOK + + + + + { + 'on_off': <['Shift+space']>, + 'convert': <['space']>, + 'predict': <['Ctrl+Q']>, + 'cancel': <['Escape', 'Ctrl+G', 'Alt+Down', 'Muhenkan']>, + 'commit': <['Ctrl+L', 'Ctrl+M', 'Ctrl+J', 'Return']>, + 'insert_space': <['space']>, + 'backspace': <['Ctrl+H', 'BackSpace']>, + 'delete': <['Ctrl+D', 'Delete']>, + 'circle_dict_method': <['Alt+Henkan']>, + + 'move_caret_backward': <['Ctrl+B', 'Left']>, + 'move_caret_forward': <['Ctrl+F', 'Right']>, + 'move_caret_first': <['Ctrl+A', 'Alt+Left']>, + 'move_caret_last': <['Ctrl+E', 'Alt+Right']>, + + 'select_prev_segment': <['Ctrl+B', 'Left']>, + 'select_next_segment': <['Ctrl+F', 'Right']>, + 'select_first_segment': <['Ctrl+A', 'Alt+Left']>, + 'select_last_segment': <['Ctrl+E', 'Alt+Right']>, + 'expand_segment': <['Ctrl+O', 'F14']>, + 'shrink_segment': <['Ctrl+I', 'F13']>, + + 'candidates_page_up': <['Tab']>, + 'candidates_page_down': <['Shift+Tab']>, + 'select_next_candidate': <['space', 'Ctrl+Q', 'Ctrl+P', 'Down']>, + 'select_prev_candidate': <['Ctrl+N', 'Up']>, + + 'select_candidates_1': <['1']>, + 'select_candidates_2': <['2']>, + 'select_candidates_3': <['3']>, + 'select_candidates_4': <['4']>, + 'select_candidates_5': <['5']>, + 'select_candidates_6': <['6']>, + 'select_candidates_7': <['7']>, + 'select_candidates_8': <['8']>, + 'select_candidates_9': <['9']>, + 'select_candidates_0': <['0']>, + + 'convert_to_hiragana': <['F6']>, + 'convert_to_katakana': <['F7']>, + 'convert_to_half': <['F8']>, + 'convert_to_wide_latin': <['F9']>, + 'convert_to_latin': <['F10']>, + 'convert_to_hiragana_all': <['Shift+F6']>, + 'convert_to_katakana_all': <['Shift+F7']>, + 'convert_to_half_all': <['Shift+F8']>, + 'convert_to_wide_latin_all': <['Shift+F9']>, + 'convert_to_latin_all': <['Shift+F10']>, + + 'dict_admin': <['F11']>, + 'add_word': <['F12']>, + + 'hiragana_for_latin_with_shift': <['Hiragana_Katakana']> + } + + WNN + + + + diff --git a/engine/python3/Makefile.am b/engine/python3/Makefile.am index 47a7574..ec9cdd6 100644 --- a/engine/python3/Makefile.am +++ b/engine/python3/Makefile.am @@ -3,8 +3,8 @@ # ibus-anthy - The Anthy engine for IBus # # Copyright (c) 2007-2008 Peng Huang -# Copyright (c) 2010-2016 Takao Fujiwara -# Copyright (c) 2007-2016 Red Hat, Inc. +# Copyright (c) 2010-2017 Takao Fujiwara +# 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/python3/_config.py.in b/engine/python3/_config.py.in index ffb1bbe..a27f082 100644 --- a/engine/python3/_config.py.in +++ b/engine/python3/_config.py.in @@ -4,8 +4,8 @@ # ibus-anthy - The Anthy engine for IBus # # Copyright (c) 2007-2008 Peng Huang -# Copyright (c) 2010-2016 Takao Fujiwara -# Copyright (c) 2007-2016 Red Hat, Inc. +# Copyright (c) 2010-2017 Takao Fujiwara +# 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 = chr(@SYMBOL_CHAR_INT@) ICON_PREFERENCE = '@ICON_PREFERENCE@' +VERSION = '@VERSION@' DEBUG = False diff --git a/engine/python3/engine.py b/engine/python3/engine.py index 243eecd..f150a9f 100644 --- a/engine/python3/engine.py +++ b/engine/python3/engine.py @@ -157,7 +157,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, @@ -179,10 +179,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 @@ -280,7 +276,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 @@ -373,7 +369,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 @@ -441,7 +437,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 @@ -521,8 +517,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='DictMode', @@ -538,8 +534,7 @@ class Engine(IBus.EngineSimple): self.__prop_dict['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='DictMode.embedded', prop_type=IBus.PropType.RADIO, # if long_label is UTF-8 @@ -550,23 +545,31 @@ 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. if long_label == None: continue - if 'is_system' in self.__prefs.keys(section) and \ - self.__prefs.get_value(section, 'is_system'): + if dict_item.is_system: uni_long_label = _(long_label) else: uni_long_label = 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 @@ -669,20 +672,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) @@ -694,7 +705,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, @@ -1011,8 +1022,8 @@ class Engine(IBus.EngineSimple): self.__context.do_set_personality(str(dict_name)) prop = self.__prop_dict['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)) @@ -1028,19 +1039,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() @@ -1641,11 +1652,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() @@ -1653,69 +1665,46 @@ 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( - key = lambda a: keys.index(a[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 @@ -1781,9 +1770,9 @@ class Engine(IBus.EngineSimple): self._MM = self._SS = 0 ret = self.__on_key_common(ord(keyval)) if (keyval in - self.__prefs.get_value('common', 'trigger_periods')): + 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: @@ -1822,7 +1811,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: @@ -1918,7 +1907,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) @@ -1952,9 +1941,9 @@ class Engine(IBus.EngineSimple): ret = self.__on_key_common(keyval, state) if (Engine.__input_mode != INPUT_MODE_LATIN and chr(keyval) in - self.__prefs.get_value('common', 'trigger_periods')): + 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: @@ -2013,7 +2002,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: @@ -2044,7 +2033,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: @@ -2066,97 +2055,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): @@ -2287,7 +2202,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: @@ -2296,7 +2211,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: @@ -2894,11 +2809,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/python3/factory.py b/engine/python3/factory.py index 4d5cf9f..b7b1e89 100644 --- a/engine/python3/factory.py +++ b/engine/python3/factory.py @@ -4,8 +4,8 @@ # ibus-anthy - The Anthy engine for IBus # # Copyright (c) 2007-2008 Peng Huang -# Copyright (c) 2010-2016 Takao Fujiwara -# Copyright (c) 2007-2016 Red Hat, Inc. +# Copyright (c) 2010-2017 Takao Fujiwara +# 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('ibus-config is not running or bus address is not correct.', - file=sys.stderr) 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/python3/jastring.py b/engine/python3/jastring.py index 255799d..b0572da 100644 --- a/engine/python3/jastring.py +++ b/engine/python3/jastring.py @@ -4,8 +4,8 @@ # ibus-anthy - The Anthy engine for IBus # # Copyright (c) 2007-2008 Peng Huang -# Copyright (c) 2010-2014 Takao Fujiwara -# Copyright (c) 2007-2014 Red Hat, Inc. +# Copyright (c) 2010-2017 Takao Fujiwara +# 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/python3/kana.py b/engine/python3/kana.py index 10e1b96..db1b4c5 100644 --- a/engine/python3/kana.py +++ b/engine/python3/kana.py @@ -4,8 +4,8 @@ # ibus-anthy - The Anthy engine for IBus # # Copyright (c) 2007-2008 Peng Huang -# Copyright (c) 2010-2014 Takao Fujiwara -# Copyright (c) 2007-2014 Red Hat, Inc. +# Copyright (c) 2010-2017 Takao Fujiwara +# 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('かきくけこさしすせそたちつてとはひ 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='', jachars=''): 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.str(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.str(prefs.str(value)) + keymap = prefs.get_value('kana-typing-rule', 'list')[method] + value = keymap.get(enchars) if value == '': value = None if value == None: diff --git a/engine/python3/romaji.py b/engine/python3/romaji.py index d495120..6fc8d88 100644 --- a/engine/python3/romaji.py +++ b/engine/python3/romaji.py @@ -4,8 +4,8 @@ # ibus-anthy - The Anthy engine for IBus # # Copyright (c) 2007-2008 Peng Huang -# Copyright (c) 2010-2014 Takao Fujiwara -# Copyright (c) 2007-2014 Red Hat, Inc. +# Copyright (c) 2010-2017 Takao Fujiwara +# 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,19 +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.get_value(section, gkey) - else: - prefs.set_no_key_warning(True) - value = prefs.get_value_direct(section, gkey) - prefs.set_no_key_warning(False) + keymap = prefs.get_value('romaji-typing-rule', 'list')[method] + value = keymap.get(gkey) if value == '': value = None if value == None: diff --git a/engine/python3/thumb.py b/engine/python3/thumb.py index 9a5604e..e5fcec9 100644 --- a/engine/python3/thumb.py +++ b/engine/python3/thumb.py @@ -5,8 +5,8 @@ # # Copyright (c) 2007-2008 Peng Huang # Copyright (c) 2009 Hideaki ABE -# Copyright (c) 2010-2016 Takao Fujiwara -# Copyright (c) 2007-2016 Red Hat, Inc. +# Copyright (c) 2010-2017 Takao Fujiwara +# 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 @@ -310,19 +302,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 @@ -457,15 +442,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) @@ -582,32 +567,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/setup/python3/Makefile.am b/setup/python3/Makefile.am index 948f0a8..4e072e9 100644 --- a/setup/python3/Makefile.am +++ b/setup/python3/Makefile.am @@ -4,8 +4,8 @@ # # Copyright (c) 2007-2008 Peng Huang # Copyright (c) 2009 Hideaki ABE -# Copyright (c) 2010-2016 Takao Fujiwara -# Copyright (c) 2007-2016 Red Hat, Inc. +# Copyright (c) 2010-2017 Takao Fujiwara +# 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 @@ -37,7 +37,6 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) BUILT_SOURCES = \ _config.py \ - anthyprefs.py \ $(NULL) libexec_SCRIPTS = ibus-setup-anthy @@ -82,15 +81,6 @@ ibus-setup-anthy: ibus-setup-anthy.in -e "s|\@PYTHON\@|$(PYTHON)|g" \ $< > $@ -anthyprefs.py: anthyprefs.py.in - sed -e "s|\@ANTHY_ZIPCODE_FILE\@|$(ANTHY_ZIPCODE_FILE)|g" \ - -e "s|\@KASUMI_EXEC_FILE\@|$(KASUMI_EXEC_FILE)|g" \ - -e "s|\@KASUMI_ICON_FILE\@|$(KASUMI_ICON_FILE)|g" \ - -e "s|\@ON_OFF_KEYS\@|$(ON_OFF_KEYS)|g" \ - -e "s|\@VERSION\@|$(VERSION)|g" \ - -e "s|\@pkgdatadir\@|$(pkgdatadir)|g" \ - $< > $@ - _config.py: _config.py.in sed -e "s|\@pkgdatadir\@|$(pkgdatadir)|g" \ -e "s|\@libexecdir\@|$(libexecdir)|g" \ @@ -98,6 +88,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" \ $< > $@ # Need a time lag between .py and .py.in files to build .py files diff --git a/setup/python3/anthyprefs.py b/setup/python3/anthyprefs.py new file mode 100644 index 0000000..33b2a31 --- /dev/null +++ b/setup/python3/anthyprefs.py @@ -0,0 +1,335 @@ +# -*- coding: utf-8 -*- +# vim:set noet ts=4: +# +# ibus-anthy - The Anthy engine for IBus +# +# Copyright (c) 2007-2008 Peng Huang +# Copyright (c) 2009 Hideaki ABE +# Copyright (c) 2010-2017 Takao Fujiwara +# 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import sys + +import _config as config +from prefs import Prefs + +N_ = lambda a : a + +__all__ = ['AnthyPrefs'] + + +class AnthyPrefs(Prefs): + _char_to_config_key = None + + def __init__(self): + super(AnthyPrefs, self).__init__() + + def get_japanese_ordered_list(self): + return _japanese_ordered_list + + def get_version(self): + return config.VERSION + + # Convert gsettings key to typing sequences + # 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('Not supported key in gsettings', gkeys, file=sys.stderr) + 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 list(_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('Not supported key in gsettings', typing, file=sys.stderr) + retval = '' + break + if retval != '': + retval += '-' + retval += key + return retval + + def get_value(self, section, key): + not_sorted = super(AnthyPrefs, self).get_value(section, key) + if section == 'shortcut' and type(not_sorted) == dict: + retval = dict.fromkeys(_cmd_keys, []) + retval.update(not_sorted) + return retval + return not_sorted + + +# 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 = [ + 'あ', 'い', 'う', 'え', 'お', + 'ぁ', 'ぃ', 'ぅ', 'ぇ', 'ぉ', + 'いぇ', + 'うぁ', 'うぃ', 'うぅ', 'うぇ', 'うぉ', + 'うゃ', 'うゅ', 'うょ', + 'か', 'き', 'く', 'け', 'こ', + 'ゕ', 'ゖ', 'ヵ', 'ヶ', + 'が', 'ぎ', 'ぐ', 'げ', 'ご', + 'きゃ', 'きぃ', 'きゅ', 'きぇ', 'きょ', + 'くぁ', 'くぃ', 'くぅ', 'くぇ', 'くぉ', + 'ぎゃ', 'ぎぃ', 'ぎゅ', 'ぎぇ', 'ぎょ', + 'ぐぁ', 'ぐぃ', 'ぐぅ', 'ぐぇ', 'ぐぉ', + 'さ', 'し', 'す', 'せ', 'そ', + 'ざ', 'じ', 'ず', 'ぜ', 'ぞ', + 'しゃ', 'しぃ', 'しゅ', 'しぇ', 'しょ', + 'じゃ', 'じぃ', 'じゅ', 'じぇ', 'じょ', + 'すぅぃ', 'すぇ', + 'ずぇ', + 'た', 'ち', 'つ', 'て', 'と', + 'だ', 'ぢ', 'づ', 'で', 'ど', + 'っ', + 'ちゃ', 'ちぃ', 'ちゅ', 'ちぇ', 'ちょ', + 'ぢぃ', 'ぢぇ', + 'ぢゃ', 'ぢゅ', 'ぢょ', + 'つぁ', 'つぃ', 'つぇ', 'つぉ', + 'つゃ', 'つぃぇ', 'つゅ', 'つょ', + 'づぁ', 'づぃ', 'づぇ', 'づぉ', + 'づゃ', 'づぃぇ', 'づゅ', 'づょ', + 'てぃ', 'てぇ', + 'てゃ', 'てゅ', 'てょ', + 'とぅ', + 'でぃ', 'でぇ', + 'でゃ', 'でゅ', 'でょ', + 'どぅ', + 'な', 'に', 'ぬ', 'ね', 'の', + 'にぃ', 'にぇ', + 'にゃ', 'にゅ', 'にょ', + 'は', 'ひ', 'ふ', 'へ', 'ほ', + 'ば', 'び', 'ぶ', 'べ', 'ぼ', + 'ぱ', 'ぴ', 'ぷ', 'ぺ', 'ぽ', + 'ひぃ', 'ひぇ', + 'ひゃ', 'ひゅ', 'ひょ', + 'びぃ', 'びぇ', + 'びゃ', 'びゅ', 'びょ', + 'ぴぃ', 'ぴぇ', + 'ぴゃ', 'ぴゅ', 'ぴょ', + 'ふぁ', 'ふぃ', 'ふぇ', 'ふぉ', + 'ふゃ', 'ふゅ', 'ふょ', + 'ぶぁ', 'ぶぇ', 'ぶぉ', + 'ぷぁ', 'ぷぇ', 'ぷぉ', + 'ま', 'み', 'む', 'め', 'も', + 'みぃ', 'みぇ', + 'みゃ', 'みゅ', 'みょ', + 'や', 'ゆ', 'よ', + 'ゃ', 'ゅ', 'ょ', + 'ら', 'り', 'る', 'れ', 'ろ', + 'りぃ', 'りぇ', + 'りゃ', 'りゅ', 'りょ', + 'わ', 'を', 'ん', + 'ゎ', + 'ゐ', 'ゑ', + 'ー', + 'ヴぁ', 'ヴぃ', 'ヴ', 'ヴぇ', 'ヴぉ', + 'ヴゃ', 'ヴぃぇ', 'ヴゅ', 'ヴょ', +] + +# 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', + 'circle_kana_mode', + 'circle_typing_method', + 'circle_dict_method', + 'latin_mode', + 'wide_latin_mode', + 'hiragana_mode', + 'katakana_mode', + 'half_katakana_mode', +# 'cancel_pseudo_ascii_mode_key', + + 'hiragana_for_latin_with_shift', + + 'insert_space', + 'insert_alternate_space', + 'insert_half_space', + 'insert_wide_space', + 'backspace', + 'delete', + 'commit', + 'convert', + 'predict', + 'cancel', + 'cancel_all', + 'reconvert', +# 'do_nothing', + + 'select_first_candidate', + 'select_last_candidate', + 'select_next_candidate', + 'select_prev_candidate', + 'candidates_page_up', + 'candidates_page_down', + + 'move_caret_first', + 'move_caret_last', + 'move_caret_forward', + 'move_caret_backward', + + 'select_first_segment', + 'select_last_segment', + 'select_next_segment', + 'select_prev_segment', + 'shrink_segment', + 'expand_segment', + 'commit_first_segment', + 'commit_selected_segment', + + 'select_candidates_1', + 'select_candidates_2', + 'select_candidates_3', + 'select_candidates_4', + 'select_candidates_5', + 'select_candidates_6', + 'select_candidates_7', + 'select_candidates_8', + 'select_candidates_9', + 'select_candidates_0', + + 'convert_to_char_type_forward', + 'convert_to_char_type_backward', + 'convert_to_hiragana', + 'convert_to_katakana', + 'convert_to_half', + 'convert_to_half_katakana', + 'convert_to_wide_latin', + 'convert_to_latin', + 'convert_to_hiragana_all', + 'convert_to_katakana_all', + 'convert_to_half_all', + 'convert_to_half_katakana_all', + 'convert_to_wide_latin_all', + 'convert_to_latin_all', + + 'dict_admin', + 'add_word', + + 'start_setup', +] + +_dummy_translatable_strings = [ + N_('General'), + N_('Zip Code Conversion'), + N_('Symbol'), + N_('Old Character Style'), + N_('Era'), + N_('Emoji'), +] diff --git a/setup/python3/anthyprefs.py.in b/setup/python3/anthyprefs.py.in deleted file mode 100644 index f397568..0000000 --- a/setup/python3/anthyprefs.py.in +++ /dev/null @@ -1,1361 +0,0 @@ -# -*- coding: utf-8 -*- -# vim:set noet ts=4: -# -# ibus-anthy - The Anthy engine for IBus -# -# Copyright (c) 2007-2008 Peng Huang -# Copyright (c) 2009 Hideaki ABE -# Copyright (c) 2010-2015 Takao Fujiwara -# Copyright (c) 2007-2015 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 -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -import sys - -from prefs import Prefs - -N_ = lambda a : a - -__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) - if _config != None: - self.default = _config - self.set_no_key_warning(True) - self.fetch_all() - self.set_no_key_warning(False) - - def __update_key (self, section, old_key, new_key): - file = __file__ - if __file__.find('/') >= 0: - file = __file__[__file__.rindex('/') + 1:] - warning_message = \ - '(' + file + ') ibus-anthy-WARNING **: ' \ - 'The key (' + old_key + ') will be removed in the future. ' \ - 'Currently the key (' + new_key + ') is used instead. ' \ - 'The ibus keys are defined in ' + \ - '/'.join(['/desktop/ibus', self._prefix, section]) + ' .' - - if not self.fetch_item(section, old_key, True): - return - print(warning_message, file=sys.stderr) - if self.fetch_item(section, new_key, True): - return - - self.fetch_item(section, old_key) - value = self.get_value(section, old_key) - self.set_value(section, new_key, value) - self.commit_item(section, new_key) - self.undo_item(section, new_key) - - def keys(self, section): - if section.startswith('shortcut/'): - return _cmd_keys - return list(self.default[section].keys()) - - def get_japanese_ordered_list(self): - return _japanese_ordered_list - - 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('Not supported key in gsettings', gkeys, file=sys.stderr) - 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 list(_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('Not supported key in gsettings', typing, file=sys.stderr) - 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'. -# The workaround is to save the order here... -_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', - 'circle_kana_mode', - 'circle_typing_method', - 'circle_dict_method', - 'latin_mode', - 'wide_latin_mode', - 'hiragana_mode', - 'katakana_mode', - 'half_katakana_mode', -# 'cancel_pseudo_ascii_mode_key', - - 'hiragana_for_latin_with_shift', - - 'insert_space', - 'insert_alternate_space', - 'insert_half_space', - 'insert_wide_space', - 'backspace', - 'delete', - 'commit', - 'convert', - 'predict', - 'cancel', - 'cancel_all', - 'reconvert', -# 'do_nothing', - - 'select_first_candidate', - 'select_last_candidate', - 'select_next_candidate', - 'select_prev_candidate', - 'candidates_page_up', - 'candidates_page_down', - - 'move_caret_first', - 'move_caret_last', - 'move_caret_forward', - 'move_caret_backward', - - 'select_first_segment', - 'select_last_segment', - 'select_next_segment', - 'select_prev_segment', - 'shrink_segment', - 'expand_segment', - 'commit_first_segment', - 'commit_selected_segment', - - 'select_candidates_1', - 'select_candidates_2', - 'select_candidates_3', - 'select_candidates_4', - 'select_candidates_5', - 'select_candidates_6', - 'select_candidates_7', - 'select_candidates_8', - 'select_candidates_9', - 'select_candidates_0', - - 'convert_to_char_type_forward', - 'convert_to_char_type_backward', - 'convert_to_hiragana', - 'convert_to_katakana', - 'convert_to_half', - 'convert_to_half_katakana', - 'convert_to_wide_latin', - 'convert_to_latin', - 'convert_to_hiragana_all', - 'convert_to_katakana_all', - 'convert_to_half_all', - 'convert_to_half_katakana_all', - 'convert_to_wide_latin_all', - 'convert_to_latin_all', - - 'dict_admin', - 'add_word', - - 'start_setup', -] - -_config = { - 'common': { - 'input_mode': 0, - 'typing_method': 0, - 'conversion_segment_mode': 0, - - 'show-input-mode': True, - 'show-typing-method': False, - 'show-segment-mode': False, - 'show-dict-mode': True, - 'show-dict-config': False, - 'show-preferences': True, - - 'period_style': 0, - 'symbol_style': 1, - 'ten_key_mode': 1, - 'behavior_on_focus_out': 0, - 'behavior_on_period': 0, - 'trigger_periods': ',.、。,.', - - 'page_size': 10, - 'half_width_symbol': False, - 'half_width_number': False, - 'half_width_space': False, - 'latin_with_shift': True, - - 'shortcut_type': 'default', - - 'dict_admin_command': ['@KASUMI_EXEC_FILE@', 'kasumi'], - 'add_word_command': ['@KASUMI_EXEC_FILE@', 'kasumi', '-a'], - 'dict_config_icon': '@KASUMI_ICON_FILE@', - 'keyboard_layouts': [ - 'default', 'jp', 'us', - # XKB options requires ibus 1.5. - 'jp[ctrl:swapcaps]', 'us[ctrl:swapcaps]', - 'jp[ctrl:swapcaps,compose:rctrl]', - 'us[ctrl:swapcaps,compose:rctrl]', - 'jp[japan:kana_lock]', - 'jp[japan:nicola_f_bs]', - 'jp[japan:nicola_f_bs,ctrl:swapcaps]', - 'jp[japan:hztg_escape]', - 'jp[japan:hztg_escape,ctrl:swapcaps]', - ], - }, - - 'romaji_typing_rule': { - 'method': 'default', - # The newkeys list is saved for every romaji_typing_rule/$method - # so that prefs.get_value_direct() is not used. - # prefs.fetch_section() doesn't get the keys if they exist - # in gconf only. - 'newkeys': [], - }, - - ##0 MS-IME - # http://www.filibeto.org/sun/lib/solaris10-docs/E19253-01/819-7844/appe-1-4/index.html - ##1 ATOK - # http://www.filibeto.org/sun/lib/solaris10-docs/E19253-01/819-7844/appe-1-3/index.html - ##2 Gairaigo http://ja.wikipedia.org/wiki/%E5%A4%96%E6%9D%A5%E8%AA%9E - ##3 ANSI/BSI Suggestions http://en.wikipedia.org/wiki/Katakana - ##4 Historical kana http://en.wikipedia.org/wiki/Romanization_of_Japanese - # Maybe we need a compatibility between MS-IME and ibus-anthy. - 'romaji_typing_rule/default': { - 'minus' : 'ー', - 'a' : 'あ', - 'i' : 'い', - 'u' : 'う', - 'e' : 'え', - 'o' : 'お', - 'x-a' : 'ぁ', - 'x-i' : 'ぃ', - 'x-u' : 'ぅ', - 'x-e' : 'ぇ', - 'x-o' : 'ぉ', - 'l-a' : 'ぁ', - 'l-i' : 'ぃ', - 'l-u' : 'ぅ', - 'l-e' : 'ぇ', - 'l-o' : 'ぉ', - 'w-h-a' : 'うぁ', - 'w-h-i' : 'うぃ', - 'w-h-e' : 'うぇ', - 'w-h-o' : 'うぉ', - 'w-y-a' : 'うゃ', ##2 - 'w-y-u' : 'うゅ', ##2 - 'w-y-o' : 'うょ', ##2 - 'v-a' : 'ヴぁ', - 'v-i' : 'ヴぃ', - 'v-u' : 'ヴ', - 'v-e' : 'ヴぇ', - 'v-o' : 'ヴぉ', - 'v-y-a' : 'ヴゃ', ##2 - 'v-y-u' : 'ヴゅ', ##2 - 'v-y-e' : 'ヴぃぇ', ##2 - 'v-y-o' : 'ヴょ', ##2 - 'k-a' : 'か', - 'k-i' : 'き', - 'k-u' : 'く', - 'k-e' : 'け', - 'k-o' : 'こ', - 'l-k-a' : 'ヵ', - 'l-k-e' : 'ヶ', -# 'x-k-a' : 'ゕ', - 'x-k-a' : 'ヵ', -# 'x-k-e' : 'ゖ', - 'x-k-e' : 'ヶ', - 'g-a' : 'が', - 'g-i' : 'ぎ', - 'g-u' : 'ぐ', - 'g-e' : 'げ', - 'g-o' : 'ご', - 'k-y-a' : 'きゃ', - 'k-y-i' : 'きぃ', - 'k-y-u' : 'きゅ', - 'k-y-e' : 'きぇ', - 'k-y-o' : 'きょ', - 'k-w-a' : 'くぁ', - 'k-w-i' : 'くぃ', ##2 - 'k-w-u' : 'くぅ', ##2 - 'k-w-e' : 'くぇ', ##2 - 'k-w-o' : 'くぉ', ##2 - 'g-y-a' : 'ぎゃ', - 'g-y-i' : 'ぎぃ', - 'g-y-u' : 'ぎゅ', - 'g-y-e' : 'ぎぇ', - 'g-y-o' : 'ぎょ', - 'g-w-a' : 'ぐぁ', - 'g-w-i' : 'ぐぃ', ##2 - 'g-w-u' : 'ぐぅ', ##2 - 'g-w-e' : 'ぐぇ', ##2 - 'g-w-o' : 'ぐぉ', ##2 - 's-a' : 'さ', - 's-i' : 'し', - 's-u' : 'す', - 's-e' : 'せ', - 's-o' : 'そ', - 'z-a' : 'ざ', - 'z-i' : 'じ', - 'z-u' : 'ず', - 'z-e' : 'ぜ', - 'z-o' : 'ぞ', - 's-y-a' : 'しゃ', - 's-y-i' : 'しぃ', - 's-y-u' : 'しゅ', - 's-y-e' : 'しぇ', - 's-y-o' : 'しょ', - 's-h-a' : 'しゃ', - 's-h-i' : 'し', - 's-h-u' : 'しゅ', - 's-h-e' : 'しぇ', - 's-h-o' : 'しょ', - 'z-y-a' : 'じゃ', - 'z-y-i' : 'じぃ', - 'z-y-u' : 'じゅ', - 'z-y-e' : 'じぇ', - 'z-y-o' : 'じょ', - 'j-a' : 'じゃ', - 'j-y-a' : 'じゃ', - 'j-i' : 'じ', - 'j-y-i' : 'じぃ', - 'j-u' : 'じゅ', - 'j-y-u' : 'じゅ', - 'j-e' : 'じぇ', - 'j-y-e' : 'じぇ', - 'j-o' : 'じょ', - 'j-y-o' : 'じょ', - 's-w-i' : 'すぅぃ', ##2 - 's-w-e' : 'すぇ', ##2 - 'z-w-e' : 'ずぇ', ##2 - 't-a' : 'た', - 't-i' : 'ち', - 't-u' : 'つ', - 't-s-u' : 'つ', - 't-e' : 'て', - 't-o' : 'と', - 'd-a' : 'だ', - 'd-i' : 'ぢ', - 'd-u' : 'づ', - 'd-e' : 'で', - 'd-o' : 'ど', - 'x-t-u' : 'っ', - 'x-t-s-u' : 'っ', - 'l-t-u' : 'っ', - 'l-t-s-u' : 'っ', - 't-y-a' : 'ちゃ', - 't-y-i' : 'ちぃ', - 't-y-u' : 'ちゅ', - 't-y-e' : 'ちぇ', - 't-y-o' : 'ちょ', - 'c-y-a' : 'ちゃ', - 'c-y-i' : 'ちぃ', - 'c-y-u' : 'ちゅ', - 'c-y-e' : 'ちぇ', - 'c-y-o' : 'ちょ', - 'c-h-a' : 'ちゃ', - 'c-h-i' : 'ち', - 'c-h-u' : 'ちゅ', - 'c-h-e' : 'ちぇ', - 'c-h-o' : 'ちょ', - 'd-y-a' : 'ぢゃ', - 'd-y-i' : 'ぢぃ', - 'd-y-u' : 'ぢゅ', - 'd-y-e' : 'ぢぇ', - 'd-y-o' : 'ぢょ', - 't-s-a' : 'つぁ', - 't-s-i' : 'つぃ', - 't-s-e' : 'つぇ', - 't-s-o' : 'つぉ', - 't-s-y-a' : 'つゃ', ##3 - 't-s-y-u' : 'つゅ', ##3 - 't-s-y-e' : 'つぃぇ', ##3 - 't-s-y-o' : 'つょ', ##3 - 'd-z-a' : 'づぁ', ##3 - 'd-z-i' : 'づぃ', ##3 - 'd-z-u' : 'づ', ##4 - 'd-z-e' : 'づぇ', ##3 - 'd-z-o' : 'づぉ', ##3 - 'd-z-y-a' : 'づゃ', ##3 - 'd-z-y-u' : 'づゅ', ##3 - 'd-z-y-e' : 'づぃぇ', ##3 - 'd-z-y-o' : 'づょ', ##3 - 't-h-a' : 'てゃ', - 't-h-i' : 'てぃ', - 't-h-u' : 'てゅ', - 't-h-e' : 'てぇ', - 't-h-o' : 'てょ', - 't-w-u' : 'とぅ', - 'd-h-a' : 'でゃ', - 'd-h-i' : 'でぃ', - 'd-h-u' : 'でゅ', - 'd-h-e' : 'でぇ', - 'd-h-o' : 'でょ', - 'd-w-u' : 'どぅ', - 'n-a' : 'な', - 'n-i' : 'に', - 'n-u' : 'ぬ', - 'n-e' : 'ね', - 'n-o' : 'の', - 'n-y-a' : 'にゃ', - 'n-y-i' : 'にぃ', - 'n-y-u' : 'にゅ', - 'n-y-e' : 'にぇ', - 'n-y-o' : 'にょ', - 'h-a' : 'は', - 'h-i' : 'ひ', - 'h-u' : 'ふ', - 'h-e' : 'へ', - 'h-o' : 'ほ', - 'b-a' : 'ば', - 'b-i' : 'び', - 'b-u' : 'ぶ', - 'b-e' : 'べ', - 'b-o' : 'ぼ', - 'p-a' : 'ぱ', - 'p-i' : 'ぴ', - 'p-u' : 'ぷ', - 'p-e' : 'ぺ', - 'p-o' : 'ぽ', - 'h-y-a' : 'ひゃ', - 'h-y-i' : 'ひぃ', - 'h-y-u' : 'ひゅ', - 'h-y-e' : 'ひぇ', - 'h-y-o' : 'ひょ', - 'b-y-a' : 'びゃ', - 'b-y-i' : 'びぃ', - 'b-y-u' : 'びゅ', - 'b-y-e' : 'びぇ', - 'b-y-o' : 'びょ', - 'p-y-a' : 'ぴゃ', - 'p-y-i' : 'ぴぃ', - 'p-y-u' : 'ぴゅ', - 'p-y-e' : 'ぴぇ', - 'p-y-o' : 'ぴょ', - 'f-a' : 'ふぁ', - 'f-i' : 'ふぃ', - 'f-u' : 'ふ', - 'f-e' : 'ふぇ', - 'f-o' : 'ふぉ', - 'f-y-a' : 'ふゃ', - 'f-y-i' : 'ふぃ', - 'f-y-u' : 'ふゅ', - 'f-y-e' : 'ふぇ', - 'f-y-o' : 'ふょ', - 'b-w-a' : 'ぶぁ', ##2 - 'b-w-e' : 'ぶぇ', ##2 - 'b-w-o' : 'ぶぉ', ##2 - 'p-w-a' : 'ぷぁ', ##2 - 'p-w-e' : 'ぷぇ', ##2 - 'p-w-o' : 'ぷぉ', ##2 - 'm-a' : 'ま', - 'm-i' : 'み', - 'm-u' : 'む', - 'm-e' : 'め', - 'm-o' : 'も', - 'm-y-a' : 'みゃ', - 'm-y-i' : 'みぃ', - 'm-y-u' : 'みゅ', - 'm-y-e' : 'みぇ', - 'm-y-o' : 'みょ', - 'y-a' : 'や', - 'y-i' : 'い', - 'y-u' : 'ゆ', - 'y-e' : 'いぇ', - 'y-o' : 'よ', - 'l-y-a' : 'ゃ', - 'l-y-i' : 'ぃ', - 'l-y-u' : 'ゅ', - 'l-y-e' : 'ぇ', - 'l-y-o' : 'ょ', - 'x-y-a' : 'ゃ', - 'x-y-i' : 'ぃ', - 'x-y-u' : 'ゅ', - 'x-y-e' : 'ぇ', - 'x-y-o' : 'ょ', - 'r-a' : 'ら', - 'r-i' : 'り', - 'r-u' : 'る', - 'r-e' : 'れ', - 'r-o' : 'ろ', - 'r-y-a' : 'りゃ', - 'r-y-i' : 'りぃ', - 'r-y-u' : 'りゅ', - 'r-y-e' : 'りぇ', - 'r-y-o' : 'りょ', - 'w-a' : 'わ', - 'w-i' : 'うぃ', - 'w-u' : 'う', - 'w-e' : 'うぇ', - 'w-o' : 'を', - 'l-w-a' : 'ゎ', - 'x-w-a' : 'ゎ', - 'n-apostrophe' : 'ん', - 'n-n' : 'ん', - 'w-y-i' : 'ゐ', - 'w-y-e' : 'ゑ', - }, - - 'kana_typing_rule': { - 'method': 'jp', - 'newkeys': [], - }, - - 'kana_typing_rule/jp': { - # no modifiers keys - '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 - '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 - '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 - '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, - 'keyboard_layout': 0, - 'fmv_extension': 2, - 'handakuten': False, - 'rs': 'Henkan', - 'ls': 'Muhenkan', - 't1': 100, - 't2': 75, - }, - - 'thumb_typing_rule': { - 'method': 'base', - 'newkeys': [], - 'nicola_j_table_newkeys': [], - 'nicola_a_table_newkeys': [], - 'nicola_f_table_newkeys': [], - 'kb231_j_fmv_table_newkeys': [], - 'kb231_a_fmv_table_newkeys': [], - 'kb231_f_fmv_table_newkeys': [], - 'kb611_j_fmv_table_newkeys': [], - 'kb611_a_fmv_table_newkeys': [], - 'kb611_f_fmv_table_newkeys': [], - }, - - 'thumb_typing_rule/base': { - 'q' : ['。', '', 'ぁ'], - 'w' : ['か', 'が', 'え'], - 'e' : ['た', 'だ', 'り'], - 'r' : ['こ', 'ご', 'ゃ'], - 't' : ['さ', 'ざ', 'れ'], - - 'y' : ['ら', 'よ', 'ぱ'], - 'u' : ['ち', 'に', 'ぢ'], - 'i' : ['く', 'る', 'ぐ'], - 'o' : ['つ', 'ま', 'づ'], - 'p' : [',', 'ぇ', 'ぴ'], - 'at' : ['、', '', ''], - 'bracketleft' : ['゛', '゜', ''], - - 'a' : ['う', '', 'を'], - 's' : ['し', 'じ', 'あ'], - 'd' : ['て', 'で', 'な'], - 'f' : ['け', 'げ', 'ゅ'], - 'g' : ['せ', 'ぜ', 'も'], - - 'h' : ['は', 'み', 'ば'], - 'j' : ['と', 'お', 'ど'], - 'k' : ['き', 'の', 'ぎ'], - 'l' : ['い', 'ょ', 'ぽ'], - 'semicolon' : ['ん', 'っ', ''], - - 'z' : ['.', '', 'ぅ'], - 'x' : ['ひ', 'び', 'ー'], - 'c' : ['す', 'ず', 'ろ'], - 'v' : ['ふ', 'ぶ', 'や'], - 'b' : ['へ', 'べ', 'ぃ'], - - 'n' : ['め', 'ぬ', 'ぷ'], - 'm' : ['そ', 'ゆ', 'ぞ'], - 'comma' : ['ね', 'む', 'ぺ'], - 'period' : ['ほ', 'わ', 'ぼ'], - 'slash' : ['・', 'ぉ', ''], - - '1' : ['1', '', '?'], - '2' : ['2', '', '/'], - '4' : ['4', '', '「'], - '5' : ['5', '', '」'], - - '6' : ['6', '[', ''], - '7' : ['7', ']', ''], - '8' : ['8', '(', ''], - '9' : ['9', ')', ''], - 'backslash' : ['¥', '', ''], - }, - - 'thumb_typing_rule/nicola_j_table': { - 'colon' : [':', '', ''], - 'at' : ['、', '', ''], - 'bracketleft' : ['゛', '゜', ''], - 'bracketright' : ['」', '', ''], - '8' : ['8', '(', ''], - '9' : ['9', ')', ''], - '0' : ['0', '', ''], - }, - - 'thumb_typing_rule/nicola_a_table': { - 'colon' : [':', '', ''], - 'at' : ['@', '', ''], - 'bracketleft' : ['、', '', ''], - 'bracketright' : ['゛', '゜', ''], - '8' : ['8', '', ''], - '9' : ['9', '(', ''], - '0' : ['0', ')', ''], - }, - - 'thumb_typing_rule/nicola_f_table': { - 'colon' : ['、', '', ''], - 'at' : ['@', '', ''], - 'bracketleft' : ['゛', '゜', ''], - 'bracketright' : ['」', '', ''], - '8' : ['8', '(', ''], - '9' : ['9', ')', ''], - '0' : ['0', '', ''], - }, - - 'thumb_typing_rule/kb231_j_fmv_table': { - '3' : ['3', '', '~'], - '0' : ['0', '『', ''], - 'minus' : ['-', '』', ''], - 'equal' : ['=', '', ''], - }, - - 'thumb_typing_rule/kb231_a_fmv_table': { - '3' : ['3', '', '~'], - '0' : ['0', ')', ''], - 'minus' : ['-', '『', ''], - 'equal' : ['=', '』', ''], - }, - - 'thumb_typing_rule/kb231_f_fmv_table': { - '3' : ['3', '', '~'], - '0' : ['0', '『', ''], - 'minus' : ['-', '』', ''], - 'equal' : ['=', '', ''], - }, - - 'thumb_typing_rule/kb611_j_fmv_table': { - 'grave' : ['‘', '', ''], - 'asciicircum' : ['々', '£', ''], - 'colon' : [':', '', ''], - 'at' : ['、', '¢', ''], - 'bracketleft' : ['゛', '゜', ''], - # keysyms are same and keycodes depend on the platforms. - #'¥' : [u'¥', u'¬', u''], - 'backslash' : ['¥', '¦', ''], - }, - - 'thumb_typing_rule/kb611_a_fmv_table': { - 'grave' : ['々', '', '£'], - 'colon' : [':', '', ''], - 'at' : ['@', '', ''], - 'bracketleft' : ['、', '¢', ''], - #'¥' : [u'¥', u'¬', u''], - 'backslash' : ['¥', '¦', ''], - }, - - 'thumb_typing_rule/kb611_f_fmv_table': { - 'grave' : ['‘', '', ''], - 'asciicircum' : ['々', '£', ''], - 'colon' : ['、', '¢', ''], - 'at' : ['@', '', ''], - 'bracketleft' : ['゛', '゜', ''], - #'¥' : [u'¥', u'¬', u''], - 'backslash' : ['¥', '¦', ''], - }, - - 'dict': { - 'zipcode': ['@pkgdatadir@/dicts/zipcode.t'], - 'symbol': ['@pkgdatadir@/dicts/symbol.t'], - 'oldchar': ['@pkgdatadir@/dicts/oldchar.t'], - 'era': ['@pkgdatadir@/dicts/era.t'], - 'emoji': ['@pkgdatadir@/dicts/emoji.t'], - 'files': [ - '@pkgdatadir@/dicts/zipcode.t', - '@pkgdatadir@/dicts/symbol.t', - '@pkgdatadir@/dicts/oldchar.t', - '@pkgdatadir@/dicts/era.t', - '@pkgdatadir@/dicts/emoji.t', - ], - }, - - 'dict/file/default': { - 'embed': False, - 'single': True, - 'icon': None, - 'short_label': None, - 'long_label': None, - 'preview_lines': 30, - 'reverse': False, - 'is_system': False, - 'encoding': 'utf-8', - }, - - 'dict/file/embedded': { - 'embed': True, - 'single': True, - 'icon': None, - 'short_label': '般', - 'long_label': N_("General"), - 'preview_lines': 0, - 'reverse': False, - 'is_system': True, - }, - - 'dict/file/zipcode': { - 'embed': False, - 'single': True, - 'icon': None, - 'short_label': '〒', - 'long_label': N_("Zip Code Conversion"), - 'preview_lines': -1, - 'reverse': False, - 'is_system': True, - }, - - 'dict/file/symbol': { - 'embed': True, - 'single': False, - 'icon': None, - 'short_label': '記', - 'long_label': N_("Symbol"), - 'preview_lines': -1, - 'reverse': False, - 'is_system': True, - }, - - 'dict/file/oldchar': { - 'embed': False, - 'single': True, - 'icon': None, - 'short_label': '旧', - 'long_label': N_("Old Character Style"), - 'preview_lines': -1, - 'reverse': False, - 'is_system': True, - }, - 'dict/file/era': { - 'embed': False, - 'single': True, - 'icon': None, - 'short_label': '年', - 'long_label': N_("Era"), - 'preview_lines': -1, - 'reverse': False, - 'is_system': True, - }, - 'dict/file/emoji': { - 'embed': False, - 'single': True, - 'icon': None, - 'short_label': '😊', - 'long_label': N_("Emoji"), - 'preview_lines': -1, - 'reverse': False, - 'is_system': True, - }, -} - -_shortcut_default = { - 'on_off': [@ON_OFF_KEYS@], - 'circle_input_mode': ['Ctrl+comma', 'Ctrl+less'], - # Removed Hiragana_Katakana key in circle_kana_mode for latin_with_shift. - 'circle_kana_mode': ['Ctrl+period', 'Ctrl+greater'], -# 'cancel_pseudo_ascii_mode_key': ['Escape'], - 'circle_typing_method': ['Alt+Romaji', 'Ctrl+slash'], - 'circle_dict_method': ['Alt+Henkan'], - - 'insert_space': ['space'], - 'insert_alternate_space': ['Shift+space'], - 'backspace': ['BackSpace', 'Ctrl+H'], - 'delete': ['Delete', 'Ctrl+D'], - 'commit': ['Return', 'KP_Enter', 'Ctrl+J', 'Ctrl+M'], - 'convert': ['space', 'KP_Space', 'Henkan'], - 'predict': ['Tab', 'ISO_Left_Tab'], - 'cancel': ['Escape', 'Ctrl+G'], - 'reconvert': ['Shift+Henkan'], - - 'move_caret_first': ['Ctrl+A', 'Home'], - 'move_caret_last': ['Ctrl+E', 'End'], - 'move_caret_forward': ['Right', 'Ctrl+F'], - 'move_caret_backward': ['Left', 'Ctrl+B'], - - 'select_first_segment': ['Ctrl+A', 'Home'], - 'select_last_segment': ['Ctrl+E', 'End'], - 'select_next_segment': ['Right', 'Ctrl+F'], - 'select_prev_segment': ['Left', 'Ctrl+B'], - 'shrink_segment': ['Shift+Left', 'Ctrl+I'], - 'expand_segment': ['Shift+Right', 'Ctrl+O'], - 'commit_first_segment': ['Shift+Down'], - 'commit_selected_segment': ['Ctrl+Down'], - - 'select_first_candidate': ['Home'], - 'select_last_candidate': ['End'], - 'select_next_candidate': ['space', 'KP_Space', 'Tab', 'ISO_Left_Tab', 'Henkan', 'Down', 'KP_Add', 'Ctrl+N'], - 'select_prev_candidate': ['Shift+Tab', 'Shift+ISO_Left_Tab', 'Up', 'KP_Subtract', 'Ctrl+P'], - 'candidates_page_up': ['Page_Up'], - 'candidates_page_down': ['Page_Down', 'KP_Tab'], - - 'select_candidates_1': ['1'], - 'select_candidates_2': ['2'], - 'select_candidates_3': ['3'], - 'select_candidates_4': ['4'], - 'select_candidates_5': ['5'], - 'select_candidates_6': ['6'], - 'select_candidates_7': ['7'], - 'select_candidates_8': ['8'], - 'select_candidates_9': ['9'], - 'select_candidates_0': ['0'], - - 'convert_to_char_type_forward': ['Muhenkan'], - 'convert_to_hiragana': ['F6'], - 'convert_to_katakana': ['F7'], - 'convert_to_half': ['F8'], - 'convert_to_half_katakana': ['Shift+F8'], - 'convert_to_wide_latin': ['F9'], - 'convert_to_latin': ['F10'], - 'convert_to_hiragana_all': ['Shift+F6'], - 'convert_to_katakana_all': ['Shift+F7'], - 'convert_to_wide_latin_all': ['Shift+F9'], - 'convert_to_latin_all': ['Shift+F10'], - - 'dict_admin': ['F11'], - 'add_word': ['F12'], - - 'hiragana_for_latin_with_shift': ['Hiragana_Katakana'], -} - -_config['shortcut/default'] = dict.fromkeys(_cmd_keys, []) -_config['shortcut/default'].update(_shortcut_default) - -_shortcut_atok = { - 'on_off': ['Henkan', 'Eisu_toggle', 'Zenkaku_Hankaku'], - 'circle_input_mode': ['F10'], - 'hiragana_mode': ['Hiragana_Katakana'], - 'katakana_mode': ['Shift+Hiragana_Katakana'], - 'circle_typing_method': ['Romaji', 'Alt+Romaji'], - 'circle_dict_method': ['Alt+Henkan'], - 'convert': ['space', 'Henkan', 'Shift+space', 'Shift+Henkan'], - 'predict': ['Tab'], - 'cancel': ['Escape', 'BackSpace', 'Ctrl+H', 'Ctrl+bracketleft'], - 'commit': ['Return', 'Ctrl+M'], - 'reconvert': ['Shift+Henkan'], - - 'insert_space': ['space'], - 'insert_alternate_space': ['Shift+space'], - 'backspace': ['BackSpace', 'Ctrl+H'], - 'delete': ['Delete', 'Ctrl+G'], - - 'move_caret_backward': ['Left', 'Ctrl+K'], - 'move_caret_forward': ['Right', 'Ctrl+L'], - 'move_caret_first': ['Ctrl+Left'], - 'move_caret_last': ['Ctrl+Right'], - - 'select_prev_segment': ['Shift+Left'], - 'select_next_segment': ['Shift+Right'], - 'select_first_segment': ['Ctrl+Left'], - 'select_last_segment': ['Ctrl+Right'], - 'expand_segment': ['Right', 'Ctrl+L'], - 'shrink_segment': ['Left', 'Ctrl+K'], - 'commit_selected_segment': ['Down', 'Ctrl+N'], - - 'candidates_page_up': ['Shift+Henkan', 'Page_Up'], - 'candidates_page_down': ['Henkan', 'Page_Down'], - 'select_next_candidate': ['space', 'Tab', 'Henkan', 'Shift+space', 'Shift+Henkan'], - 'select_prev_candidate': ['Up'], - - 'select_candidates_1': ['1'], - 'select_candidates_2': ['2'], - 'select_candidates_3': ['3'], - 'select_candidates_4': ['4'], - 'select_candidates_5': ['5'], - 'select_candidates_6': ['6'], - 'select_candidates_7': ['7'], - 'select_candidates_8': ['8'], - 'select_candidates_9': ['9'], - 'select_candidates_0': ['0'], - - 'convert_to_hiragana': ['F6', 'Ctrl+U'], - 'convert_to_katakana': ['F7', 'Ctrl+I'], - 'convert_to_half': ['F8', 'Ctrl+O'], - 'convert_to_half_katakana': ['Shift+F8'], - 'convert_to_wide_latin': ['F9', 'Ctrl+P'], - 'convert_to_latin': ['F10', 'Ctrl+at'], - 'convert_to_hiragana_all': ['Shift+F6'], - 'convert_to_katakana_all': ['Shift+F7'], - 'convert_to_wide_latin_all': ['Shift+F9'], - 'convert_to_latin_all': ['Shift+F10'], - - 'dict_admin': ['F11'], - 'add_word': ['Ctrl+F7'], - - 'hiragana_for_latin_with_shift': ['Ctrl+J'], -} - -_config['shortcut/atok'] = dict.fromkeys(_cmd_keys, []) -_config['shortcut/atok'].update(_shortcut_atok) - -_shortcut_wnn = { - 'on_off': ['Shift+space'], - 'convert': ['space'], - 'predict': ['Ctrl+Q'], - 'cancel': ['Escape', 'Ctrl+G', 'Alt+Down', 'Muhenkan'], - 'commit': ['Ctrl+L', 'Ctrl+M', 'Ctrl+J', 'Return'], - 'insert_space': ['space'], - 'backspace': ['Ctrl+H', 'BackSpace'], - 'delete': ['Ctrl+D', 'Delete'], - 'circle_dict_method': ['Alt+Henkan'], - - 'move_caret_backward': ['Ctrl+B', 'Left'], - 'move_caret_forward': ['Ctrl+F', 'Right'], - 'move_caret_first': ['Ctrl+A', 'Alt+Left'], - 'move_caret_last': ['Ctrl+E', 'Alt+Right'], - - 'select_prev_segment': ['Ctrl+B', 'Left'], - 'select_next_segment': ['Ctrl+F', 'Right'], - 'select_first_segment': ['Ctrl+A', 'Alt+Left'], - 'select_last_segment': ['Ctrl+E', 'Alt+Right'], - 'expand_segment': ['Ctrl+O', 'F14'], - 'shrink_segment': ['Ctrl+I', 'F13'], - - 'candidates_page_up': ['Tab'], - 'candidates_page_down': ['Shift+Tab'], - 'select_next_candidate': ['space', 'Ctrl+Q', 'Ctrl+P', 'Down'], - 'select_prev_candidate': ['Ctrl+N', 'Up'], - - 'select_candidates_1': ['1'], - 'select_candidates_2': ['2'], - 'select_candidates_3': ['3'], - 'select_candidates_4': ['4'], - 'select_candidates_5': ['5'], - 'select_candidates_6': ['6'], - 'select_candidates_7': ['7'], - 'select_candidates_8': ['8'], - 'select_candidates_9': ['9'], - 'select_candidates_0': ['0'], - - 'convert_to_hiragana': ['F6'], - 'convert_to_katakana': ['F7'], - 'convert_to_half': ['F8'], - 'convert_to_wide_latin': ['F9'], - 'convert_to_latin': ['F10'], - 'convert_to_hiragana_all': ['Shift+F6'], - 'convert_to_katakana_all': ['Shift+F7'], - 'convert_to_half_all': ['Shift+F8'], - 'convert_to_wide_latin_all': ['Shift+F9'], - 'convert_to_latin_all': ['Shift+F10'], - - 'dict_admin': ['F11'], - 'add_word': ['F12'], - - 'hiragana_for_latin_with_shift': ['Hiragana_Katakana'], -} - -_config['shortcut/wnn'] = dict.fromkeys(_cmd_keys, []) -_config['shortcut/wnn'].update(_shortcut_wnn) - diff --git a/setup/python3/main.py b/setup/python3/main.py index 6346e43..e43c458 100644 --- a/setup/python3/main.py +++ b/setup/python3/main.py @@ -4,8 +4,8 @@ # # Copyright (c) 2007-2008 Peng Huang # Copyright (c) 2009 Hideaki ABE -# Copyright (c) 2010-2016 Takao Fujiwara -# Copyright (c) 2007-2016 Red Hat, Inc. +# Copyright (c) 2010-2017 Takao Fujiwara +# 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 @@ -32,6 +32,7 @@ import gettext from gettext import dgettext from gi import require_version as gi_require_version +gi_require_version('Gio', '2.0') gi_require_version('GLib', '2.0') gi_require_version('Gtk', '3.0') gi_require_version('Gdk', '3.0') @@ -39,6 +40,7 @@ gi_require_version('GdkX11', '3.0') gi_require_version('Pango', '1.0') gi_require_version('IBus', '1.0') +from gi.repository import Gio from gi.repository import GLib # set_prgname before importing other modules to show the name in warning @@ -76,6 +78,8 @@ class AnthySetup(object): gettext.bindtextdomain(DOMAINNAME, config.LOCALEDIR) gettext.bind_textdomain_codeset(DOMAINNAME, 'UTF-8') + self.__prefs = AnthyPrefs() + # IBus.Bus() calls ibus_bus_new(). # Gtk.Builder().add_from_file() also calls ibus_bus_new_async() # via ibus_im_context_new(). @@ -143,13 +147,12 @@ class AnthySetup(object): bus.connect('connected', self.__init_bus_connected) def __init_bus_connected(self, bus): - self.__config = bus.get_config() builder = self.__builder + prefs = self.__prefs self.__thumb_kb_layout_mode = None self.__thumb_kb_layout = None self.__japanese_ordered_dict = {} - self.prefs = prefs = AnthyPrefs(None, self.__config) # glade 'icon_name' property has a custom scaling and it seems # to be difficult to show the complicated small icon in metacity. @@ -164,17 +167,25 @@ class AnthySetup(object): icon_path = 'ibus-anthy' builder.get_object('main').set_icon_name(icon_path) - for name in ['input_mode', 'typing_method', 'conversion_segment_mode', - 'period_style', 'symbol_style', 'ten_key_mode', - 'behavior_on_focus_out', 'behavior_on_period', - 'half_width_symbol', 'half_width_number', 'half_width_space', - 'latin_with_shift', - 'thumb:keyboard_layout_mode', 'thumb:keyboard_layout', - 'thumb:fmv_extension', 'thumb:handakuten']: + for name in ['input-mode', 'typing-method', 'conversion-segment-mode', + 'period-style', 'symbol-style', 'ten-key-mode', + 'behavior-on-focus-out', 'behavior-on-period', + 'half-width-symbol', 'half-width-number', 'half-width-space', + 'latin-with-shift', + 'thumb:keyboard-layout-mode', 'thumb:keyboard-layout', + 'thumb:fmv-extension', 'thumb:handakuten']: section, key = self.__get_section_key(name) - builder.get_object(name).set_active(prefs.get_value(section, key)) + prefs.bind(section, key, + builder.get_object(name), + 'active', + Gio.SettingsBindFlags.DEFAULT) + + prefs.bind('thumb', 'keyboard-layout-mode', + builder.get_object('thumb:keyboard-layout'), + 'sensitive', + Gio.SettingsBindFlags.INVERT_BOOLEAN) - tv = builder.get_object('menu_visible:treeview') + tv = builder.get_object('menu-visible:treeview') ls = Gtk.ListStore(str, bool, str) tv.set_model(ls) @@ -199,12 +210,14 @@ class AnthySetup(object): self.__append_menus_in_model() l = ['default', 'atok', 'wnn'] - s_type = prefs.get_value('common', 'shortcut_type') + s_type = prefs.get_value('common', 'shortcut-type') s_type = s_type if s_type in l else 'default' - builder.get_object('shortcut_type').set_active(l.index(s_type)) + builder.get_object('shortcut-type').set_active(l.index(s_type)) - builder.get_object('page_size').set_value(prefs.get_value('common', - 'page_size')) + prefs.bind('common', 'page-size', + builder.get_object('page-size').get_adjustment(), + 'value', + Gio.SettingsBindFlags.DEFAULT) tv = builder.get_object('shortcut') tv.append_column(Gtk.TreeViewColumn(_("Command"), @@ -216,17 +229,17 @@ class AnthySetup(object): tv.get_selection().connect_after('changed', self.on_selection_changed, 0) ls = Gtk.ListStore(str, str) - sec = 'shortcut/' + s_type - for k in self.prefs.keys(sec): - ls.append([k, l_to_s(self.prefs.get_value(sec, k))]) + shortcuts = self.__prefs.get_value('shortcut', s_type) + for k in shortcuts.keys(): + ls.append([k, l_to_s(shortcuts[k])]) tv.set_model(ls) self.__keymap = None GLib.idle_add(self.__update_keymap_label, priority = GLib.PRIORITY_LOW) - self.__thumb_kb_layout_mode = builder.get_object('thumb:keyboard_layout_mode') - self.__thumb_kb_layout = builder.get_object('thumb:keyboard_layout') + self.__thumb_kb_layout_mode = builder.get_object('thumb:keyboard-layout-mode') + self.__thumb_kb_layout = builder.get_object('thumb:keyboard-layout') self.__set_thumb_kb_label() for name in ['thumb:ls', 'thumb:rs']: @@ -239,13 +252,13 @@ class AnthySetup(object): self.on_selection_changed, 1) tv.set_model(Gtk.ListStore(str)) - key = 'dict_admin_command' + key = 'dict-admin-command' cli = self.__get_dict_cli_from_list(prefs.get_value('common', key)) - name = 'dict:entry_edit_dict_command' + name = 'dict:entry-edit-dict-command' builder.get_object(name).set_text(cli) - key = 'add_word_command' + key = 'add-word-command' cli = self.__get_dict_cli_from_list(prefs.get_value('common', key)) - name = 'dict:entry_add_word_command' + name = 'dict:entry-add-word-command' builder.get_object(name).set_text(cli) tv = builder.get_object('dict:view') @@ -301,7 +314,7 @@ class AnthySetup(object): def __init_japanese_sort(self): japanese_ordered_dict = {} - japanese_ordered_list = self.prefs.get_japanese_ordered_list() + 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; @@ -309,7 +322,7 @@ class AnthySetup(object): def __init_about_vbox(self, icon_path): about_dialog = self.__builder.get_object('about_dialog') about_vbox = self.__builder.get_object('about_vbox') - about_dialog.set_version(self.prefs.get_version()) + about_dialog.set_version(self.__prefs.get_version()) if icon_path != None: if icon_path[0] == '/': image = Gtk.Image.new_from_file(icon_path) @@ -359,6 +372,20 @@ class AnthySetup(object): dlg.run() dlg.destroy() + def _get_shortcut_sec(self): + l = ['default', 'atok', 'wnn'] + iter = self.__builder.get_object('shortcut-type').get_active_iter() + model = self.__builder.get_object('shortcut-type').get_model() + s_type = model[iter][0].lower() + return 'shortcut/' + (s_type if s_type in l else 'default') + + def __get_shortcut_group(self): + l = ['default', 'atok', 'wnn'] + iter = self.__builder.get_object('shortcut-type').get_active_iter() + model = self.__builder.get_object('shortcut-type').get_model() + s_type = model[iter][0].lower() + return s_type if s_type in l else 'default' + def __japanese_tuple_sort(self, a, b): if a[1] == b[1]: # http://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons @@ -381,26 +408,25 @@ class AnthySetup(object): return (a[0] > b[0]) - (a[0] < b[0]) def __renderer_toggled_cb(self, renderer, path, model): - prefs = self.prefs + prefs = self.__prefs enabled = not model[path][1] model[path][1] = enabled key = model[path][0] prefs.set_value('common', key, enabled) - self.__builder.get_object('btn_apply').set_sensitive(True) def __toggle_menu_visible_cell_cb(self, column, renderer, model, iter, id): - l = self.__builder.get_object('menu_visible:treeview').get_model() + l = self.__builder.get_object('menu-visible:treeview').get_model() active = l.get_value(iter, id) renderer.set_property('active', active) def __text_menu_visible_cell_cb(self, column, renderer, model, iter, id): - l = self.__builder.get_object('menu_visible:treeview').get_model() + l = self.__builder.get_object('menu-visible:treeview').get_model() text = l.get_value(iter, id) renderer.set_property('text', text) def __append_menus_in_model(self): - prefs = self.prefs - l = self.__builder.get_object('menu_visible:treeview').get_model() + prefs = self.__prefs + l = self.__builder.get_object('menu-visible:treeview').get_model() l.append(['show-input-mode', prefs.get_value('common', 'show-input-mode'), _("Input mode")]) @@ -421,30 +447,20 @@ class AnthySetup(object): _("Preferences - Anthy")]) def __get_romaji_treeview_custom_key_table(self, method): - prefs = self.prefs + prefs = self.__prefs rule = {} ls = Gtk.ListStore(str, str, str) tv = self.__builder.get_object('treeview_custom_key_table') - section_base = 'romaji_typing_rule' - section = section_base + '/' + prefs.str(method) - for key in prefs.keys(section): - key = prefs.str(key) - value = prefs.get_value(section, key) + section = 'romaji-typing-rule' + keymap = prefs.get_value(section, 'list')[method] + for key in keymap.keys(): + value = keymap[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[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[ch] = prefs.str(value) + rule[ch] = value for key, value in sorted(list(rule.items()), \ key = functools.cmp_to_key(self.__japanese_tuple_sort)): ls.append(['romaji', key, value]) @@ -457,30 +473,20 @@ class AnthySetup(object): return tv def __get_kana_treeview_custom_key_table(self, method): - prefs = self.prefs + prefs = self.__prefs rule = {} ls = Gtk.ListStore(str, str, str) tv = self.__builder.get_object('treeview_custom_key_table') - section_base = 'kana_typing_rule' - section = section_base + '/' + prefs.str(method) - 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[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) + section = 'kana-typing-rule' + keymap = prefs.get_value(section, 'list')[method] + for key in keymap.keys(): + value = keymap[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[ch] = prefs.str(value) + rule[ch] = value for key, value in sorted(list(rule.items()), \ key = functools.cmp_to_key(self.__japanese_tuple_sort)): ls.append(['kana', key, value]) @@ -493,15 +499,14 @@ class AnthySetup(object): return tv def __get_thumb_treeview_custom_key_table(self, method): - prefs = self.prefs + prefs = self.__prefs rule = {} ls = Gtk.ListStore(str, str, str, str, str) tv = self.__builder.get_object('treeview_custom_key_table') - section_base = 'thumb_typing_rule' - section = section_base + '/' + prefs.str(method) - for key in prefs.keys(section): - key = prefs.str(key) - value = prefs.get_value(section, key) + section = 'thumb-typing-rule' + keymap = prefs.get_value(section, 'list')[method] + for key in keymap.keys(): + value = keymap[key] ch = prefs.typing_from_config_key(key) if ch == '': continue @@ -511,24 +516,9 @@ class AnthySetup(object): (value[1] != None and value[1] != '') or \ (value[2] != None and value[2] != '')): rule[ch] = {} - rule[ch][0] = prefs.str(value[0]) - rule[ch][1] = prefs.str(value[1]) - rule[ch][2] = prefs.str(value[2]) - 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 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[ch] = {} - rule[ch][0] = prefs.str(value[0]) - rule[ch][1] = prefs.str(value[1]) - rule[ch][2] = prefs.str(value[2]) + rule[ch][0] = value[0] + rule[ch][1] = value[1] + rule[ch][2] = value[2] for key, value in sorted(list(rule.items()), \ key = functools.cmp_to_key(self.__japanese_thumb_sort)): ls.append(['thumb', key, value[0], value[2], value[1]]) @@ -614,7 +604,7 @@ class AnthySetup(object): combobox.disconnect_by_func(self.on_cb_custom_key_table_changed) def __run_dialog_custom_key_table(self, widget, mode): - prefs = self.prefs + prefs = self.__prefs dlg = self.__builder.get_object('dialog_custom_key_table') dlg.set_transient_for(widget.get_toplevel()) label = self.__builder.get_object('label_custom_key_table') @@ -638,15 +628,15 @@ class AnthySetup(object): 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")], + ['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) @@ -660,17 +650,17 @@ class AnthySetup(object): tv = None if mode == 'romaji': - method = prefs.get_value('romaji_typing_rule', 'method') + 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') + method = prefs.get_value('kana-typing-rule', 'method') if method == None: method = 'jp' tv = self.__get_kana_treeview_custom_key_table(method) if mode == 'thumb': - method = prefs.get_value('thumb_typing_rule', 'method') + method = prefs.get_value('thumb-typing-rule', 'method') if method == None: method = 'base' tv = self.__get_thumb_treeview_custom_key_table(method) @@ -698,7 +688,7 @@ class AnthySetup(object): return section, key = self.__get_section_key( Gtk.Buildable.get_name(self.__thumb_kb_layout_mode)) - layout_mode = self.prefs.get_value(section, key) + layout_mode = self.__prefs.get_value(section, key) if layout_mode: self.__thumb_kb_layout.set_sensitive(False) else: @@ -735,60 +725,52 @@ class AnthySetup(object): return id def __get_dict_file_from_id(self, selected_id): - files = self.prefs.get_value('dict', 'files') - retval = None - - for file in files: - id = self.__get_quoted_id(file) - # The selected_id is already quoted. - if selected_id == id: - retval = file - break - return retval + files = self.__prefs.get_value('dict', 'files') + return files.get(selected_id, None) def __is_system_dict_file_from_id(self, selected_id): - prefs = self.prefs - section = 'dict/file/' + selected_id - key = 'is_system' - - if key not in prefs.keys(section): - return False - return prefs.get_value(section, key) + prefs = self.__prefs + dict_item = prefs.get_value('dict', 'list')[selected_id] + return dict_item.is_system - def __append_dict_id_in_model(self, id, is_gettext): - prefs = self.prefs + def __append_dict_id_in_model(self, id): + prefs = self.__prefs section = 'dict/file/' + id - # user value is dbus.String - prefs.set_value(section, 'short_label', - prefs.str(prefs.get_value(section, 'short_label'))) - prefs.set_value(section, 'long_label', - prefs.str(prefs.get_value(section, 'long_label'))) - short_label = prefs.get_value(section, 'short_label') - long_label = prefs.get_value(section, 'long_label') - embed = prefs.get_value(section, 'embed') - single = prefs.get_value(section, 'single') - reverse = prefs.get_value(section, 'reverse') - if is_gettext: + dicts = prefs.get_value('dict', 'list') + dict_item = dicts[id] + short_label = dict_item.short_label + long_label = dict_item.long_label + embed = dict_item.embed + single = dict_item.single + reverse = dict_item.reverse + if dict_item.is_system: long_label = _(long_label) l = self.__builder.get_object('dict:view').get_model() l.append([id, short_label, long_label, embed, single, reverse]) def __append_dicts_in_model(self): - prefs = self.prefs - for file in prefs.get_value('dict', 'files'): - if not path.exists(file): + prefs = self.__prefs + order = prefs.get_value('dict', 'order') + dict_files = prefs.get_value('dict', 'files') + if len(order) == 0: + order = list(dict_files.keys()) + for id in order: + if id == 'embedded': continue - id = self.__get_quoted_id(file) - section = 'dict/file/' + id - if section not in prefs.sections(): - self.__fetch_dict_values(section) - is_system_dict = self.__is_system_dict_file_from_id(id) - self.__append_dict_id_in_model(id, is_system_dict) + files = dict_files[id] + for file in files: + if not path.exists(file): + continue + self.__append_dict_id_in_model(id) def __append_user_dict_from_dialog(self, file, id, new): - files = self.prefs.get_value('dict', 'files') + files_dict = self.__prefs.get_value('dict', 'files') if new: + files = [] + for v in files_dict.values(): + for f in v: + files.append(f) if file in files: self.__run_message_dialog(_("Your choosed file has already been added: ") + file, Gtk.MessageType.ERROR) @@ -805,6 +787,8 @@ class AnthySetup(object): self.__run_message_dialog(_("You cannot add dictionaries in the anthy private directory: " + file), Gtk.MessageType.ERROR) return + else: + file = files_dict[id][0] if new: id = self.__get_quoted_id(file) @@ -822,15 +806,23 @@ class AnthySetup(object): long_label = self.__builder.get_object('dict:long_entry').get_text() if new: - files.append(file) - self.prefs.set_value('dict', 'files', files) - + order = self.__prefs.get_value('dict', 'order') + if len(order) == 0: + order = list(self.__prefs.get_value('dict', 'files').keys()) + order.append(id) + self.__prefs.set_value('dict', 'order', order) + self.__prefs.set_list_item('dict', 'files', id, [file]) + + filename = file + if filename.find('/') >=0: + filename = filename[filename.rindex('/') + 1:] + if filename.find('.') >=0: + filname = filename[:filename.rindex('.')] if short_label == None or short_label == '': - short_label = id[0] + short_label = filename[0] if long_label == None or long_label == '': - long_label = id + long_label = filename self.__update_dict_values(new, id, short_label, long_label, embed, single, reverse) - self.__builder.get_object('btn_apply').set_sensitive(True) files = [] def __init_dict_chooser_dialog(self): @@ -856,15 +848,13 @@ class AnthySetup(object): if selected_id == None: return None - is_system_dict = self.__is_system_dict_file_from_id(selected_id) - - prefs = self.prefs - section = 'dict/file/' + selected_id - short_label = prefs.get_value(section, 'short_label') - long_label = prefs.get_value(section, 'long_label') - embed = prefs.get_value(section, 'embed') - single = prefs.get_value(section, 'single') - reverse = prefs.get_value(section, 'reverse') + dict_item = self.__prefs.get_value('dict', 'list')[selected_id] + short_label = dict_item.short_label + long_label = dict_item.long_label + embed = dict_item.embed + single = dict_item.single + reverse = dict_item.reverse + is_system_dict = dict_item.is_system if len(short_label) > 1: short_label = short_label[0] @@ -885,56 +875,32 @@ class AnthySetup(object): return selected_id - def __fetch_dict_values(self, section): - prefs = self.prefs - prefs.set_new_section(section) - prefs.set_new_key(section, 'short_label') - prefs.fetch_item(section, 'short_label') - # user value is dbus.String - prefs.set_value(section, 'short_label', - prefs.str(prefs.get_value(section, 'short_label'))) - prefs.set_new_key(section, 'long_label') - prefs.fetch_item(section, 'long_label') - prefs.set_value(section, 'long_label', - prefs.str(prefs.get_value(section, 'long_label'))) - prefs.set_new_key(section, 'embed') - prefs.fetch_item(section, 'embed') - prefs.set_new_key(section, 'single') - prefs.fetch_item(section, 'single') - prefs.set_new_key(section, 'reverse') - prefs.fetch_item(section, 'reverse') - def __update_dict_values(self, new, id, short_label, long_label, embed, single, reverse): - prefs = self.prefs - section = 'dict/file/' + id - if section not in prefs.sections(): - prefs.set_new_section(section) - - is_system_dict = self.__is_system_dict_file_from_id(id) - if is_system_dict: - if 'short_label' in prefs.keys(section): - short_label = prefs.get_value(section, 'short_label') - if 'long_label' in prefs.keys(section): - long_label = prefs.get_value(section, 'long_label') + prefs = self.__prefs if new: + dict_item = prefs.get_value('dict', 'template') + dict_item.id = id + dict_item.short_label = short_label + dict_item.long_label = long_label + dict_item.embed = embed + dict_item.single = single + dict_item.reverse = reverse l = self.__builder.get_object('dict:view').get_model() l.append([id, short_label, long_label, embed, single, reverse]) else: + dict_item = prefs.get_value('dict', 'list')[id] + if not dict_item.is_system: + dict_item.short_label = short_label + dict_item.long_label = long_label + dict_item.embed = embed + dict_item.single = single + dict_item.reverse = reverse l, i = self.__builder.get_object('dict:view').get_selection().get_selected() if i : l[i] = [id, short_label, long_label, embed, single, reverse] - key = 'short_label' - prefs.set_value(section, key, short_label) - key = 'long_label' - prefs.set_value(section, key, long_label) - key = 'embed' - prefs.set_value(section, key, embed) - key = 'single' - prefs.set_value(section, key, single) - key = 'reverse' - prefs.set_value(section, key, reverse) + prefs.set_list_item('dict', 'list', id, dict_item) def __text_cell_data_cb(self, column, renderer, model, iter, id): l = self.__builder.get_object('dict:view').get_model() @@ -1098,13 +1064,13 @@ class AnthySetup(object): def __update_keymap_label(self): self.__resync_engine_file() - prefs = self.prefs + prefs = self.__prefs keymap = self.__get_keymap() if keymap == None: return if keymap == '': keymap = 'default' - keymap_list = prefs.get_value('common', 'keyboard_layouts') + keymap_list = prefs.get_value('common', 'keyboard-layouts') if keymap != None and not keymap in keymap_list: keymap_list.append(keymap) index = -1 @@ -1124,11 +1090,6 @@ class AnthySetup(object): self.on_cb_keymap_changed, 0) - def __save_preferences(self): - self.prefs.commit_all() - if self.__keymap != None: - self.__save_keymap() - def __search_and_mark(self, buffer, text, start, end, onetime, forward): if forward: match = start.forward_search(text, 0, end) @@ -1211,51 +1172,12 @@ class AnthySetup(object): button = self.__builder.get_object('button_remove_custom_key') button.set_sensitive(True) - def on_main_delete(self, widget, event): - self.on_btn_cancel_clicked(widget) + def on_main_quit(self, widget, event): + Gtk.main_quit() return True - def on_btn_ok_clicked(self, widget): - if self.__builder.get_object('btn_apply').get_state() == \ - Gtk.StateType.INSENSITIVE: - Gtk.main_quit() - return True - dlg = self.__builder.get_object('quit_check') - dlg.set_transient_for(widget.get_toplevel()) - dlg.set_markup('%s' % _("Confirmation")) - dlg.format_secondary_text( - _("You are about to close the setup dialog, is that OK?")) - id = dlg.run() - dlg.hide() - if id == Gtk.ResponseType.YES: - self.__save_preferences() - Gtk.main_quit() - return True - - def on_btn_cancel_clicked(self, widget): - if self.__builder.get_object('btn_apply').get_state() == \ - Gtk.StateType.INSENSITIVE: - Gtk.main_quit() - return True - dlg = self.__builder.get_object('quit_check_without_save') - dlg.set_transient_for(widget.get_toplevel()) - dlg.set_markup('%s' % _("Notice!")) - dlg.format_secondary_text( - _("You are about to close the setup dialog without saving your changes, is that OK?")) - id = dlg.run() - dlg.hide() - if id == Gtk.ResponseType.YES: - Gtk.main_quit() - return True - - def on_btn_apply_clicked(self, widget): - self.__save_preferences() - widget.set_sensitive(False) - - def on_cb_changed(self, widget): - section, key = self.__get_section_key(Gtk.Buildable.get_name(widget)) - self.prefs.set_value(section, key, widget.get_active()) - self.__builder.get_object('btn_apply').set_sensitive(True) + def on_btn_close_clicked(self, widget): + Gtk.main_quit() def on_cb_keymap_changed(self, widget, id): it = widget.get_active() @@ -1266,10 +1188,11 @@ class AnthySetup(object): if self.__keymap == keymap: return self.__keymap = keymap - self.__builder.get_object('btn_apply').set_sensitive(True) + self.__save_keymap() + self.__keymap = None def on_cb_custom_key_table_changed(self, widget, user_data): - prefs = self.prefs + prefs = self.__prefs tv = self.__builder.get_object('treeview_custom_key_table') mode = user_data id = widget.get_active() @@ -1283,27 +1206,12 @@ class AnthySetup(object): if mode == 'romaji': tv = self.__get_romaji_treeview_custom_key_table(method) elif mode == 'kana': - prefs.set_value('kana_typing_rule', 'method', method) - self.__builder.get_object('btn_apply').set_sensitive(True) + prefs.set_value('kana-typing-rule', 'method', method) tv = self.__get_kana_treeview_custom_key_table(method) elif mode == 'thumb': # thumb uses all tables so do not save the method. tv = self.__get_thumb_treeview_custom_key_table(method) - def on_sb_changed(self, widget): - section, key = self.__get_section_key(Gtk.Buildable.get_name(widget)) - self.prefs.set_value(section, key, widget.get_value_as_int()) - self.__builder.get_object('btn_apply').set_sensitive(True) - - def on_ck_toggled(self, widget): - section, key = self.__get_section_key(Gtk.Buildable.get_name(widget)) - self.prefs.set_value(section, key, widget.get_active()) - self.__builder.get_object('btn_apply').set_sensitive(True) - if self.__thumb_kb_layout_mode and \ - Gtk.Buildable.get_name(widget) == \ - Gtk.Buildable.get_name(self.__thumb_kb_layout_mode): - self.__set_thumb_kb_label() - def on_btn_edit_clicked(self, widget): ls, it = self.__builder.get_object('shortcut').get_selection().get_selected() m = self.__builder.get_object('es:treeview').get_model() @@ -1320,19 +1228,20 @@ class AnthySetup(object): if id == Gtk.ResponseType.OK: new = l_to_s([m[i][0] for i in range(len(m))]) if new != ls.get(it, 1)[0]: - sec = self._get_shortcut_sec() - self.prefs.set_value(sec, ls.get(it, 0)[0], s_to_l(new)) + group = self.__get_shortcut_group() + self.__prefs.set_list_item('shortcut', group, + ls.get(it, 0)[0], s_to_l(new)) ls.set(it, 1, new) - self.__builder.get_object('btn_apply').set_sensitive(True) def on_btn_default_clicked(self, widget): ls, it = self.__builder.get_object('shortcut').get_selection().get_selected() - sec = self._get_shortcut_sec() - new = l_to_s(self.prefs.default[sec][ls.get(it, 0)[0]]) + group = self.__get_shortcut_group() + shortcuts = self.__prefs.get_default_value('shortcut', group) + new = l_to_s(shortcuts[ls.get(it, 0)[0]]) if new != ls.get(it, 1)[0]: - self.prefs.set_value(sec, ls.get(it, 0)[0], s_to_l(new)) + self.__prefs.set_list_item('shortcut', group, + ls.get(it, 0)[0], s_to_l(new)) ls.set(it, 1, new) - self.__builder.get_object('btn_apply').set_sensitive(True) def on_btn_romaji_custom_table_clicked(self, widget): self.__run_dialog_custom_key_table(widget, 'romaji') @@ -1344,7 +1253,7 @@ class AnthySetup(object): self.__run_dialog_custom_key_table(widget, 'thumb') def on_btn_add_custom_key(self, widget, user_data): - prefs = self.prefs + prefs = self.__prefs input = self.__builder.get_object('entry_input_custom_key') output = self.__builder.get_object('entry_output_custom_key') left = self.__builder.get_object('entry_left_thumb_shift_custom_key') @@ -1375,43 +1284,33 @@ class AnthySetup(object): return if type == 'romaji': - section_base = 'romaji_typing_rule' + section = 'romaji-typing-rule' model.append([type, key, value]) elif type == 'kana': - section_base = 'kana_typing_rule' + section = 'kana-typing-rule' model.append([type, key, value]) elif type == 'thumb': - section_base = 'thumb_typing_rule' + section = 'thumb-typing-rule' model.append([type, key, value, left_text, right_text]) - if section_base == None: + if section == None: self.__run_message_dialog(_("Your custom key is not assigned in any sections. Maybe a bug.")) return 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(). - # prefs.fetch_section() doesn't get the keys if they exist - # in gconf only. - # Use newkeys for that way. - newkeys = prefs.get_value(section_base, 'newkeys') - if key not in newkeys: - newkeys.append(key) - prefs.set_value(section_base, 'newkeys', newkeys) if type != 'thumb': - prefs.set_value(section, key, value) + prefs.set_list_item(section, 'list', (method, key), value) else: - prefs.set_value(section, key, [value, right_text, left_text]) + prefs.set_list_item(section, 'list', + (method, key), [value, right_text, left_text]) left.set_text('') right.set_text('') input.set_text('') output.set_text('') - self.__builder.get_object('btn_apply').set_sensitive(True) def on_btn_remove_custom_key(self, widget, user_data): - prefs = self.prefs + prefs = self.__prefs combobox = self.__builder.get_object('combobox_custom_key_table') id = combobox.get_active() model_combobox = combobox.get_model() @@ -1422,31 +1321,21 @@ class AnthySetup(object): key = l[i][1] section_base = None if type == 'romaji': - section_base = 'romaji_typing_rule' + section = 'romaji-typing-rule' elif type == 'kana': - section_base = 'kana_typing_rule' + section = 'kana-typing-rule' elif type == 'thumb': - section_base = 'thumb_typing_rule' - if section_base == None: + section = 'thumb-typing-rule' + if section == None: self.__run_message_dialog(_("Your custom key is not assigned in any sections. Maybe a bug.")) return - section = section_base + '/' + method - newkeys = prefs.get_value(section_base, 'newkeys') 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) - # config.set_value(key, None) is not supported. - if type != 'thumb': - prefs.set_value(section, key, '') - else: - prefs.set_value(section, key, ['', '', '']) + prefs.delete_list_item(section, 'list', (method, key)) l.remove(i) widget.set_sensitive(False) - self.__builder.get_object('btn_apply').set_sensitive(True) def on_btn_thumb_key_clicked(self, widget): if Gtk.Buildable.get_name(widget) == 'thumb:button_ls': @@ -1481,18 +1370,17 @@ class AnthySetup(object): new = l[i][0] if new != text: section, key = self.__get_section_key(entry) - self.prefs.set_value(section, key, new) + self.__prefs.set_value(section, key, new) self.__builder.get_object(entry).set_text(new) - self.__builder.get_object('btn_apply').set_sensitive(True) def on_btn_dict_command_clicked(self, widget): if Gtk.Buildable.get_name(widget) == 'dict:btn_edit_dict_command': - key = 'dict_admin_command' + key = 'dict-admin-command' elif Gtk.Buildable.get_name(widget) == 'dict:btn_add_word_command': - key = 'add_word_command' + key = 'add-word-command' else: return - command = self.prefs.get_value('common', key) + command = self.__prefs.get_value('common', key) if not path.exists(command[0]): self.__run_message_dialog(_("Your file does not exist: ") + command[0], Gtk.MessageType.ERROR) @@ -1553,17 +1441,19 @@ class AnthySetup(object): if selected_id == None: return - if self.__is_system_dict_file_from_id(selected_id): + dict_item = self.__prefs.get_value('dict', 'list')[selected_id] + if dict_item.is_system: self.__run_message_dialog(_("You cannot delete the system dictionary."), Gtk.MessageType.ERROR) return file = self.__get_dict_file_from_id(selected_id) if file != None: - files = self.prefs.get_value('dict', 'files') - files.remove(file) - self.prefs.set_value('dict', 'files', files) - self.__builder.get_object('btn_apply').set_sensitive(True) + order = self.__prefs.get_value('dict', 'order') + order.remove(selected_id) + order = self.__prefs.set_value('dict', 'order', order) + self.__prefs.delete_list_item('dict', 'files', selected_id) + self.__prefs.delete_list_item('dict', 'list', selected_id) l.remove(i) return @@ -1575,32 +1465,25 @@ class AnthySetup(object): if selected_id == None: return + print('test', selected_id) dict_file = self.__get_dict_file_from_id(selected_id) if dict_file == None: self.__run_message_dialog(_("Your file is not good."), Gtk.MessageType.ERROR) return - if not path.exists(dict_file): + if not path.exists(dict_file[0]): self.__run_message_dialog(_("Your file does not exist: ") + dict_file, Gtk.MessageType.ERROR) return - if dict_file == None: - return - # The selected id is already quoted. - section = 'dict/file/' + selected_id - if 'preview_lines' not in self.prefs.keys(section): - section = 'dict/file/default' - nline = self.prefs.get_value(section, 'preview_lines') - - section = 'dict/file/' + selected_id - if 'encoding' not in self.prefs.keys(section): - section = 'dict/file/default' - encoding = self.prefs.get_value(section, 'encoding') + dicts = self.__prefs.get_value('dict', 'list') + dict_item = dicts[selected_id] + nline = dict_item.preview_lines + encoding = dict_item.encoding lines = ''; - for i, line in enumerate(list(codecs.open(dict_file, 'r', 'utf-8'))): + for i, line in enumerate(list(codecs.open(dict_file[0], 'r', 'utf-8'))): if nline >= 0 and i >= nline: break; lines = lines + line @@ -1645,7 +1528,6 @@ class AnthySetup(object): dlg.destroy() def on_btn_dict_order_clicked(self, widget): - dict_file = None l, it = self.__builder.get_object('dict:view').get_selection().get_selected() if not it: @@ -1666,45 +1548,35 @@ class AnthySetup(object): if next_it: l.swap(it, next_it) - dict_file = self.__get_dict_file_from_id(selected_id) - files = self.prefs.get_value('dict', 'files') + order = self.__prefs.get_value('dict', 'order') + if len(order) == 0: + order = list(self.__prefs.get_value('dict', 'files').keys()) + i = order.index(selected_id) - if dict_file == None: - return - - i = files.index(dict_file) if Gtk.Buildable.get_name(widget) == 'dict:btn_up': if i <= 0: return next_i = i - 1 elif Gtk.Buildable.get_name(widget) == 'dict:btn_down': - if i + 1 >= len(dict_file): + if i + 1 >= len(order): return next_i = i + 1 - f = files[i] - files[i] = files[next_i] - files[next_i] = f - self.prefs.set_value('dict', 'files', files) - self.__builder.get_object('btn_apply').set_sensitive(True) - - def _get_shortcut_sec(self): - l = ['default', 'atok', 'wnn'] - iter = self.__builder.get_object('shortcut_type').get_active_iter() - model = self.__builder.get_object('shortcut_type').get_model() - s_type = model[iter][0].lower() - return 'shortcut/' + (s_type if s_type in l else 'default') + f = order[i] + order[i] = order[next_i] + order[next_i] = f + self.__prefs.set_value('dict', 'order', order) def on_shortcut_type_changed(self, widget): ls = self.__builder.get_object('shortcut').get_model() ls.clear() - sec = self._get_shortcut_sec() - for k in self.prefs.keys(sec): - ls.append([k, l_to_s(self.prefs.get_value(sec, k))]) + group = self.__get_shortcut_group() + shortcuts = self.__prefs.get_value('shortcut', group) + for k in shortcuts.keys(): + ls.append([k, l_to_s(shortcuts[k])]) section, key = self.__get_section_key(Gtk.Buildable.get_name(widget)) - self.prefs.set_value(section, key, sec[len('shortcut/'):]) - self.__builder.get_object('btn_apply').set_sensitive(True) + self.__prefs.set_value(section, key, group) def on_shortcut_key_release_event(self, widget, event): if event.hardware_keycode in [36, 65]: @@ -1749,7 +1621,9 @@ class AnthySetup(object): if not widget.get_text(): return list = widget.get_text().split() - if list[0][0] == '/': + if len(list) == 0: + return + elif list[0][0] == '/': if len(list) == 1: list.append(list[0][list[0].rfind('/') + 1:]) else: @@ -1760,14 +1634,14 @@ class AnthySetup(object): else: list.insert(0, '/usr/bin/' + list[0]) list[1] = list[1][list[1].rfind('/') + 1:] - if Gtk.Buildable.get_name(widget) == 'dict:entry_edit_dict_command': - key = 'dict_admin_command' - elif Gtk.Buildable.get_name(widget) == 'dict:entry_add_word_command': - key = 'add_word_command' + if Gtk.Buildable.get_name(widget) == 'dict:entry-edit-dict-command': + key = 'dict-admin-command' + elif Gtk.Buildable.get_name(widget) == 'dict:entry-add-word-command': + key = 'add-word-command' else: return - self.prefs.set_value('common', key, list) - self.__builder.get_object('btn_apply').set_sensitive(True) + print('test', key, list) + self.__prefs.set_value('common', key, list) def on_es_entry_changed(self, widget): if not widget.get_text(): diff --git a/setup/python3/prefs.py b/setup/python3/prefs.py index 269e353..0509ecb 100644 --- a/setup/python3/prefs.py +++ b/setup/python3/prefs.py @@ -4,8 +4,8 @@ # # Copyright (c) 2007-2008 Peng Huang # Copyright (c) 2009 Hideaki ABE -# Copyright (c) 2010-2016 Takao Fujiwara -# Copyright (c) 2007-2016 Red Hat, Inc. +# Copyright (c) 2010-2017 Takao Fujiwara +# 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 @@ -24,39 +24,101 @@ import sys from gi import require_version as gi_require_version +gi_require_version('Gio', '2.0') gi_require_version('GLib', '2.0') gi_require_version('IBus', '1.0') +from gi.repository import Gio from gi.repository import GLib +from gi.repository import GObject from gi.repository import IBus -class Prefs(object): - _prefix = 'engine/dummy' - - def __init__(self, bus=None, config=None): - self.default = {} - self.modified = {} - self.new = {} - self.__no_key_warning = False - - # self._config is used by AnthyPrefs . - self._config = config if config else \ - bus.get_config() if bus else \ - IBus.Bus().get_config() - - # ibus_config_get_values enhances the performance. - self.__has_config_get_values = False - - if self._config != None: - self.__has_config_get_values = hasattr(self._config, 'get_values') - else: - self.printerr( - 'ibus-config is not running or bus address is not correct.') - - def __log_handler(self, domain, level, message, data): - if not data: - return - GLib.log_default_handler(domain, level, message, '') +class DictItem(): + def __init__(self, + id='', + short_label='', + long_label='', + icon='', + is_system=False, + preview_lines=-1, + embed=False, + single=True, + reverse=False, + encoding='utf-8'): + self.id = id + self.short_label = short_label + self.long_label = long_label + self.icon = icon + self.is_system = is_system + self.preview_lines = preview_lines + self.embed = embed + self.single = single + self.reverse = reverse + self.encoding = encoding + + def __str__(self): + retval = ('id:', self.id, + 'short-label:', self.short_label, + 'long-label:', self.long_label, + 'icon:', self.icon, + 'is-system:', self.is_system, + 'preview-lines:', self.preview_lines, + 'embed:', self.embed, + 'single:', self.single, + 'reverse:', self.reverse, + 'encoding:', self.encoding) + return str(retval) + + @classmethod + def serialize(cls, dict_item): + builder = GLib.VariantBuilder(GLib.VariantType('r')) + builder.add_value(GLib.Variant.new_string(dict_item.id)) + builder.add_value(GLib.Variant.new_string(dict_item.short_label)) + builder.add_value(GLib.Variant.new_string(dict_item.long_label)) + builder.add_value(GLib.Variant.new_string(dict_item.icon)) + builder.add_value(GLib.Variant.new_boolean(dict_item.is_system)) + builder.add_value(GLib.Variant.new_int32(dict_item.preview_lines)) + builder.add_value(GLib.Variant.new_boolean(dict_item.embed)) + builder.add_value(GLib.Variant.new_boolean(dict_item.single)) + builder.add_value(GLib.Variant.new_boolean(dict_item.reverse)) + builder.add_value(GLib.Variant.new_string(dict_item.encoding)) + return builder.end() + +class Prefs(GObject.GObject): + __gsignals__ = { + 'changed' : ( + GObject.SignalFlags.RUN_FIRST, + None, + (str, str, GLib.Variant)), + } + + def __init__(self): + super(Prefs, self).__init__() + self.__cache = {} + self.__settings = {} + self.__schema_prefix = 'org.freedesktop.ibus.engine.anthy.' + self.__schema_sections = ['common', + 'shortcut', + 'romaji-typing-rule', + 'kana-typing-rule', + 'thumb-typing-rule', + 'thumb', + 'dict'] + for section in self.__schema_sections: + self.__settings[section] = Gio.Settings( + schema=self.__schema_prefix + section) + self.__settings[section].connect('changed', + self.__settings_on_changed) + + def __settings_on_changed(self, settings, key): + section = settings.props.schema[len(self.__schema_prefix):] + variant_value = self.__settings[section].get_value(key) + variant_key = self.__cache.get(section) + if variant_key == None: + variant_key = {} + variant_key[key] = variant_value + self.__cache[section] = variant_key + self.emit('changed', section, key, variant_value) def variant_to_value(self, variant): if type(variant) != GLib.Variant: @@ -68,7 +130,9 @@ class Prefs(object): return variant.get_int32() elif type_string == 'b': return variant.get_boolean() - elif type_string == 'as': + elif type_string == 'v': + return variant.unpack() + elif len(type_string) > 0 and type_string[0] == 'a': # Use unpack() instead of dup_strv() in python. # In the latest pygobject3 3.3.4 or later, g_variant_dup_strv # returns the allocated strv but in the previous release, @@ -79,193 +143,165 @@ class Prefs(object): sys.abrt() return variant - def set_no_key_warning(self, no_key_warning): - if no_key_warning and hasattr(IBus, 'unset_log_handler'): - self.__no_key_warning = True - else: - self.__no_key_warning = False - - def keys(self, section): - return list(self.default[section].keys()) - - def sections(self): - return list(self.default.keys()) - - def set_new_section(self, section): - self.default.setdefault(section, {}) + def variant_from_value(self, value): + variant = None + if type(value) == str: + variant = GLib.Variant.new_string(value) + elif type(value) == int: + variant = GLib.Variant.new_int32(value) + elif type(value) == bool: + variant = GLib.Variant.new_boolean(value) + elif type(value) == list: + variant = GLib.Variant.new_strv(value) + if variant == None: + self.printerr('Unknown value type: %s' % type(value)) + return variant - def set_new_key(self, section, key): - self.default[section].setdefault(key) + def get_variant(self, section, key): + variant_key = self.__cache.get(section) + if variant_key != None: + variant_value = variant_key.get(key) + if variant_value != None: + return variant_value + variant_value = self.__settings[section].get_value(key) + if variant_key == None: + variant_key = {} + variant_key[key] = variant_value + self.__cache[section] = variant_key + return variant_value + + def get_default_variant(self, section, key): + return self.__settings[section].get_default_value(key) + + def get_readable_value(self, section, key, variant): + value = self.variant_to_value(variant) + if section == 'dict' and key == 'list': + dicts = {} + for item in value: + dict_item = DictItem(*item) + dicts[dict_item.id] = dict_item + value = dicts + if section == 'dict' and key == 'template': + value = DictItem(*value) + return value def get_value(self, section, key): - try: - return self.new[section][key] - except: - try: - return self.modified[section][key] - except: - return self.default[section][key] + variant = self.get_variant(section, key) + return self.get_readable_value(section, key, variant) - def get_value_direct(self, section, key, default=None): - if self._config == None: - return default + def get_default_value(self, section, key): + variant = self.get_default_variant(section, key) + return self.get_readable_value(section, key, variant) - s = section - section = '/'.join( - [s for s in '/'.join([self._prefix, section]).split('/') if s]) - try: - if self.__no_key_warning: - IBus.set_log_handler(False) - variant = self._config.get_value(section, key) - if self.__no_key_warning: - IBus.unset_log_handler() - return self.variant_to_value(variant) - except: - return default + def set_variant(self, section, key, variant): + self.__settings[section].set_value(key, variant) + self.__settings[section].apply() def set_value(self, section, key, value): - if section not in self.sections(): - self.set_new_section(section) - if key not in self.keys(section): - self.set_new_key(section, key) - self.default[section][key] - self.new.setdefault(section, {})[key] = value - - def fetch_all(self): - for s in self.sections(): - self.fetch_section(s) - - def fetch_section(self, section): - if self._config == None: + variant = self.variant_from_value(value) + if variant == None: return + self.set_variant(section, key, variant) - if not self.__has_config_get_values: - for k in self.keys(section): - self.fetch_item(section, k) + def set_list_item(self, section, key, item, values): + variant = self.get_variant(section, key) + if variant == None: + printerrr('%s:%s does not exist' % (section, key)) return - - s = '/'.join( - [s for s in '/'.join([self._prefix, section]).split('/') if s]) - variant = self._config.get_values(s) - for key in list(variant.keys()): - v = variant[key] - self.modified.setdefault(section, {})[key] = v if v != [''] else [] - # FIXME: ibus-dconf converts the keys. - if section == 'common': - self.fetch_item(section, 'show-input-mode') - self.fetch_item(section, 'show-typing-method') - self.fetch_item(section, 'show-segment-mode') - self.fetch_item(section, 'show-dict-mode') - self.fetch_item(section, 'show-dict-config') - self.fetch_item(section, 'show-preferences') - - def fetch_item(self, section, key, readonly=False): - if self._config == None: + if section == 'shortcut': + variant_dict = GLib.VariantDict(variant) + array = [] + for value in values: + array.append(GLib.Variant.new_string(value)) + varray = GLib.Variant.new_array(GLib.VariantType('s'), array) + variant_dict.insert_value(item, varray) + # GVariantDict uses GHashTable internally and + # GVariantDict.end() does not support the order. + self.set_variant(section, key, variant_dict.end()) + return + if section == 'romaji-typing-rule' or \ + section == 'kana-typing-rule' or \ + section == 'thumb-typing-rule': + (method, keymap_key) = item + variant_dict = GLib.VariantDict(variant) + keymap = variant_dict.lookup_value(method, None) + keymap_dict = GLib.VariantDict(keymap) + if section == 'thumb-typing-rule': + array = [] + for value in values: + array.append(GLib.Variant.new_string(value)) + vvalue = GLib.Variant.new_array(GLib.VariantType('s'), array) + else: + vvalue = GLib.Variant.new_string(values) + keymap_dict.insert_value(keymap_key, vvalue) + keymap = keymap_dict.end() + variant_dict.insert_value(method, keymap) + self.set_variant(section, key, variant_dict.end()) + return + if section == 'dict' and key == 'files': + variant_dict = GLib.VariantDict(variant) + array = [] + for value in values: + array.append(GLib.Variant.new_string(value)) + varray = GLib.Variant.new_array(GLib.VariantType('s'), array) + variant_dict.insert_value(item, varray) + self.set_variant(section, key, variant_dict.end()) + return + if section == 'dict' and key == 'list': + array = [] + has_item = False + for v in variant: + dict_item = DictItem(*v) + if dict_item.id == values.id: + array.append(GLib.Variant.new_variant( + DictItem.serialize(values))) + has_item = True + else: + array.append(GLib.Variant.new_variant( + DictItem.serialize(dict_item))) + if not has_item: + array.append(GLib.Variant.new_variant(DictItem.serialize(values))) + varray = GLib.Variant.new_array(GLib.VariantType('v'), array) + self.set_variant(section, key, varray) return - s = '/'.join( - [s for s in '/'.join([self._prefix, section]).split('/') if s]) - try: - v = None - # gobject-introspection has a bug. - # https://bugzilla.gnome.org/show_bug.cgi?id=670509 - # GLib.log_set_handler("IBUS", GLib.LogLevelFlags.LEVEL_MASK, - # self.__log_handler, False) - if self.__no_key_warning: - IBus.set_log_handler(False) - variant = self._config.get_value(s, key) - if self.__no_key_warning: - IBus.unset_log_handler() - v = self.variant_to_value(variant) - except: - v = None - if readonly: - return v != None - if v != None: - self.modified.setdefault(section, {})[key] = v if v != [''] else [] - return True - - def commit_all(self): - for s in list(self.new.keys()): - self.commit_section(s) - - def commit_section(self, section): - if section in self.new: - for k in list(self.new[section].keys()): - self.commit_item(section, k) - - def commit_item(self, section, key): - if section in self.new and key in self.new[section]: - s = '/'.join( - [s for s in '/'.join([self._prefix, section]).split('/') if s]) - v = self.new[section][key] - if v == []: - v = [''] - variant = None - if type(v) == str: - variant = GLib.Variant.new_string(v) - elif type(v) == int: - variant = GLib.Variant.new_int32(v) - elif type(v) == bool: - variant = GLib.Variant.new_boolean(v) - elif type(v) == list: - variant = GLib.Variant.new_strv(v) - if variant == None: - self.printerr('Unknown value type: %s' % type(v)) - sys.abrt() - if self._config != None: - self._config.set_value(s, key, variant) - self.modified.setdefault(section, {})[key] = v - del(self.new[section][key]) - - def undo_all(self): - self.new.clear() - - def undo_section(self, section): - try: - del(self.new[section]) - except: - pass - - def undo_item(self, section, key): - try: - del(self.new[section][key]) - except: - pass - - def set_default_all(self): - for s in self.sections(): - self.set_default_section(s) - - def set_default_section(self, section): - for k in self.keys(section): - self.set_default_item(section, k) - - def set_default_item(self, section, key): - try: - if key in self.modified[section] or key in self.new[section]: - self.new[section][key] = self.default[section][key] - except: - pass - - # Convert DBus.String to str - # sys.getdefaultencoding() == 'utf-8' with pygtk2 but - # sys.getdefaultencoding() == 'ascii' with gi gtk3 - # so the simple str(unicode_string) causes an error and need to use - # unicode_string.encode('utf-8') instead. - def str(self, uni): - if uni == None: - return None - if type(uni) == str: - return uni - return str(uni) + def delete_list_item(self, section, key, item): + variant = self.get_variant(section, key) + if variant == None: + printerrr('%s:%s does not exist' % (section, key)) + return + if section == 'romaji-typing-rule' or \ + section == 'kana-typing-rule' or \ + section == 'thumb-typing-rule': + (method, keymap_key) = item + variant_dict = GLib.VariantDict(variant) + keymap = variant_dict.lookup_value(method, None) + keymap_dict = GLib.VariantDict(keymap) + keymap_dict.remove(keymap_key) + keymap = keymap_dict.end() + variant_dict.insert_value(method, keymap) + self.set_variant(section, key, variant_dict.end()) + return + if section == 'dict' and key == 'files': + variant_dict = GLib.VariantDict(variant) + variant_dict.remove(item) + self.set_variant(section, key, variant_dict.end()) + return + if section == 'dict' and key == 'list': + array = [] + for v in variant: + dict_item = DictItem(*v) + if dict_item.id == item: + continue + else: + array.append(GLib.Variant.new_variant( + DictItem.serialize(dict_item))) + varray = GLib.Variant.new_array(GLib.VariantType('v'), array) + self.set_variant(section, key, varray) + return - # The simple unicode(string) causes an error and need to use - # unicode(string, 'utf-8') instead. - def unicode(self, string): - if string == None: - return None - return string + def bind(self, section, key, object, property, flags): + self.__settings[section].bind(key, object, property, flags) # If the parent process exited, the std io/out/error will be lost. @staticmethod diff --git a/setup/python3/setup.ui b/setup/python3/setup.ui index f0acbc6..61d9325 100644 --- a/setup/python3/setup.ui +++ b/setup/python3/setup.ui @@ -196,7 +196,7 @@ False Setup - IBus-Anthy dialog - + True @@ -232,7 +232,7 @@ 0 _Input Mode: True - input_mode + input-mode GTK_FILL @@ -240,9 +240,8 @@ - + True - model1 @@ -263,7 +262,7 @@ 0 _Typing Method: True - typing_method + typing-method 1 @@ -273,9 +272,8 @@ - + True - model2 @@ -298,7 +296,7 @@ 0 Conversion _Mode: True - conversion_segment_mode + conversion-segment-mode 2 @@ -308,9 +306,8 @@ - + True - model3 @@ -366,7 +363,7 @@ automatic in - + True True @@ -430,7 +427,7 @@ 0 _Period Style: True - period_style + period-style GTK_FILL @@ -443,7 +440,7 @@ 0 Symbo_l Style: True - symbol_style + symbol-style 1 @@ -458,7 +455,7 @@ 0 Numpad _Key Type: True - ten_key_mode + ten-key-mode 2 @@ -468,9 +465,8 @@ - + True - model4 @@ -488,9 +484,8 @@ - + True - model5 @@ -508,9 +503,8 @@ - + True - model6 @@ -531,7 +525,7 @@ 0 _Behavior on Period: True - behavior_on_period + behavior-on-period 3 @@ -546,7 +540,7 @@ 0 Behavior on _Focus Out: True - behavior_on_focus_out + behavior-on-focus-out 4 @@ -556,9 +550,8 @@ - + True - model7 @@ -576,9 +569,8 @@ - + True - model8 @@ -636,7 +628,7 @@ 0 Candidate _Window Page Size: True - page_size + page-size False @@ -645,12 +637,11 @@ - + True True adjustment1 0.97999999999999998 - False @@ -664,14 +655,13 @@ - + Convert _symbols with the one column width True True False True True - @@ -681,14 +671,13 @@ - + Convert _numbers with the one column width True True False True True - @@ -698,14 +687,13 @@ - + Con_vert spaces with the one column width True True False True True - @@ -715,14 +703,13 @@ - + Swi_tch “Hiragana” and “Latin” with Shift key and Hiragana–Katakana key in preedit True True False True True - @@ -777,7 +764,7 @@ _Shortcut Type: True word-char - shortcut_type + shortcut-type False @@ -787,7 +774,7 @@ - + True model9 @@ -1271,7 +1258,7 @@ - + Adjust _input method layout to system keyboard layout Adjust IM layout to XKB layout True @@ -1279,7 +1266,6 @@ False True True - @@ -1299,7 +1285,7 @@ 0 True Input _Method Layout: - thumb:keyboard_layout + thumb:keyboard-layout False @@ -1308,9 +1294,8 @@ - + True - model51 @@ -1378,7 +1363,7 @@ 0 True _Additional Key Arrangement: - thumb:fmv_extension + thumb:fmv-extension False @@ -1387,10 +1372,9 @@ - + True '~', '『', '¢', '£' and so on can be output with Thumb Shift key - model11 @@ -1457,7 +1441,6 @@ False True True - @@ -1576,7 +1559,7 @@ True _Edit Dictionary Command: True - dict:entry_edit_dict_command + dict:entry-edit-dict-command GTK_FILL @@ -1587,7 +1570,7 @@ - + True True True @@ -1627,7 +1610,7 @@ True _Add Word Command: True - dict:entry_add_word_command + dict:entry-add-word-command GTK_FILL @@ -1640,7 +1623,7 @@ - + True True True @@ -1921,15 +1904,14 @@ horizontal end - - _Apply + + _Close True True - False True True False - + False @@ -1937,38 +1919,6 @@ 0 - - - _Cancel - True - True - True - True - False - - - - False - False - 1 - - - - - _OK - True - True - True - True - False - - - - False - False - 2 - - False @@ -1979,9 +1929,7 @@ - btn_apply - btn_cancel - btn_ok + btn_close @@ -2762,8 +2710,8 @@ IBus-Anthy Copyright © 2007–2008 Peng Huang Copyright © 2009 Hideaki ABE -Copyright © 2009–2016 Takao Fujiwara -Copyright © 2007–2016 Red Hat, Inc. +Copyright © 2009–2017 Takao Fujiwara +Copyright © 2007–2017 Red Hat, Inc. The Anthy engine for the IBus input platform GPL https://github.com/ibus/ibus/wiki -- cgit v1.2.1