diff options
author | Huang Peng <shawn.p.huang@gmail.com> | 2008-07-15 11:34:11 +0800 |
---|---|---|
committer | Huang Peng <shawn.p.huang@gmail.com> | 2008-07-15 11:34:11 +0800 |
commit | 7bf8b4112a5d180d30dcb998012ea58b48392be2 (patch) | |
tree | cdd193c292e18892f549e6b40af80546bf621be2 /daemon | |
parent | 45da4ba549e312680838bf67e27eb79ff6f09a08 (diff) | |
download | ibus-7bf8b4112a5d180d30dcb998012ea58b48392be2.tar.gz ibus-7bf8b4112a5d180d30dcb998012ea58b48392be2.tar.xz ibus-7bf8b4112a5d180d30dcb998012ea58b48392be2.zip |
Refine coding style of ibusdaemon.py
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/factorymanager.py | 1 | ||||
-rw-r--r-- | daemon/ibusdaemon.py | 99 |
2 files changed, 34 insertions, 66 deletions
diff --git a/daemon/factorymanager.py b/daemon/factorymanager.py index 8f63d1e..9a1d1f2 100644 --- a/daemon/factorymanager.py +++ b/daemon/factorymanager.py @@ -35,7 +35,6 @@ class FactoryManager(ibus.Object): def __init__(self): super(FactoryManager, self).__init__() - ibus.Object.__init__(self) self._factories = {} self._ibusconn_factory_dict = {} self._default_factory = None diff --git a/daemon/ibusdaemon.py b/daemon/ibusdaemon.py index 6f8143b..02829c5 100644 --- a/daemon/ibusdaemon.py +++ b/daemon/ibusdaemon.py @@ -32,41 +32,40 @@ import dbus.mainloop.glib import ibus from bus import IBus, IBusProxy -class DBus (dbus.service.Object): - SUPPORTS_MULTIPLE_CONNECTIONS = True +class DBus(dbus.service.Object): method = lambda **args: \ - dbus.service.method (dbus_interface = dbus.BUS_DAEMON_IFACE, \ + dbus.service.method(dbus_interface = dbus.BUS_DAEMON_IFACE, \ **args) signal = lambda **args: \ - dbus.service.signal (dbus_interface = dbus.BUS_DAEMON_IFACE, \ + dbus.service.signal(dbus_interface = dbus.BUS_DAEMON_IFACE, \ **args) - def __init__ (self): - dbus.service.Object.__init__ (self) + def __init__(self): + super(DBus, self).__init__() - @method (in_signature = "s", out_signature = "s") - def GetNameOwner (self, name): + @method(in_signature = "s", out_signature = "s") + def GetNameOwner(self, name): if name == dbus.BUS_DAEMON_NAME: return dbus.BUS_DAEMON_NAME elif name == ibus.IBUS_NAME: return ibus.IBUS_NAME - raise dbus.DBusException ( + raise dbus.DBusException( "org.freedesktop.DBus.Error.NameHasNoOwner: Could not get owner of name '%s': no such name" % name) - @method (in_signature = "s") - def AddMatch (self, rule): + @method(in_signature = "s") + def AddMatch(self, rule): pass - @signal (signature = "sss") - def NameOwnerChanged (self, name, old_owner, new_owner): + @signal(signature = "sss") + def NameOwnerChanged(self, name, old_owner, new_owner): pass class IBusServer(dbus.server.Server): def __init__(self, *args, **kargs): - super(IBusServer, self).__init__ () + super(IBusServer, self).__init__() self._ibus = IBus() @@ -75,83 +74,53 @@ class IBusServer(dbus.server.Server): # self._dbus = DBus() # self.register_object(self._dbus, dbus.BUS_DAEMON_PATH) - def _on_new_connection (self, dbusconn): - IBusProxy (self._ibus, dbusconn) - - def new_connection (self, server, dbusconn): - dbusconn.add_message_filter (self.message_filter_cb) - self._ibus.new_connection (dbusconn) - - def remove_connection (self, dbusconn): - self._ibus.remove_connection (dbusconn) - - def message_filter_cb (self, dbusconn, message): - # if message.is_method_call (dbus.LOCAL_IFACE, "Disconnected"): - # return dbus.lowlevel.HANDLER_RESULT_NOT_YET_HANDLED - - if message.get_type () == 4: # is signal - if self._ibus.dispatch_dbus_signal (dbusconn, message): - return dbus.lowlevel.HANDLER_RESULT_HANDLED - - return dbus.lowlevel.HANDLER_RESULT_NOT_YET_HANDLED - - def _print_message (self, message): - print "Got a Message (%s) : " % message.__class__.__name__ - print "\t From: %s" % message.get_sender () - print "\t To: %s" % message.get_destination () - print "\t Interface: %s" % message.get_interface () - print "\t Path: %s" % message.get_path () - print "\t Member: %s" % message.get_member () - print "\t Arguments:" - i = 0 - for arg in message.get_args_list(): - print "\t\t Arg[%d] : %s" % (i, arg) - i = i + 1 - -def launch_ibus (): - dbus.mainloop.glib.DBusGMainLoop (set_as_default = True) - loop = gobject.MainLoop () + def _on_new_connection(self, dbusconn): + IBusProxy(self._ibus, dbusconn) + +def launch_ibus(): + dbus.mainloop.glib.DBusGMainLoop(set_as_default = True) + loop = gobject.MainLoop() try: - os.mkdir ("/tmp/ibus-%s" % getpass.getuser ()) + os.mkdir("/tmp/ibus-%s" % getpass.getuser()) except: pass - bus = IBusServer (ibus.IBUS_ADDR) + bus = IBusServer(ibus.IBUS_ADDR) try: - loop.run () + loop.run() except KeyboardInterrupt, e: print "daemon exits" - sys.exit () + sys.exit() -def print_help (out, v = 0): +def print_help(out, v = 0): print >> out, "-h, --help show this message." print >> out, "-d, --daemonize daemonize ibus" - sys.exit (v) + sys.exit(v) -def main (): +def main(): daemonize = False shortopt = "hd" longopt = ["help", "daemonize"] try: - opts, args = getopt.getopt (sys.argv[1:], shortopt, longopt) + opts, args = getopt.getopt(sys.argv[1:], shortopt, longopt) except getopt.GetoptError, err: - print_help (sys.stderr, 1) + print_help(sys.stderr, 1) for o, a in opts: if o in ("-h", "--help"): - print_help (sys.stdout) + print_help(sys.stdout) elif o in ("-d", "--daemonize"): daemonize = True else: print >> sys.stderr, "Unknown argument: %s" % o - print_help (sys.stderr, 1) + print_help(sys.stderr, 1) if daemonize: - if os.fork (): - sys.exit () + if os.fork(): + sys.exit() - launch_ibus () + launch_ibus() if __name__ == "__main__": - main () + main() |