3 # ibus-tmpl - The Input Bus template project
5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 import dbus
.connection
26 import dbus
.mainloop
.glib
33 self
._dbusconn
= dbus
.connection
.Connection (ibus
.IBUS_ADDR
)
34 self
._dbusconn
.add_signal_receiver (self
._disconnected
_cb
,
36 dbus_interface
= dbus
.LOCAL_IFACE
)
37 self
._engine
= factory
.DemoEngineFactory (self
._dbusconn
)
38 self
._ibus
= self
._dbusconn
.get_object (ibus
.IBUS_NAME
, ibus
.IBUS_PATH
)
39 self
._ibus
.RegisterFactories ([factory
.FACTORY_PATH
], **ibus
.DEFAULT_ASYNC_HANDLERS
)
44 def _disconnected_cb (self
):
50 dbus
.mainloop
.glib
.DBusGMainLoop (set_as_default
=True)
53 def print_help (out
, v
= 0):
54 print >> out
, "-h, --help show this message."
55 print >> out
, "-d, --daemonize daemonize ibus"
61 longopt
= ["help", "daemonize"]
63 opts
, args
= getopt
.getopt (sys
.argv
[1:], shortopt
, longopt
)
64 except getopt
.GetoptError
, err
:
65 print_help (sys
.stderr
, 1)
68 if o
in ("-h", "--help"):
69 print_help (sys
.stdout
)
70 elif o
in ("-d", "--daemonize"):
73 print >> sys
.stderr
, "Unknown argument: %s" % o
74 print_help (sys
.stderr
, 1)
82 if __name__
== "__main__":