diff options
author | fujiwarat <takao.fujiwara1@gmail.com> | 2012-10-05 21:24:54 +0900 |
---|---|---|
committer | fujiwarat <takao.fujiwara1@gmail.com> | 2012-10-05 21:24:54 +0900 |
commit | acaaa1578cbff50806bbd977e42b37f6358b0734 (patch) | |
tree | 402ac6b6e446d4e785a72e19e695b7f9a802db08 /engine | |
parent | 70dc912db827c333995c09e06dda88ab076e792d (diff) | |
download | ibus-anthy-acaaa1578cbff50806bbd977e42b37f6358b0734.tar.gz |
Added keyboard layout customization.
Diffstat (limited to 'engine')
-rw-r--r-- | engine/Makefile.am | 18 | ||||
-rw-r--r-- | engine/_config.py.in | 4 | ||||
-rw-r--r-- | engine/anthy.xml.in.in | 22 | ||||
-rw-r--r-- | engine/default.xml.in.in | 16 | ||||
-rw-r--r-- | engine/engine.py | 20 | ||||
-rw-r--r-- | engine/main.py | 45 |
6 files changed, 87 insertions, 38 deletions
diff --git a/engine/Makefile.am b/engine/Makefile.am index 8991c90..8faf0b9 100644 --- a/engine/Makefile.am +++ b/engine/Makefile.am @@ -75,8 +75,10 @@ PYGTK2_ANTHY_GEN = endif libexec_SCRIPTS = ibus-engine-anthy -engine_DATA = anthy.xml -enginedir = $(datadir)/ibus/component +component_DATA = anthy.xml +componentdir = $(datadir)/ibus/component +engine_DATA = default.xml +enginedir = $(pkgdatadir)/engine anthy.xml: anthy.xml.in ( \ @@ -86,11 +88,21 @@ anthy.xml: anthy.xml.in eval "echo \"$${s}\""; \ ) > $@ +default.xml: default.xml.in + ( \ + libexecdir=${libexecdir}; \ + pkgdatadir=${pkgdatadir}; \ + s=`cat $<`; \ + eval "echo \"$${s}\""; \ + ) > $@ + _config.py: _config.py.in ( \ PKGDATADIR=$(pkgdatadir); \ LIBEXECDIR=$(libexecdir); \ DATADIR=$(datadir); \ + LAYOUT=$(LAYOUT); \ + SYMBOL_CHAR_INT=$(SYMBOL_CHAR_INT); \ s=`cat $<`; \ eval "echo \"$${s}\""; \ ) > $@ @@ -107,6 +119,7 @@ EXTRA_DIST = \ $(engine_anthy_built_in_files) \ $(PYGTK2_ANTHY_RAW) \ anthy.xml.in.in \ + default.xml.in.in \ ibus-engine-anthy.in \ $(NULL) @@ -114,6 +127,7 @@ CLEANFILES = \ $(BUILT_SOURCES) \ $(PYGTK2_ANTHY_GEN) \ anthy.xml \ + default.xml \ *.pyc \ $(NULL) diff --git a/engine/_config.py.in b/engine/_config.py.in index 17c2274..d543829 100644 --- a/engine/_config.py.in +++ b/engine/_config.py.in @@ -23,4 +23,6 @@ PKGDATADIR = '${PKGDATADIR}' LIBEXECDIR = '${LIBEXECDIR}' -LOCALEDIR= '${DATADIR}/locale' +LOCALEDIR = '${DATADIR}/locale' +LAYOUT = '${LAYOUT}' +SYMBOL_CHAR = unichr(${SYMBOL_CHAR_INT}) diff --git a/engine/anthy.xml.in.in b/engine/anthy.xml.in.in index 0162cf6..9a93744 100644 --- a/engine/anthy.xml.in.in +++ b/engine/anthy.xml.in.in @@ -10,20 +10,10 @@ <homepage>http://code.google.com/p/ibus</homepage> <textdomain>ibus-anthy</textdomain> - <!-- for static engines --> - <engines> - <engine> - <name>anthy</name> - <language>ja</language> - <license>GPL</license> - <author>Peng Huang <shawn.p.huang@gmail.com></author> - <icon>ibus-anthy</icon> - @LAYOUT_XML@ - <longname>Anthy</longname> - <description>Anthy Input Method</description> - <rank>99</rank> - @HOTKEYS_XML@ - @SYMBOL_XML@ - </engine> - </engines> + <!-- for engines --> + <observed-paths> + <path>~/.config/ibus-anthy/engines.xml</path> + <path>${pkgdatadir}/engine/default.xml</path> + </observed-paths> + <engines exec=\"${libexecdir}/ibus-engine-anthy --xml\" /> </component> diff --git a/engine/default.xml.in.in b/engine/default.xml.in.in new file mode 100644 index 0000000..c130285 --- /dev/null +++ b/engine/default.xml.in.in @@ -0,0 +1,16 @@ +<?xml version=\"1.0\" encoding=\"utf-8\"?> +<engines> + <engine> + <name>anthy</name> + <language>ja</language> + <license>GPL</license> + <author>Peng Huang <shawn.p.huang@gmail.com></author> + <icon>ibus-anthy</icon> + @LAYOUT_XML@ + <longname>Anthy</longname> + <description>Anthy Input Method</description> + <rank>99</rank> + @HOTKEYS_XML@ + @SYMBOL_XML@ + </engine> +</engines> diff --git a/engine/engine.py b/engine/engine.py index cef6aa0..1915f5b 100644 --- a/engine/engine.py +++ b/engine/engine.py @@ -27,6 +27,8 @@ import signal import sys from gettext import dgettext +from main import get_userhome + try: from locale import getpreferredencoding except: @@ -1633,16 +1635,6 @@ class Engine(IBus.EngineSimple): cls.__thumb.reset() @classmethod - def _get_userhome(cls): - if 'HOME' not in environ: - import pwd - userhome = pwd.getpwuid(os.getuid()).pw_dir - else: - userhome = environ['HOME'] - userhome = userhome.rstrip('/') - return userhome - - @classmethod def _get_quoted_id(cls, file): id = file has_mbcs = False @@ -1686,10 +1678,10 @@ class Engine(IBus.EngineSimple): if id == None: return if link_mode == LINK_DICT_EMBEDDED: - directory = cls._get_userhome() + '/.anthy/' + IMPORTED_EMBEDDED_DICT_DIR + directory = get_userhome() + '/.anthy/' + IMPORTED_EMBEDDED_DICT_DIR name = IMPORTED_EMBEDDED_DICT_PREFIX + id elif link_mode == LINK_DICT_SINGLE: - directory = cls._get_userhome() + '/.anthy' + directory = get_userhome() + '/.anthy' name = IMPORTED_SINGLE_DICT_PREFIX + id else: return @@ -1718,10 +1710,10 @@ class Engine(IBus.EngineSimple): if id == None: return if link_mode == LINK_DICT_EMBEDDED: - directory = cls._get_userhome() + '/.anthy/' + IMPORTED_EMBEDDED_DICT_DIR + directory = get_userhome() + '/.anthy/' + IMPORTED_EMBEDDED_DICT_DIR name = IMPORTED_EMBEDDED_DICT_PREFIX + id elif link_mode == LINK_DICT_SINGLE: - directory = cls._get_userhome() + '/.anthy' + directory = get_userhome() + '/.anthy' name = IMPORTED_SINGLE_DICT_PREFIX + id else: return diff --git a/engine/main.py b/engine/main.py index ccb66d5..d339bd2 100644 --- a/engine/main.py +++ b/engine/main.py @@ -44,13 +44,15 @@ class IMApp: command_line=command_line, textdomain='ibus-anthy') engine = IBus.EngineDesc(name='anthy', - longname='anthy', - description='Japanese Anthy', + longname='Anthy', + description='Anthy Input Method', language='ja', license='GPL', author='Peng Huang <shawn.p.huang@gmail.com>', icon='ibus-anthy', - layout='en') + layout=config.LAYOUT, + symbol=config.SYMBOL_CHAR, + rank=99) self.__component.add_engine(engine) self.__mainloop = GObject.MainLoop() self.__bus = IBus.Bus() @@ -71,10 +73,36 @@ class IMApp: def launch_engine(exec_by_ibus): IMApp(exec_by_ibus).run() +def get_userhome(): + if 'HOME' not in os.environ: + import pwd + userhome = pwd.getpwuid(os.getuid()).pw_dir + else: + userhome = os.environ['HOME'] + userhome = userhome.rstrip('/') + return userhome + +def print_xml(): + user_config = os.path.join(get_userhome(), '.config', + 'ibus-anthy', 'engines.xml') + system_config = os.path.join(config.PKGDATADIR, 'engine', 'default.xml') + xml = None + for f in [user_config, system_config]: + if os.path.exists(f): + xml = f + break + if xml == None: + print >> sys.stderr, 'Not exist: %s' % system_config + return + file = open(xml, 'r') + print file.read() + file.close() + def print_help(out, v = 0): print >> out, '-i, --ibus executed by ibus.' print >> out, '-h, --help show this message.' print >> out, '-d, --daemonize daemonize ibus.' + print >> out, '-x, --xml print engine xml.' sys.exit(v) def main(): @@ -85,9 +113,10 @@ def main(): exec_by_ibus = False daemonize = False + xml = False - shortopt = 'ihd' - longopt = ['ibus', 'helpn', 'daemonize'] + shortopt = 'ihdx' + longopt = ['ibus', 'help', 'daemonize', 'xml'] try: opts, args = getopt.getopt(sys.argv[1:], shortopt, longopt) @@ -101,6 +130,8 @@ def main(): daemonize = True elif o in ('-i', '--ibus'): exec_by_ibus = True + elif o in ('-x', '--xml'): + xml = True else: print >> sys.stderr, 'Unknown argument: %s' % o print_help(sys.stderr, 1) @@ -109,6 +140,10 @@ def main(): if os.fork(): sys.exit() + if xml: + print_xml() + return + launch_engine(exec_by_ibus) if __name__ == '__main__': |