From a19cf9ed2787f9db492fcac4505d5bc52dbaf3a0 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Fri, 24 Jul 2015 11:19:57 -0300 Subject: [PATCH] Do not trigger events on EventIcons when button release is outside - #4863 The industry convention for mouse driven menu options is for them to be activated when two conditions are met: * a button down event occurs with the pointer inside the option, and; * a button up event occurs with the pointer inside the option. This issue was already solved on the PaletteMenuItem, but the EventIcon have the same problem. This change add a 'activate' event, that control that the two conditions are meet. The code in Sugar need use this event instead of button-release-event. --- src/sugar3/graphics/icon.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py index 43b78a75..185463c8 100644 --- a/src/sugar3/graphics/icon.py +++ b/src/sugar3/graphics/icon.py @@ -557,6 +557,10 @@ class EventIcon(Gtk.EventBox): cursor-positioned palette invoker. """ + __gsignals__ = { + 'activate': (GObject.SignalFlags.RUN_FIRST, None, []), + } + __gtype_name__ = 'SugarEventIcon' def __init__(self, **kwargs): @@ -569,6 +573,7 @@ class EventIcon(Gtk.EventBox): self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.TOUCH_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK) + self.connect('button-release-event', self.__button_release_event_cb) for key, value in kwargs.iteritems(): self.set_property(key, value) @@ -756,6 +761,11 @@ class EventIcon(Gtk.EventBox): self.set_palette(Palette(text)) + def __button_release_event_cb(self, icon, event): + alloc = self.get_allocation() + if 0 < event.x < alloc.width and 0 < event.y < alloc.height: + self.emit('activate') + class CanvasIcon(EventIcon): """