Popdown the palette if an item in the content box gets activated, SL #4191 and SL #4253

The Palette is popped down when an item is activated. We can
listen on the 'button-release-event' on that widget. We make
sure the widget is of type PaletteMenuItem. This is similar
to what the GtkMenu is doing, see gtk_menu_shell_button_release [1].

[1] http://git.gnome.org/browse/gtk+/tree/gtk/gtkmenushell.c#n915

Signed-off-by: Simon Schampijer <simon@laptop.org>
Acked-by: Manuel Quiñones <manuq@laptop.org>
This commit is contained in:
Simon Schampijer 2012-12-10 15:47:52 +01:00
parent e49f621110
commit f5fee8a144

View File

@ -33,6 +33,7 @@ from sugar3.graphics import style
from sugar3.graphics.icon import Icon
from sugar3.graphics.palettewindow import PaletteWindow, \
_PaletteWindowWidget, _PaletteMenuWidget
from sugar3.graphics.palettemenu import PaletteMenuItem
# DEPRECATED
# Import these for backwards compatibility
@ -342,6 +343,8 @@ class Palette(PaletteWindow):
self._content.remove(self._content.get_children()[0])
if widget is not None:
widget.connect('button-release-event',
self.__widget_button_release_cb)
self._content.add(widget)
self._content.show()
else:
@ -352,6 +355,12 @@ class Palette(PaletteWindow):
self._update_accept_focus()
self._update_separators()
def __widget_button_release_cb(self, widget, event):
event_widget = Gtk.get_event_widget(event)
if isinstance(event_widget, PaletteMenuItem):
self.popdown(immediate=True)
return False
def get_label_width(self):
# Gtk.AccelLabel request doesn't include the accelerator.
label_width = self._label_alignment.get_preferred_width()[1] + \