This commit is contained in:
Huang Peng 2008-07-25 14:51:33 +08:00
Родитель d2ad570e65
Коммит 2cc8ae3671
2 изменённых файлов: 405 добавлений и 371 удалений

Просмотреть файл

@ -33,368 +33,370 @@ from register import Register
class IBus(ibus.Object):
def __init__(self):
super(IBus, self).__init__()
self._context_manager = ContextManager()
self._factory_manager = FactoryManager()
self._panel = DummyPanel()
self._config = DummyConfig()
self._register = Register()
self._config_watch = dict()
self.__context_manager = ContextManager()
self.__factory_manager = FactoryManager()
self.__panel = DummyPanel()
self.__config = DummyConfig()
self.__register = Register()
self.__config_watch = dict()
self._focused_context = None
self._last_focused_context = None
self._context_handlers = list()
self.__focused_context = None
self.__last_focused_context = None
self.__context_handlers = list()
self._last_key = None
self.__last_key = None
##########################################################
# 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()
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)
self.__context_manager.release_input_context(ic, conn)
def focus_in(self, ic, conn):
context = self._lookup_context(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()
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.__focused_context = context
self.__install_focused_context_handlers()
self._panel.focus_in(context.get_id())
self._last_focused_context = context
self.__panel.focus_in(context.get_id())
self.__last_focused_context = context
context.focus_in()
def focus_out(self, ic, conn):
context = self._lookup_context(ic, conn)
context = self.__lookup_context(ic, conn)
if context == self._focused_context:
self._remove_focused_context_handlers()
self._focused_context = None
if context == self.__focused_context:
self.__remove_focused_context_handlers()
self.__focused_context = None
context.focus_out()
self._panel.focus_out(context.get_id())
self.__panel.focus_out(context.get_id())
def reset(self, ic, conn):
context = self._lookup_context(ic, conn)
context = self.__lookup_context(ic, conn)
context.reset()
def is_enabled(self, ic, conn):
context = self._lookup_context(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)
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)
context = self.__lookup_context(ic, conn)
if self._filter_hotkeys(context, keyval, is_press, state):
if self.__filter_hotkeys(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 = self.__lookup_context(ic, conn)
context.set_cursor_location(x, y, w, h)
self._panel.set_cursor_location(x, y, w, h)
self.__panel.set_cursor_location(x, y, w, h)
def _filter_hotkeys(self, context, keyval, is_press, state):
def __filter_hotkeys(self, context, keyval, is_press, state):
if is_press and keyval == keysyms.space \
and (state & ~modifier.MOD2_MASK) == modifier.CONTROL_MASK:
enable = not context.is_enabled()
if context.get_engine() == None and enable:
factory = self._factory_manager.get_default_factory()
factory = self.__factory_manager.get_default_factory()
if factory:
engine = factory.create_engine()
engine.focus_in()
context.set_engine(engine)
context.set_enable(enable)
self._panel.states_changed()
if not enable:
self.__panel.reset()
self.__panel.states_changed()
return True
return False
def _lookup_context(self, ic, conn):
return self._context_manager.lookup_context(ic, conn)
def __lookup_context(self, ic, conn):
return self.__context_manager.lookup_context(ic, conn)
def _install_focused_context_handlers(self):
def __install_focused_context_handlers(self):
# Install all callback functions
if self._focused_context == None:
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)
("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)
id = self.__focused_context.connect(name, handler)
self.__context_handlers.append(id)
def _remove_focused_context_handlers(self):
if self._focused_context == None:
def __remove_focused_context_handlers(self):
if self.__focused_context == None:
return
map(self._focused_context.disconnect, self._context_handlers)
self._context_handlers = []
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 __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 __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 __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 __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 __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 __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 __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 __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 __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_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 __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_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 __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 __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 __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 __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._focused_context = None
self._panel.reset()
def __context_destroy_cb(self, context):
assert context == self.__focused_context
self.__remove_focused_context_handlers()
self.__focused_context = None
self.__panel.reset()
##########################################################
# methods for im engines
##########################################################
def register_factories(self, object_paths, conn):
self._factory_manager.register_factories(object_paths, conn)
self.__factory_manager.register_factories(object_paths, conn)
def _lookup_engine(self, dbusconn, path):
return self._factory_manager.lookup_engine(conn, path)
def __lookup_engine(self, dbusconn, path):
return self.__factory_manager.lookup_engine(conn, path)
##########################################################
# methods for panel
##########################################################
def register_panel(self, object_path, replace, conn):
if not isinstance(self._panel, DummyPanel) and replace == False:
if not isinstance(self.__panel, DummyPanel) and replace == False:
raise ibus.Exception("has have a panel!")
if not isinstance(self._panel, DummyPanel):
self._panel.destroy()
self._panel = Panel(conn, 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("property-activate", self._panel_property_active_cb)
self._panel.connect("property-show", self._panel_property_show_cb)
self._panel.connect("property-hide", self._panel_property_hide_cb)
self._panel.connect("destroy", self._panel_destroy_cb)
if not isinstance(self.__panel, DummyPanel):
self.__panel.destroy()
self.__panel = Panel(conn, 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("property-activate", self.__panel_property_active_cb)
self.__panel.connect("property-show", self.__panel_property_show_cb)
self.__panel.connect("property-hide", self.__panel_property_hide_cb)
self.__panel.connect("destroy", self.__panel_destroy_cb)
def _panel_page_up_cb(self, panel):
assert panel == self._panel
if self._focused_context:
self._focused_context.page_up()
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_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_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_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_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_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_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()
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, DummyConfig) and replace == False:
if not isinstance(self.__config, DummyConfig) and replace == False:
raise ibus.Exception("has have a config!")
if not isinstance(self._config, DummyConfig):
self._config.destroy()
self._config = Config(conn, object_path)
self._config.connect("value-changed", self._config_value_changed_cb)
self._config.connect("destroy", self._config_destroy_cb)
if not isinstance(self.__config, DummyConfig):
self.__config.destroy()
self.__config = Config(conn, object_path)
self.__config.connect("value-changed", self.__config_value_changed_cb)
self.__config.connect("destroy", self.__config_destroy_cb)
def config_set_string(self, key, value, dbusconn, **kargs):
self._config.set_string(key, value, **kargs)
self.__config.set_string(key, value, **kargs)
def config_set_int(self, key, value, dbusconn, **kargs):
self._config.set_int(key, value, **kargs)
self.__config.set_int(key, value, **kargs)
def config_set_bool(self, key, value, dbusconn, **kargs):
self._config.set_bool(key, value, **kargs)
self.__config.set_bool(key, value, **kargs)
def config_get_string(self, key, dbusconn, **kargs):
self._config.get_string(key, value, **kargs)
self.__config.get_string(key, value, **kargs)
def config_get_int(self, key, dbusconn, **kargs):
self._config.get_int(key, value, **kargs)
self.__config.get_int(key, value, **kargs)
def config_get_bool(self, key, dbusconn, **kargs):
self._config.get_bool(key, value, **kargs)
self.__config.get_bool(key, value, **kargs)
def config_add_watch_dir(self, dir, conn, **kargs):
if not dir.endswith("/"):
dir += "/"
if conn.add_watch_dir(dir):
if dir not in self._config_watch:
self._config_watch[dir] = set()
self._config_watch[dir].add(conn)
if dir not in self.__config_watch:
self.__config_watch[dir] = set()
self.__config_watch[dir].add(conn)
def config_remove_watch_dir(self, dir, conn, **kargs):
if not dir.endswith("/"):
dir += "/"
if conn.remove_watch_dir(dir):
if dir in self._config_watch:
self._config_watch[dir].remove(conn)
if dir in self.__config_watch:
self.__config_watch[dir].remove(conn)
def _config_value_changed_cb(self, config, key, value):
for dir in self._config_watch.keys():
def __config_value_changed_cb(self, config, key, value):
for dir in self.__config_watch.keys():
if dir.startswith(key):
for conn in self._config[dir]:
for conn in self.__config[dir]:
conn.emit_dbus_signal("ConfigValueChanged", key, value)
def _config_destroy_cb(self, config, key, value):
if config == self._config:
self._config = DummyConfig()
def __config_destroy_cb(self, config, key, value):
if config == self.__config:
self.__config = DummyConfig()
##########################################################
# engine register methods
##########################################################
def register_list_engines(self, conn):
return self._register.list_engines()
return self.__register.list_engines()
def register_start_engine(self, lang, name, conn):
return self._register.start_engine(lang, name)
return self.__register.start_engine(lang, name)
def register_restart_engine(self, lang, name, conn):
return self._register.restart_engine(lang, name)
return self.__register.restart_engine(lang, name)
def register_stop_engine(self, lang, name, conn):
return self._register.stop_engine(lang, name)
return self.__register.stop_engine(lang, name)
##########################################################
# general methods
##########################################################
def get_factories(self):
return self._factory_manager.get_factories()
return self.__factory_manager.get_factories()
def get_factory_info(self, factory_path):
return self._factory_manager.get_factory_info(factory_path)
return self.__factory_manager.get_factory_info(factory_path)
def set_factory(self, factory_path):
if self._focused_context == None:
if self.__focused_context == None:
return
self._panel.reset()
factory = self._factory_manager.get_factory(factory_path)
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)
self.__focused_context.set_engine(engine)
self.__focused_context.set_enable(True)
engine.focus_in()
self._panel.states_changed()
self.__panel.states_changed()
def get_input_context_states(self, ic, conn):
factory_path = ""
context = self._lookup_context(ic, conn)
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()
@ -403,107 +405,107 @@ class IBus(ibus.Object):
class IBusProxy(ibus.IIBus):
def __init__(self, bus, dbusconn):
super(IBusProxy, self).__init__(dbusconn, ibus.IBUS_PATH)
self._ibus = bus
self._conn = Connection(dbusconn)
self.__ibus = bus
self.__conn = Connection(dbusconn)
def GetIBusAddress(self, dbusconn):
return self._ibus_addr
return self.__ibus_addr
def CreateInputContext(self, context_name, dbusconn):
return self._ibus.create_input_context(context_name, self._conn)
return self.__ibus.create_input_context(context_name, self.__conn)
def ReleaseInputContext(self, ic, dbusconn):
self._ibus.release_input_context(ic, self._conn)
self.__ibus.release_input_context(ic, self.__conn)
def RegisterFactories(self, object_paths, dbusconn):
self._ibus.register_factories(object_paths, self._conn)
self.__ibus.register_factories(object_paths, self.__conn)
def UnregisterEngines(self, object_paths, dbusconn):
self._ibus.unregister_engines(object_paths, self._conn)
self.__ibus.unregister_engines(object_paths, self.__conn)
def RegisterPanel(self, object_path, replace, dbusconn):
self._ibus.register_panel(object_path, replace, self._conn)
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)
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)
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)
self.__ibus.set_cursor_location(ic, x, y, w, h, self.__conn)
def FocusIn(self, ic, dbusconn):
self._ibus.focus_in(ic, self._conn)
self.__ibus.focus_in(ic, self.__conn)
def FocusOut(self, ic, dbusconn):
self._ibus.focus_out(ic, self._conn)
self.__ibus.focus_out(ic, self.__conn)
def Reset(self, ic, dbusconn):
self._ibus.reset(ic, self._conn)
self.__ibus.reset(ic, self.__conn)
def IsEnabled(self, ic, dbusconn):
return self._ibus.is_enabled(ic, self._conn)
return self.__ibus.is_enabled(ic, self.__conn)
def SetCapabilities(self, ic, caps, dbusconn):
return self._ibus.set_capabilities(ic, caps, self._conn)
return self.__ibus.set_capabilities(ic, caps, self.__conn)
def GetFactories(self, dbusconn):
return self._ibus.get_factories()
return self.__ibus.get_factories()
def GetFactoryInfo(self, factory_path, dbusconn):
return self._ibus.get_factory_info(factory_path)
return self.__ibus.get_factory_info(factory_path)
def SetFactory(self, factory_path, dbusconn):
return self._ibus.set_factory(factory_path)
return self.__ibus.set_factory(factory_path)
def GetInputContextStates(self, ic, dbusconn):
return self._ibus.get_input_context_states(ic, self._conn)
return self.__ibus.get_input_context_states(ic, self.__conn)
def ConfigSetString(self, key, value, dbusconn, reply_cb, error_cb):
self._ibus.config_set_string(key, value, self._conn,
self.__ibus.config_set_string(key, value, self.__conn,
reply_handler = reply_cb,
error_handler = error_cb)
def ConfigSetInt(self, key, value, dbusconn, reply_cb, error_cb):
self._ibus.config_set_int(key, value, self._conn,
self.__ibus.config_set_int(key, value, self.__conn,
reply_handler = reply_cb,
error_handler = error_cb)
def ConfigSetBool(self, key, value, dbusconn, reply_cb, error_cb):
self._ibus.config_set_bool(key, value, self._conn,
self.__ibus.config_set_bool(key, value, self.__conn,
reply_handler = reply_cb,
error_handler = error_cb)
def ConfigGetString(self, key, dbusconn, reply_cb, error_cb):
self._ibus.config_get_string(key, self._conn,
self.__ibus.config_get_string(key, self.__conn,
reply_handler = reply_cb,
error_handler = error_cb)
def ConfigGetInt(self, key, dbusconn, reply_cb, error_cb):
self._ibus.config_get_int(key, self._conn,
self.__ibus.config_get_int(key, self.__conn,
reply_handler = reply_cb,
error_handler = error_cb)
def ConfigGetBool(self, key, dbusconn, reply_cb, error_cb):
self._ibus.config_get_bool(key, self._conn,
self.__ibus.config_get_bool(key, self.__conn,
reply_handler = reply_cb,
error_handler = error_cb)
def RegisterListEngines(self, dbusconn):
return self._ibus.register_list_engines(self._conn)
return self.__ibus.register_list_engines(self.__conn)
def RegisterStartEngine(self, lang, name, dbusconn):
return self._ibus.register_start_engine(lang, name, self._conn)
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)
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)
return self.__ibus.register_stop_engine(lang, name, self.__conn)

Просмотреть файл

@ -93,273 +93,305 @@ class InputContext(ibus.Object):
def __init__(self, name, ibusconn):
super(InputContext, self).__init__()
self._id = "%d" % InputContext.id
self.__id = "%d" % InputContext.id
InputContext.id += 1
self._ibusconn = ibusconn
self._ibusconn.connect("destroy", self._ibusconn_destroy_cb)
self.__ibusconn = ibusconn
self.__ibusconn.connect("destroy", self.__ibusconn_destroy_cb)
# init default values
self._enable = False
self._engine = None
self._engine_handlers = []
self.__enable = False
self.__engine = None
self.__engine_handlers = []
# client state
self._aux_string = None
self._aux_attrs = None
self._aux_visible = False
self.__aux_string = None
self.__aux_attrs = None
self.__aux_visible = False
self._use_preedit = True
self._preedit_string = None
self._preedit_attrs = None
self._cursor_pos = 0
self._preedit_visible = False
self.__use_preedit = True
self.__preedit_string = None
self.__preedit_attrs = None
self.__cursor_pos = 0
self.__preedit_visible = False
self._lookup_table = None
self._lookup_table_visible = False
self.__lookup_table = None
self.__lookup_table_visible = False
def get_id(self):
return self._id;
return self.__id;
def get_preedit_string(self):
return self._preedit_string, self._preedit_attrs, self._cursor_pos
return self.__preedit_string, self.__preedit_attrs, self.__cursor_pos
def get_use_preedit(self):
return self._use_preedit
return self.__use_preedit
def get_aux_string(self):
return self._aux_string, self._aux_attrs
return self.__aux_string, self.__aux_attrs
def process_key_event(self, keyval, is_press, state,
reply_cb, error_cb):
if self._engine != None and self._enable:
self._engine.process_key_event(keyval, is_press, state,
if self.__engine != None and self.__enable:
self.__engine.process_key_event(keyval, is_press, state,
reply_cb, error_cb)
else:
reply_cb(False)
def set_cursor_location(self, x, y, w, h):
if self._engine:
self._engine.set_cursor_location(x, y, w, h)
if self.__engine:
self.__engine.set_cursor_location(x, y, w, h)
def focus_in(self):
if self._engine:
self._engine.focus_in()
if self.__engine and self.__enable:
self.__engine.focus_in()
def focus_out(self):
if self._engine:
self._engine.focus_out()
if self.__engine and self.__enable:
self.__engine.focus_out()
def reset(self):
if self._engine:
self._engine.reset()
if self.__engine and self.__enable:
self.__engine.reset()
def page_up(self):
if self._engine:
self._engine.page_up()
if self.__engine and self.__enable:
self.__engine.page_up()
def page_down(self):
if self._engine:
self._engine.page_down()
if self.__engine and self.__enable:
self.__engine.page_down()
def cursor_up(self):
if self._engine:
self._engine.cursor_up()
if self.__engine and self.__enable:
self.__engine.cursor_up()
def cursor_down(self):
if self._engine:
self._engine.cursor_down()
if self.__engine and self.__enable:
self.__engine.cursor_down()
def property_activate(self, prop_name, prop_state):
if self._engine:
self._engine.property_activate(prop_name, prop_state)
if self.__engine and self.__enable:
self.__engine.property_activate(prop_name, prop_state)
def property_show(self, prop_name):
if self._engine:
self._engine.property_show(prop_name)
if self.__engine and self.__enable:
self.__engine.property_show(prop_name)
def property_hide(self, prop_name):
if self._engine:
self._engine.property_hide(prop_name)
if self.__engine and self.__enable:
self.__engine.property_hide(prop_name)
def is_enabled(self):
return self._enable
return self.__enable
def set_capabilities(self, caps):
if caps == 0:
self._use_preedit = False
self.__use_preedit = False
else:
self._use_preedit = True
self.__use_preedit = True
def set_enable(self, enable):
if self._enable != enable:
self._enable = enable
if self._enable:
self._ibusconn.emit_dbus_signal("Enabled", self._id)
if self._engine:
self._engine.enable()
if self.__enable != enable:
self.__enable = enable
if self.__enable:
self.__ibusconn.emit_dbus_signal("Enabled", self.__id)
if self.__engine:
self.__engine.enable()
else:
self._ibusconn.emit_dbus_signal("Disabled", self._id)
if self._engine:
self._engine.disable()
self.__ibusconn.emit_dbus_signal("Disabled", self.__id)
if self.__engine:
self.__engine.disable()
def commit_string(self, text):
self._ibusconn.emit_dbus_signal("CommitString", self._id, text)
self.__ibusconn.emit_dbus_signal("CommitString", self.__id, text)
def update_preedit(self, text, attrs, cursor_pos, visible):
self._preedit_string = text
self._preedit_attrs = attrs
self._cursor_pos = cursor_pos
self._preedit_visible = visible
if self._use_preedit:
self._ibusconn.emit_dbus_signal("UpdatePreedit", self._id, text, attrs, cursor_pos, visible)
self.__preedit_string = text
self.__preedit_attrs = attrs
self.__cursor_pos = cursor_pos
self.__preedit_visible = visible
if self.__use_preedit:
self.__ibusconn.emit_dbus_signal("UpdatePreedit", self.__id, text, attrs, cursor_pos, visible)
else:
# show preedit on panel
self.emit("update-preedit", text, attrs, cursor_pos, visible)
def show_preedit(self):
self._preedit_visible = True
if self._use_preedit:
self._ibusconn.emit_dbus_signal("ShowPreedit", self._id)
self.__preedit_visible = True
if self.__use_preedit:
self.__ibusconn.emit_dbus_signal("ShowPreedit", self.__id)
else:
# show preedit on panel
self.emit("show-preedit")
def hide_preedit(self):
self._preedit_visible = False
if self._use_preedit:
self._ibusconn.emit_dbus_signal("HidePreedit", self._id)
self.__preedit_visible = False
if self.__use_preedit:
self.__ibusconn.emit_dbus_signal("HidePreedit", self.__id)
else:
# show preedit on panel
self.emit("hide-preedit")
def set_engine(self, engine):
if self._engine == engine:
if self.__engine == engine:
return
if self._engine != None:
self._remove_engine_handlers()
self._engine.destroy()
self._engine = None
if self.__engine != None:
self.__remove_engine_handlers()
self.__engine.destroy()
self.__engine = None
self._engine = engine
self._install_engine_handlers()
self.__engine = engine
self.__install_engine_handlers()
def get_engine(self):
return self._engine
return self.__engine
def get_factory(self):
if self._engine:
return self._engine.get_factory()
if self.__engine:
return self.__engine.get_factory()
return None
def _engine_destroy_cb(self, engine):
if self._engine == engine:
self._remove_engine_handlers()
self._engine = None
self._enable = False
if self._use_preedit:
self._ibusconn.emit_dbus_signal("UpdatePreedit",
self._id,
def __engine_destroy_cb(self, engine):
if self.__engine == engine:
self.__remove_engine_handlers()
self.__engine = None
self.__enable = False
if self.__use_preedit:
self.__ibusconn.emit_dbus_signal("UpdatePreedit",
self.__id,
u"",
ibus.AttrList().to_dbus_value(),
0,
False)
self._ibusconn.emit_dbus_signal("Disabled", self._id)
self.__ibusconn.emit_dbus_signal("Disabled", self.__id)
self.emit("engine-lost")
def _ibusconn_destroy_cb(self, ibusconn):
if self._engine != None:
self._remove_engine_handlers()
self._engine.destroy()
self._engine = None
def __ibusconn_destroy_cb(self, ibusconn):
if self.__engine != None:
self.__remove_engine_handlers()
self.__engine.destroy()
self.__engine = None
self.destroy()
def _commit_string_cb(self, engine, text):
def __commit_string_cb(self, engine, text):
if not self.__enable:
return
self.commit_string(text)
def _update_preedit_cb(self, engine, text, attrs, cursor_pos, visible):
def __update_preedit_cb(self, engine, text, attrs, cursor_pos, visible):
if not self.__enable:
return
self.update_preedit(text, attrs, cursor_pos, visible)
def _show_preedit_cb(self, engine):
def __show_preedit_cb(self, engine):
if not self.__enable:
return
self.show_preedit()
def _hide_preedit_cb(self, engine):
def __hide_preedit_cb(self, engine):
if not self.__enable:
return
self.hide_preedit()
def _update_aux_string_cb(self, engine, text, attrs, visible):
self._aux_string = text
self._aux_attrs = attrs
self._aux_visible = visible
def __update_aux_string_cb(self, engine, text, attrs, visible):
if not self.__enable:
return
self.__aux_string = text
self.__aux_attrs = attrs
self.__aux_visible = visible
self.emit("update-aux-string", text, attrs, visible)
def _show_aux_string_cb(self, engine):
self._aux_visible = True
def __show_aux_string_cb(self, engine):
if not self.__enable:
return
self.__aux_visible = True
self.emit("show-aux-string")
def _hide_aux_string_cb(self, engine):
self._aux_visible = False
def __hide_aux_string_cb(self, engine):
if not self.__enable:
return
self.__aux_visible = False
self.emit("hide-aux-string")
def _update_lookup_table_cb(self, engine, lookup_table, visible):
self._lookup_table = lookup_table
self._lookup_table_visible = visible
def __update_lookup_table_cb(self, engine, lookup_table, visible):
if not self.__enable:
return
self.__lookup_table = lookup_table
self.__lookup_table_visible = visible
self.emit("update-lookup-table", lookup_table, visible)
def _show_lookup_table_cb(self, engine):
self._lookup_table_visible = True
def __show_lookup_table_cb(self, engine):
if not self.__enable:
return
self.__lookup_table_visible = True
self.emit("show-lookup-table")
def _hide_lookup_table_cb(self, engine):
self._lookup_table_visible = False
def __hide_lookup_table_cb(self, engine):
if not self.__enable:
return
self.__lookup_table_visible = False
self.emit("hide-lookup-table")
def _page_up_lookup_table_cb(self, engine):
def __page_up_lookup_table_cb(self, engine):
if not self.__enable:
return
self.emit("page-up-lookup-table")
def _page_down_lookup_table_cb(self, engine):
def __page_down_lookup_table_cb(self, engine):
if not self.__enable:
return
self.emit("page-down-lookup-table")
def _cursor_up_lookup_table_cb(self, engine):
def __cursor_up_lookup_table_cb(self, engine):
if not self.__enable:
return
self.emit("cursor-up-lookup-table")
def _cursor_down_lookup_table_cb(self, engine):
def __cursor_down_lookup_table_cb(self, engine):
if not self.__enable:
return
self.emit("cursor-down-lookup-table")
def _register_properties_cb(self, engine, props):
def __register_properties_cb(self, engine, props):
if not self.__enable:
return
self.emit("register-properties", props)
def _update_property_cb(self, engine, prop):
def __update_property_cb(self, engine, prop):
if not self.__enable:
return
self.emit("update-property", prop)
def _remove_engine_handlers(self):
assert self._engine != None
def __remove_engine_handlers(self):
assert self.__engine != None
map(self._engine.disconnect, self._engine_handlers)
del self._engine_handlers[:]
map(self.__engine.disconnect, self.__engine_handlers)
del self.__engine_handlers[:]
def _install_engine_handlers(self):
def __install_engine_handlers(self):
signals = (
("destroy", self._engine_destroy_cb),
("commit-string", self._commit_string_cb),
("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)
("destroy", self.__engine_destroy_cb),
("commit-string", self.__commit_string_cb),
("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)
)
for signal, handler in signals:
id = self._engine.connect(signal, handler)
self._engine_handlers.append(id)
id = self.__engine.connect(signal, handler)
self.__engine_handlers.append(id)
gobject.type_register(InputContext)