Allow clicking the keybinding button a second time to cancel the binding

operation.
This commit is contained in:
Michael Webster 2013-03-31 21:11:54 -04:00
parent 3cf26cf96c
commit 4b963d4069

View File

@ -172,20 +172,30 @@ class KeybindingWidget(Gtk.HBox):
self.pack_start(self.label, False, False, 0) self.pack_start(self.label, False, False, 0)
self.button = Gtk.Button() self.button = Gtk.Button()
self.button.set_tooltip_text(_("Click to set a new accelerator key for opening and closing the menu. ") + self.button.set_tooltip_text(_("Click to set a new accelerator key for opening and closing the menu. ") +
_("Press Escape to cancel the operation")) _("Press Escape or click again to cancel the operation"))
self.button.connect("clicked", self.focus_grabbed) self.button.connect("clicked", self.clicked)
self.button.set_size_request(200, -1) self.button.set_size_request(200, -1)
self.pack_start(self.button, False, False, 4) self.pack_start(self.button, False, False, 4)
self.show_all() self.show_all()
self.event_id = None self.event_id = None
self.teaching = False
def focus_grabbed(self, widget): def clicked(self, widget):
if not self.teaching:
self.button.set_label(_("Pick an accelerator")) self.button.set_label(_("Pick an accelerator"))
self.event_id = self.win.connect( "key-release-event", self.on_key_release ) 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 on_key_release(self, widget, event): def on_key_release(self, widget, event):
self.win.disconnect(self.event_id) self.win.disconnect(self.event_id)
self.event_id = None
if event.keyval == Gdk.KEY_Escape: if event.keyval == Gdk.KEY_Escape:
self.button.set_label(self.value) self.button.set_label(self.value)
return True return True
@ -195,6 +205,7 @@ class KeybindingWidget(Gtk.HBox):
self.value = accel_string self.value = accel_string
self.emit("accel-edited") self.emit("accel-edited")
self.button.set_label(self.value) self.button.set_label(self.value)
self.teaching = False
return True return True
def sanitize(self, string): def sanitize(self, string):