# methods for dbus rpc
def ProcessKeyEvent (self, keyval, is_press, state):
+ try:
+ return self._process_key_event (keyval, is_press, state)
+ except Exception, e:
+ print e
+ return False
+ def _process_key_event (self, keyval, is_press, state):
# ignore key release events
if not is_press:
return False
if self._preedit_string:
if keyval == keysyms.Return:
- self.CommitString (self._preedit_string)
- self._preedit_string = ""
- self._update ()
+ self._commit_string (self._preedit_string)
return True
elif keyval == keysyms.BackSpace:
self._preedit_string = self._preedit_string[:-1]
self._update ()
return True
elif keyval == keysyms.space:
- self.CommitString (self._preedit_string)
+ self._commit_string (self._preedit_string)
self._preedit_string = ""
self._update ()
return False
if index >= len (candidates):
return False
candidate = candidates[index][0]
- self.CommitString (candidate + " ")
- self._preedit_string = ""
- self._update ()
+ 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
else:
if keyval < 128 and self._preedit_string:
- self.CommitString (self._preedit_string)
- self._preedit_string = ""
- self._update ()
+ self._commit_string (self._preedit_string)
+
+ return False
+ def _cursor_up (self):
+ if self._lookup_table.cursor_up ():
+ self._update_lookup_table ()
+ return True
return False
+
+ def _cursor_down (self):
+ if self._lookup_table.cursor_down ():
+ self._update_lookup_table ()
+ return True
+ return False
+
+ def _commit_string (self, text):
+ self._preedit_string = ""
+ self._update ()
+ self.CommitString (text)
def _update (self):
preedit_len = len (self._preedit_string)
def Reset (self):
print "Reset"
+ def PageUp (self):
+ print "PageUp"
+
+ def PageDown (self):
+ print "PageDown"
+
+ def CursorUp (self):
+ print "CursorUp"
+ self._cursor_up ()
+
+ def CursorDown (self):
+ self._cursor_down ()
+ print "CursorDown"
+
def SetEnable (self, enable):
self._enable = enable
@method ()
def Reset (self): pass
-
+
+ # signals for lookup table
+ @method ()
+ def PageUp (self): pass
+
+ @method ()
+ def PageDown (self): pass
+
+ @method ()
+ def CursorUp (self): pass
+
+ @method ()
+ def CursorDown (self): pass
+
@method (in_signature = "b")
def SetEnable (self, enable): pass
def PageDown (self): pass
@signal ()
- def CursorBack (self): pass
+ def CursorUp (self): pass
@signal ()
- def CursorForward (self): pass
+ def CursorDown (self): pass
def register_client (self, name, dbusconn):
ibusconn = self._lookup_ibus_connection (dbusconn)
client = self._client_manager.register_client (name, ibusconn)
+ client.connect ("destroy", self._client_destroy_cb)
factory = self._factory_manager.get_default_factory ()
if factory:
engine = factory.create_engine ()
self._panel.hide_candidate_window ()
+ def _client_destroy_cb (self, client):
+ if client == self._focused_client:
+ del self._client_handlers[:]
+ self._focused_client = None
+
##########################################################
# methods for im engines
##########################################################
self._panel.destroy ()
ibusconn = self._lookup_ibus_connection (dbusconn)
self._panel = Panel (ibusconn, object_path)
+ self._panel.connect ("page-up", self._panel_page_up_cb)
+ self._panel.connect ("page-down", self._panel_page_down_cb)
+ self._panel.connect ("cursor-up", self._panel_cursor_up_cb)
+ self._panel.connect ("cursor-down", self._panel_cursor_down_cb)
self._panel.connect ("destroy", self._panel_destroy_cb)
+ def _panel_page_up_cb (self, panel):
+ assert panel == self._panel
+ if self._focused_client:
+ self._focused_client.page_up ()
+
+ def _panel_page_down_cb (self, panel):
+ assert panel == self._panel
+ if self._focused_client:
+ self._focused_client.page_down ()
+
+ def _panel_cursor_up_cb (self, panel):
+ assert panel == self._panel
+ if self._focused_client:
+ self._focused_client.cursor_up ()
+
+ def _panel_cursor_down_cb (self, panel):
+ assert panel == self._panel
+ if self._focused_client:
+ self._focused_client.cursor_down ()
def _panel_destroy_cb (self, panel):
- if panel == self._panel:
- self._panel = DummyPanel ()
+ assert panel == self._panel
+ self._panel = DummyPanel ()
class IBusProxy (ibus.IIBus):
SUPPORTS_MULTIPLE_CONNECTIONS = True
if self._engine:
self._engine.reset ()
+ def page_up (self):
+ if self._engine:
+ self._engine.page_up ()
+
+ def page_down (self):
+ if self._engine:
+ self._engine.page_down ()
+
+ def cursor_up (self):
+ if self._engine:
+ self._engine.cursor_up ()
+
+ def cursor_down (self):
+ if self._engine:
+ self._engine.cursor_down ()
+
def is_enabled (self):
return self._enable
def set_enable (self, enable):
self._engine.SetEnable (enable)
+ # cursor for lookup table
+
+ def page_up (self):
+ self._engine.PageUp ()
+
+ def page_down (self):
+ self._engine.PageDown ()
+
+ def cursor_up (self):
+ self._engine.CursorUp ()
+
+ def cursor_down (self):
+ self._engine.CursorDown ()
+
def destroy (self):
ibus.Object.destroy (self)
if self._engine:
import weakref
import gobject
import ibus
-from ibus import interface
class Panel (ibus.Object):
+ __gsignals__ = {
+ "page-up" : (
+ gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ()),
+ "page-down" : (
+ gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ()),
+ "cursor-up" : (
+ gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ()),
+ "cursor-down" : (
+ gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ()),
+ }
+
def __init__ (self, ibusconn, object_path):
ibus.Object.__init__ (self)
self._ibusconn = ibusconn
self.destroy ()
def _dbus_signal_cb (self, ibusconn, message):
- if message.is_signal (interface.IBUS_PANEL_IFACE, "PageUp"):
- pass
- elif message.is_signal (interface.IBUS_PANEL_IFACE, "PageDown"):
- pass
- elif message.is_signal (interface.IBUS_PANEL_IFACE, "CursorBack"):
- pass
- elif message.is_signal (interface.IBUS_PANEL_IFACE, "CursorForward"):
- pass
+ if message.is_signal (ibus.IBUS_PANEL_IFACE, "PageUp"):
+ self.emit ("page-up")
+ elif message.is_signal (ibus.IBUS_PANEL_IFACE, "PageDown"):
+ self.emit ("page-down")
+ elif message.is_signal (ibus.IBUS_PANEL_IFACE, "CursorUp"):
+ self.emit ("cursor-up")
+ elif message.is_signal (ibus.IBUS_PANEL_IFACE, "CursorDown"):
+ self.emit ("cursor-down")
# methods for cmp
# def __lt__ (self, other):
# if x[1] > y[1]: return True
# if x[1] == y[1]: return x[0] > y[0]
+gobject.type_register (Panel)
+
class DummyPanel:
pass
gobject.PARAM_READWRITE) # flags
}
+ __gsignals__ = {
+ "cursor-up" : (
+ gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ()),
+ "cursor-down" : (
+ gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ()),
+ }
+
def __init__ (self):
gtk.VBox.__init__ (self)
self._tooltips = gtk.Tooltips ()
# create candidates area
self._candidate_area = CandidateArea (self._orientation)
- candidates = []
- for i in xrange (0, 7):
- candidates.append (("你好", pango.AttrList ()))
- self._candidate_area.set_candidates (candidates)
# create state label
self._state_label = gtk.Label ()
# create buttons
self._prev_button = gtk.Button ()
+ self._prev_button.connect ("clicked", lambda x: self.emit ("cursor-up"))
self._prev_button.set_relief (gtk.RELIEF_NONE)
self._tooltips.set_tip (self._prev_button, "Previous candidate")
self._next_button = gtk.Button ()
+ self._next_button.connect ("clicked", lambda x: self.emit ("cursor-down"))
self._next_button.set_relief (gtk.RELIEF_NONE)
self._tooltips.set_tip (self._next_button, "Next candidate")
self._lookup_table = lookup_table
candidates = self._lookup_table.get_canidates_in_current_page ()
candidates = map (lambda x: (x[0], PangoAttrList (x[1])), candidates)
- self._candidate_area.set_candidates (candidates)
+ self._candidate_area.set_candidates (candidates, self._lookup_table.get_cursor_pos_in_current_page ())
def set_orientation (self, orientation):
if self._orientation == orientation:
from candidatepanel import CandidatePanel
class CandidateWindow (gtk.Window):
+ __gsignals__ = {
+ "cursor-up" : (
+ gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ()),
+ "cursor-down" : (
+ gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ()),
+ }
+
def __init__ (self):
gtk.Window.__init__ (self, gtk.WINDOW_POPUP)
self.add_events (
self._candidate_panel = CandidatePanel ()
self._begin_move = False
self._candidate_panel.connect ("size-request", self._size_request_cb)
+ self._candidate_panel.connect ("cursor-up", lambda x: self.emit ("cursor-up"))
+ self._candidate_panel.connect ("cursor-down", lambda x: self.emit ("cursor-down"))
self.add (self._candidate_panel)
self.move (100, 100)
self.show_all ()
self._proxy = proxy
self._language_bar = LanguageBarWindow ()
self._candidate_panel = CandidateWindow ()
+ self._candidate_panel.connect ("cursor-up", lambda x: self._proxy.CursorUp ())
+ self._candidate_panel.connect ("cursor-down", lambda x: self._proxy.CursorDown ())
def set_cursor_location (self, x, y, w, h):
self._candidate_panel.move (x + w, y + h)