From 7e28ed0209cc811b7443e15304174a730f75f8d5 Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Sat, 27 Sep 2008 19:00:53 +0800 Subject: [PATCH] WIP. --- daemon/_dbus.py | 29 +++++++- ibus/bus.py | 207 +++++++++++++++++++++++++++++++------------------------- ibus/panel.py | 14 ++-- 3 files changed, 149 insertions(+), 101 deletions(-) diff --git a/daemon/_dbus.py b/daemon/_dbus.py index f6216ef..1569b98 100644 --- a/daemon/_dbus.py +++ b/daemon/_dbus.py @@ -87,6 +87,13 @@ class MatchRule: 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() @@ -157,6 +164,7 @@ class DBusReal(ibus.Object): 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 @@ -166,6 +174,7 @@ class DBusReal(ibus.Object): 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 @@ -176,6 +185,15 @@ class DBusReal(ibus.Object): conn.send_message(message) break + 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()) @@ -197,12 +215,17 @@ class DBusReal(ibus.Object): def __ibusconn_destroy_cb(self, ibusconn): name = ibusconn.get_unique_name() - if name: - del self.__unique_name_dict[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: \ @@ -213,7 +236,7 @@ class DBus(dbus.service.Object): dbus.service.signal(dbus_interface = dbus.BUS_DAEMON_IFACE, \ **args) - __bus = DBusReal() + __bus = bus def __init__(self, ibusconn): super(DBus, self).__init__(ibusconn.get_dbusconn(), dbus.BUS_DAEMON_PATH) diff --git a/ibus/bus.py b/ibus/bus.py index 5b2b614..79eade1 100644 --- a/ibus/bus.py +++ b/ibus/bus.py @@ -25,6 +25,7 @@ __all__ = ( import sys import gobject +import dbus import dbus.lowlevel import dbus.connection import dbus.mainloop.glib @@ -119,9 +120,120 @@ class Bus(ibus.Object): def __init__(self): super(Bus, self).__init__() self.__dbusconn = dbus.connection.Connection(ibus.IBUS_ADDR) - self.__bus = self.__dbusconn.get_object(ibus.IBUS_NAME, ibus.IBUS_PATH) + self.__ibus = self.__dbusconn.get_object(ibus.IBUS_NAME, ibus.IBUS_PATH) + self.__dbus = self.__dbusconn.get_object(dbus.BUS_DAEMON_NAME, dbus.BUS_DAEMON_PATH) self.__dbusconn.add_message_filter(self.__dbus_message_cb) + # define dbus methods + def get_dbus(self): + return self.__dbus + + def hello(self): + return self.__dbus.Hello() + + def request_name(self, name, flags): + return self.__dbus.RequestName(name, flags) + + def release_name(self, name): + return self.__dbus.ReleaseName(name) + + def get_name_owner(self, name): + return self.__dbus.GetNameOwner(name) + + def get_dbusconn(self): + return self.__dbusconn + + def get_address(self): + return ibus.IBUS_ADDR + + def create_input_context(self, client_name): + return self.__ibus.CreateInputContext(client_name) + + def release_input_context(self, ic): + return self.__ibus.ReleaseInputContext(ic) + + def process_key_event(self, ic, keyval, is_press, state): + return self.__ibus.ProcessKeyEvent(ic, keyval, is_press, state) + + def set_cursor_location(self, ic, x, y, w, h): + return self.__ibus.SetCursorLocation(ic, x, y, w, h) + + def foucs_in(self, ic): + return self.__ibus.FocusIn(ic) + + def foucs_out(self, ic): + return self.__ibus.FocusOut(ic) + + def reset(self, ic): + return self.__ibus.Reset(ic) + + def is_enabled(self, ic): + return self.__ibus.IsEnabled(ic) + + def set_capabilities(self, ic, caps): + return self.__ibus.SetCapabilities(ic, caps) + + def register_factories(self, object_paths): + return self.__ibus.RegisterFactories(object_paths, **ibus.DEFAULT_ASYNC_HANDLERS) + + def unregister_factories(self, object_paths): + return self.__ibus.UnregisterFactories(object_paths) + + def register_panel(self, object_path, replace = False): + return self.__ibus.RegisterPanel(object_path, replace) + + def register_config(self, object_path, replace = False): + return self.__ibus.RegisterConfig(object_path, replace) + + def get_factories(self): + return self.__ibus.GetFactories() + + def get_factory_info(self, factory_path): + return self.__ibus.GetFactoryInfo(factory_path) + + def set_factory(self, factory_path): + return self.__ibus.SetFactory(factory_path) + + def get_input_context_states(self, ic): + return self.__ibus.GetInputContextStates(ic) + + def config_add_watch(self, key): + return self.__ibus.ConfigAddWatch(key) + + def config_remove_watch(self, key): + return self.__ibus.ConfigRemoveWatch(key) + + def config_set_value(self, key, value): + return self.__ibus.ConfigSetValue(key, value) + + def config_set_list(self, key, value, list_type): + value = dbus.Array(value, signature = list_type) + return self.__ibus.ConfigSetValue(key, value) + + def config_get_value(self, key, default_value = None): + try: + return self.__ibus.ConfigGetValue(key) + except Exception, e: + return default_value + + def register_list_engines(self): + return self.__ibus.RegisterListEngines() + + def register_reload_engines(self): + return self.__ibus.RegisterReloadEngines() + + def register_start_engine(self, lang, name): + return self.__ibus.RegisterStartEngine(lang, name) + + def register_restart_engine(self, lang, name): + return self.__ibus.RegisterRestartEngine(lang, name) + + def register_stop_engine(self, lang, name): + return self.__ibus.RegisterStopEngine(lang, name) + + def kill(self): + return self.__ibus.Kill() + def __dbus_message_cb(self, conn, message): # commit string signal if message.is_signal(ibus.IBUS_IFACE, "CommitString"): @@ -225,96 +337,3 @@ class Bus(ibus.Object): return retval - def get_dbusconn(self): - return self.__dbusconn - - def get_address(self): - return ibus.IBUS_ADDR - - def create_input_context(self, client_name): - return self.__bus.CreateInputContext(client_name) - - def release_input_context(self, ic): - return self.__bus.ReleaseInputContext(ic) - - def process_key_event(self, ic, keyval, is_press, state): - return self.__bus.ProcessKeyEvent(ic, keyval, is_press, state) - - def set_cursor_location(self, ic, x, y, w, h): - return self.__bus.SetCursorLocation(ic, x, y, w, h) - - def foucs_in(self, ic): - return self.__bus.FocusIn(ic) - - def foucs_out(self, ic): - return self.__bus.FocusOut(ic) - - def reset(self, ic): - return self.__bus.Reset(ic) - - def is_enabled(self, ic): - return self.__bus.IsEnabled(ic) - - def set_capabilities(self, ic, caps): - return self.__bus.SetCapabilities(ic, caps) - - def register_factories(self, object_paths): - return self.__bus.RegisterFactories(object_paths, **ibus.DEFAULT_ASYNC_HANDLERS) - - def unregister_factories(self, object_paths): - return self.__bus.UnregisterFactories(object_paths) - - def register_panel(self, object_path, replace = False): - return self.__bus.RegisterPanel(object_path, replace) - - def register_config(self, object_path, replace = False): - return self.__bus.RegisterConfig(object_path, replace) - - def get_factories(self): - return self.__bus.GetFactories() - - def get_factory_info(self, factory_path): - return self.__bus.GetFactoryInfo(factory_path) - - def set_factory(self, factory_path): - return self.__bus.SetFactory(factory_path) - - def get_input_context_states(self, ic): - return self.__bus.GetInputContextStates(ic) - - def config_add_watch(self, key): - return self.__bus.ConfigAddWatch(key) - - def config_remove_watch(self, key): - return self.__bus.ConfigRemoveWatch(key) - - def config_set_value(self, key, value): - return self.__bus.ConfigSetValue(key, value) - - def config_set_list(self, key, value, list_type): - value = dbus.Array(value, signature = list_type) - return self.__bus.ConfigSetValue(key, value) - - def config_get_value(self, key, default_value = None): - try: - return self.__bus.ConfigGetValue(key) - except Exception, e: - return default_value - - def register_list_engines(self): - return self.__bus.RegisterListEngines() - - def register_reload_engines(self): - return self.__bus.RegisterReloadEngines() - - def register_start_engine(self, lang, name): - return self.__bus.RegisterStartEngine(lang, name) - - def register_restart_engine(self, lang, name): - return self.__bus.RegisterRestartEngine(lang, name) - - def register_stop_engine(self, lang, name): - return self.__bus.RegisterStopEngine(lang, name) - - def kill(self): - return self.__bus.Kill() diff --git a/ibus/panel.py b/ibus/panel.py index de8e3e8..81bfb2e 100644 --- a/ibus/panel.py +++ b/ibus/panel.py @@ -25,8 +25,13 @@ __all__ = ( "PanelButton", "PanelToggleButton", "PanelMenu", + "IBUS_PANEL_NAME", + "IBUS_PANEL_PATH" ) +IBUS_PANEL_NAME = "org.freedesktop.ibus.Panel" +IBUS_PANEL_PATH = "/org/freedesktop/ibus/Panel" + import ibus from ibus import interface @@ -43,9 +48,10 @@ class PanelMenu(PanelItem): pass class PanelBase(ibus.Object): - def __init__(self, bus, object_path): + def __init__(self, bus): super(PanelBase, self).__init__() - self.__proxy = PanelProxy(self, bus.get_dbusconn(), object_path) + bus.request_name(IBUS_PANEL_NAME) + self.__proxy = PanelProxy(self, bus.get_dbusconn()) def set_cursor_location(self, x, y, w, h): pass @@ -142,8 +148,8 @@ class PanelBase(ibus.Object): class PanelProxy(interface.IPanel): - def __init__ (self, panel, dbusconn, object_path): - super(PanelProxy, self).__init__(dbusconn, object_path) + def __init__ (self, panel, dbusconn): + super(PanelProxy, self).__init__(dbusconn, IBUS_PANEL_PATH) self.__dbusconn = dbusconn self.__panel = panel -- 2.7.4