~ubuntu-branches/debian/squeeze/ibus-hangul/squeeze

« back to all changes in this revision

Viewing changes to engine/main.py

  • Committer: Bazaar Package Importer
  • Author(s): LI Daobing
  • Date: 2009-02-13 20:45:24 UTC
  • Revision ID: james.westby@ubuntu.com-20090213204524-p3y4n0ttnbi78pau
Tags: upstream-0.1.1.20081023
ImportĀ upstreamĀ versionĀ 0.1.1.20081023

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim:set et sts=4 sw=4:
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# ibus-anthy - The Anthy engine for IBus
 
5
#
 
6
# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free Software Foundation; either version 2, or (at your option)
 
11
# any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program; if not, write to the Free Software
 
20
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 
 
22
import os
 
23
import sys
 
24
import getopt
 
25
import ibus
 
26
import factory
 
27
import gobject
 
28
 
 
29
class IMApp:
 
30
    def __init__(self):
 
31
        self.__mainloop = gobject.MainLoop()
 
32
        self.__bus = ibus.Bus()
 
33
        self.__bus.connect("destroy", self.__bus_destroy_cb)
 
34
        self.__engine = factory.EngineFactory(self.__bus)
 
35
        self.__bus.register_factories([factory.FACTORY_PATH])
 
36
 
 
37
    def run(self):
 
38
        self.__mainloop.run()
 
39
 
 
40
    def __bus_destroy_cb(self, bus):
 
41
        self.__mainloop.quit()
 
42
 
 
43
 
 
44
def launch_engine():
 
45
    IMApp().run()
 
46
 
 
47
def print_help(out, v = 0):
 
48
    print >> out, "-h, --help             show this message."
 
49
    print >> out, "-d, --daemonize        daemonize ibus"
 
50
    sys.exit(v)
 
51
 
 
52
def main():
 
53
    daemonize = False
 
54
    shortopt = "hd"
 
55
    longopt = ["help", "daemonize"]
 
56
    try:
 
57
        opts, args = getopt.getopt(sys.argv[1:], shortopt, longopt)
 
58
    except getopt.GetoptError, err:
 
59
        print_help(sys.stderr, 1)
 
60
 
 
61
    for o, a in opts:
 
62
        if o in ("-h", "--help"):
 
63
            print_help(sys.stdout)
 
64
        elif o in ("-d", "--daemonize"):
 
65
            daemonize = True
 
66
        else:
 
67
            print >> sys.stderr, "Unknown argument: %s" % o
 
68
            print_help(sys.stderr, 1)
 
69
 
 
70
    if daemonize:
 
71
        if os.fork():
 
72
            sys.exit()
 
73
 
 
74
    launch_engine()
 
75
 
 
76
if __name__ == "__main__":
 
77
    main()