From 3e6fc7dde3feda5c11d67b15be3c765e15f1ea2d Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Thu, 21 Aug 2008 08:18:48 +0800 Subject: [PATCH] WIP. --- setup/keyboardshortcut.py | 9 ++++++--- setup/main.py | 28 ++++++++++++++++++++++++++++ setup/setup.glade | 5 ++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/setup/keyboardshortcut.py b/setup/keyboardshortcut.py index 621f17b..eeca766 100644 --- a/setup/keyboardshortcut.py +++ b/setup/keyboardshortcut.py @@ -124,7 +124,7 @@ class KeyboardShortcutSelection(gtk.VBox): model.clear() for shortcut in shortcuts: model.insert(0, (shortcut,)) - self.__shortcut_view.set_model(model) + # self.__shortcut_view.set_model(model) def get_shortcuts(self): model = self.__shortcut_view.get_model() @@ -188,13 +188,15 @@ class KeyboardShortcutSelection(gtk.VBox): shortcut = self.__get_shortcut_from_buttons() selected_shortcut = self.__get_selected_shortcut() self.__add_button.set_sensitive(shortcut != None) - self.__apply_button.set_sensitive(shortcut != selected_shortcut and shortcut != None and selected_shortcut != None) + can_apply = shortcut != selected_shortcut and shortcut != None and selected_shortcut != None + self.__apply_button.set_sensitive(can_apply) def __keycode_entry_notify_cb(self, entry, arg): shortcut = self.__get_shortcut_from_buttons() selected_shortcut = self.__get_selected_shortcut() self.__add_button.set_sensitive(shortcut != None) - self.__apply_button.set_sensitive(shortcut != selected_shortcut and shortcut != None and selected_shortcut != None) + can_apply = shortcut != selected_shortcut and shortcut != None and selected_shortcut != None + self.__apply_button.set_sensitive(can_apply) def __keycode_button_clicked_cb(self, button): out = [] @@ -256,6 +258,7 @@ if __name__ == "__main__": title = "Select test", buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) dlg.add_shortcut("Ctrl+Shift+space") + dlg.set_shortcuts(None) print dlg.run() print dlg.get_shortcuts() diff --git a/setup/main.py b/setup/main.py index 9e7f4e2..9b0315b 100644 --- a/setup/main.py +++ b/setup/main.py @@ -28,6 +28,7 @@ import gtk import gobject import ibus from gtk import gdk, glade +import keyboardshortcut from gettext import dgettext _ = lambda a : dgettext("ibus", a) @@ -53,6 +54,7 @@ N_ = lambda a : a DATA_PRELOAD ) = range(8) +CONFIG_GENERAL_SHORTCUT = "/general/keyboard_shortcut_%s" CONFIG_PRELOAD_ENGINES = "/general/preload_engines" CONFIG_PANEL_LOOKUP_TABLE_ORIENTATION = "/panel/lookup_table_orientation" @@ -85,6 +87,14 @@ class Setup(object): self.__checkbutton_auto_start.set_active(self.__is_auto_start()) self.__checkbutton_auto_start.connect("toggled", self.__checkbutton_auto_start_toggled_cb) + # keyboard shortcut + for name in (N_("trigger"), N_("next_engine"), N_("prev_engine")): + shortcuts = self.__bus.config_get_value(CONFIG_GENERAL_SHORTCUT % name, []) + button = self.__xml.get_widget("button_%s" % name) + entry = self.__xml.get_widget("entry_%s" % name) + entry.set_text(";".join(shortcuts)) + button.connect("clicked", self.__shortcut_button_clicked_cb, name, entry) + # lookup table orientation self.__combobox_lookup_table_orientation = self.__xml.get_widget("combobox_lookup_table_orientation") self.__combobox_lookup_table_orientation.set_active( @@ -181,6 +191,24 @@ class Setup(object): column = gtk.TreeViewColumn("", renderer) self.__tree.append_column(column) + def __shortcut_button_clicked_cb(self, button, name, entry): + buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK) + title = _("Select keyboart shortcut for %s") % _(name) + dialog = keyboardshortcut.KeyboardShortcutSelectionDialog(buttons = buttons, title = title) + text = entry.get_text() + if text: + shortcuts = text.split(';') + else: + shortcuts = None + dialog.set_shortcuts(shortcuts) + id = dialog.run() + shortcuts = dialog.get_shortcuts() + dialog.destroy() + if id != gtk.RESPONSE_OK: + return + self.__bus.config_set_value(CONFIG_GENERAL_SHORTCUT % name, shortcuts) + entry.set_text(";".join(shortcuts)) + def __item_started_column_toggled_cb(self, cell, path_str, model): diff --git a/setup/setup.glade b/setup/setup.glade index 1744a5d..79294cd 100644 --- a/setup/setup.glade +++ b/setup/setup.glade @@ -1,6 +1,6 @@ - + 5 @@ -66,6 +66,7 @@ True True + False 1 @@ -128,6 +129,7 @@ True True + False 1 @@ -143,6 +145,7 @@ True True + False 1 -- 2.7.4