From 4b963d4069fca2156069cb41f9d38066770c73d9 Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Sun, 31 Mar 2013 21:11:54 -0400 Subject: [PATCH] Allow clicking the keybinding button a second time to cancel the binding operation. --- usr/lib/linuxmint/mintMenu/keybinding.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/usr/lib/linuxmint/mintMenu/keybinding.py b/usr/lib/linuxmint/mintMenu/keybinding.py index 3d49b17..d7b256c 100644 --- a/usr/lib/linuxmint/mintMenu/keybinding.py +++ b/usr/lib/linuxmint/mintMenu/keybinding.py @@ -172,20 +172,30 @@ class KeybindingWidget(Gtk.HBox): self.pack_start(self.label, False, False, 0) self.button = Gtk.Button() self.button.set_tooltip_text(_("Click to set a new accelerator key for opening and closing the menu. ") + - _("Press Escape to cancel the operation")) - self.button.connect("clicked", self.focus_grabbed) + _("Press Escape or click again to cancel the operation")) + self.button.connect("clicked", self.clicked) self.button.set_size_request(200, -1) self.pack_start(self.button, False, False, 4) self.show_all() self.event_id = None + self.teaching = False + + def clicked(self, widget): + if not self.teaching: + self.button.set_label(_("Pick an accelerator")) + self.event_id = self.win.connect( "key-release-event", self.on_key_release ) + self.teaching = True + else: + if self.event_id: + self.win.disconnect(self.event_id) + self.button.set_label(self.value) + self.teaching = False - def focus_grabbed(self, widget): - self.button.set_label(_("Pick an accelerator")) - self.event_id = self.win.connect( "key-release-event", self.on_key_release ) def on_key_release(self, widget, event): self.win.disconnect(self.event_id) + self.event_id = None if event.keyval == Gdk.KEY_Escape: self.button.set_label(self.value) return True @@ -195,6 +205,7 @@ class KeybindingWidget(Gtk.HBox): self.value = accel_string self.emit("accel-edited") self.button.set_label(self.value) + self.teaching = False return True def sanitize(self, string):