diff options
| author | Huang Peng <shawn.p.huang@gmail.com> | 2008-08-13 11:04:32 +0800 |
|---|---|---|
| committer | Huang Peng <shawn.p.huang@gmail.com> | 2008-08-13 11:04:32 +0800 |
| commit | 9e2c9217c60ca9c58b5071ec8a0da1a4abfef2d5 (patch) | |
| tree | b871594843baff5ba6f1a2088429eb113b4877d4 | |
| parent | cb0293353d50fc3c9bd38f06f9a052cd6405924f (diff) | |
| download | ibus-9e2c9217c60ca9c58b5071ec8a0da1a4abfef2d5.tar.gz ibus-9e2c9217c60ca9c58b5071ec8a0da1a4abfef2d5.tar.xz ibus-9e2c9217c60ca9c58b5071ec8a0da1a4abfef2d5.zip | |
Refine launcher code.
| -rw-r--r-- | ibus/common.py | 20 | ||||
| -rw-r--r-- | launcher/ibus.in | 20 |
2 files changed, 33 insertions, 7 deletions
diff --git a/ibus/common.py b/ibus/common.py index e0a4561..bd84862 100644 --- a/ibus/common.py +++ b/ibus/common.py @@ -30,7 +30,9 @@ __all__ = ( "IBUS_PANEL_IFACE", "default_reply_handler", "default_error_handler", - "DEFAULT_ASYNC_HANDLERS" + "DEFAULT_ASYNC_HANDLERS", + "main", + "main_quit" ) import os @@ -76,3 +78,19 @@ DEFAULT_ASYNC_HANDLERS = { "reply_handler" : default_reply_handler, "error_handler" : default_error_handler } + +__mainloop = None + +def main(): + global __mainloop + if __mainloop == None: + import gobject + __mainloop = gobject.MainLoop() + + __mainloop.run() + +def main_quit(): + global __mainloop + if __mainloop: + __mainloop.quit() + diff --git a/launcher/ibus.in b/launcher/ibus.in index 77aaf91..9db50d7 100644 --- a/launcher/ibus.in +++ b/launcher/ibus.in @@ -27,7 +27,6 @@ import sys import time import ibus import dbus -import gtk import signal daemon = "@prefix@/libexec/ibus-daemon" @@ -56,21 +55,27 @@ class IBusLauncher(object): def __bus_destroy_cb(self, bus): self.__bus = None - gtk.main_quit() + ibus.main_quit() def __signal_cb(self, sig, stack): if sig == signal.SIGCHLD: pid, status = os.wait() if pid == self.__daemon_pid: self.__daemon_pid = 0 + self.__bus = None elif pid == self.__x11_pid: self.__x11_pid = 0 elif pid == self.__panel_pid: self.__panel_pid = 0 + elif sig == signal.SIGTERM or sig == signal.SIGINT: + sys.exit(1) def __atexit_cb(self): if self.__bus: - self.__bus.kill() + try: + self.__bus.kill() + except: + pass os.kill(-os.getpid(), signal.SIGTERM) def run(self): @@ -86,6 +91,9 @@ class IBusLauncher(object): os.setpgid(0, 0) signal.signal(signal.SIGCHLD, self.__signal_cb) + signal.signal(signal.SIGINT, self.__signal_cb) + signal.signal(signal.SIGTERM, self.__signal_cb) + atexit.register(self.__atexit_cb) # start ibus-daemon self.__daemon_pid = self.__start_process(daemon, [daemon], "ibus-daemon") @@ -106,10 +114,10 @@ class IBusLauncher(object): self.__bus.connect("destroy", self.__bus_destroy_cb) - self.__x11_pid = self.__start_process(x11, [x11], "ibus-x11") + self.__x11_pid = self.__start_process(x11, [x11, "--kill-daemon"], "ibus-x11") self.__panel_pid = self.__start_process(panel, [panel], "ibus-panel") - - gtk.main() + + ibus.main() if __name__ == "__main__": IBusLauncher().run() |
