From c77adbb5dea1bfd4fe275c9789623a0360677c9e Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Thu, 21 Aug 2008 13:49:34 +0800 Subject: Add configure items for keyboard shortcuts. --- daemon/bus.py | 49 +++++++++++++++++--- ibus/modifier.py | 10 +++++ setup/keyboardshortcut.py | 2 +- setup/setup.glade | 111 +++++++++++++++++++++++----------------------- 4 files changed, 110 insertions(+), 62 deletions(-) diff --git a/daemon/bus.py b/daemon/bus.py index 6e68f1e..068da15 100644 --- a/daemon/bus.py +++ b/daemon/bus.py @@ -60,9 +60,29 @@ class IBus(ibus.Object): self.__connections = list() self.__prev_key = None - self.__shortcut_trigger = [(keysyms.space, modifier.CONTROL_MASK)] - m = modifier.CONTROL_MASK | modifier.SHIFT_MASK | modifier.RELEASE_MASK - self.__shortcut_next_engine = [(keysyms.Shift_L, m), (keysyms.Shift_R, m)] + + self.__shortcut_trigger = self.__load_config_shortcut( + CONFIG_GENERAL_SHORTCUT_TRIGGER, ["Ctrl+space"]) + self.__shortcut_next_engine = self.__load_config_shortcut( + CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE, + ["Ctrl+Shift+Release+Shift_L", "Ctrl+Shift+Release+Shift_R"]) + self.__shortcut_prev_engine = self.__load_config_shortcut( + CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE, []) + + def __load_config_shortcut(self, config_key, default_value): + + # load trigger + shortcut_strings = default_value + try: + shortcut_strings = self.__config.get_value(config_key) + except: + pass + shortcuts = [] + for s in shortcut_strings: + keyval, keymask = self.__parse_shortcut_string(s) + if keyval != 0: + shortcuts.append((keyval, keymask)) + return shortcuts def new_connection(self, dbusconn): conn = Connection(dbusconn) @@ -436,6 +456,19 @@ class IBus(ibus.Object): if key in self.__config_watch: self.__config_watch[key].remove(conn) + def __parse_shortcut_string(self, string): + keys = string.split("+") + keymask = 0 + for name, mask in modifier.MODIFIER_NAME_TABLE: + if name in keys[:-1]: + keymask |= mask + keyname = keys[-1] + if keyname[0] in "1234567890": + keyname = "_" + keyname + keyval = keysyms.__dict__.get(keyname, 0) + + return keyval, keymask + def __config_value_changed_cb(self, config, key, value): for _dir in self.__config_watch.keys(): if key.startswith(_dir): @@ -444,11 +477,15 @@ class IBus(ibus.Object): # check daemon configure if key == CONFIG_GENERAL_SHORTCUT_TRIGGER: - print value + self.__shortcut_trigger = self.__load_config_shortcut( + CONFIG_GENERAL_SHORTCUT_TRIGGER, ["Ctrl+space"]) elif key == CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE: - print value + self.__shortcut_next_engine = self.__load_config_shortcut( + CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE, + ["Ctrl+Shift+Release+Shift_L", "Ctrl+Shift+Release+Shift_R"]) elif key == CONFIG_GENERAL_SHORTCUT_PREV_ENGINE: - print value + self.__shortcut_prev_engine = self.__load_config_shortcut( + CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE, []) def __config_destroy_cb(self, config): if config == self.__config: diff --git a/ibus/modifier.py b/ibus/modifier.py index b652bd9..7f6afad 100644 --- a/ibus/modifier.py +++ b/ibus/modifier.py @@ -42,3 +42,13 @@ RELEASE_MASK = 1 << 30 MODIFIER_MASK = 0x5c001fff +MODIFIER_NAME_TABLE = ( + ("Shift", SHIFT_MASK), + ("CapsLock", LOCK_MASK), + ("Ctrl", CONTROL_MASK), + ("Alt", MOD1_MASK), + ("SUPER", SUPER_MASK), + ("Hyper", HYPER_MASK), + ("Meta", META_MASK), + ("Release", RELEASE_MASK), +) diff --git a/setup/keyboardshortcut.py b/setup/keyboardshortcut.py index eeca766..eb6219e 100644 --- a/setup/keyboardshortcut.py +++ b/setup/keyboardshortcut.py @@ -82,11 +82,11 @@ class KeyboardShortcutSelection(gtk.VBox): self.__modifier_buttons.append(("Ctrl", gtk.CheckButton("_Ctrl"), gdk.CONTROL_MASK)) self.__modifier_buttons.append(("Alt", gtk.CheckButton("A_lt"), gdk.MOD1_MASK)) self.__modifier_buttons.append(("Shift", gtk.CheckButton("_Shift"), gdk.SHIFT_MASK)) - self.__modifier_buttons.append(("Release", gtk.CheckButton("_Release"), gdk.RELEASE_MASK)) self.__modifier_buttons.append(("Meta", gtk.CheckButton("_Meta"), gdk.META_MASK)) self.__modifier_buttons.append(("Super", gtk.CheckButton("S_uper"), gdk.SUPER_MASK)) self.__modifier_buttons.append(("Hyper", gtk.CheckButton("_Hyper"), gdk.HYPER_MASK)) self.__modifier_buttons.append(("Capslock", gtk.CheckButton("Capsloc_k"), gdk.LOCK_MASK)) + self.__modifier_buttons.append(("Release", gtk.CheckButton("_Release"), gdk.RELEASE_MASK)) for name, button, mask in self.__modifier_buttons: button.connect("toggled", self.__modifier_button_toggled_cb, name) diff --git a/setup/setup.glade b/setup/setup.glade index 79294cd..d8d1c9d 100644 --- a/setup/setup.glade +++ b/setup/setup.glade @@ -1,6 +1,6 @@ - + 5 @@ -49,13 +49,19 @@ 3 3 - + True - 1 - Trigger: - GTK_JUSTIFY_RIGHT + False + True + True + ... + 0 + 2 + 3 + 2 + 3 GTK_FILL GTK_FILL 4 @@ -63,46 +69,51 @@ - + True True - False + True + ... + 0 - 1 - 2 + 2 + 3 + 1 + 2 + GTK_FILL GTK_FILL 4 4 - + True - 1 - Next engine: - GTK_JUSTIFY_RIGHT + True + False - 1 - 2 - GTK_FILL + 1 + 2 + 2 + 3 GTK_FILL 4 4 - + True - 1 - Previous engine: - GTK_JUSTIFY_RIGHT + True + False - 2 - 3 - GTK_FILL + 1 + 2 + 1 + 2 GTK_FILL 4 4 @@ -126,69 +137,59 @@ - + True - True - False + 1 + Previous engine: + GTK_JUSTIFY_RIGHT - 1 - 2 - 1 - 2 + 2 + 3 + GTK_FILL GTK_FILL 4 4 - + True - True - False + 1 + Next engine: + GTK_JUSTIFY_RIGHT - 1 - 2 - 2 - 3 + 1 + 2 + GTK_FILL GTK_FILL 4 4 - + True True - True - ... - 0 + False - 2 - 3 - 1 - 2 - GTK_FILL + 1 + 2 GTK_FILL 4 4 - + True - True - True - ... - 0 + 1 + Trigger: + GTK_JUSTIFY_RIGHT - 2 - 3 - 2 - 3 GTK_FILL GTK_FILL 4 -- cgit