Improve button handling of EditableLabel. Closes LP#1092775

This commit is contained in:
Chris Jones 2013-01-30 11:27:01 +00:00
parent abf0dbfd8c
commit 9d2fb4b95c
1 changed files with 15 additions and 0 deletions

View File

@ -72,6 +72,8 @@ class EditableLabel(gtk.EventBox):
def _on_click_text(self, widget, event):
# pylint: disable-msg=W0613
"""event handling text edition"""
if event.button != 1:
return False
if event.type == gtk.gdk._2BUTTON_PRESS:
self.remove (self._label)
self._entry = gtk.Entry ()
@ -85,6 +87,9 @@ class EditableLabel(gtk.EventBox):
sig = self._entry.connect ("key-press-event",
self._on_entry_keypress)
self._entry_handler_id.append(sig)
sig = self._entry.connect("button-press-event",
self._on_entry_buttonpress)
self._entry_handler_id.append(sig)
self._entry.grab_focus ()
return(True)
return(False)
@ -126,6 +131,16 @@ class EditableLabel(gtk.EventBox):
if key == 'Escape':
self._entry_to_label (None, None)
def _on_entry_buttonpress (self, widget, event):
"""handle button events in gtk.Entry."""
# Block right clicks to avoid a deadlock.
# The correct solution here would be for _entry_to_label to trigger a
# deferred execution handler and for that handler to check if focus is
# in a GtkMenu. The problem being that we are unable to get a context
# menu for the GtkEntry.
if event.button == 3:
return True
def modify_fg(self, state, color):
"""Set the label foreground"""
self._label.modify_fg(state, color)