summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfujiwarat <takao.fujiwara1@gmail.com>2012-03-27 12:57:09 +0900
committerfujiwarat <takao.fujiwara1@gmail.com>2012-03-27 12:57:09 +0900
commit430b07188d267420fe7f318617a5fdc30466d3a1 (patch)
tree4b7caab7079263e769092071a4d4266991c4e30e
parent3c1d831b3418926e3b19b5095e3a4878f1fbb5cc (diff)
downloadibus-anthy-430b07188d267420fe7f318617a5fdc30466d3a1.tar.gz
Added work arounds to be compatible with ibus 1.41.3.99.20120327
-rw-r--r--engine/engine.py93
-rw-r--r--engine/factory.py6
-rw-r--r--engine/main.py16
3 files changed, 80 insertions, 35 deletions
diff --git a/engine/engine.py b/engine/engine.py
index 76c2d0f..f9614dd 100644
--- a/engine/engine.py
+++ b/engine/engine.py
@@ -93,6 +93,34 @@ IMPORTED_EMBEDDED_DICT_DIR = 'imported_words_default.d'
IMPORTED_EMBEDDED_DICT_PREFIX = 'ibus__'
IMPORTED_SINGLE_DICT_PREFIX = 'imported_words_ibus__'
+if not hasattr(IBus, 'KEY_plus'):
+ IBus.KEY_plus = IBus.plus
+ IBus.KEY_period = IBus.period
+ IBus.KEY_slash = IBus.slash
+ IBus.KEY_Return = IBus.Return
+ IBus.KEY_equal = IBus.equal
+ IBus.KEY_asterisk = IBus.asterisk
+ IBus.KEY_comma = IBus.comma
+ IBus.KEY_space = IBus.space
+ IBus.KEY_minus = IBus.minus
+ IBus.KEY_exclam = IBus.exclam
+ IBus.KEY_asciitilde = IBus.asciitilde
+ IBus.KEY_yen = IBus.yen
+ IBus.KEY_A = IBus.A
+ IBus.KEY_Z = IBus.Z
+ IBus.KEY_a = IBus.a
+ IBus.KEY_z = IBus.z
+ IBus.KEY_0 = 48 #IBus.0
+ IBus.KEY_KP_Add = IBus.KP_Add
+ IBus.KEY_KP_Decimal = IBus.KP_Decimal
+ IBus.KEY_KP_Divide = IBus.KP_Divide
+ IBus.KEY_KP_Enter = IBus.KP_Enter
+ IBus.KEY_KP_Equal = IBus.KP_Equal
+ IBus.KEY_KP_Multiply = IBus.KP_Multiply
+ IBus.KEY_KP_Separator = IBus.KP_Separator
+ IBus.KEY_KP_Space = IBus.KP_Space
+ IBus.KEY_KP_Subtract = IBus.KP_Subtract
+
KP_Table = {}
for s in dir(IBus):
if s.startswith('KEY_KP_'):
@@ -107,7 +135,8 @@ for k, v in zip(['KEY_KP_Add', 'KEY_KP_Decimal', 'KEY_KP_Divide', 'KEY_KP_Enter'
'KEY_space', 'KEY_minus']):
KP_Table[getattr(IBus, k)] = getattr(IBus, v)
-class Engine(IBus.EngineSimple):
+# IBus.EngineSimple is not available in ibus 1.4
+class Engine(IBus.Engine):
__typing_mode = jastring.TYPING_MODE_ROMAJI
__setup_pid = 0
@@ -537,14 +566,11 @@ class Engine(IBus.EngineSimple):
def update_preedit(self, string, attrs, cursor_pos, visible):
text = IBus.Text.new_from_string(string)
- i = 0
- while attrs.get(i) != None:
- attr = attrs.get(i)
- text.append_attribute(attr.get_attr_type(),
- attr.get_value(),
- attr.get_start_index(),
- attr.get_end_index())
- i += 1
+ for attr in attrs:
+ text.append_attribute(attr['type'],
+ attr['value'],
+ attr['start_index'],
+ attr['end_index'])
mode = self.__prefs.get_value('common', 'behavior_on_focus_out')
if self.__get_ibus_version() >= 1.003 and mode == 1:
self.update_preedit_text_with_mode(text,
@@ -1040,10 +1066,11 @@ class Engine(IBus.EngineSimple):
def __update_input_chars(self):
text, cursor = self.__get_preedit()
- attrs = IBus.AttrList()
- attrs.append(IBus.attr_underline_new(
- IBus.AttrUnderline.SINGLE, 0,
- len(text)))
+ attrs = []
+ attrs.append({'type': IBus.AttrType.UNDERLINE,
+ 'value': IBus.AttrUnderline.SINGLE,
+ 'start_index': 0,
+ 'end_index': len(text)})
self.update_preedit(text,
attrs, cursor, not self.__preedit_ja_string.is_empty())
@@ -1092,13 +1119,19 @@ class Engine(IBus.EngineSimple):
text, cursor = self.__preedit_ja_string.get_wide_latin()
text = text.capitalize()
self.__convert_chars = text
- attrs = IBus.AttrList()
- attrs.append(IBus.attr_underline_new(
- IBus.AttrUnderline.SINGLE, 0, len(text)))
- attrs.append(IBus.attr_background_new(self.__rgb(200, 200, 240),
- 0, len(text)))
- attrs.append(IBus.attr_foreground_new(self.__rgb(0, 0, 0),
- 0, len(text)))
+ attrs = []
+ attrs.append({'type': IBus.AttrType.UNDERLINE,
+ 'value': IBus.AttrUnderline.SINGLE,
+ 'start_index': 0,
+ 'end_index': len(text)})
+ attrs.append({'type': IBus.AttrType.BACKGROUND,
+ 'value': self.__rgb(200, 200, 240),
+ 'start_index': 0,
+ 'end_index': len(text)})
+ attrs.append({'type': IBus.AttrType.FOREGROUND,
+ 'value': self.__rgb(0, 0, 0),
+ 'start_index': 0,
+ 'end_index': len(text)})
self.update_preedit(text, attrs, len(text), True)
self.update_aux_string(u'',
@@ -1113,13 +1146,19 @@ class Engine(IBus.EngineSimple):
self.__convert_chars += text
if i < self.__cursor_pos:
pos += len(text)
- attrs = IBus.AttrList()
- attrs.append(IBus.attr_underline_new(
- IBus.AttrUnderline.SINGLE, 0, len(self.__convert_chars)))
- attrs.append(IBus.attr_background_new(self.__rgb(200, 200, 240),
- pos, pos + len(self.__segments[self.__cursor_pos][1])))
- attrs.append(IBus.attr_foreground_new(self.__rgb(0, 0, 0),
- pos, pos + len(self.__segments[self.__cursor_pos][1])))
+ attrs = []
+ attrs.append({'type': IBus.AttrType.UNDERLINE,
+ 'value': IBus.AttrUnderline.SINGLE,
+ 'start_index': 0,
+ 'end_index': len(self.__convert_chars)})
+ attrs.append({'type': IBus.AttrType.BACKGROUND,
+ 'value': self.__rgb(200, 200, 240),
+ 'start_index': pos,
+ 'end_index': pos + len(self.__segments[self.__cursor_pos][1])})
+ attrs.append({'type': IBus.AttrType.FOREGROUND,
+ 'value': self.__rgb(0, 0, 0),
+ 'start_index': pos,
+ 'end_index': pos + len(self.__segments[self.__cursor_pos][1])})
self.update_preedit(self.__convert_chars, attrs, pos, True)
aux_string = u'( %d / %d )' % (self.__lookup_table.get_cursor_pos() + 1, self.__lookup_table.get_number_of_candidates())
self.update_aux_string(aux_string,
diff --git a/engine/factory.py b/engine/factory.py
index 1f434c9..71f7688 100644
--- a/engine/factory.py
+++ b/engine/factory.py
@@ -57,6 +57,12 @@ class EngineFactory(IBus.Factory):
self.__name_owner_changed_cb,
bus)
+ if not hasattr(IBus.Factory, 'do_create_engine'):
+ self.connect('create-engine', self.__create_engine_cb)
+
+ def __create_engine_cb(self, factory, engine_name):
+ return self.do_create_engine(engine_name)
+
def do_create_engine(self, engine_name):
if engine_name == 'anthy':
self.__id += 1
diff --git a/engine/main.py b/engine/main.py
index ccb66d5..a08e494 100644
--- a/engine/main.py
+++ b/engine/main.py
@@ -35,14 +35,14 @@ import factory
class IMApp:
def __init__(self, exec_by_ibus):
command_line = config.LIBEXECDIR + '/ibus-engine-anthy --ibus'
- self.__component = IBus.Component(name='org.freedesktop.IBus.Anthy',
- description='Anthy Component',
- version='0.1.0',
- license='GPL',
- author='Peng Huang <shawn.p.huang@gmail.com>',
- homepage='http://code.google.com/p/ibus/',
- command_line=command_line,
- textdomain='ibus-anthy')
+ self.__component = IBus.Component.new('org.freedesktop.IBus.Anthy',
+ 'Anthy Component',
+ '0.1.0',
+ 'GPL',
+ 'Peng Huang <shawn.p.huang@gmail.com>',
+ 'http://code.google.com/p/ibus/',
+ command_line,
+ 'ibus-anthy')
engine = IBus.EngineDesc(name='anthy',
longname='anthy',
description='Japanese Anthy',