Ticket #4253: 0001-Popdown-the-palette-if-an-item-in-the-content-box-ge.patch

File 0001-Popdown-the-palette-if-an-item-in-the-content-box-ge.patch, 2.1 KB (added by erikos, 10 years ago)

Popdown the palette if an item in the content box gets activated (toolkit)

  • src/sugar3/graphics/palette.py

    From 15dfb444e9cd105e9be7eac4d18107102608a3ee Mon Sep 17 00:00:00 2001
    From: Simon Schampijer <simon@laptop.org>
    Date: Mon, 10 Dec 2012 15:47:52 +0100
    Subject: [PATCH toolkit-gtk3] 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>
    ---
     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 0e49e35..a085fa9 100644
    a b from sugar3.graphics import style 
    3333from sugar3.graphics.icon import Icon
    3434from sugar3.graphics.palettewindow import PaletteWindow, \
    3535    _PaletteWindowWidget, _PaletteMenuWidget
     36from sugar3.graphics.palettemenu import PaletteMenuItem
    3637
    3738# DEPRECATED
    3839# Import these for backwards compatibility
    class Palette(PaletteWindow): 
    342343            self._content.remove(self._content.get_children()[0])
    343344
    344345        if widget is not None:
     346            widget.connect('button-release-event',
     347                           self.__widget_button_release_cb)
    345348            self._content.add(widget)
    346349            self._content.show()
    347350        else:
    class Palette(PaletteWindow): 
    352355        self._update_accept_focus()
    353356        self._update_separators()
    354357
     358    def __widget_button_release_cb(self, widget, event):
     359        event_widget = Gtk.get_event_widget(event)
     360        if isinstance(event_widget, PaletteMenuItem):
     361            self.popdown(immediate=True)
     362        return False
     363
    355364    def get_label_width(self):
    356365        # Gtk.AccelLabel request doesn't include the accelerator.
    357366        label_width = self._label_alignment.get_preferred_width()[1] + \