diff options
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/.gitignore | 1 | ||||
-rw-r--r-- | daemon/Makefile.am | 55 | ||||
-rw-r--r-- | daemon/_dbus.py | 319 | ||||
-rw-r--r-- | daemon/bus.py | 714 | ||||
-rw-r--r-- | daemon/config.py | 101 | ||||
-rw-r--r-- | daemon/connection.py | 98 | ||||
-rw-r--r-- | daemon/contextmanager.py | 45 | ||||
-rw-r--r-- | daemon/engine.py | 221 | ||||
-rw-r--r-- | daemon/enginefactory.py | 83 | ||||
-rw-r--r-- | daemon/factorymanager.py | 123 | ||||
-rw-r--r-- | daemon/ibus-daemon.in | 25 | ||||
-rw-r--r-- | daemon/ibusdaemon.py | 112 | ||||
-rw-r--r-- | daemon/inputcontext.py | 449 | ||||
-rw-r--r-- | daemon/lookuptable.py | 95 | ||||
-rw-r--r-- | daemon/notifications.py | 92 | ||||
-rw-r--r-- | daemon/panel.py | 262 | ||||
-rw-r--r-- | daemon/register.py | 205 |
17 files changed, 0 insertions, 3000 deletions
diff --git a/daemon/.gitignore b/daemon/.gitignore deleted file mode 100644 index 76a720d..0000000 --- a/daemon/.gitignore +++ /dev/null @@ -1 +0,0 @@ -ibus-daemon diff --git a/daemon/Makefile.am b/daemon/Makefile.am deleted file mode 100644 index 0d32443..0000000 --- a/daemon/Makefile.am +++ /dev/null @@ -1,55 +0,0 @@ -# vim:set noet ts=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 -ibusdaemon_PYTHON = \ - bus.py \ - _dbus.py \ - config.py \ - connection.py \ - contextmanager.py \ - enginefactory.py \ - engine.py \ - factorymanager.py \ - ibusdaemon.py \ - inputcontext.py \ - lookuptable.py \ - panel.py \ - notifications.py \ - register.py \ - $(NULL) - -bin_SCRIPTS = ibus-daemon - -ibusdaemondir = $(pkgdatadir)/daemon - -CLEANFILES = \ - *.pyc \ - $(NULL) - -EXTRA_DIST = \ - ibus-daemon.in \ - $(NULL) - -test: - $(ENV) \ - DBUS_DEBUG=true \ - PYTHONPATH=$${PYTHONPATH}:$(top_srcdir) \ - IBUS_DATAROOTDIR=${datarootdir} \ - $(PYTHON) $(srcdir)/ibusdaemon.py diff --git a/daemon/_dbus.py b/daemon/_dbus.py deleted file mode 100644 index 1b007a0..0000000 --- a/daemon/_dbus.py +++ /dev/null @@ -1,319 +0,0 @@ -# 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 gobject -import dbus -import dbus.service -import ibus - -class MatchRule: - def __init__(self, rule): - m = self.__eval_rule(rule) - self.__type = m.get('type', None) - self.__sender = m.get('sender', None) - self.__interface = m.get('interface', None) - self.__member = m.get('member', None) - self.__path = m.get('path', None) - self.__destination = m.get('destination', None) - self.__args = [] - for i in range(64): - arg = m.get('arg%d'%i, None) - if arg == None: - continue - self.__args.append((i, arg)) - - def __eval_rule(self, rule): - _fn = lambda **kargs: kargs - try: - return eval("_fn(%s)" % rule) - except: - raise ibus.IBusException("Parse match rule failed\n%s" % rule) - - def __cmp_bus_name(self, dbusobj, a, b): - if a == None or b == None: - return a == b - a_is_unique = a.startswith(":") - b_is_unique = b.startswith(":") - if a_is_unique == b_is_unique: - return a == b - else: - try: - if not a_is_unique: - a = dbusobj.get_name_owner(a).get_unique_name() - if not b_is_unique: - b = dbusobj.get_name_owner(b).get_unique_name() - return a == b - except: - return False - - def match_message(self, dbusobj, message): - if self.__type == 'signal' and message.get_type() != 4: - return False - - if self.__sender: - if not self.__cmp_bus_name(dbusobj, self.__sender, message.get_sender()): - return False - - if self.__interface and self.__interface != message.get_interface(): - return False - - if self.__member and self.__member != message.get_member(): - return False - - if self.__path and self.__path != message.get_path(): - return False - - if self.__destination: - if not self.__cmp_bus_name(dbusobj, self.__destination, message.get_destination()): - return False - args = message.get_args_list() - for i, arg in self.__args: - if i >= len(args): - return False - if arg != args[i]: - return False - return True - -class DBusReal(ibus.Object): - __gsignals__ = { - "name-owner-changed" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)), - } - - def __init__(self): - super(DBusReal, self).__init__() - self.__connections = dict() - self.__unique_name_dict = dict() - self.__name_dict = dict() - self.__id = 0 - - def add_connection(self, ibusconn): - self.__connections[ibusconn] = list() - ibusconn.connect("dbus-message", self.__dbus_message_cb) - ibusconn.connect("destroy", self.__ibusconn_destroy_cb) - - def register_connection(self, ibusconn): - name = ibusconn.get_unique_name() - if name: - raise ibus.IBusException("Already handled an Hello message") - self.__id += 1 - name = ":1.%d" % self.__id - self.__unique_name_dict[name] = ibusconn - ibusconn.set_unique_name(name) - return name - - def list_names(self): - return self.__name_dict.keys() + self.__unique_name_dict.keys() - - def list_activatable_names(self): - return self.__name_dict.keys() + self.__unique_name_dict.keys() - - def name_has_owner(self, name): - if name.startswith(":"): - return name in self.__unique_name_dict - return name in self.__name_dict - - def get_name_owner(self, name): - if name == dbus.BUS_DAEMON_NAME or \ - name == ibus.IBUS_NAME: - return name - if name.startswith(":"): - if name in self.__unique_name_dict: - return name - elif name in self.__name_dict: - ibusconn = self.__name_dict[name] - return ibusconn.get_unique_name() - - raise ibus.IBusException( - "org.freedesktop.DBus.Error.NameHasNoOwner:\n" - "\tCould not get owner of name '%s': no such name" % name) - - def start_service_by_name(self, name, flags): - return 0 - - def get_connection_unix_user(self, connection_name): - return 0 - - def add_match(self, ibusconn, rule): - self.__connections[ibusconn].append(MatchRule(rule)) - - def remove_match(self, ibusconn, rule): - pass - - def request_name(self, ibusconn, name, flags): - if name.startswith(":"): - raise ibus.IBusException("Only unique name can start with ':'") - if not ibusconn.get_unique_name(): - raise ibus.IBusException("Can not call any method before Hello.") - if name in ibusconn.get_names(): - return 0 - if name in self.__name_dict: - raise ibus.IBusException("Name has been registered") - self.__name_dict[name] = ibusconn - self.emit("name-owner-changed", name, "", ibusconn.get_unique_name()) - ibusconn.add_name(name) - return 1 - - def release_name(self, ibusconn, name): - if name.startswith(":"): - raise ibus.IBusException("Only unique name can start with ':'") - if name not in ibusconn.get_names(): - return 2 - del self.__name_dict[name] - self.emit("name-owner-changed", name, ibusconn.get_unique_name(), "") - ibusconn.remove_name(name) - return 1 - - def dispatch_dbus_signal(self, message): - for conn, rules in self.__connections.items(): - for rule in rules: - if rule.match_message(self, message): - conn.send_message(message) - break - def get_connection_by_name(self, name): - if not name.startswith(":"): - return None - return self.__unique_name_dict.get(name, None) - - def do_name_owner_changed(self, name, old_name, new_name): - message = dbus.lowlevel.SignalMessage(dbus.BUS_DAEMON_PATH, - dbus.BUS_DAEMON_IFACE, "NameOwnerChanged") - # message.set_sender(dbus.BUS_DAEMON_NAME) - message.append(name) - message.append(old_name) - message.append(new_name) - self.dispatch_dbus_signal(message) - - def __dbus_message_cb(self, ibusconn, message): - dest = message.get_destination() - message.set_sender(ibusconn.get_unique_name()) - if (not dest): - if message.get_type() != 4: # Is not signal - raise ibus.IBusException("Message without destination") - self.dispatch_dbus_signal(message) - return True - - if not dest.startswith(":"): - raise ibus.IBusException("Destination of message must be an unique name") - - destconn = self.__unique_name_dict.get(dest, None) - if destconn == None: - raise ibus.IBusException("Can not find the destination(%s)" % dest) - - destconn.send_message(message) - return True - - def __ibusconn_destroy_cb(self, ibusconn): - name = ibusconn.get_unique_name() - for name in ibusconn.get_names(): - del self.__name_dict[name] - self.emit("name-owner-changed", name, ibusconn.get_unique_name(), "") - if name: - del self.__unique_name_dict[name] - self.emit("name-owner-changed", name, name, "") - - del self.__connections[ibusconn] - -bus = DBusReal() - -class DBus(dbus.service.Object): - - method = lambda **args: \ - dbus.service.method(dbus_interface = dbus.BUS_DAEMON_IFACE, \ - **args) - - signal = lambda **args: \ - dbus.service.signal(dbus_interface = dbus.BUS_DAEMON_IFACE, \ - **args) - - __bus = bus - - def __init__(self, ibusconn): - super(DBus, self).__init__(ibusconn.get_dbusconn(), dbus.BUS_DAEMON_PATH) - self.__ibusconn = ibusconn - self.__name = DBus.__bus.register_connection(self.__ibusconn) - self.__active = False - self.__bus.add_connection(ibusconn) - - @method(out_signature="s") - def Hello(self): - if not self.__active: - self.__active = True - return self.__name - raise ibus.IBusException("Already handled an Hello message") - - @method(out_signature="as") - def ListNames(self): - return DBus.__bus.list_names() - - @method(out_signature="as") - def ListActivatableNames(self): - return DBus.__bus.list_activatable_names() - - @method(in_signature="s", out_signature="as") - def NameHasOwner(self, name): - return DBus.__bus.name_has_owner(name) - - @method(in_signature="si", out_signature="i") - def StartServiceByName(self, name, flags): - return DBus.__bus.start_service_by_name(name, flags) - - @method(in_signature="s", out_signature="s") - def GetNameOwner(self, name): - return DBus.__bus.get_name_owner(name) - - @method(in_signature="s", out_signature="i") - def GetConnectionUnixUser(self, connection_name): - return DBus.__bus.get_connection_unix_user(connection_name) - - @method(in_signature="s") - def AddMatch(self, rule): - return DBus.__bus.add_match(self.__ibusconn, rule) - - @method(in_signature="s") - def RemoveMatch(self, rule): - return DBus.__bus.remove_match(self.__ibusconn, rule) - - @method(out_signature="s") - def GetId(self): - return self.__name - - @method(in_signature="su", out_signature="u") - def RequestName(self, name, flags): - return self.__bus.request_name(self.__ibusconn, name, flags) - - @method(in_signature="s", out_signature="u") - def ReleaseName(self, name): - return self.__bus.release_name(self.__ibusconn, name) - - @signal(signature="sss") - def NameOwnerChanged(self, name, old_owner, new_owner): - pass - - @signal(signature="s") - def NameLost(self, name): - pass - - @signal(signature="s") - def NameAcquired(self, name): - pass diff --git a/daemon/bus.py b/daemon/bus.py deleted file mode 100644 index 5c5cb3a..0000000 --- a/daemon/bus.py +++ /dev/null @@ -1,714 +0,0 @@ -# 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 ibus -import gobject -from ibus import keysyms -from ibus import modifier -from contextmanager import ContextManager -from factorymanager import FactoryManager -from panel import Panel, DummyPanel -from notifications import Notifications, DummyNotifications -from config import Config, DummyConfig -from register import Register -import _dbus - -from gettext import dgettext -_ = lambda a : dgettext("ibus", a) -N_ = lambda a : a - -class IBus(ibus.Object): - def __init__(self): - super(IBus, self).__init__() - _dbus.bus.connect("name-owner-changed", self.__dbus_name_owner_changed_cb) - self.__context_manager = ContextManager() - self.__factory_manager = FactoryManager() - self.__factory_manager.connect("default-factory-changed", - self.__factory_manager_default_factory_changed_cb) - - self.__panel = DummyPanel() - self.__panel_handlers = list() - self.__install_panel_handlers() - - self.__notifications = DummyNotifications() - self.__notifications_handlers = list() - self.__install_notifications_handlers() - - self.__no_engine_notification_id = 0 - self.__no_engine_notification_show = True - - self.__config = DummyConfig() - self.__config_handlers = list() - self.__install_config_handlers() - - self.__register = Register() - - self.__focused_context = None - self.__last_focused_context = None - self.__context_handlers = list() - - self.__connections = list() - - self.__prev_key = None - self.__config_load_settings () - - def __config_load_settings (self): - self.__shortcut_trigger = self.__load_config_shortcut( - "general", "keyboard_shortcut_trigger", - ibus.CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT) - self.__shortcut_next_engine = self.__load_config_shortcut( - "general", "keyboard_shortcut_next_engine", - ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT) - self.__shortcut_prev_engine = self.__load_config_shortcut( - "general", "keyboard_shortcut_next_engine", - ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT) - self.__default_factory = None - - def __dbus_name_owner_changed_cb(self, bus, name, old_name, new_name): - if name == ibus.IBUS_PANEL_NAME: - self.__panel_changed(new_name) - elif name == ibus.IBUS_CONFIG_NAME: - self.__config_changed(new_name) - elif name == ibus.IBUS_NOTIFICATIONS_NAME: - self.__notifications_changed(new_name) - - def __factory_manager_default_factory_changed_cb(self, manager, factory): - if self.__default_factory != factory: - self.__default_factory = factory - if factory == None: - return - self.__config.set_value("general", "default_factory", factory.get_object_path()) - - def __load_config_shortcut(self, section, name, default_value): - - # load trigger - shortcut_strings = default_value - try: - shortcut_strings = self.__config.get_value(section, name) - 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, conn): - IBusProxy(self, conn) - conn.connect("destroy", self.__conn_destroy_cb) - self.__connections.append(conn) - - def __conn_destroy_cb(self, conn): - self.__connections.remove(conn) - - ########################################################## - # methods for im context - ########################################################## - def __load_default_factory(self): - if self.__default_factory != None: - return - try: - factory_path = self.__config.get_value("general", "default_factory") - self.__default_factory = self.__factory_manager.get_factory(factory_path) - except: - pass - if self.__default_factory != None: - self.__factory_manager.set_default_factory(self.__default_factory) - return - - def create_input_context(self, name, conn): - context = self.__context_manager.create_input_context(name, conn) - self.__load_default_factory() - if self.__default_factory != None: - engine = self.__default_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 not context.get_support_focus(): - return - 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 - self.__panel.focus_out(context.get_id()) - - context.focus_out() - - 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) - - # focus in the context, if context supports focus - if context != self.__focused_context and context.get_support_focus(): - self.focus_in(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: - self.__load_default_factory() - if self.__default_factory == None: - self.__default_factory = self.__factory_manager.get_default_factory() - if self.__default_factory: - engine = self.__default_factory.create_engine() - engine.focus_in() - context.set_engine(engine) - else: - if self.__no_engine_notification_show: - self.__no_engine_notification_id = self.__notifications.notify( - self.__no_engine_notification_id, - "ibus", _("Cannot enable input engine"), - _("IBus can not enable input engine, because IBus does not load any input engines!\n" - "Please use ibus-setup program to load some input engines."), - ["Setup", _("Setup"), "NoAgain", _("Don't show this again")], - 15000) - - if context.get_engine() != None: - 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) - self.__factory_manager.set_default_factory(new_factory) - engine = new_factory.create_engine() - self.__panel.reset() - 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 __panel_changed(self, bus_name): - if not isinstance(self.__panel, DummyPanel): - self.__uninstall_panel_handlers() - self.__panel.destroy() - ibusconn = _dbus.bus.get_connection_by_name(bus_name) - if ibusconn == None: - self.__panel = DummyPanel() - else: - self.__panel = Panel(ibusconn) - 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.__uninstall_panel_handlers() - self.__panel = DummyPanel() - - ########################################################## - # methods for notifications - ########################################################## - def __notifications_changed(self, bus_name): - if not isinstance(self.__notifications, DummyNotifications): - self.__uninstall_notifications_handlers() - self.__notifications.destroy() - ibusconn = _dbus.bus.get_connection_by_name(bus_name) - if ibusconn == None: - self.__notifications = DummyNotifications() - else: - self.__notifications = Notifications(ibusconn) - self.__install_notifications_handlers() - - def __install_notifications_handlers(self): - signals = ( - ("notification-closed", self.__notifications_notification_closed_cb), - ("action-invoked", self.__notifications_action_invoked_cb), - ("destroy", self.__notifications_destroy_cb) - ) - - for signal, handler in signals: - id = self.__notifications.connect(signal, handler) - self.__notifications_handlers.append(id) - - def __uninstall_notifications_handlers(self): - map(lambda id:self.__notifications.disconnect(id), self.__notifications_handlers) - self.__notifications_handlers = list() - - def __notifications_notification_closed_cb(self, notifications, id, reason): - pass - - def __notifications_action_invoked_cb(self, notifications, id, action_key): - if id == self.__no_engine_notification_id: - if action_key == "NoAgain": - self.__no_engine_notification_show = False - elif action_key == "Setup": - self.__panel.start_setup() - - - def __notifications_destroy_cb(self, notifications): - if notifications == self.__notifications: - self.__uninstall_notifications_handlers() - self.__notifications = DummyNotifications() - - - ########################################################## - # methods for config - ########################################################## - def __config_changed(self, bus_name): - ibusconn = _dbus.bus.get_connection_by_name(bus_name) - self.__uninstall_config_handlers() - self.__config.destroy() - self.__config = Config(ibusconn) - self.__install_config_handlers() - gobject.idle_add (self.__config_load_settings) - - 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 __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] - keyval = keysyms.name_to_keycode(keyname) - if keyval == None: - keyval = 0 - - return keyval, keymask - - def __config_value_changed_cb (self, config, section, name, value): - if section == "general": - if name == "keyboard_shortcut_trigger": - self.__shortcut_trigger = self.__load_config_shortcut( - "general", "keyboard_shortcut_trigger", - ibus.CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT) - elif name =="keyboard_shortcut_next_engine": - self.__shortcut_next_engine = self.__load_config_shortcut( - "general", "keyboard_shortcut_next_engine", - ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT) - - 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) - self.__factory_manager.set_default_factory(factory) - 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 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) - diff --git a/daemon/config.py b/daemon/config.py deleted file mode 100644 index 3a41c9c..0000000 --- a/daemon/config.py +++ /dev/null @@ -1,101 +0,0 @@ -# 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 - -__all__ = ( - "Config", - "DefaultConfig" -) - -import gobject -import ibus - -class Config(ibus.Object): - __gsignals__ = { - "value-changed" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)), - } - - def __init__(self, ibusconn): - super(Config, self).__init__() - self.__ibusconn = ibusconn - self.__config = self.__ibusconn.get_object(ibus.IBUS_CONFIG_PATH) - - self.__ibusconn.connect("destroy", self.__ibusconn_destroy_cb) - self.__ibusconn.connect("dbus-signal", self.__dbus_signal_cb) - - def get_value(self, section, name, **kargs): - return self.__config.GetValue(section, name, **kargs) - - def set_value(self, section, name, value, **kargs): - return self.__config.SetValue(section, name, value, **kargs) - - def destroy(self): - if self.__ibusconn != None: - self.__config.Destroy(**ibus.DEFAULT_ASYNC_HANDLERS) - - self.__ibusconn = None - self.__config = None - ibus.Object.destroy(self) - - # signal callbacks - def __ibusconn_destroy_cb(self, ibusconn): - self.__ibusconn = None - self.destroy() - - def __dbus_signal_cb(self, ibusconn, message): - if message.is_signal(ibus.IBUS_CONFIG_IFACE, "ValueChanged"): - args = message.get_args_list() - self.emit("value-changed", args[0], args[1], args[2]) - return False - -gobject.type_register(Config) - -class DummyConfig(ibus.Object): - __gsignals__ = { - "value-changed" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)), - } - - def __init__(self): - super(DummyConfig, self).__init__() - self.__values = dict() - - def get_value(self, section, name, **kargs): - value = self.__values.get((section, name), None) - if value == None: - raise ibus.IBusException("Can not get config section=%s name=%s" % (section, name)) - return value - - def set_value(self, section, name, value, **kargs): - old_value = self.__values.get((section, name), None) - if value == old_value: - return - if value == None: - del self.__values[(section, name)] - else: - self.__values[(section, name)] = value - self.emit("value-changed", section, name, value) - -gobject.type_register(DummyConfig) diff --git a/daemon/connection.py b/daemon/connection.py deleted file mode 100644 index f897e08..0000000 --- a/daemon/connection.py +++ /dev/null @@ -1,98 +0,0 @@ -# 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 dbus.lowlevel -import ibus -import gobject - -class Connection(ibus.Object): - __gsignals__ = { - "dbus-signal" : ( - gobject.SIGNAL_RUN_LAST, - gobject.TYPE_BOOLEAN, - (gobject.TYPE_PYOBJECT, ) - ), - "dbus-message" : ( - gobject.SIGNAL_RUN_LAST, - gobject.TYPE_BOOLEAN, - (gobject.TYPE_PYOBJECT, ) - ) - } - def __init__(self, dbusconn): - super(Connection, self).__init__() - self.__dbusconn = dbusconn - self.__unique_name = "" - self.__names = set() - dbusconn.add_message_filter(self.message_filter_cb) - - def message_filter_cb(self, dbusconn, message): - if message.is_signal(dbus.LOCAL_IFACE, "Disconnected"): - self.destroy() - return dbus.lowlevel.HANDLER_RESULT_HANDLED - - if message.get_destination() in set(["org.freedesktop.IBus", "org.freedesktop.DBus"]): - return dbus.lowlevel.HANDLER_RESULT_NOT_YET_HANDLED - - if message.get_type() == 4: # is signal - if self.emit("dbus-signal", message): - return dbus.lowlevel.HANDLER_RESULT_HANDLED - if self.emit("dbus-message", message): - return dbus.lowlevel.HANDLER_RESULT_HANDLED - return dbus.lowlevel.HANDLER_RESULT_NOT_YET_HANDLED - - def get_object(self, path): - return self.__dbusconn.get_object("no.name", path) - - def emit_dbus_signal(self, name, *args): - message = dbus.lowlevel.SignalMessage(ibus.IBUS_PATH, ibus.IBUS_IFACE, name) - message.append(*args) - self.send_message(message) - - def send_message(self, message): - self.__dbusconn.send_message(message) - self.__dbusconn.flush() - - def do_destroy(self): - self.__dbusconn = None - - def get_dbusconn(self): - return self.__dbusconn - - def get_unique_name(self): - return self.__unique_name - - def set_unique_name(self, name): - assert name - assert not self.__unique_name - self.__unique_name = name - - def get_names(self): - return self.__names - - def add_name(self, name): - if name not in self.__names: - self.__names.add(name) - - def remove_name(self, name): - if name in self.__names: - self.__names.remove(name) - -gobject.type_register(Connection) diff --git a/daemon/contextmanager.py b/daemon/contextmanager.py deleted file mode 100644 index 44b4bdb..0000000 --- a/daemon/contextmanager.py +++ /dev/null @@ -1,45 +0,0 @@ -# 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 ibus -from inputcontext import InputContext - -class ContextManager(ibus.Object): - def __init__(self): - super(ContextManager, self).__init__() - self._contexts = {} - - def create_input_context(self, name, ibusconn): - context = InputContext(name, ibusconn) - self._contexts[context.get_id()] = context - context.connect("destroy", self._context_destroy_cb) - return context - - def release_input_context(self, ic, ibusconn): - context = self._contexts[ic] - context.destroy() - - def lookup_context(self, ic, ibusconn): - return self._contexts[ic] - - def _context_destroy_cb(self, context): - del self._contexts[context.get_id()] - diff --git a/daemon/engine.py b/daemon/engine.py deleted file mode 100644 index e4bc048..0000000 --- a/daemon/engine.py +++ /dev/null @@ -1,221 +0,0 @@ -# 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 gobject -import ibus - -class Engine(ibus.Object): - __gsignals__ = { - "commit-string" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, )), - "forward-key-event" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_UINT, gobject.TYPE_BOOLEAN, gobject.TYPE_UINT )), - "update-preedit" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_INT, gobject.TYPE_BOOLEAN)), - "show-preedit" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "hide-preedit" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "update-aux-string" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN)), - "show-aux-string" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "hide-aux-string" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "update-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN)), - "show-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "hide-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "page-up-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "page-down-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "cursor-up-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "cursor-down-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "register-properties" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, )), - "update-property" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, )), - } - - def __init__(self, factory, ibusconn, object_path): - super(Engine, self).__init__() - self.__factory = factory - self.__ibusconn = ibusconn - self.__object_path = object_path - self.__engine = ibusconn.get_object(self.__object_path) - self.__lookup_table = ibus.LookupTable() - self.__ibusconn.connect("destroy", self.__ibusconn_destroy_cb) - - def get_factory(self): - return self.__factory - - def get_object_path(self): - return self.__object_path - - def handle_dbus_signal(self, message): - if message.is_signal(ibus.IBUS_ENGINE_IFACE, "CommitString"): - args = message.get_args_list() - self.emit("commit-string", args[0]) - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "ForwardKeyEvent"): - args = message.get_args_list() - self.emit("forward-key-event", args[0], bool(arg[1]), arg[2]) - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "UpdatePreedit"): - args = message.get_args_list() - self.emit("update-preedit", args[0], args[1], args[2], args[3]) - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "ShowPreedit"): - self.emit("show-preedit") - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "HidePreedit"): - self.emit("hide-preedit") - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "UpdateAuxString"): - args = message.get_args_list() - self.emit("update-aux-string", args[0], args[1], args[2]) - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "ShowAuxString"): - self.emit("show-aux-string") - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "HideAuxString"): - self.emit("hide-aux-string") - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "UpdateLookupTable"): - args = message.get_args_list() - self.emit("update-lookup-table", args[0], args[1]) - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "ShowLookupTable"): - self.emit("show-lookup-table") - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "HideLookupTable"): - self.emit("hide-lookup-table") - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "PageUpLookupTable"): - self.emit("page-up-lookup-table") - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "PageDownLookupTable"): - self.emit("page-down-lookup-table") - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "CursorUpLookupTable"): - self.emit("cursor-up-lookup-table") - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "CursorDownLookupTable"): - self.emit("cursor-down-lookup-table") - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "RegisterProperties"): - args = message.get_args_list() - self.emit("register-properties", args[0]) - elif message.is_signal(ibus.IBUS_ENGINE_IFACE, "UpdateProperty"): - args = message.get_args_list() - self.emit("update-property", args[0]) - else: - return False - - return True - - def focus_in(self): - self.__engine.FocusIn(**ibus.DEFAULT_ASYNC_HANDLERS) - - def focus_out(self): - self.__engine.FocusOut(**ibus.DEFAULT_ASYNC_HANDLERS) - - def reset(self): - self.__engine.Reset(**ibus.DEFAULT_ASYNC_HANDLERS) - - def process_key_event(self, keyval, is_press, state, reply_cb, error_cb): - self.__engine.ProcessKeyEvent(keyval, is_press, state, - reply_handler = reply_cb, - error_handler = error_cb) - - def set_cursor_location(self, x, y, w, h): - self.__engine.SetCursorLocation(x, y, w, h, - **ibus.DEFAULT_ASYNC_HANDLERS) - - def enable(self): - self.__engine.Enable(**ibus.DEFAULT_ASYNC_HANDLERS) - - def disable(self): - self.__engine.Disable(**ibus.DEFAULT_ASYNC_HANDLERS) - - # cursor for lookup table - - def page_up(self): - self.__engine.PageUp(**ibus.DEFAULT_ASYNC_HANDLERS) - - def page_down(self): - self.__engine.PageDown(**ibus.DEFAULT_ASYNC_HANDLERS) - - def cursor_up(self): - self.__engine.CursorUp(**ibus.DEFAULT_ASYNC_HANDLERS) - - def cursor_down(self): - self.__engine.CursorDown(**ibus.DEFAULT_ASYNC_HANDLERS) - - def property_activate(self, prop_name, prop_state): - self.__engine.PropertyActivate(prop_name, prop_state, - **ibus.DEFAULT_ASYNC_HANDLERS) - - def property_show(self, prop_name): - self.__engine.PropertyShow(prop_name, - **ibus.DEFAULT_ASYNC_HANDLERS) - - def property_hide(self, prop_name): - self.__engine.PropertyHide(prop_name, - **ibus.DEFAULT_ASYNC_HANDLERS) - - def destroy(self): - ibus.Object.destroy(self) - if self.__engine: - self.__engine.Destroy(**ibus.DEFAULT_ASYNC_HANDLERS) - self.__engine = None - self.__ibusconn = None - - def __ibusconn_destroy_cb(self, ibusconn): - self.__engine = None - self.destroy() - -gobject.type_register(Engine) - diff --git a/daemon/enginefactory.py b/daemon/enginefactory.py deleted file mode 100644 index 5ef6cc6..0000000 --- a/daemon/enginefactory.py +++ /dev/null @@ -1,83 +0,0 @@ -# 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 weakref -import gobject -import ibus -from engine import Engine - -class EngineFactory(ibus.Object): - def __init__(self, ibusconn, object_path): - super(EngineFactory, self).__init__() - self._ibusconn = ibusconn - self._object_path = object_path - self._factory = self._ibusconn.get_object(self._object_path) - - self._ibusconn.connect("destroy", self.__ibusconn_destroy_cb) - - self._ibusconn.connect("dbus-signal", self.__dbus_signal_cb) - self._engines = weakref.WeakValueDictionary() - - self._info = None - - def get_object_path(self): - return self._object_path - - def get_info(self): - if self._info == None: - self._info = self._factory.GetInfo() - return self._info - - def create_engine(self): - object_path = self._factory.CreateEngine() - engine = Engine(self, self._ibusconn, object_path) - self._engines[object_path] = engine - return engine - - def destroy(self): - ibus.Object.destroy(self) - self._ibusconn = None - self._factory = None - - def __ibusconn_destroy_cb(self, ibusconn): - self.destroy() - - def __dbus_signal_cb(self, ibusconn, message): - object_path = message.get_path() - if object_path in self._engines: - if self._engines[object_path].handle_dbus_signal(message): - ibusconn.stop_emission("dbus-signal") - return True - return False - - # methods for cmp - def __lt__(self, other): - x = self.get_info() - y = other.get_info() - if x[1] < y[1]: return True - if x[1] == y[1]: return x[0] < y[0] - - def __gt__(self, other): - x = self.get_info() - y = other.get_info() - if x[1] > y[1]: return True - if x[1] == y[1]: return x[0] > y[0] - diff --git a/daemon/factorymanager.py b/daemon/factorymanager.py deleted file mode 100644 index 351f40c..0000000 --- a/daemon/factorymanager.py +++ /dev/null @@ -1,123 +0,0 @@ -# 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 gobject -import ibus -from enginefactory import EngineFactory - -class FactoryManager(ibus.Object): - __gsignals__ = { - 'new-factories-added' : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, ) - ), - 'default-factory-changed' : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, ) - ) - } - - def __init__(self): - super(FactoryManager, self).__init__() - self.__factories = {} - self.__ibusconn_factory_dict = {} - self.__default_factory = None - self.__sorted_factories = None - - def register_factories(self, object_paths, ibusconn): - if ibusconn in self.__factories: - raise ibus.IBusException("this conn has registered factories!") - - self.__ibusconn_factory_dict[ibusconn] = [] - - for object_path in object_paths: - if object_path in self.__factories: - raise ibus.IBusException( - "Factory [%s] has been registered!" % object_path) - - factory = EngineFactory(ibusconn, object_path) - self.__factories[object_path] = factory - self.__ibusconn_factory_dict[ibusconn].append(object_path) - self.__sorted_factories = None - - ibusconn.connect("destroy", self.__ibusconn_destroy_cb) - - self.emit("new-factories-added", - self.__ibusconn_factory_dict[ibusconn][:]) - - def get_default_factory(self): - if self.__default_factory == None: - factories = self.__get_sorted_factories() - if factories: - self.set_default_factory(factories[0]) - - return self.__default_factory - - def set_default_factory(self, factory): - if factory in self.__get_sorted_factories() or factory == None: - if self.__default_factory != factory: - self.__default_factory = factory - self.emit("default-factory-changed", self.__default_factory) - else: - print "unknown factory" - - def get_next_factory(self, factory): - factories = self.__get_sorted_factories() - i = factories.index(factory) + 1 - if i >= len(factories): - i = 0 - - return factories[i] - - def get_factories(self): - return self.__factories.keys() - - def get_factory_info(self, factory_path): - factory = self.__factories[factory_path] - return factory.get_info() - - def get_factory(self, factory_path): - factory = self.__factories.get(factory_path, None) - return factory - - def __get_sorted_factories(self, resort = False): - if not self.__sorted_factories or resort: - factories = self.__factories.values() - factories.sort() - self.__sorted_factories = factories - return self.__sorted_factories - - def __ibusconn_destroy_cb(self, ibusconn): - assert ibusconn in self.__ibusconn_factory_dict - - for object_path in self.__ibusconn_factory_dict[ibusconn]: - factory = self.__factories[object_path] - if factory == self.__default_factory: - self.set_default_factory(None) - del self.__factories[object_path] - - del self.__ibusconn_factory_dict[ibusconn] - self.__sorted_factories = None - -gobject.type_register(FactoryManager) - diff --git a/daemon/ibus-daemon.in b/daemon/ibus-daemon.in deleted file mode 100644 index a572c8b..0000000 --- a/daemon/ibus-daemon.in +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -# -# 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 - -prefix=@prefix@ -export IBUS_DATAROOTDIR=@datarootdir@ -exec python @prefix@/share/@PACKAGE@/daemon/ibusdaemon.py $@ - diff --git a/daemon/ibusdaemon.py b/daemon/ibusdaemon.py deleted file mode 100644 index b2f44c8..0000000 --- a/daemon/ibusdaemon.py +++ /dev/null @@ -1,112 +0,0 @@ -# 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 os -import sys -import getopt -import getpass -import gobject -import dbus.server -import dbus.mainloop.glib -import ibus -from _dbus import DBus -from bus import IBus -from connection import Connection - - -class IBusServer(dbus.server.Server): - def __init__(self, *args, **kargs): - super(IBusServer, self).__init__() - - self.__ibus = IBus() - # self.__launch_auto_load_engines() - - # def __launch_auto_load_engines(self): - # engines = [] - # try: - # engines = self.__ibus.config_get_value("general", "preload_engines", None) - # if not engines: - # engines = [] - # except: - # pass - # for e in engines: - # try: - # lang, name = e.split(":") - # self.__ibus.register_start_engine(lang, name, None) - # except: - # pass - - def connection_added(self, dbusconn): - conn = Connection(dbusconn) - self.__ibus.new_connection(conn) - DBus(conn) - - def connection_removed(self, dbusconn): - # do nothing. - pass - -def launch_ibus(): - dbus.mainloop.glib.DBusGMainLoop(set_as_default = True) - loop = gobject.MainLoop() - try: - os.mkdir("/tmp/ibus-%s" % getpass.getuser()) - except: - pass - bus = IBusServer(ibus.IBUS_ADDR) - try: - loop.run() - except KeyboardInterrupt, e: - print "daemon exits" - sys.exit() - - -def print_help(out, v = 0): - print >> out, "-h, --help show this message." - print >> out, "-d, --daemonize daemonize ibus" - sys.exit(v) - -def main(): - daemonize = False - shortopt = "hd" - longopt = ["help", "daemonize"] - try: - opts, args = getopt.getopt(sys.argv[1:], shortopt, longopt) - except getopt.GetoptError, err: - print_help(sys.stderr, 1) - - for o, a in opts: - if o in ("-h", "--help"): - print_help(sys.stdout) - elif o in ("-d", "--daemonize"): - daemonize = True - else: - print >> sys.stderr, "Unknown argument: %s" % o - print_help(sys.stderr, 1) - - if daemonize: - if os.fork(): - sys.exit() - - launch_ibus() - - -if __name__ == "__main__": - main() diff --git a/daemon/inputcontext.py b/daemon/inputcontext.py deleted file mode 100644 index 8e433a2..0000000 --- a/daemon/inputcontext.py +++ /dev/null @@ -1,449 +0,0 @@ -# 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 gobject -import ibus - -IBUS_CAP_PREEDIT = 1 -IBUS_CAP_AUX_STRING = 1 << 1 -IBUS_CAP_LOOKUP_TABLE = 1 << 2 -IBUS_CAP_FOCUS = 1 << 3 - -class InputContext(ibus.Object): - id = 1 - __gsignals__ = { - "update-preedit" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_INT, gobject.TYPE_BOOLEAN)), - "show-preedit" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "hide-preedit" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "update-aux-string" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN)), - "show-aux-string" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "hide-aux-string" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "update-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN)), - "show-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "hide-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "page-up-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "page-down-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "cursor-up-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "cursor-down-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "register-properties" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, )), - "update-property" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, )), - "engine-lost" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - } - - def __init__(self, name, ibusconn): - super(InputContext, self).__init__() - self.__id = "%d" % InputContext.id - InputContext.id += 1 - self.__ibusconn = ibusconn - self.__ibusconn.connect("destroy", self.__ibusconn_destroy_cb) - - # init default values - self.__enable = False - self.__engine = None - self.__engine_handlers = [] - - # client state - self.__aux_string = None - self.__aux_attrs = None - self.__aux_visible = False - - # capabitlies - self.__support_preedit = True - self.__support_aux_string = False - self.__support_lookup_table = False - self.__support_focus = 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 - - def get_id(self): - return self.__id; - - def get_preedit_string(self): - return self.__preedit_string, self.__preedit_attrs, self.__cursor_pos - - def get_aux_string(self): - 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, - 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) - - def focus_in(self): - if self.__engine and self.__enable: - self.__engine.focus_in() - - def focus_out(self): - if self.__engine and self.__enable: - self.__engine.focus_out() - - def reset(self): - if self.__engine and self.__enable: - self.__engine.reset() - - def page_up(self): - if self.__engine and self.__enable: - self.__engine.page_up() - - def page_down(self): - if self.__engine and self.__enable: - self.__engine.page_down() - - def cursor_up(self): - if self.__engine and self.__enable: - self.__engine.cursor_up() - - def cursor_down(self): - if self.__engine and self.__enable: - self.__engine.cursor_down() - - def property_activate(self, 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 and self.__enable: - self.__engine.property_show(prop_name) - - def property_hide(self, prop_name): - if self.__engine and self.__enable: - self.__engine.property_hide(prop_name) - - def is_enabled(self): - return self.__enable - - def set_capabilities(self, caps): - self.__support_preedit = bool(caps & IBUS_CAP_PREEDIT) - self.__support_aux_string = bool(caps & IBUS_CAP_AUX_STRING) - self.__support_lookup_table = bool(caps & IBUS_CAP_LOOKUP_TABLE) - self.__support_focus = bool(caps & IBUS_CAP_FOCUS) - - def get_support_focus(self): - return self.__support_focus - - 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() - self.__engine.focus_in() - else: - self.hide_preedit() - 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) - - 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.__support_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.__support_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.__support_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: - return - - if self.__engine != None: - self.__remove_engine_handlers() - self.__engine.destroy() - self.__engine = None - - self.__engine = engine - self.__install_engine_handlers() - - def get_engine(self): - return self.__engine - - def get_factory(self): - 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.__support_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.emit("engine-lost") - - 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): - if not self.__enable: - return - self.commit_string(text) - - 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): - if not self.__enable: - return - self.show_preedit() - - def __hide_preedit_cb(self, engine): - if not self.__enable: - return - self.hide_preedit() - - 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 - - if self.__support_aux_string: - self.__ibusconn.emit_dbus_signal("UpdateAuxString", self.__id, text, attrs, visible) - else: - self.emit("update-aux-string", text, attrs, visible) - - def __show_aux_string_cb(self, engine): - if not self.__enable: - return - self.__aux_visible = True - - if self.__support_aux_string: - self.__ibusconn.emit_dbus_signal("ShowAuxString", self.__id) - else: - self.emit("show-aux-string") - - def __hide_aux_string_cb(self, engine): - if not self.__enable: - return - self.__aux_visible = False - - if self.__support_aux_string: - self.__ibusconn.emit_dbus_signal("HideAuxString", self.__id) - else: - self.emit("hide-aux-string") - - 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 - - if self.__support_lookup_table: - self.__ibusconn.emit_dbus_signal("UpdateLookupTable", self.__id, lookup_table, visible) - else: - self.emit("update-lookup-table", lookup_table, visible) - - def __show_lookup_table_cb(self, engine): - if not self.__enable: - return - self.__lookup_table_visible = True - - if self.__support_lookup_table: - self.__ibusconn.emit_dbus_signal("ShowLookupTable", self.__id) - else: - self.emit("show-lookup-table") - - def __hide_lookup_table_cb(self, engine): - if not self.__enable: - return - self.__lookup_table_visible = False - - if self.__support_lookup_table: - self.__ibusconn.emit_dbus_signal("HideLookupTable", self.__id) - else: - self.emit("hide-lookup-table") - - def __page_up_lookup_table_cb(self, engine): - if not self.__enable: - return - - if self.__support_lookup_table: - self.__ibusconn.emit_dbus_signal("PageUpLookupTable", self.__id) - else: - self.emit("page-up-lookup-table") - - def __page_down_lookup_table_cb(self, engine): - if not self.__enable: - return - - if self.__support_lookup_table: - self.__ibusconn.emit_dbus_signal("PageDownLookupTable", self.__id) - else: - self.emit("page-down-lookup-table") - - def __cursor_up_lookup_table_cb(self, engine): - if not self.__enable: - return - - if self.__support_lookup_table: - self.__ibusconn.emit_dbus_signal("CursorUpLookupTable", self.__id) - else: - self.emit("cursor-up-lookup-table") - - def __cursor_down_lookup_table_cb(self, engine): - if not self.__enable: - return - - if self.__support_lookup_table: - self.__ibusconn.emit_dbus_signal("CursorDownLookupTable", self.__id) - else: - self.emit("cursor-down-lookup-table") - - def __register_properties_cb(self, engine, props): - if not self.__enable: - return - self.emit("register-properties", props) - - 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 - - map(self.__engine.disconnect, self.__engine_handlers) - del self.__engine_handlers[:] - - 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) - ) - - for signal, handler in signals: - id = self.__engine.connect(signal, handler) - self.__engine_handlers.append(id) - -gobject.type_register(InputContext) diff --git a/daemon/lookuptable.py b/daemon/lookuptable.py deleted file mode 100644 index 02d2cbc..0000000 --- a/daemon/lookuptable.py +++ /dev/null @@ -1,95 +0,0 @@ -# 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 dbus - -class Candidates(list): - SIGNATURE = "a(saau)" - def to_dbus_value(self): - value = dbus.Array(signature = "(saau)") - for text, attrs in self: - value.append((text, attrs.to_dbus_value()), "(s%s)" % attrs.SIGNATURE) - - def from_dbus_value(self): - pass - -class LookupTable(object): - SIGNATURE = "(ibia(saau))" - - def __init__(self, page_size = 5): - self._page_size = page_size - self._cursor_visible = False - self._cursor_pos = 0 - self._candidates = [] - - def set_page_size(self, page_size): - self._page_size = page_size - - def get_page_size(self): - return self._page_size - - def show_cursor(self): - self._cursor_visible = True - - def hide_cursor(self): - self._cursor_visible = False - - def is_cursor_visible(self): - return self._cursor_visible - - def get_current_page_start(self): - return(self._cursor_pos / self._page_size) * self._page_size - - def set_cursor_pos(self, pos): - self._current_pos = pos - - def get_cursor_pos(self): - return self._current_pos - - def get_cursor_pos_in_current_page(self): - return self._current_pos % self._page_size - - def page_up(self): - pass - - def page_down(self): - pass - - def cursor_up(self): - pass - - def cursor_down(self): - pass - - def clear(self): - self._candidates = [] - - def append_candidate(self, candidate, attrs = None): - self._candidates.append((candidates, attrs)) - - def get_candidate(self, index): - return self._candidates[index] - - def to_dbus_struct(self): - pass - - def from_dbus_struct(self, value): - pass diff --git a/daemon/notifications.py b/daemon/notifications.py deleted file mode 100644 index 370bdac..0000000 --- a/daemon/notifications.py +++ /dev/null @@ -1,92 +0,0 @@ -# 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 gobject -import ibus - -class Notifications(ibus.Object): - __gsignals__ = { - "notification-closed" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_UINT, gobject.TYPE_UINT)), - "action-invoked" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_UINT, gobject.TYPE_STRING)), - } - - def __init__(self, ibusconn): - super(Notifications, self).__init__() - self.__ibusconn = ibusconn - self.__notifications = self.__ibusconn.get_object(ibus.IBUS_NOTIFICATIONS_PATH) - - self.__ibusconn.connect("destroy", self.__ibusconn_destroy_cb) - self.__ibusconn.connect("dbus-signal", self.__dbus_signal_cb) - - def notify(self, replaces_id, app_icon, summary, body, actions, expire_timeout): - id = self.__notifications.Notify( - replaces_id, app_icon, summary, body, actions, expire_timeout) - return id - - def close_notification(self, id): - return self.__notifications.CloseNotifications(id) - - def __dbus_signal_cb(self, ibusconn, message): - if message.is_signal(ibus.IBUS_NOTIFICATIONS_IFACE, "NotificationsClosed"): - args = message.get_args_list() - self.emit("notifications-closed", args[0], args[1]) - elif message.is_signal(ibus.IBUS_NOTIFICATIONS_IFACE, "ActionInvoked"): - args = message.get_args_list() - self.emit("action-invoked", args[0], args[1]) - else: - return False - ibusconn.stop_emission("dbus-signal") - return False - - def __ibusconn_destroy_cb(self, ibusconn): - self.__ibusconn = None - self.destroy() - -gobject.type_register(Notifications) - - -class DummyNotifications(ibus.Object): - __gsignals__ = { - "notification-closed" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_UINT, gobject.TYPE_UINT)), - "action-invoked" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_UINT, gobject.TYPE_STRING)), - } - - def notify(self, replaces_id, app_icon, summary, body, actions, expire_timeout): - return 0 - - def close_notification(self, id): - pass - -gobject.type_register(DummyNotifications) - - diff --git a/daemon/panel.py b/daemon/panel.py deleted file mode 100644 index aee1185..0000000 --- a/daemon/panel.py +++ /dev/null @@ -1,262 +0,0 @@ -# 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 gobject -import ibus - -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, - ()), - "property-activate" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_STRING, gobject.TYPE_INT)), - "property-show" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_STRING, )), - "property-hide" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_STRING, )), - } - - def __init__(self, ibusconn): - super(Panel, self).__init__() - self.__ibusconn = ibusconn - self.__panel = self.__ibusconn.get_object(ibus.IBUS_PANEL_PATH) - - self.__ibusconn.connect("destroy", self.__ibusconn_destroy_cb) - self.__ibusconn.connect("dbus-signal", self.__dbus_signal_cb) - - def set_cursor_location(self, x, y, w, h): - self.__panel.SetCursorLocation(x, y, w, h, - **ibus.DEFAULT_ASYNC_HANDLERS) - - def update_preedit(self, text, attrs, cursor_pos, visible): - self.__panel.UpdatePreedit(text, attrs, cursor_pos, visible, - **ibus.DEFAULT_ASYNC_HANDLERS) - - def show_preedit(self): - self.__panel.ShowPreedit(**ibus.DEFAULT_ASYNC_HANDLERS) - - def hide_preedit(self): - self.__panel.HidePreedit(**ibus.DEFAULT_ASYNC_HANDLERS) - - def update_aux_string(self, text, attrs, visible): - self.__panel.UpdateAuxString(text, attrs, visible, - **ibus.DEFAULT_ASYNC_HANDLERS) - - def show_aux_string(self): - self.__panel.ShowAuxString(**ibus.DEFAULT_ASYNC_HANDLERS) - - def hide_aux_string(self): - self.__panel.HideAuxString(**ibus.DEFAULT_ASYNC_HANDLERS) - - def update_lookup_table(self, lookup_table, visible): - self.__panel.UpdateLookupTable(lookup_table, visible, - **ibus.DEFAULT_ASYNC_HANDLERS) - - def show_lookup_table(self): - self.__panel.ShowLookupTable(**ibus.DEFAULT_ASYNC_HANDLERS) - - def hide_lookup_table(self): - self.__panel.HideLookupTable(**ibus.DEFAULT_ASYNC_HANDLERS) - - def page_up_lookup_table(self): - self.__panel.PageUpLookupTable(**ibus.DEFAULT_ASYNC_HANDLERS) - - def page_down_lookup_table(self): - self.__panel.PageDownLookupTable(**ibus.DEFAULT_ASYNC_HANDLERS) - - def cursor_up_lookup_table(self): - self.__panel.CursorUpLookupTable(**ibus.DEFAULT_ASYNC_HANDLERS) - - def cursor_down_lookup_table(self): - self.__panel.CursorDownLookupTable(**ibus.DEFAULT_ASYNC_HANDLERS) - - def register_properties(self, props): - self.__panel.RegisterProperties(props, - **ibus.DEFAULT_ASYNC_HANDLERS) - - def update_property(self, prop): - self.__panel.UpdateProperty(prop, - **ibus.DEFAULT_ASYNC_HANDLERS) - - def show_language_bar(self): - self.__panel.ShowLanguageBar(**ibus.DEFAULT_ASYNC_HANDLERS) - - def hide_language_bar(self): - self.__panel.HideLanguageBar(**ibus.DEFAULT_ASYNC_HANDLERS) - - def focus_in(self, ic): - self.__panel.FocusIn(ic, **ibus.DEFAULT_ASYNC_HANDLERS) - - def focus_out(self, ic): - self.__panel.FocusOut(ic, **ibus.DEFAULT_ASYNC_HANDLERS) - - def states_changed(self): - self.__panel.StatesChanged(**ibus.DEFAULT_ASYNC_HANDLERS) - - def reset(self): - self.__panel.Reset(**ibus.DEFAULT_ASYNC_HANDLERS) - - def start_setup(self): - self.__panel.StartSetup(**ibus.DEFAULT_ASYNC_HANDLERS) - - def destroy(self): - if self.__ibusconn != None: - self.__panel.Destroy(**ibus.DEFAULT_ASYNC_HANDLERS) - - self.__ibusconn = None - self.__panel = None - ibus.Object.destroy(self) - - # signal callbacks - def __ibusconn_destroy_cb(self, ibusconn): - self.__ibusconn = None - self.destroy() - - def __dbus_signal_cb(self, ibusconn, message): - 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") - elif message.is_signal(ibus.IBUS_PANEL_IFACE, "PropertyActivate"): - args = message.get_args_list() - self.emit("property-activate", args[0], args[1]) - elif message.is_signal(ibus.IBUS_PANEL_IFACE, "PropertyShow"): - args = message.get_args_list() - self.emit("property-show", args[0]) - elif message.is_signal(ibus.IBUS_PANEL_IFACE, "PropertyHide"): - args = message.get_args_list() - self.emit("property-hide", args[0]) - else: - return False - ibusconn.stop_emission("dbus-signal") - return True - - # methods for cmp - # def __lt__(self, other): - # x = self.get_info() - # y = other.get_info() - # if x[1] < y[1]: return True - # if x[1] == y[1]: return x[0] < y[0] - # - # def __gt__(self, other): - # x = self.get_info() - # y = other.get_info() - # if x[1] > y[1]: return True - # if x[1] == y[1]: return x[0] > y[0] - -gobject.type_register(Panel) - -class DummyPanel(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, - ()), - "property-activate" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_STRING, )), - "property-show" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_STRING, )), - "property-hide" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_STRING, )), - } - - def set_cursor_location(self, x, y, w, h): - pass - - def update_preedit(self, text, attrs, cursor_pos, visible): - pass - - def update_aux_string(self, text, attrs, visible): - pass - - def update_lookup_table(self, lookup_table, visible): - pass - - def register_properties(self, props): - pass - - def update_property(self, prop): - pass - - def show_language_bar(self): - pass - - def hide_language_bar(self): - pass - - def focus_in(self, ic): - pass - - def focus_out(self, ic): - pass - - def states_changed(self): - pass - - def reset(self): - pass - - def start_setup(self): - pass - -gobject.type_register(DummyPanel) diff --git a/daemon/register.py b/daemon/register.py deleted file mode 100644 index bfef2b3..0000000 --- a/daemon/register.py +++ /dev/null @@ -1,205 +0,0 @@ -# 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 os -from os import path -import signal -import glob -import ibus -import locale - -locale.setlocale(locale.LC_ALL, "") - -LANG = tuple() -try: - LANG = locale.getlocale()[0], locale.getlocale()[0].split("_")[0] -except: - pass - -IBUS_DATAROOTDIR = os.getenv("IBUS_DATAROOTDIR") - -class Engine(ibus.Object): - def __init__(self, name, local_name, lang = "other", icon = "", author = "", credits = "", _exec = "", pid = 0): - super(Engine, self).__init__() - self.name = name - self.local_name = local_name - self.lang = lang - self.icon = icon - self.author = author - self.credits = credits - self._exec = _exec - self.pid = pid - - def start(self): - if self.pid != 0: - return - pid = os.fork() - if pid > 0: # parent - self.pid = pid - elif pid == 0: # child - os.setpgrp() - args = self._exec.split() - os.execv(args[0], args) - sys.exit(1) - - def stop(self, force = False): - if self.pid == 0: - return - try: - if force: - os.kill(-self.pid, signal.SIGKILL) - else: - os.kill(-self.pid, signal.SIGTERM) - except: - pass - - def engine_exit(self, pid): - if self.pid == pid: - self.pid = 0 - return True - return False - - def __eq__(self, o): - # We don't test icon author & credits - return self.name == o.name and \ - self.lang == o.lang and \ - self._exec == o._exec - - def __str__(self): - return "Engine('%s', '%s', '%s', '%s', '%s', '%s', '%s', %d" % (self.name, self.local_name, self.lang, \ - self.icon, self.author, \ - self.credits, self._exec, \ - self.pid) - -class Register(ibus.Object): - def __init__(self): - super(Register, self).__init__() - self.__engines = dict() - self.__load() - signal.signal(signal.SIGCHLD, self.__sigchld_cb) - - def start_engine(self, lang, name): - key = (lang, name) - if key not in self.__engines: - raise ibus.IBusException("Can not find engine(%s, %s)" % (lang, name)) - - engine = self.__engines[(lang, name)] - engine.start() - - def stop_engine(self, lang, name): - key = (lang, name) - if key not in self.__engines: - raise ibus.IBusException("Can not find engine(%s, %s)" % (lang, name)) - - engine = self.__engines[(lang, name)] - engine.stop() - - def restart_engine(self, lang, name): - key = (lang, name) - if key not in self.__engines: - raise ibus.IBusException("Can not find engine (%s, %s)" % (lang, name)) - - engine = self.__engines[(lang, name)] - engine.stop() - engine.start() - - def list_engines(self): - engines = [] - for key, e in self.__engines.items(): - engines.append((e.name, e.local_name, e.lang, e.icon, e.author, e.credits, e._exec, e.pid != 0)) - return engines - - def reload_engines(self): - self.__load() - - def __sigchld_cb(self, sig, f): - pid, state = os.wait() - for key, engine in self.__engines.items(): - if engine.engine_exit(pid): - break - - def __load(self): - _dir = path.join(IBUS_DATAROOTDIR, "ibus/engine") - for _file in glob.glob(_dir + "/*.engine"): - engine = self.__load_engine(_file) - if (engine.lang, engine.name) in self.__engines: - old_engine = self.__engines[(engine.lang, engine.name)] - if old_engine == engine: - engine.pid = old_engine.pid - self.__engines[(engine.lang, engine.name)] = engine - else: - self.__engines[(engine.lang, engine.name + " (old)")] = old_engine - self.__engines[(engine.lang, engine.name)] = engine - else: - self.__engines[(engine.lang, engine.name)] = engine - - - - def __load_engine(self, _file): - f = file(_file) - name = None - local_name = None - lang = "other" - icon = "" - author = "" - credits = "" - _exec = None - line = 0 - for l in f: - line += 1 - l = l.strip() - if l.startswith("#"): - continue - n, v = l.split("=") - if n == "Name": - name = v - if local_name == None: - local_name = name - elif n.startswith("Name."): - if n[5:] in LANG: - local_name = v - elif n == "Lang": - lang = v - elif n == "Icon": - icon = v - elif n == "Author": - author = v - elif n == "Credits": - credits = v - elif n == "Exec": - _exec = v - else: - raise Exception("%s:%d\nUnknown value name = %s" % (_file, line, n)) - - if name == None: - raise Exception("%s: no name" % _file) - if _exec == None: - raise Exception("%s: no exec" % _file) - - return Engine(name, local_name, lang, icon, author, credits, _exec) - -if __name__ == "__main__": - import time - reg = Register() - reg.start_engine("zh", "py") - time.sleep(3) - reg.stop_engine("zh", "py") - |