From f5fee8a1445f76d3b04497671a93179329fe1efb Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Mon, 10 Dec 2012 15:47:52 +0100 Subject: [PATCH] Popdown the palette if an item in the content box gets activated, SL #4191 and SL #4253 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Acked-by: Manuel QuiƱones --- src/sugar3/graphics/palette.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sugar3/graphics/palette.py b/src/sugar3/graphics/palette.py index 0e49e358..a085fa97 100644 --- a/src/sugar3/graphics/palette.py +++ b/src/sugar3/graphics/palette.py @@ -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] + \