Repository :
http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : libyokan_port_20130711
---------------------------------------------------------------
commit d209a6bb297fccf3ac38ce643b17857213cd2468
Author: anish <apatil(a)redhat.com>
Date: Tue Jul 9 19:18:12 2013 +0530
With libyokan,you get suggestions from libyokan library itself, so update_candidate
function should be present in the engine class not in the editor class
---------------------------------------------------------------
ibus-typing-booster/engine/hunspell_table.py | 108 ++++++++++----------------
1 files changed, 40 insertions(+), 68 deletions(-)
diff --git a/ibus-typing-booster/engine/hunspell_table.py
b/ibus-typing-booster/engine/hunspell_table.py
index e59c46a..e16fe5f 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -288,73 +288,6 @@ class editor(object):
'''
self._typed_string_cursor = len(self._typed_string)
- def append_candidate_to_lookup_table(self, phrase=u'', user_freq=0):
- '''append candidate to lookup_table'''
- if not phrase:
- return
- phrase = unicodedata.normalize('NFC', phrase)
- transliterated_string = unicodedata.normalize('NFC',
self._transliterated_string)
- attrs = IBus.AttrList ()
- if not phrase.startswith(transliterated_string):
- # this is a candidate which does not start exactly
- # as the transliterated user input, i.e. it is a suggestion
- # for a spelling correction:
- if debug_level > 0:
- phrase = phrase + u' ✓'
- attrs.append(IBus.attr_foreground_new(rgb(0xff,0x00,0x00), 0, len(phrase)))
- elif user_freq > 10:
- # this is a frequently used phrase:
- attrs.append(IBus.attr_foreground_new(rgb(0xff,0x7f,0x00), 0, len(phrase)))
- else:
- # this is a system phrase that has been used less then 10 times or maybe
never:
- attrs.append(IBus.attr_foreground_new(rgb(0x00,0x00,0x00), 0, len(phrase)))
- if debug_level > 0:
- phrase += u' ' + str(user_freq)
- attrs.append(IBus.attr_foreground_new(
- rgb(0x00,0xff,0x00), len(phrase) - len(str(user_freq)), len(phrase)))
- text = IBus.Text.new_from_string(phrase)
- 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
- self._lookup_table.append_candidate(text)
- self._lookup_table.set_cursor_visible(False)
-
- def update_candidates (self):
- '''Update lookuptable'''
- if self._typed_string ==
self._typed_string_when_update_candidates_was_last_called:
- # The input did not change since we came here last, do nothing and leave
- # candidates and lookup table unchanged:
- return True
- self._typed_string_when_update_candidates_was_last_called =
self._typed_string[:]
- self._lookup_table.clear()
- self._lookup_table.set_cursor_visible(False)
- self._candidates = []
- prefix_length = 0
- prefix = u''
- if self._transliterated_string:
- stripped_transliterated_string =
itb_util.lstrip_token(self._transliterated_string)
- if stripped_transliterated_string:
- prefix_length = len(self._transliterated_string) -
len(stripped_transliterated_string)
- if prefix_length:
- prefix = self._transliterated_string[0:prefix_length]
- try:
- self._candidates =
self.db.select_words(stripped_transliterated_string, p_phrase=self._p_phrase,
pp_phrase=self._pp_phrase)
- except:
- import traceback
- traceback.print_exc()
- if self._candidates:
- if prefix:
- self._candidates = map(lambda x: (prefix+x[0], x[1]), self._candidates)
- map(lambda x:
- self.append_candidate_to_lookup_table(phrase=x[0], user_freq=x[1]),
- self._candidates)
- return True
-
def arrow_down(self):
'''Process Arrow Down Key Event
Move Lookup Table cursor down'''
@@ -556,6 +489,43 @@ class tabengine (IBus.Engine):
def preedit_signal_cb(self,arg):
self._update_ui ()
+ self.update_candidates()
+
+ def update_candidates(self):
+ self._candidates = self._editor.yokan.get_suggestions();
+ print self._candidates
+ if self._candidates:
+ self.update_lookup_table(self._editor.get_lookup_table(), True)
+ map(lambda x:
+ self.append_candidate_to_lookup_table(phrase=x, user_freq=1),
+ self._candidates)
+ else:
+ self.hide_lookup_table()
+ return True
+
+ def append_candidate_to_lookup_table(self, phrase=u'', user_freq=0):
+ '''append candidate to lookup_table'''
+ if not phrase:
+ return
+ #phrase = unicodedata.normalize('NFC', phrase)
+ #transliterated_string = unicodedata.normalize('NFC',
self._transliterated_string)
+ attrs = IBus.AttrList ()
+ attrs.append(IBus.attr_foreground_new(rgb(0x00,0x00,0x00), 0, len(phrase)))
+ if debug_level > 0:
+ phrase += u' ' + str(user_freq)
+ attrs.append(IBus.attr_foreground_new(
+ rgb(0x00,0xff,0x00), len(phrase) - len(str(user_freq)), len(phrase)))
+ text = IBus.Text.new_from_string(phrase)
+ 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
+ self._editor._lookup_table.append_candidate(text)
+ self._editor._lookup_table.set_cursor_visible(False)
def reset (self):
self._editor.clear_input()
@@ -628,6 +598,8 @@ class tabengine (IBus.Engine):
def _update_lookup_table (self):
'''Update Lookup Table in UI'''
+ self.update_lookup_table(self._editor.get_lookup_table(), True)
+ return
if self._editor.is_empty ():
if self._tab_enable:
# if everything has been cleared from the editor
@@ -654,7 +626,7 @@ class tabengine (IBus.Engine):
def _update_ui (self):
'''Update User Interface'''
- self._update_lookup_table ()
+ #self._update_lookup_table ()
self._update_preedit ()
self._update_aux ()