WIP.
[ibus.git] / daemon / engine.py
blob28b2481be4131aaea65f6ef0223f7decb41c3cdb
1 # vim:set noet ts=4:
3 # ibus - The Input Bus
5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA 02111-1307 USA
22 import weakref
23 import gobject
24 import ibus
26 class Engine (ibus.Object):
27 __gsignals__ = {
28 "commit-string" : (
29 gobject.SIGNAL_RUN_FIRST,
30 gobject.TYPE_NONE,
31 (gobject.TYPE_PYOBJECT, )),
32 "forward-key-event" : (
33 gobject.SIGNAL_RUN_FIRST,
34 gobject.TYPE_NONE,
35 (gobject.TYPE_UINT, gobject.TYPE_BOOLEAN, gobject.TYPE_UINT )),
36 "update-preedit" : (
37 gobject.SIGNAL_RUN_FIRST,
38 gobject.TYPE_NONE,
39 (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_INT, gobject.TYPE_BOOLEAN)),
40 "update-aux-string" : (
41 gobject.SIGNAL_RUN_FIRST,
42 gobject.TYPE_NONE,
43 (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN)),
44 "update-lookup-table" : (
45 gobject.SIGNAL_RUN_FIRST,
46 gobject.TYPE_NONE,
47 (gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN)),
48 "register-properties" : (
49 gobject.SIGNAL_RUN_FIRST,
50 gobject.TYPE_NONE,
51 (gobject.TYPE_PYOBJECT, )),
52 "update-property" : (
53 gobject.SIGNAL_RUN_FIRST,
54 gobject.TYPE_NONE,
55 (gobject.TYPE_PYOBJECT, )),
58 def __init__ (self, factory, ibusconn, object_path):
59 ibus.Object.__init__ (self)
60 self._factory = factory
61 self._ibusconn = ibusconn
62 self._object_path = object_path
63 self._engine = ibusconn.get_object (self._object_path)
64 self._lookup_table = ibus.LookupTable ()
65 self._ibusconn.connect ("destroy", self._ibusconn_destroy_cb)
67 def get_factory (self):
68 return self._factory
70 def get_object_path (self):
71 return self._object_path
73 def handle_dbus_signal (self, message):
74 if message.is_signal (ibus.IBUS_ENGINE_IFACE, "CommitString"):
75 args = message.get_args_list ()
76 self.emit ("commit-string", args[0])
77 elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "ForwardKeyEvent"):
78 args = message.get_args_list ()
79 self.emit ("forward-key-event", args[0], bool (arg[1]), arg[2])
80 elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "UpdatePreedit"):
81 args = message.get_args_list ()
82 self.emit ("update-preedit", args[0], args[1], args[2], args[3])
83 elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "UpdateAuxString"):
84 args = message.get_args_list ()
85 self.emit ("update-aux-string", args[0], args[1], args[2])
86 elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "UpdateLookupTable"):
87 args = message.get_args_list ()
88 self.emit ("update-lookup-table", args[0], args[1])
89 elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "RegisterProperties"):
90 args = message.get_args_list ()
91 self.emit ("register-properties", args[0])
92 elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "UpdateProperty"):
93 args = message.get_args_list ()
94 self.emit ("update-property", args[0])
95 else:
96 return False
98 return True
100 def focus_in (self):
101 self._engine.FocusIn (**ibus.DEFAULT_ASYNC_HANDLERS)
103 def focus_out (self):
104 self._engine.FocusOut (**ibus.DEFAULT_ASYNC_HANDLERS)
106 def reset (self):
107 self._engine.Reset (**ibus.DEFAULT_ASYNC_HANDLERS)
109 def process_key_event (self, keyval, is_press, state, reply_cb, error_cb):
110 self._engine.ProcessKeyEvent (keyval, is_press, state,
111 reply_handler = reply_cb,
112 error_handler = error_cb)
114 def set_cursor_location (self, x, y, w, h):
115 self._engine.SetCursorLocation (x, y, w, h,
116 **ibus.DEFAULT_ASYNC_HANDLERS)
119 def set_enable (self, enable):
120 self._engine.SetEnable (enable,
121 **ibus.DEFAULT_ASYNC_HANDLERS)
123 # cursor for lookup table
125 def page_up (self):
126 self._engine.PageUp (**ibus.DEFAULT_ASYNC_HANDLERS)
128 def page_down (self):
129 self._engine.PageDown (**ibus.DEFAULT_ASYNC_HANDLERS)
131 def cursor_up (self):
132 self._engine.CursorUp (**ibus.DEFAULT_ASYNC_HANDLERS)
134 def cursor_down (self):
135 self._engine.CursorDown (**ibus.DEFAULT_ASYNC_HANDLERS)
137 def property_activate (self, prop_name, prop_state):
138 self._engine.PropertyActivate (prop_name, prop_state,
139 **ibus.DEFAULT_ASYNC_HANDLERS)
141 def property_show (self, prop_name):
142 self._engine.PropertyShow (prop_name,
143 **ibus.DEFAULT_ASYNC_HANDLERS)
145 def property_hide (self, prop_name):
146 self._engine.PropertyHide (prop_name,
147 **ibus.DEFAULT_ASYNC_HANDLERS)
149 def destroy (self):
150 ibus.Object.destroy (self)
151 if self._engine:
152 self._engine.Destroy (**ibus.DEFAULT_ASYNC_HANDLERS)
153 self._engine = None
154 self._ibusconn = None
156 def _ibusconn_destroy_cb (self, ibusconn):
157 self._engine = None
158 self.destroy ()
160 gobject.type_register (Engine)