From 907edb10fd53e91f05bb4327df201345525f4d90 Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Tue, 13 Nov 2012 22:38:19 +0900 Subject: [PATCH] Disabled to show non-used GUI. --- setup/keyboardshortcut.py | 87 +++++++++++++++++++++++++---------------------- setup/main.py | 23 +++++++------ setup/setup.ui | 26 +++++++------- 3 files changed, 72 insertions(+), 64 deletions(-) diff --git a/setup/keyboardshortcut.py b/setup/keyboardshortcut.py index 3861d2f..efbdeb7 100644 --- a/setup/keyboardshortcut.py +++ b/setup/keyboardshortcut.py @@ -185,15 +185,17 @@ class KeyboardShortcutSelection(Gtk.VBox): modifiers.append(name) if keycode.startswith("_"): keycode = keycode[1:] - keys = modifiers + [keycode] - shortcut = "+".join(keys) + shortcut = "".join(map(lambda m: '<' + m + '>', modifiers)) + shortcut += keycode return shortcut def __set_shortcut_to_buttons(self, shortcut): - keys = shortcut.split("+") - mods = keys[:-1] + (keyval, state) = Gtk.accelerator_parse(shortcut) + if keyval == 0 and state == 0: + return + keys = shortcut.split('>') for name, button, mask in self.__modifier_buttons: - if name in mods: + if state & mask: button.set_active(True) else: button.set_active(False) @@ -247,54 +249,59 @@ class KeyboardShortcutSelection(Gtk.VBox): self.__update_add_and_apply_buttons() def __keycode_button_clicked_cb(self, button): - out = [] dlg = Gtk.MessageDialog(parent = self.get_toplevel(), buttons = Gtk.ButtonsType.CLOSE) + out = [dlg] message = _("Please press a key (or a key combination).\nThe dialog will be closed when the key is released.") dlg.set_markup(message) dlg.set_title(_("Please press a key (or a key combination)")) - - def __key_press_event(d, k, out): - out.append(k.copy()) - - def __key_release_event(d, k, out): - d.response(Gtk.ResponseType.OK) - - dlg.connect("key-press-event", __key_press_event, out) - dlg.connect("key-release-event", __key_release_event, None) + sw = Gtk.ScrolledWindow() + + def __accel_edited_cb(c, path, keyval, state, keycode, out): + dlg = out[0] + out.append(keyval) + out.append(state) + out.append(keycode) + dlg.response(Gtk.ResponseType.OK) + + model = Gtk.ListStore(GObject.TYPE_INT, + GObject.TYPE_UINT, + GObject.TYPE_UINT) + accel_view = Gtk.TreeView(model) + sw.add(accel_view) + column = Gtk.TreeViewColumn() + renderer = Gtk.CellRendererAccel(accel_mode=Gtk.CellRendererAccelMode.OTHER, + editable=True) + renderer.connect('accel-edited', __accel_edited_cb, out) + column.pack_start(renderer, True) + column.add_attribute(renderer, 'accel-mods', 0) + column.add_attribute(renderer, 'accel-key', 1) + column.add_attribute(renderer, 'keycode', 2) + accel_view.append_column(column) + it = model.append(None) + area = dlg.get_message_area() + area.pack_end(sw, True, True, 0) + sw.show_all() id = dlg.run() dlg.destroy() - if id != Gtk.ResponseType.OK or not out: + if id != Gtk.ResponseType.OK or len(out) == 1: return - keyevent = out[len(out) - 1] - state = keyevent.state & (Gdk.ModifierType.CONTROL_MASK | \ - Gdk.ModifierType.SHIFT_MASK | \ - Gdk.ModifierType.MOD1_MASK | \ - Gdk.ModifierType.META_MASK | \ - Gdk.ModifierType.SUPER_MASK | \ - Gdk.ModifierType.HYPER_MASK) - - - if state == 0: - state = state | Gdk.ModifierType.RELEASE_MASK - elif keyevent.keyval in (Gdk.KEY_Control_L, Gdk.KEY_Control_R) and state == Gdk.ModifierType.CONTROL_MASK: - state = state | Gdk.ModifierType.RELEASE_MASK - elif keyevent.keyval in (Gdk.KEY_Shift_L, Gdk.KEY_Shift_R) and state == Gdk.ModifierType.SHIFT_MASK: - state = state | Gdk.ModifierType.RELEASE_MASK - elif keyevent.keyval in (Gdk.KEY_Alt_L, Gdk.KEY_Alt_R) and state == Gdk.ModifierType.MOD1_MASK: - state = state | Gdk.ModifierType.RELEASE_MASK - elif keyevent.keyval in (Gdk.KEY_Meta_L, Gdk.KEY_Meta_R) and state == Gdk.ModifierType.META_MASK: - state = state | Gdk.ModifierType.RELEASE_MASK - elif keyevent.keyval in (Gdk.KEY_Super_L, Gdk.KEY_Super_R) and state == Gdk.ModifierType.SUPER_MASK: - state = state | Gdk.ModifierType.RELEASE_MASK - elif keyevent.keyval in (Gdk.KEY_Hyper_L, Gdk.KEY_Hyper_R) and state == Gdk.ModifierType.HYPER_MASK: - state = state | Gdk.ModifierType.RELEASE_MASK + keyval = out[1] + state = out[2] + keycode = out[3] for name, button, mask in self.__modifier_buttons: if state & mask: button.set_active(True) else: button.set_active(False) - self.__keycode_entry.set_text(Gdk.keyval_name(keyevent.keyval)) + + shortcut = Gtk.accelerator_name_with_keycode(None, + keyval, + keycode, + state) + shortcut = shortcut.replace('', '') + keys = shortcut.split('>') + self.__keycode_entry.set_text(keys[-1]) def __add_button_clicked_cb(self, button): shortcut = self.__get_shortcut_from_buttons() diff --git a/setup/main.py b/setup/main.py index 46209b6..1b98e17 100644 --- a/setup/main.py +++ b/setup/main.py @@ -93,21 +93,23 @@ class Setup(object): def __init_hotkey(self): default_values = { - "trigger" : (N_("trigger"), ["Control+space"]), - "enable_unconditional" : (N_("enable"), []), - "disable_unconditional" : (N_("disable"), []) + 'trigger_accel' : ('next_engine', ['space']), + 'trigger_accel_backward' : ('prev_engine', ['space']), } 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) + button = self.__builder.get_object("button_%s" % label) + entry = self.__builder.get_object("entry_%s" % label) entry.set_text("; ".join(shortcuts)) - entry.set_tooltip_text("\n".join(shortcuts)) + text = '\n'.join(shortcuts) + text = "Use ';' separated values\n" + text + entry.set_tooltip_text(text) button.connect("clicked", self.__shortcut_button_clicked_cb, - label, "general/hotkey", name, entry) + name, "general/hotkey", label, entry) + button.set_tooltip_text("Save the left entry string") def __init_panel(self): values = dict(self.__config.get_values("panel")) @@ -449,7 +451,9 @@ 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") % \ + _("next engine") if name == 'next_engine' else \ + _("previous engine") dialog = keyboardshortcut.KeyboardShortcutSelectionDialog(buttons = buttons, title = title) text = entry.get_text() if text: @@ -462,12 +466,11 @@ 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) - def __item_started_column_toggled_cb(self, cell, path_str, model): # get toggled iter diff --git a/setup/setup.ui b/setup/setup.ui index 2026172..fb4340d 100644 --- a/setup/setup.ui +++ b/setup/setup.ui @@ -122,7 +122,6 @@ True - False False The shortcut keys for switching to previous input method in the list 0 @@ -137,7 +136,7 @@ - True + True False 6 @@ -172,6 +171,7 @@ 1 2 + GTK_FILL @@ -223,7 +223,6 @@ True - False True False @@ -238,7 +237,6 @@ ... False True - False True False False @@ -260,7 +258,7 @@ - True + True False The shortcut keys for turning input method on or off 0 @@ -273,7 +271,7 @@ - True + True False 0 Enable: @@ -287,7 +285,7 @@ - True + True False 6 @@ -328,7 +326,7 @@ - True + True False 0 Disable: @@ -342,7 +340,7 @@ - True + True False 6 @@ -452,7 +450,7 @@ - True + True False Set the behavior of ibus how to show or hide language bar 0 @@ -481,7 +479,7 @@ - True + True False model_panel_show_mode @@ -521,7 +519,7 @@ Show icon on system tray False - True + True True False Show icon on system tray @@ -540,7 +538,7 @@ Show input method name on language bar False - True + True True False Show input method's name on language bar when check the checkbox @@ -1001,7 +999,7 @@ You may use up/down buttons to change it.</i></small> - True + True False 0 none -- 1.8.0