summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHuang Peng <shawn.p.huang@gmail.com>2009-02-05 15:25:13 +0800
committerHuang Peng <shawn.p.huang@gmail.com>2009-02-05 15:25:13 +0800
commit5fc311c8a1195afca7a29006f8d3e785b35c6b00 (patch)
tree72b31b0f8a3c3ee8b1766d002af3013c4cb44646
parent87c79e5ebdbac37e6a7533f2d41a3905ca62692a (diff)
downloadibus-anthy-c_impl.tar.gz
Migrate ibus-anthy to ibus-1.1.xc_impl
-rw-r--r--configure.ac6
-rw-r--r--engine/Makefile.am10
-rw-r--r--engine/anthy.engine.in6
-rw-r--r--engine/anthy.xml.in26
-rw-r--r--engine/engine.py86
-rw-r--r--engine/factory.py20
-rw-r--r--engine/ibus-engine-anthy.in3
-rw-r--r--engine/main.py42
-rw-r--r--ibus-anthy.spec.in7
9 files changed, 128 insertions, 78 deletions
diff --git a/configure.ac b/configure.ac
index b89edcb..34b93f4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,9 +20,9 @@
# if not 1, append datestamp to the version number.
m4_define([ibus_released], [0])
-m4_define([ibus_major_version], [0])
+m4_define([ibus_major_version], [1])
m4_define([ibus_minor_version], [1])
-m4_define([ibus_micro_version], [1])
+m4_define([ibus_micro_version], [0])
m4_define(ibus_maybe_datestamp,
m4_esyscmd([if test x]ibus_released[ != x1; then date +.%Y%m%d | tr -d '\n\r'; fi]))
@@ -97,7 +97,7 @@ Makefile
ibus-anthy.spec
engine/Makefile
engine/ibus-engine-anthy
-engine/anthy.engine
+engine/anthy.xml
icons/Makefile
m4/Makefile
])
diff --git a/engine/Makefile.am b/engine/Makefile.am
index e0f4df6..6f45a2b 100644
--- a/engine/Makefile.am
+++ b/engine/Makefile.am
@@ -55,9 +55,9 @@ _anthy_la_LDFLAGS = \
-module \
$(NULL)
-bin_SCRIPTS = ibus-engine-anthy
-engine_DATA = anthy.engine
-enginedir = $(datadir)/ibus/engine
+libexec_SCRIPTS = ibus-engine-anthy
+engine_DATA = anthy.xml
+enginedir = $(datadir)/ibus/component
anthy.py anthy_wrap.c: anthy.i
$(SWIG) -python -I/usr/include -o anthy_wrap.c $(srcdir)/anthy.i
@@ -66,13 +66,13 @@ test:
$(ENV) \
DBUS_DEBUG=true \
IBUS_ANTHY_PKGDATADIR=$(abs_top_srcdir) \
- PYTHONPATH=$(builddir)/.libs \
+ PYTHONPATH=$(builddir)/.libs:@pyexecdir@ \
$(PYTHON) \
$(srcdir)/main.py
EXTRA_DIST = \
anthy.i \
- anthy.engine.in \
+ anthy.xml.in \
ibus-engine-anthy.in \
$(NULL)
diff --git a/engine/anthy.engine.in b/engine/anthy.engine.in
deleted file mode 100644
index edde898..0000000
--- a/engine/anthy.engine.in
+++ /dev/null
@@ -1,6 +0,0 @@
-Exec=@prefix@/bin/ibus-engine-anthy
-Name=anthy
-Lang=ja
-Icon=@prefix@/share/@PACKAGE@/icons/ibus-anthy.png
-Author=Huang Peng <shawn.p.huang@gmail.com>
-Credits=
diff --git a/engine/anthy.xml.in b/engine/anthy.xml.in
new file mode 100644
index 0000000..2aa1e2c
--- /dev/null
+++ b/engine/anthy.xml.in
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- filename: pinyin.xml -->
+<component>
+ <name>org.freedesktop.IBus.Anthy</name>
+ <description>Anthy Component</description>
+ <exec>@prefix@/libexec/ibus-engine-anthy --ibus</exec>
+ <version>@VERSION@</version>
+ <author>Peng Huang &lt;shawn.p.huang@gmail.com&gt;</author>
+ <license>GPL</license>
+ <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 &lt;shawn.p.huang@gmail.com&gt;</author>
+ <icon>@prefix@/share/ibus-anthy/icons/ibus-anthy.png</icon>
+ <layout>us</layout>
+ <longname>Anthy</longname>
+ <description>Anthy Input Method</description>
+ </engine>
+ </engines>
+</component>
diff --git a/engine/engine.py b/engine/engine.py
index 271e280..3a8f92e 100644
--- a/engine/engine.py
+++ b/engine/engine.py
@@ -84,64 +84,70 @@ class Engine(ibus.EngineBase):
anthy_props = ibus.PropList()
# init input mode properties
- input_mode_prop = ibus.Property(name = u"InputMode",
- type = ibus.PROP_TYPE_MENU,
- label = u"あ",
- tooltip = _(u"Switch input mode"))
+ input_mode_prop = ibus.Property(key=u"InputMode",
+ type=ibus.PROP_TYPE_MENU,
+ label=u"あ",
+ tooltip=_(u"Switch input mode"))
self.__prop_dict[u"InputMode"] = input_mode_prop
props = ibus.PropList()
- props.append(ibus.Property(name = u"InputMode.Hiragana",
- type = ibus.PROP_TYPE_RADIO,
- label = _(u"Hiragana")))
- props.append(ibus.Property(name = u"InputMode.Katakana",
- type = ibus.PROP_TYPE_RADIO,
- label = _(u"Katakana")))
- props.append(ibus.Property(name = u"InputMode.HalfWidthKatakana",
- type = ibus.PROP_TYPE_RADIO,
- label = _(u"Half width katakana")))
- props.append(ibus.Property(name = u"InputMode.Latin",
- type = ibus.PROP_TYPE_RADIO,
- label = _(u"Latin")))
- props.append(ibus.Property(name = u"InputMode.WideLatin",
- type = ibus.PROP_TYPE_RADIO,
- label = _(u"Wide Latin")))
+ props.append(ibus.Property(key=u"InputMode.Hiragana",
+ type=ibus.PROP_TYPE_RADIO,
+ label=_(u"Hiragana")))
+ props.append(ibus.Property(key=u"InputMode.Katakana",
+ type=ibus.PROP_TYPE_RADIO,
+ label=_(u"Katakana")))
+ props.append(ibus.Property(key=u"InputMode.HalfWidthKatakana",
+ type=ibus.PROP_TYPE_RADIO,
+ label=_(u"Half width katakana")))
+ props.append(ibus.Property(key=u"InputMode.Latin",
+ type=ibus.PROP_TYPE_RADIO,
+ label=_(u"Latin")))
+ props.append(ibus.Property(key=u"InputMode.WideLatin",
+ type=ibus.PROP_TYPE_RADIO,
+ label=_(u"Wide Latin")))
props[self.__input_mode].set_state(ibus.PROP_STATE_CHECKED)
for prop in props:
- self.__prop_dict[prop.name] = prop
+ self.__prop_dict[prop.key] = prop
input_mode_prop.set_sub_props(props)
anthy_props.append(input_mode_prop)
# typing input mode properties
- typing_mode_prop = ibus.Property(name = u"TypingMode",
- type = ibus.PROP_TYPE_MENU,
- label = u"R",
- tooltip = _(u"Switch typing mode"))
+ typing_mode_prop = ibus.Property(key=u"TypingMode",
+ type=ibus.PROP_TYPE_MENU,
+ label=u"R",
+ tooltip=_(u"Switch typing mode"))
self.__prop_dict[u"TypingMode"] = typing_mode_prop
props = ibus.PropList()
- props.append(ibus.Property(name = u"TypingMode.Romaji",
- type = ibus.PROP_TYPE_RADIO,
- label = _(u"Romaji")))
- props.append(ibus.Property(name = u"TypingMode.Kana",
- type = ibus.PROP_TYPE_RADIO,
- label = _(u"Kana")))
+ props.append(ibus.Property(key=u"TypingMode.Romaji",
+ type=ibus.PROP_TYPE_RADIO,
+ label=_(u"Romaji")))
+ props.append(ibus.Property(key=u"TypingMode.Kana",
+ type=ibus.PROP_TYPE_RADIO,
+ label=_(u"Kana")))
# props.append(ibus.Property(name = u"TypingMode.ThumbShift",
# type = ibus.PROP_TYPE_RADIO,
# label = _(u"Thumb shift")))
props[Engine.__typing_mode].set_state(ibus.PROP_STATE_CHECKED)
for prop in props:
- self.__prop_dict[prop.name] = prop
+ self.__prop_dict[prop.key] = prop
typing_mode_prop.set_sub_props(props)
anthy_props.append(typing_mode_prop)
return anthy_props
+ def update_preedit(self, string, attrs, cursor_pos, visible):
+ self.update_preedit_text(ibus.Text(string, attrs), cursor_pos, visible)
+
+ def update_aux_string(self, string, attrs, visible):
+ self.update_auxiliary_text(ibus.Text(string, attrs), visible)
+
def page_up(self):
# only process cursor down in convert mode
if self.__convert_mode != CONV_MODE_ANTHY:
@@ -150,7 +156,7 @@ class Engine(ibus.EngineBase):
if not self.__lookup_table.page_up():
return False
- candidate = self.__lookup_table.get_current_candidate()[0]
+ candidate = self.__lookup_table.get_current_candidate().text
index = self.__lookup_table.get_cursor_pos()
self.__segments[self.__cursor_pos] = index, candidate
self.__invalidate()
@@ -164,7 +170,7 @@ class Engine(ibus.EngineBase):
if not self.__lookup_table.page_down():
return False
- candidate = self.__lookup_table.get_current_candidate()[0]
+ candidate = self.__lookup_table.get_current_candidate().text
index = self.__lookup_table.get_cursor_pos()
self.__segments[self.__cursor_pos] = index, candidate
self.__invalidate()
@@ -178,7 +184,7 @@ class Engine(ibus.EngineBase):
if not self.__lookup_table.cursor_up():
return False
- candidate = self.__lookup_table.get_current_candidate()[0]
+ candidate = self.__lookup_table.get_current_candidate().text
index = self.__lookup_table.get_cursor_pos()
self.__segments[self.__cursor_pos] = index, candidate
self.__invalidate()
@@ -192,7 +198,7 @@ class Engine(ibus.EngineBase):
if not self.__lookup_table.cursor_down():
return False
- candidate = self.__lookup_table.get_current_candidate()[0]
+ candidate = self.__lookup_table.get_current_candidate().text
index = self.__lookup_table.get_cursor_pos()
self.__segments[self.__cursor_pos] = index, candidate
self.__invalidate()
@@ -200,7 +206,7 @@ class Engine(ibus.EngineBase):
def __commit_string(self, text):
self.__reset()
- self.commit_string(text)
+ self.commit_text(ibus.Text(text))
self.__invalidate()
def __shrink_segment(self, relative_size):
@@ -217,7 +223,9 @@ class Engine(ibus.EngineBase):
self.__invalidate()
return True
- def process_key_event(self, keyval, is_press, state):
+ def process_key_event(self, keyval, state):
+
+ is_press = (state & modifier.RELEASE_MASK) == 0
state = state & (modifier.SHIFT_MASK | \
modifier.CONTROL_MASK | \
@@ -413,7 +421,7 @@ class Engine(ibus.EngineBase):
for i in xrange(0, seg_stat.nr_candidate):
buf = self.__context.get_segment(self.__cursor_pos, i)
candidate = unicode(buf, "utf-8")
- self.__lookup_table.append_candidate(candidate)
+ self.__lookup_table.append_candidate(ibus.Text(candidate))
def __invalidate(self):
@@ -670,7 +678,7 @@ class Engine(ibus.EngineBase):
candidates = self.__lookup_table.get_canidates_in_current_page()
if self.__lookup_table.set_cursor_pos_in_current_page(index):
index = self.__lookup_table.get_cursor_pos()
- candidate = self.__lookup_table.get_current_candidate()[0]
+ candidate = self.__lookup_table.get_current_candidate().text
self.__segments[self.__cursor_pos] = index, candidate
self.__lookup_table_visible = False
self.__on_key_right()
diff --git a/engine/factory.py b/engine/factory.py
index f2d7105..d460bde 100644
--- a/engine/factory.py
+++ b/engine/factory.py
@@ -39,14 +39,12 @@ class EngineFactory(ibus.EngineFactoryBase):
CREDITS = "GPLv2"
def __init__(self, bus):
- self.__info = [
- self.NAME,
- self.LANG,
- self.ICON,
- self.AUTHORS,
- self.CREDITS
- ]
-
- super(EngineFactory, self).__init__(self.__info, engine.Engine, ENGINE_PATH, bus, FACTORY_PATH)
-
-
+ self.__bus = bus
+ self.__id = 0
+ super(EngineFactory, self).__init__(bus)
+
+ def create_engine(self, engine_name):
+ if engine_name == "anthy":
+ self.__id += 1
+ return engine.Engine(self.__bus, "/org/freedesktop/IBus/Anthy/%d" % self.__id)
+ return super(EngineFactory, self).create_engine(engine_name)
diff --git a/engine/ibus-engine-anthy.in b/engine/ibus-engine-anthy.in
index 4bf32db..01b0b62 100644
--- a/engine/ibus-engine-anthy.in
+++ b/engine/ibus-engine-anthy.in
@@ -20,6 +20,9 @@
# Boston, MA 02111-1307 USA
prefix=@prefix@
datarootdir=@datarootdir@
+exec_prefix=@exec_prefix@
+pyexecdir=@pyexecdir@
+export PYTHONPATH=@pyexecdir@:$PYTHONPATH
export IBUS_PREFIX=@prefix@
export IBUS_ANTHY_PKGDATADIR=@datarootdir@/@PACKAGE@
exec python @datarootdir@/@PACKAGE@/engine/main.py $@
diff --git a/engine/main.py b/engine/main.py
index 3f0801e..456ae29 100644
--- a/engine/main.py
+++ b/engine/main.py
@@ -28,24 +28,41 @@ import gobject
import locale
class IMApp:
- def __init__(self):
+ def __init__(self, exec_by_ibus):
+ self.__component = ibus.Component("org.freedesktop.IBus.Anthy",
+ "Anthy Component",
+ "0.1.0",
+ "GPL",
+ "Peng Huang <shawn.p.huang@gmail.com>")
+ self.__component.add_engine("anthy",
+ "anthy",
+ "Japanese Anthy",
+ "ja",
+ "GPL",
+ "Peng Huang <shawn.p.huang@gmail.com>",
+ "",
+ "en")
self.__mainloop = gobject.MainLoop()
self.__bus = ibus.Bus()
- self.__bus.connect("destroy", self.__bus_destroy_cb)
- self.__engine = factory.EngineFactory(self.__bus)
- self.__bus.register_factories([factory.FACTORY_PATH])
+ self.__bus.connect("disconnected", self.__bus_disconnected_cb)
+ self.__factory = factory.EngineFactory(self.__bus)
+ if exec_by_ibus:
+ self.__bus.request_name("org.freedesktop.IBus.Anthy", 0)
+ else:
+ self.__bus.register_component(self.__component)
def run(self):
self.__mainloop.run()
- def __bus_destroy_cb(self, bus):
+ def __bus_disconnected_cb(self, bus):
self.__mainloop.quit()
-def launch_engine():
- IMApp().run()
+def launch_engine(exec_by_ibus):
+ IMApp(exec_by_ibus).run()
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"
sys.exit(v)
@@ -56,9 +73,12 @@ def main():
except:
pass
+ exec_by_ibus = False
daemonize = False
- shortopt = "hd"
- longopt = ["help", "daemonize"]
+
+ shortopt = "ihd"
+ longopt = ["ibus", "help", "daemonize"]
+
try:
opts, args = getopt.getopt(sys.argv[1:], shortopt, longopt)
except getopt.GetoptError, err:
@@ -69,6 +89,8 @@ def main():
print_help(sys.stdout)
elif o in ("-d", "--daemonize"):
daemonize = True
+ elif o in ("-i", "--ibus"):
+ exec_by_ibus = True
else:
print >> sys.stderr, "Unknown argument: %s" % o
print_help(sys.stderr, 1)
@@ -77,7 +99,7 @@ def main():
if os.fork():
sys.exit()
- launch_engine()
+ launch_engine(exec_by_ibus)
if __name__ == "__main__":
main()
diff --git a/ibus-anthy.spec.in b/ibus-anthy.spec.in
index 0df0a61..233aa55 100644
--- a/ibus-anthy.spec.in
+++ b/ibus-anthy.spec.in
@@ -49,10 +49,9 @@ rm -rf $RPM_BUILD_ROOT
# %dir %{python_sitearch}/ibus
%{python_sitearch}/anthy.py*
%{python_sitearch}/_anthy.so
-%dir %{_datadir}/@PACKAGE@
-%{_bindir}/ibus-engine-anthy
-%{_datadir}/@PACKAGE@/*
-%{_datadir}/ibus/engine/anthy.engine
+%{_libexecdir}/ibus-engine-anthy
+%{_datadir}/@PACKAGE@
+%{_datadir}/ibus/component/*
%changelog
* Fri Aug 08 2008 Huang Peng <shawn.p.huang@gmail.com> - @VERSION@-1