summaryrefslogtreecommitdiffstats
path: root/daemon/bus.py
blob: b8eee23a58f8519895853db4f5c86843403070e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
# vim:set et sts=4 sw=4:
#
# ibus - The Input Bus
#
# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA

import sys
import dbus
import ibus
from ibus import keysyms
from ibus import modifier
from connection import Connection
from contextmanager import ContextManager
from factorymanager import FactoryManager
from panel import Panel, DummyPanel
from config import Config, DefaultConfig
from register import Register

CONFIG_GENERAL_SHORTCUT_TRIGGER     =  "/general/keyboard_shortcut_trigger"
CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE =  "/general/keyboard_shortcut_next_engine"
CONFIG_GENERAL_SHORTCUT_PREV_ENGINE =  "/general/keyboard_shortcut_prev_engine"

class IBus(ibus.Object):
    def __init__(self):
        super(IBus, self).__init__()
        self.__context_manager = ContextManager()
        self.__factory_manager = FactoryManager()

        self.__panel = DummyPanel()
        self.__panel_handlers = list()
        self.__install_panel_handlers()

        self.__config = DefaultConfig()
        self.__config_handlers = list()
        self.__install_config_handlers()

        self.__register = Register()

        self.__config_watch = dict()

        self.__focused_context = None
        self.__last_focused_context = None
        self.__context_handlers = list()

        self.__connections = list()

        self.__prev_key = None

        self.__shortcut_trigger = self.__load_config_shortcut(
                CONFIG_GENERAL_SHORTCUT_TRIGGER, ["Ctrl+space"])
        self.__shortcut_next_engine = self.__load_config_shortcut(
                CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE,
                ["Ctrl+Shift+Release+Shift_L", "Ctrl+Shift+Release+Shift_R"])
        self.__shortcut_prev_engine = self.__load_config_shortcut(
                CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE, [])

    def __load_config_shortcut(self, config_key, default_value):

        # load trigger
        shortcut_strings = default_value
        try:
            shortcut_strings = self.__config.get_value(config_key)
        except:
            pass
        shortcuts = []
        for s in shortcut_strings:
            keyval, keymask = self.__parse_shortcut_string(s)
            if keyval != 0:
                shortcuts.append((keyval, keymask))
        return shortcuts

    def new_connection(self, dbusconn):
        conn = Connection(dbusconn)
        IBusProxy(self, conn)
        conn.connect("destroy", self.__conn_destroy_cb)
        self.__connections.append(conn)

    def __conn_destroy_cb(self, conn):
        for key in conn.config_get_watch():
            self.config_remove_watch(key, conn)
        self.__connections.remove(conn)

    ##########################################################
    # methods for im context
    ##########################################################
    def create_input_context(self, name, conn):
        context = self.__context_manager.create_input_context(name, conn)
        factory = self.__factory_manager.get_default_factory()
        if factory:
            engine = factory.create_engine()
            context.set_engine(engine)
        return context.get_id()

    def release_input_context(self, ic, conn):
        self.__context_manager.release_input_context(ic, conn)

    def focus_in(self, ic, conn):
        context = self.__lookup_context(ic, conn)

        if self.__focused_context != context and self.__focused_context != None:
            self.__remove_focused_context_handlers()
            self.__focused_context.focus_out()

        self.__focused_context = context
        self.__install_focused_context_handlers()

        self.__panel.focus_in(context.get_id())
        self.__last_focused_context = context
        context.focus_in()
        self.__prev_key = None

    def focus_out(self, ic, conn):
        context = self.__lookup_context(ic, conn)

        if context == self.__focused_context:
            self.__remove_focused_context_handlers()
            self.__focused_context = None

        context.focus_out()
        self.__panel.focus_out(context.get_id())

    def reset(self, ic, conn):
        context = self.__lookup_context(ic, conn)
        context.reset()

    def is_enabled(self, ic, conn):
        context = self.__lookup_context(ic, conn)
        return context.is_enabled()

    def set_capabilities(self, ic, caps, conn):
        context = self.__lookup_context(ic, conn)
        return context.set_capabilities(caps)

    def process_key_event(self, ic, keyval, is_press, state,
                                conn, reply_cb, error_cb):
        context = self.__lookup_context(ic, conn)

        if self.__filter_keyboard_shortcuts(context, keyval, is_press, state):
            reply_cb(True)
            return
        else:
            context.process_key_event(keyval, is_press, state, reply_cb, error_cb)

    def set_cursor_location(self, ic, x, y, w, h, conn):
        context = self.__lookup_context(ic, conn)
        context.set_cursor_location(x, y, w, h)
        if context == self.__focused_context:
            self.__panel.set_cursor_location(x, y, w, h)

    def __context_enable(self, context):
        if context.get_engine() == None:
            factory = self.__factory_manager.get_default_factory()
            if factory:
                engine = factory.create_engine()
                engine.focus_in()
                context.set_engine(engine)
        context.set_enable(True)
        self.__panel.states_changed()

    def __context_disable(self, context):
        context.set_enable(False)
        self.__panel.reset()
        self.__panel.states_changed()

    def __context_next_factory(self, context):
        old_factory = context.get_factory()
        new_factory = self.__factory_manager.get_next_factory(old_factory)
        engine = new_factory.create_engine()
        engine.focus_in()
        context.set_engine(engine)
        self.__panel.states_changed()

    def __match_keyboard_shortcuts(self, keyval, is_press, state, shortcuts):
        for sc in shortcuts:
            if state == sc[1] and keyval == sc[0]:
                if state & modifier.RELEASE_MASK == 0:
                    return True
                if self.__prev_key[0] == keyval and \
                    self.__prev_key[1] == True:
                    return True
        return False

    def __filter_keyboard_shortcuts(self, context, keyval, is_press, state):
        state = state & (modifier.CONTROL_MASK | \
            modifier.SHIFT_MASK | \
            modifier.MOD1_MASK | \
            modifier.SUPER_MASK | \
            modifier.HYPER_MASK | \
            modifier.META_MASK)
        if not is_press:
            state = state | modifier.RELEASE_MASK

        retval = True
        if self.__match_keyboard_shortcuts(keyval,
            is_press, state, self.__shortcut_trigger):
            if context.is_enabled():
                self.__context_disable(context)
            else:
                self.__context_enable(context)
            retval = True
        elif self.__match_keyboard_shortcuts(keyval,
            is_press, state, self.__shortcut_next_engine):
            if not context.is_enabled():
                self.__context_enable(context)
            else:
                self.__context_next_factory(context)
        else:
            retval = False

        self.__prev_key = (keyval, is_press, state)
        return retval

    def __lookup_context(self, ic, conn):
        return self.__context_manager.lookup_context(ic, conn)

    def __install_focused_context_handlers(self):
        # Install all callback functions
        if self.__focused_context == None:
            return
        signals = (
            ("update-preedit", self.__update_preedit_cb),
            ("show-preedit", self.__show_preedit_cb),
            ("hide-preedit", self.__hide_preedit_cb),
            ("update-aux-string", self.__update_aux_string_cb),
            ("show-aux-string", self.__show_aux_string_cb),
            ("hide-aux-string", self.__hide_aux_string_cb),
            ("update-lookup-table", self.__update_lookup_table_cb),
            ("show-lookup-table", self.__show_lookup_table_cb),
            ("hide-lookup-table", self.__hide_lookup_table_cb),
            ("page-up-lookup-table", self.__page_up_lookup_table_cb),
            ("page-down-lookup-table", self.__page_down_lookup_table_cb),
            ("cursor-up-lookup-table", self.__cursor_up_lookup_table_cb),
            ("cursor-down-lookup-table", self.__cursor_down_lookup_table_cb),
            ("register-properties", self.__register_properties_cb),
            ("update-property", self.__update_property_cb),
            ("engine-lost", self.__engine_lost_cb),
            ("destroy", self.__context_destroy_cb)
        )
        for name, handler in signals:
            id = self.__focused_context.connect(name, handler)
            self.__context_handlers.append(id)

    def __remove_focused_context_handlers(self):
        if self.__focused_context == None:
            return
        map(self.__focused_context.disconnect, self.__context_handlers)
        self.__context_handlers = []

    def __update_preedit_cb(self, context, text, attrs, cursor_pos, visible):
        assert self.__focused_context == context
        self.__panel.update_preedit(text, attrs, cursor_pos, visible)

    def __show_preedit_cb(self, context):
        assert self.__focused_context == context
        self.__panel.show_preedit()

    def __hide_preedit_cb(self, context):
        assert self.__focused_context == context
        self.__panel.hide_preedit()

    def __update_aux_string_cb(self, context, text, attrs, visible):
        assert self.__focused_context == context
        self.__panel.update_aux_string(text, attrs, visible)

    def __show_aux_string_cb(self, context):
        assert self.__focused_context == context
        self.__panel.show_aux_string()

    def __hide_aux_string_cb(self, context):
        assert self.__focused_context == context
        self.__panel.hide_aux_string()

    def __update_lookup_table_cb(self, context, lookup_table, visible):
        assert self.__focused_context == context
        self.__panel.update_lookup_table(lookup_table, visible)

    def __show_lookup_table_cb(self, context):
        assert self.__focused_context == context
        self.__panel.show_lookup_table()

    def __hide_lookup_table_cb(self, context):
        assert self.__focused_context == context
        self.__panel.hide_lookup_table()

    def __page_up_lookup_table_cb(self, context):
        assert self.__focused_context == context
        self.__panel.page_up_lookup_table()

    def __page_down_lookup_table_cb(self, context):
        assert self.__focused_context == context
        self.__panel.page_down_lookup_table()

    def __cursor_up_lookup_table_cb(self, context):
        assert self.__focused_context == context
        self.__panel.cursor_up_lookup_table()

    def __cursor_down_lookup_table_cb(self, context):
        assert self.__focused_context == context
        self.__panel.cursor_down_lookup_table()

    def __register_properties_cb(self, context, props):
        assert self.__focused_context == context
        self.__panel.register_properties(props)


    def __update_property_cb(self, context, prop):
        assert self.__focused_context == context
        self.__panel.update_property(prop)

    def __engine_lost_cb(self, context):
        assert self.__focused_context == context
        self.__panel.reset()

    def __context_destroy_cb(self, context):
        assert context == self.__focused_context
        self.__remove_focused_context_handlers()
        self.__panel.focus_out(context.get_id())
        self.__focused_context = None

    ##########################################################
    # methods for im engines
    ##########################################################
    def register_factories(self, object_paths, conn):
        self.__factory_manager.register_factories(object_paths, conn)


    ##########################################################
    # methods for panel
    ##########################################################
    def register_panel(self, object_path, replace, conn):
        if not isinstance(self.__panel, DummyPanel) and replace == False:
            raise ibus.Exception("has have a panel!")
        self.__uninstall_panel_handlers()
        self.__panel.destroy()

        self.__panel = Panel(conn, object_path)
        self.__install_panel_handlers()
        if self.__focused_context:
            self.__panel.focus_in(self.__focused_context.get_id())

    def __install_panel_handlers(self):
        signals = (
            ("page-up", self.__panel_page_up_cb),
            ("page-down", self.__panel_page_down_cb),
            ("cursor-up", self.__panel_cursor_up_cb),
            ("cursor-down", self.__panel_cursor_down_cb),
            ("property-activate", self.__panel_property_active_cb),
            ("property-show", self.__panel_property_show_cb),
            ("property-hide", self.__panel_property_hide_cb),
            ("destroy", self.__panel_destroy_cb)
        )

        for signal, handler in signals:
            id = self.__panel.connect(signal, handler)
            self.__panel_handlers.append(id)

    def __uninstall_panel_handlers(self):
        map(lambda id:self.__panel.disconnect(id), self.__panel_handlers)
        self.__panel_handlers = list()


    def __panel_page_up_cb(self, panel):
        assert panel == self.__panel
        if self.__focused_context:
            self.__focused_context.page_up()

    def __panel_page_down_cb(self, panel):
        assert panel == self.__panel
        if self.__focused_context:
            self.__focused_context.page_down()

    def __panel_cursor_up_cb(self, panel):
        assert panel == self.__panel
        if self.__focused_context:
            self.__focused_context.cursor_up()

    def __panel_cursor_down_cb(self, panel):
        assert panel == self.__panel
        if self.__focused_context:
            self.__focused_context.cursor_down()

    def __panel_property_active_cb(self, panel, prop_name, prop_state):
        assert panel == self.__panel
        if self.__focused_context:
            self.__focused_context.property_activate(prop_name, prop_state)

    def __panel_property_show_cb(self, panel, prop_name):
        assert panel == self.__panel
        if self.__focused_context:
            self.__focused_context.property_show(prop_name)

    def __panel_property_hide_cb(self, panel, prop_name):
        assert panel == self.__panel
        if self.__focused_context:
            self.__focused_context.property_hide(prop_name)

    def __panel_destroy_cb(self, panel):
        if panel == self.__panel:
            self.__panel = DummyPanel()

    ##########################################################
    # methods for panel
    ##########################################################
    def register_config(self, object_path, replace, conn):
        if not isinstance(self.__config, DefaultConfig) and replace == False:
            raise ibus.Exception("has have a config!")
        self.__uninstall_config_handlers()
        self.__config.destroy()
        self.__config = Config(conn, object_path)
        self.__install_config_handlers()
        for conn in self.__connections:
            conn.emit_dbus_signal("ConfigReload")

    def __install_config_handlers(self):
        signals = (
            ("value-changed", self.__config_value_changed_cb),
            ("destroy", self.__config_destroy_cb)
        )
        for signal, handler in signals:
            id = self.__config.connect(signal, handler)
            self.__config_handlers.append(id)

    def __uninstall_config_handlers(self):
        map(lambda id:self.__config.disconnect(id), self.__config_handlers)
        self.__config_handlers = list()

    def config_set_value(self, key, value, conn, **kargs):
        return self.__config.set_value(key, value, **kargs)

    def config_get_value(self, key, conn, **kargs):
        return self.__config.get_value(key, **kargs)

    def config_add_watch(self, key, conn):
        if not key.endswith("/"):
            key += "/"

        if conn.config_add_watch(key):
            if key not in self.__config_watch:
                self.__config_watch[key] = set()
            self.__config_watch[key].add(conn)

    def config_remove_watch(self, key, conn):
        if not key.endswith("/"):
            key += "/"

        if conn.config_remove_watch(key):
            if key in self.__config_watch:
                self.__config_watch[key].remove(conn)

    def __parse_shortcut_string(self, string):
        keys = string.split("+")
        keymask = 0
        for name, mask in modifier.MODIFIER_NAME_TABLE:
            if name in keys[:-1]:
                keymask |= mask
            keyname = keys[-1]
            if keyname[0] in "1234567890":
                keyname = "_" + keyname
            keyval = keysyms.__dict__.get(keyname, 0)

        return keyval, keymask

    def __config_value_changed_cb(self, config, key, value):
        for _dir in self.__config_watch.keys():
            if key.startswith(_dir):
                for conn in self.__config_watch[_dir]:
                    conn.emit_dbus_signal("ConfigValueChanged", key, value)

        # check daemon configure
        if key == CONFIG_GENERAL_SHORTCUT_TRIGGER:
            self.__shortcut_trigger = self.__load_config_shortcut(
                CONFIG_GENERAL_SHORTCUT_TRIGGER, ["Ctrl+space"])
        elif key == CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE:
            self.__shortcut_next_engine = self.__load_config_shortcut(
                CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE,
                ["Ctrl+Shift+Release+Shift_L", "Ctrl+Shift+Release+Shift_R"])
        elif key == CONFIG_GENERAL_SHORTCUT_PREV_ENGINE:
            self.__shortcut_prev_engine = self.__load_config_shortcut(
                CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE, [])

    def __config_destroy_cb(self, config):
        if config == self.__config:
            self.__config = DefaultConfig()

    ##########################################################
    # engine register methods
    ##########################################################
    def register_list_engines(self, conn):
        return self.__register.list_engines()

    def register_reload_engines(self, conn):
        return self.__register.reload_engines()

    def register_start_engine(self, lang, name, conn):
        return self.__register.start_engine(lang, name)

    def register_restart_engine(self, lang, name, conn):
        return self.__register.restart_engine(lang, name)

    def register_stop_engine(self, lang, name, conn):
        return self.__register.stop_engine(lang, name)

    ##########################################################
    # general methods
    ##########################################################
    def get_factories(self):
        return self.__factory_manager.get_factories()

    def get_factory_info(self, factory_path):
        return self.__factory_manager.get_factory_info(factory_path)

    def set_factory(self, factory_path):
        if self.__focused_context == None:
            return
        self.__panel.reset()
        factory = self.__factory_manager.get_factory(factory_path)
        engine = factory.create_engine()
        self.__focused_context.set_engine(engine)
        self.__focused_context.set_enable(True)
        engine.focus_in()
        self.__panel.states_changed()

    def get_input_context_states(self, ic, conn):
        factory_path = ""
        context = self.__lookup_context(ic, conn)
        if context.get_factory() != None:
            factory_path = context.get_factory().get_object_path()
        return factory_path, context.is_enabled()

    def kill(self, conn):
        print "be killed"
        sys.exit(0)


class IBusProxy(ibus.IIBus):
    def __init__(self, bus, conn):
        super(IBusProxy, self).__init__(conn.get_dbusconn(), ibus.IBUS_PATH)
        self.__ibus = bus
        self.__conn = conn
        self.__conn.connect("destroy", self.__conn_destroy_cb)

    def __conn_destroy_cb(self, conn):
        self.__conn = None
        self.__ibus = None

    def GetIBusAddress(self, dbusconn):
        return self.__ibus_addr

    def CreateInputContext(self, context_name, dbusconn):
        return self.__ibus.create_input_context(context_name, self.__conn)

    def ReleaseInputContext(self, ic, dbusconn):
        self.__ibus.release_input_context(ic, self.__conn)

    def RegisterFactories(self, object_paths, dbusconn):
        self.__ibus.register_factories(object_paths, self.__conn)

    def UnregisterEngines(self, object_paths, dbusconn):
        self.__ibus.unregister_engines(object_paths, self.__conn)

    def RegisterPanel(self, object_path, replace, dbusconn):
        self.__ibus.register_panel(object_path, replace, self.__conn)

    def RegisterConfig(self, object_path, replace, dbusconn):
        self.__ibus.register_config(object_path, replace, self.__conn)

    def ProcessKeyEvent(self, ic, keyval, is_press, state, \
                            dbusconn, reply_cb, error_cb):
        try:
            self.__ibus.process_key_event(ic, keyval, is_press, state,
                            self.__conn, reply_cb, error_cb)
        except Exception, e:
            error_cb(e)

    def SetCursorLocation(self, ic, x, y, w, h, dbusconn):
        self.__ibus.set_cursor_location(ic, x, y, w, h, self.__conn)

    def FocusIn(self, ic, dbusconn):
        self.__ibus.focus_in(ic, self.__conn)

    def FocusOut(self, ic, dbusconn):
        self.__ibus.focus_out(ic, self.__conn)

    def Reset(self, ic, dbusconn):
        self.__ibus.reset(ic, self.__conn)

    def IsEnabled(self, ic, dbusconn):
        return self.__ibus.is_enabled(ic, self.__conn)

    def SetCapabilities(self, ic, caps, dbusconn):
        return self.__ibus.set_capabilities(ic, caps, self.__conn)

    def GetFactories(self, dbusconn):
        return self.__ibus.get_factories()

    def GetFactoryInfo(self, factory_path, dbusconn):
        return self.__ibus.get_factory_info(factory_path)

    def SetFactory(self, factory_path, dbusconn):
        return self.__ibus.set_factory(factory_path)

    def GetInputContextStates(self, ic, dbusconn):
        return self.__ibus.get_input_context_states(ic, self.__conn)

    def ConfigAddWatch(self, key, dbusconn):
        return self.__ibus.config_add_watch(key, self.__conn)

    def ConfigRemoveWatch(self, key, dbusconn):
        return self.__ibus.config_remove_watch(key, self.__conn)

    def ConfigSetValue(self, key, value, dbusconn, reply_cb, error_cb):
        self.__ibus.config_set_value(key, value, self.__conn,
                reply_handler = reply_cb,
                error_handler = error_cb)

    def ConfigGetValue(self, key, dbusconn, reply_cb, error_cb):
        self.__ibus.config_get_value(key, self.__conn,
                reply_handler = reply_cb,
                error_handler = error_cb)

    def RegisterListEngines(self, dbusconn):
        return self.__ibus.register_list_engines(self.__conn)

    def RegisterReloadEngines(self, dbusconn):
        return self.__ibus.register_reload_engines(self.__conn)

    def RegisterStartEngine(self, lang, name, dbusconn):
        return self.__ibus.register_start_engine(lang, name, self.__conn)

    def RegisterRestartEngine(self, lang, name, dbusconn):
        return self.__ibus.register_restart_engine(lang, name, self.__conn)

    def RegisterStopEngine(self, lang, name, dbusconn):
        return self.__ibus.register_stop_engine(lang, name, self.__conn)

    def Kill(self, dbusconn, reply_cb, error_cb):
        reply_cb()
        self.__ibus.kill(self.__conn)