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
26 class Engine (ibus
.Object
):
29 gobject
.SIGNAL_RUN_FIRST
,
31 (gobject
.TYPE_PYOBJECT
, )),
32 "forward-key-event" : (
33 gobject
.SIGNAL_RUN_FIRST
,
35 (gobject
.TYPE_UINT
, gobject
.TYPE_BOOLEAN
, gobject
.TYPE_UINT
)),
37 gobject
.SIGNAL_RUN_FIRST
,
39 (gobject
.TYPE_PYOBJECT
, gobject
.TYPE_PYOBJECT
, gobject
.TYPE_INT
, gobject
.TYPE_BOOLEAN
)),
40 "update-aux-string" : (
41 gobject
.SIGNAL_RUN_FIRST
,
43 (gobject
.TYPE_PYOBJECT
, gobject
.TYPE_PYOBJECT
, gobject
.TYPE_BOOLEAN
)),
44 "update-lookup-table" : (
45 gobject
.SIGNAL_RUN_FIRST
,
47 (gobject
.TYPE_PYOBJECT
, gobject
.TYPE_BOOLEAN
)),
48 "register-properties" : (
49 gobject
.SIGNAL_RUN_FIRST
,
51 (gobject
.TYPE_PYOBJECT
, )),
53 gobject
.SIGNAL_RUN_FIRST
,
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
):
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])
101 self
._engine
.FocusIn (**ibus
.DEFAULT_ASYNC_HANDLERS
)
103 def focus_out (self
):
104 self
._engine
.FocusOut (**ibus
.DEFAULT_ASYNC_HANDLERS
)
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
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
)
150 ibus
.Object
.destroy (self
)
152 self
._engine
.Destroy (**ibus
.DEFAULT_ASYNC_HANDLERS
)
154 self
._ibusconn
= None
156 def _ibusconn_destroy_cb (self
, ibusconn
):
160 gobject
.type_register (Engine
)