Add Ctrl+space customization.
[platform/upstream/ibus.git] / setup / main.py
index 300f11b..a8acc7a 100644 (file)
@@ -66,31 +66,40 @@ class Setup(object):
 
     def __init__(self):
         super(Setup, self).__init__()
+
+        # IBus.Bus() calls ibus_bus_new().
+        # Gtk.Builder().add_from_file() also calls ibus_bus_new_async()
+        # via ibus_im_context_new().
+        # Then if IBus.Bus() is called after Gtk.Builder().add_from_file(),
+        # the connection delay would be happened without an async
+        # finish function.
+        self.__bus = None
+        self.__init_bus()
+
         gtk_builder_file = path.join(path.dirname(__file__), "./setup.ui")
         self.__builder = Gtk.Builder()
         self.__builder.set_translation_domain(DOMAINNAME)
         self.__builder.add_from_file(gtk_builder_file);
-        self.__bus = None
-        self.__init_bus()
         self.__init_ui()
 
     def __init_hotkey(self):
-        default_values = {
-            "trigger" : (N_("trigger"), ["Control+space"]),
-            "enable_unconditional" : (N_("enable"), []),
-            "disable_unconditional" : (N_("disable"), [])
-        }
-
-        values = dict(self.__config.get_values("general/hotkey"))
-
-        for name, (label, shortcuts) in default_values.items():
-            shortcuts = values.get(name, shortcuts)
-            button = self.__builder.get_object("button_%s" % name)
-            entry = self.__builder.get_object("entry_%s" % name)
-            entry.set_text("; ".join(shortcuts))
-            entry.set_tooltip_text("\n".join(shortcuts))
-            button.connect("clicked", self.__shortcut_button_clicked_cb,
-                    label, "general/hotkey", name, entry)
+        name = 'triggers'
+        label = 'switch_engine'
+        variant = self.__config.get_value('general/hotkey', name)
+        if variant != None:
+            shortcuts = variant.dup_strv()
+        else:
+            shortcuts =  ['<Control>space']
+
+        button = self.__builder.get_object("button_%s" % label)
+        entry = self.__builder.get_object("entry_%s" % label)
+        entry.set_text("; ".join(shortcuts))
+        tooltip = "\n".join(shortcuts)
+        tooltip += "\n" + \
+            _("Use shortcut with shift to switch to the previous input method") 
+        entry.set_tooltip_text(tooltip)
+        button.connect("clicked", self.__shortcut_button_clicked_cb,
+                name, "general/hotkey", label, entry)
 
     def __init_panel(self):
         values = dict(self.__config.get_values("panel"))
@@ -354,7 +363,8 @@ class Setup(object):
             dlg.destroy()
             self.__flush_gtk_events()
         else:
-            message = _("IBus daemon coundn't be started in %d seconds")
+            # Translators: %d == 5 currently
+            message = _("IBus daemon could not be started in %d seconds")
             dlg = Gtk.MessageDialog(type = Gtk.MessageType.INFO,
                                     buttons = Gtk.ButtonsType.OK,
                                     text = message % timeout)
@@ -366,7 +376,8 @@ class Setup(object):
     def __shortcut_button_clicked_cb(self, button, name, section, _name, entry):
         buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                 Gtk.STOCK_OK, Gtk.ResponseType.OK)
-        title = _("Select keyboard shortcut for %s") %  _(name)
+        title = _("Select keyboard shortcut for %s") % \
+                _("switching input methods")
         dialog = keyboardshortcut.KeyboardShortcutSelectionDialog(buttons = buttons, title = title)
         text = entry.get_text()
         if text:
@@ -379,11 +390,13 @@ class Setup(object):
         dialog.destroy()
         if id != Gtk.ResponseType.OK:
             return
-        self.__config.set_value(section, _name, GLib.Variant.new_strv(shortcuts))
+        self.__config.set_value(section, name, GLib.Variant.new_strv(shortcuts))
         text = "; ".join(shortcuts)
         entry.set_text(text)
-        entry.set_tooltip_text(text)
-
+        tooltip = "\n".join(shortcuts)
+        tooltip += "\n" + \
+            _("Use shortcut with shift to switch to the previous input method") 
+        entry.set_tooltip_text(tooltip)
 
     def __item_started_column_toggled_cb(self, cell, path_str, model):
 
@@ -540,7 +553,12 @@ class Setup(object):
         Gtk.main()
 
 if __name__ == "__main__":
-    locale.setlocale(locale.LC_ALL, '')
+    try:
+        locale.setlocale(locale.LC_ALL, '')
+    except locale.Error:
+        print >> sys.stderr, "Using the fallback 'C' locale"
+        locale.setlocale(locale.LC_ALL, 'C')
+
     i18n_init()
     setup = Setup()
     setup.run()