summaryrefslogtreecommitdiff
path: root/engine/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'engine/main.py')
-rw-r--r--engine/main.py42
1 files changed, 32 insertions, 10 deletions
diff --git a/engine/main.py b/engine/main.py
index 3f0801e..456ae29 100644
--- a/engine/main.py
+++ b/engine/main.py
@@ -28,24 +28,41 @@ import gobject
import locale
class IMApp:
- def __init__(self):
+ def __init__(self, exec_by_ibus):
+ self.__component = ibus.Component("org.freedesktop.IBus.Anthy",
+ "Anthy Component",
+ "0.1.0",
+ "GPL",
+ "Peng Huang <shawn.p.huang@gmail.com>")
+ self.__component.add_engine("anthy",
+ "anthy",
+ "Japanese Anthy",
+ "ja",
+ "GPL",
+ "Peng Huang <shawn.p.huang@gmail.com>",
+ "",
+ "en")
self.__mainloop = gobject.MainLoop()
self.__bus = ibus.Bus()
- self.__bus.connect("destroy", self.__bus_destroy_cb)
- self.__engine = factory.EngineFactory(self.__bus)
- self.__bus.register_factories([factory.FACTORY_PATH])
+ self.__bus.connect("disconnected", self.__bus_disconnected_cb)
+ self.__factory = factory.EngineFactory(self.__bus)
+ if exec_by_ibus:
+ self.__bus.request_name("org.freedesktop.IBus.Anthy", 0)
+ else:
+ self.__bus.register_component(self.__component)
def run(self):
self.__mainloop.run()
- def __bus_destroy_cb(self, bus):
+ def __bus_disconnected_cb(self, bus):
self.__mainloop.quit()
-def launch_engine():
- IMApp().run()
+def launch_engine(exec_by_ibus):
+ IMApp(exec_by_ibus).run()
def print_help(out, v = 0):
+ print >> out, "-i, --ibus executed by ibus."
print >> out, "-h, --help show this message."
print >> out, "-d, --daemonize daemonize ibus"
sys.exit(v)
@@ -56,9 +73,12 @@ def main():
except:
pass
+ exec_by_ibus = False
daemonize = False
- shortopt = "hd"
- longopt = ["help", "daemonize"]
+
+ shortopt = "ihd"
+ longopt = ["ibus", "help", "daemonize"]
+
try:
opts, args = getopt.getopt(sys.argv[1:], shortopt, longopt)
except getopt.GetoptError, err:
@@ -69,6 +89,8 @@ def main():
print_help(sys.stdout)
elif o in ("-d", "--daemonize"):
daemonize = True
+ elif o in ("-i", "--ibus"):
+ exec_by_ibus = True
else:
print >> sys.stderr, "Unknown argument: %s" % o
print_help(sys.stderr, 1)
@@ -77,7 +99,7 @@ def main():
if os.fork():
sys.exit()
- launch_engine()
+ launch_engine(exec_by_ibus)
if __name__ == "__main__":
main()