self._convert_begined = False
self._segments = []
self._lookup_table.clean ()
+ self._lookup_table_visible = False
# begine convert
def _begin_convert (self):
self._segments.append ((0, text))
self._cursor_pos = 0
-
self._fill_lookup_table ()
+ self._lookup_table_visible = False
- def _fill_lookup_table ():
+ def _fill_lookup_table (self):
# get segment stat
seg_stat = anthy.anthy_segment_stat ()
- self._context.get_segment_stat (self._current_pos, seg_stat)
+ self._context.get_segment_stat (self._cursor_pos, seg_stat)
# fill lookup_table
self._lookup_table.clean ()
candidate = unicode (buf[:l], "utf-8")
self._lookup_table.append_candidate (candidate)
- def _process_key_event (self, keyval, is_press, state):
- # ignore key release events
- if not is_press:
- return False
-
- if self._input_chars:
- if keyval == keysyms.Return:
- self._commit_string (self._input_chars)
- return True
- elif keyval == keysyms.Escape:
- self._reset ()
- return True
- elif keyval == keysyms.BackSpace:
- self._input_chars = self._input_chars[:self._cursor_pos - 1] + self._input_chars [self._cursor_pos:]
- self._invalidate ()
- return True
- elif keyval == keysyms.space:
- if not self._convert_begined:
- self._begine_convert ()
- self._invalidate ()
- else:
- self._cursor_down ()
- return True
- elif keyval >= keysyms._1 and keyval <= keysyms._9:
- index = keyval - keysyms._1
- candidates = self._lookup_table.get_canidates_in_current_page ()
- if index >= len (candidates):
- return False
- candidate = candidates[index][0]
- self._commit_string (candidate)
- return True
- elif keyval == keysyms.Page_Up or keyval == keysyms.KP_Page_Up:
- if self._lookup_table.page_up ():
- self._update_lookup_table ()
- return True
- elif keyval == keysyms.Up:
- self._cursor_up ()
- return True
- elif keyval == keysyms.Down:
- self._cursor_down ()
- return True
- elif keyval == keysyms.Left or keyval == keysyms.Right:
- return True
- elif keyval == keysyms.Page_Down or keyval == keysyms.KP_Page_Down:
- if self._lookup_table.page_down ():
- self._update_lookup_table ()
- return True
- if keyval in xrange (keysyms.a, keysyms.z + 1) or \
- keyval in xrange (keysyms.A, keysyms.Z + 1):
- if state & (keysyms.CONTROL_MASK | keysyms.ALT_MASK) == 0:
- self._input_chars += unichr (keyval)
- self._cursor_pos += 1
- self._invalidate ()
- return True
- else:
- if keyval < 128 and self._input_chars:
- self._commit_string (self._input_chars)
-
- return False
def _invalidate (self):
if self._need_update:
self._need_update = True
gobject.idle_add (self._update, priority = gobject.PRIORITY_LOW)
+ def _page_up (self):
+ # only process cursor down in convert mode
+ if not self._convert_begined:
+ return False
+
+ if not self._lookup_table.page_up ():
+ return False
+
+ candidate = self._lookup_table.get_current_candidate ()[0]
+ index = self._lookup_table.get_cursor_pos ()
+ self._segments[self._cursor_pos] = index, candidate
+ self._invalidate ()
+ return True
+
+ def _page_down (self):
+ # only process cursor down in convert mode
+ if not self._convert_begined:
+ return False
+
+ if not self._lookup_table.page_down ():
+ return False
+
+ candidate = self._lookup_table.get_current_candidate ()[0]
+ index = self._lookup_table.get_cursor_pos ()
+ self._segments[self._cursor_pos] = index, candidate
+ self._invalidate ()
+ return True
+
def _cursor_up (self):
# only process cursor down in convert mode
if not self._convert_begined:
attrs.to_dbus_value (),
dbus.Int32 (self._cursor_pos),
len (self._input_chars) > 0)
+ self.UpdateAuxString (u"", ibus.AttrList ().to_dbus_value (), False)
+ self.UpdateLookupTable (self._lookup_table.to_dbus_value (), self._lookup_table_visible)
def _update_convert_chars (self):
self._convert_chars = u""
i = 0
for seg_index, text in self._segments:
self._convert_chars += text
- if i < self._cursor_pos:
+ if i <= self._cursor_pos:
pos += len (text)
i += 1
attrs.to_dbus_value (),
dbus.Int32 (pos),
True)
+ aux_string = u"( %d / %d )" % (self._lookup_table.get_cursor_pos () + 1, self._lookup_table.get_number_of_candidates())
+ self.UpdateAuxString (aux_string, ibus.AttrList ().to_dbus_value (), self._lookup_table_visible)
+ self.UpdateLookupTable (self._lookup_table.to_dbus_value (), self._lookup_table_visible)
def _update (self):
self._need_update = False
- if self._convert_begined:
+ if self._convert_begined == False:
self._update_input_chars ()
else:
self._update_convert_chars ()
+ def _on_key_return (self):
+ if not self._input_chars:
+ return False
+ if self._convert_begined == False:
+ self._commit_string (self._input_chars)
+ else:
+ i = 0
+ for seg_index, text in self._segments:
+ self._context.commit_segment (i, seg_index)
+ self._commit_string (self._convert_chars)
+ return True
+
+ def _on_key_escape (self):
+ if not self._input_chars:
+ return False
+ self._reset ()
+ return True
+
+ def _on_key_back_space (self):
+ if not self._input_chars:
+ return False
+ self._input_chars = self._input_chars[:self._cursor_pos - 1] + self._input_chars [self._cursor_pos:]
+ self._invalidate ()
+ return True
+
+ def _on_key_space (self):
+ if not self._input_chars:
+ return False
+ if self._convert_begined == False:
+ self._begin_convert ()
+ self._invalidate ()
+ else:
+ self._lookup_table_visible = True
+ self._cursor_down ()
+ return True
+
+ def _on_key_up (self):
+ if not self._input_chars:
+ return False
+ self._lookup_table_visible = True
+ self._cursor_up ()
+ return True
+
+ def _on_key_down (self):
+ if not self._input_chars:
+ return False
+ self._lookup_table_visible = True
+ self._cursor_down ()
+ return True
+
+ def _on_key_page_up (self):
+ if not self._input_chars:
+ return False
+ if self._lookup_table_visible == True:
+ self._page_up ()
+ return True
+
+ def _on_key_page_down (self):
+ if not self._input_chars:
+ return False
+ if self._lookup_table_visible == True:
+ self._page_down ()
+ return True
+
+ def _on_key_left (self):
+ if not self._input_chars:
+ return False
+ if self._cursor_pos == 0:
+ return True
+ self._cursor_pos -= 1
+ self._lookup_table_visible = False
+ self._fill_lookup_table ()
+ self._invalidate ()
+ return True
+
+ def _on_key_right (self):
+ if not self._input_chars:
+ return False
+
+ if self._convert_begined:
+ max_pos = len (self._segments) - 1
+ else:
+ max_pos = len (self._input_chars)
+ if self._cursor_pos == max_pos:
+ return True
+ self._cursor_pos += 1
+ self._lookup_table_visible = False
+ self._fill_lookup_table ()
+ self._invalidate ()
+
+ return True
+
+ def _on_key_number (self, index):
+ if not self._input_chars:
+ return False
+
+ if self._convert_begined and self._lookup_table_visible:
+ 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]
+ self._segments[self._cursor_pos] = index, candidate
+ self._lookup_table_visible = False
+ self._on_key_right ()
+ self._invalidate ()
+ return True
+
+
+ def _on_key_common (self, keyval):
+ self._input_chars += unichr (keyval)
+ self._cursor_pos += 1
+ self._invalidate ()
+ return True
+
+ def _process_key_event (self, keyval, is_press, state):
+ # ignore key release events
+ if not is_press:
+ return False
+
+ if keyval == keysyms.Return:
+ return self._on_key_return ()
+ elif keyval == keysyms.Escape:
+ return self._on_key_escape ()
+ elif keyval == keysyms.BackSpace:
+ return self._on_key_back_space ()
+ elif keyval == keysyms.space:
+ return self._on_key_space ()
+ elif keyval >= keysyms._1 and keyval <= keysyms._9:
+ index = keyval - keysyms._1
+ return self._on_key_number (index)
+ elif keyval == keysyms.Page_Up or keyval == keysyms.KP_Page_Up:
+ return self._on_key_page_up ()
+ elif keyval == keysyms.Page_Down or keyval == keysyms.KP_Page_Down:
+ return self._on_key_page_down ()
+ elif keyval == keysyms.Up:
+ return self._on_key_up ()
+ elif keyval == keysyms.Down:
+ return self._on_key_down ()
+ elif keyval == keysyms.Left:
+ return self._on_key_left ()
+ elif keyval == keysyms.Right:
+ return self._on_key_right ()
+ elif keyval in xrange (keysyms.a, keysyms.z + 1) or \
+ keyval in xrange (keysyms.A, keysyms.Z + 1):
+ return self._on_key_common (keyval)
+ else:
+ return True
+
+ return False
+
# methods for dbus rpc
def ProcessKeyEvent (self, keyval, is_press, state):
try:
print "Reset"
def PageUp (self):
- print "PageUp"
+ self._page_up ()
def PageDown (self):
- print "PageDown"
+ self._page_down ()
def CursorUp (self):
self._cursor_up ()