diff options
author | Huang Peng <shawn.p.huang@gmail.com> | 2008-09-28 10:56:11 +0800 |
---|---|---|
committer | Huang Peng <shawn.p.huang@gmail.com> | 2008-09-28 10:56:11 +0800 |
commit | 0a19866bcc57beb1d15bfe996b7c58fd054abdbc (patch) | |
tree | c44c3e05c2b5448f8c09466ca6271a1fca768f02 | |
parent | 7e28ed0209cc811b7443e15304174a730f75f8d5 (diff) | |
download | ibus-0a19866bcc57beb1d15bfe996b7c58fd054abdbc.tar.gz ibus-0a19866bcc57beb1d15bfe996b7c58fd054abdbc.tar.xz ibus-0a19866bcc57beb1d15bfe996b7c58fd054abdbc.zip |
Change Panel interface.
-rw-r--r-- | daemon/_dbus.py | 7 | ||||
-rw-r--r-- | daemon/bus.py | 22 | ||||
-rw-r--r-- | ibus/panel.py | 1 | ||||
-rw-r--r-- | panel/main.py | 6 | ||||
-rw-r--r-- | panel/panel.py | 5 |
5 files changed, 25 insertions, 16 deletions
diff --git a/daemon/_dbus.py b/daemon/_dbus.py index 1569b98..9a738ed 100644 --- a/daemon/_dbus.py +++ b/daemon/_dbus.py @@ -19,6 +19,7 @@ # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA +import gobject import dbus import dbus.service import ibus @@ -184,11 +185,15 @@ class DBusReal(ibus.Object): 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.set_sender(dbus.BUS_DAEMON_NAME) message.append(name) message.append(old_name) message.append(new_name) diff --git a/daemon/bus.py b/daemon/bus.py index 55f3c99..b5b0363 100644 --- a/daemon/bus.py +++ b/daemon/bus.py @@ -28,11 +28,12 @@ from factorymanager import FactoryManager from panel import Panel, DummyPanel from config import Config, DefaultConfig from register import Register - +import _dbus 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", @@ -69,6 +70,10 @@ class IBus(ibus.Object): 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.panel.IBUS_PANEL_NAME: + self.__panel_changed(new_name) + def __factory_manager_default_factory_changed_cb(self, manager, factory): if self.__default_factory != factory: self.__default_factory = factory @@ -371,13 +376,15 @@ class IBus(ibus.Object): ########################################################## # methods for panel ########################################################## - def register_panel(self, object_path, replace, conn): - if not isinstance(self.__panel, DummyPanel) and replace == False: - raise ibus.Exception("has have a panel!") - self.__uninstall_panel_handlers() - self.__panel.destroy() + 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() - self.__panel = Panel(conn, object_path) + self.__panel = Panel(ibusconn, ibus.panel.IBUS_PANEL_PATH) self.__install_panel_handlers() if self.__focused_context: self.__panel.focus_in(self.__focused_context.get_id()) @@ -440,6 +447,7 @@ class IBus(ibus.Object): def __panel_destroy_cb(self, panel): if panel == self.__panel: + self.__uninstall_panel_handlers() self.__panel = DummyPanel() ########################################################## diff --git a/ibus/panel.py b/ibus/panel.py index 81bfb2e..66b18bc 100644 --- a/ibus/panel.py +++ b/ibus/panel.py @@ -50,7 +50,6 @@ class PanelMenu(PanelItem): class PanelBase(ibus.Object): def __init__(self, bus): super(PanelBase, self).__init__() - bus.request_name(IBUS_PANEL_NAME) self.__proxy = PanelProxy(self, bus.get_dbusconn()) def set_cursor_location(self, x, y, w, h): diff --git a/panel/main.py b/panel/main.py index dabe085..07ea3c0 100644 --- a/panel/main.py +++ b/panel/main.py @@ -27,16 +27,12 @@ import gtk import locale import panel -PANEL_PATH = "/org/freedesktop/IBus/Panel" - class PanelApplication: def __init__ (self): self.__bus = ibus.Bus() self.__bus.connect("destroy", self.__bus_destroy_cb) - self.__panel = panel.Panel(self.__bus, PANEL_PATH) - - self.__bus.register_panel(PANEL_PATH, True) + self.__panel = panel.Panel(self.__bus) def run(self): gtk.main() diff --git a/panel/panel.py b/panel/panel.py index 1c4ad59..f745cdc 100644 --- a/panel/panel.py +++ b/panel/panel.py @@ -56,8 +56,8 @@ gtk.about_dialog_set_url_hook(url_hook, None) gtk.about_dialog_set_email_hook(email_hook, None) class Panel(ibus.PanelBase): - def __init__ (self, bus, object_path): - super(Panel, self).__init__(bus, object_path) + def __init__ (self, bus): + super(Panel, self).__init__(bus) self.__bus = bus self.__focus_ic = None self.__setup_pid = 0 @@ -102,6 +102,7 @@ class Panel(ibus.PanelBase): self.__config_load_lookup_table_orientation() self.__config_load_auto_hide() self.__config_load_custom_font() + self.__bus.request_name(ibus.panel.IBUS_PANEL_NAME, 0) def set_cursor_location(self, x, y, w, h): self.__candidate_panel.set_cursor_location(x + w, y + h) |