~ubuntu-branches/ubuntu/quantal/ibus/quantal

« back to all changes in this revision

Viewing changes to .pc/05_appindicator.patch/ui/gtk/main.py

  • Committer: Bazaar Package Importer
  • Author(s): Barry Warsaw
  • Date: 2011-08-11 17:00:57 UTC
  • mfrom: (6.2.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110811170057-6dmbfs4s3cchzl7x
Tags: 1.3.99.20110419-1ubuntu1
* Merge with Debian unstable.  Remaining Ubuntu changes:
  - Indicator support:
    + Add 05_appindicator.patch: Use an indicator rather than a notification
      icon.
    + debian/control: Recommend python-appindicator.
  - debian/control: Install im-switch instead of im-config by default.
  - debian/README.source: Removed, it was outdated and no longer correct
  - debian/patches/01_ubuntu_desktop: Fix "Desktop entry needs the
    X-Ubuntu-Gettext-Domain key"  (LP: #457632)
  - debian/patches/02_title_update.patch: Rename "IBus Preferences" to
    "Keyboard Input Methods"
  - debian/patches/06_locale_parser.patch: Cherry-picked from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
import gettext
36
36
import panel
37
37
import pynotify
38
 
 
39
 
from gettext import dgettext
40
 
_  = lambda a : dgettext("ibus", a)
 
38
from i18n import _, N_
41
39
 
42
40
class UIApplication:
43
 
    def __init__ (self):
 
41
    def __init__ (self, replace):
44
42
        pynotify.init("ibus")
45
43
        self.__bus = ibus.Bus()
46
44
        self.__bus.connect("disconnected", gtk.main_quit)
52
50
        self.__bus.add_match(match_rule)
53
51
 
54
52
        self.__panel = panel.Panel(self.__bus)
55
 
        self.__bus.request_name(ibus.IBUS_SERVICE_PANEL, 0)
 
53
        flag = ibus.BUS_NAME_FLAG_ALLOW_REPLACEMENT
 
54
        if replace:
 
55
            flag = flag | ibus.BUS_NAME_FLAG_REPLACE_EXISTING
 
56
        self.__bus.request_name(ibus.IBUS_SERVICE_PANEL, flag)
 
57
        self.__bus.get_dbusconn().add_signal_receiver(self.__name_acquired_cb,
 
58
                                                      signal_name="NameAcquired")
 
59
        self.__bus.get_dbusconn().add_signal_receiver(self.__name_lost_cb,
 
60
                                                      signal_name="NameLost")
56
61
        self.__notify = pynotify.Notification("IBus", \
57
62
                            _("Some input methods have been installed, removed or updated. " \
58
63
                            "Please restart ibus input platform."), \
68
73
    def __registry_changed_cb(self, bus):
69
74
        self.__notify.show()
70
75
 
 
76
    def __name_acquired_cb(self, name):
 
77
        self.__panel.show()
 
78
 
 
79
    def __name_lost_cb(self, name):
 
80
        self.__panel.hide()
 
81
 
71
82
    def run(self):
72
83
        try:
73
84
            gtk.main()
74
85
        except KeyboardInterrupt:
75
86
            pass
76
87
 
77
 
def launch_panel():
 
88
def launch_panel(replace):
78
89
    # gtk.settings_get_default().props.gtk_theme_name = "/home/phuang/.themes/aud-Default/gtk-2.0/gtkrc"
79
90
    # gtk.rc_parse("./themes/default/gtkrc")
80
 
    UIApplication().run()
 
91
    UIApplication(replace).run()
81
92
 
82
93
def print_help(out, v = 0):
83
94
    print >> out, "-h, --help             show this message."
84
95
    print >> out, "-d, --daemonize        daemonize ibus"
 
96
    print >> out, "-r, --replace          replace existing ibus UI"
85
97
    sys.exit(v)
86
98
 
87
99
def main():
88
100
    daemonize = False
89
 
    shortopt = "hd"
90
 
    longopt = ["help", "daemonize"]
 
101
    replace = False
 
102
    shortopt = "hdr"
 
103
    longopt = ["help", "daemonize", "replace"]
91
104
    try:
92
105
        opts, args = getopt.getopt(sys.argv[1:], shortopt, longopt)
93
106
    except getopt.GetoptError, err:
98
111
            print_help(sys.stdout)
99
112
        elif o in("-d", "--daemonize"):
100
113
            daemonize = True
 
114
        elif o in("-r", "--replace"):
 
115
            replace = True
101
116
        else:
102
117
            print >> sys.stderr, "Unknown argument: %s" % o
103
118
            print_help(sys.stderr, 1)
106
121
        if os.fork():
107
122
            sys.exit()
108
123
 
109
 
    launch_panel()
 
124
    launch_panel(replace)
110
125
 
111
126
if __name__ == "__main__":
112
 
    localedir = os.getenv("IBUS_LOCALEDIR")
113
 
    gettext.bindtextdomain("ibus", localedir)
114
 
    gettext.bind_textdomain_codeset("ibus", "UTF-8")
 
127
    import i18n
 
128
    i18n.init()
115
129
    main()