CursurInvoker: add long-press gesture to raise Palette

This adds long-press gesture detection to the CursorInvoker
used in the EventIcon. This will make this gesture available
for the View icons for example.

We need to keep a boolean around to detect when a lon-press
event has happened and ignore the button-release event in
that case.

We add as well checks in the CursorInvoker and WidgetInvoker
for the enter events if they are of type Gdk.CrossingMode.NORMAL,
otherwise the Gdk.CrossingMode.TOUCH_BEGIN enter events that are detected
when a touch starts are handled and interfere.

Signed-off-by: Simon Schampijer <simon@laptop.org>
Acked-by: Manuel Quiñones <manuq@laptop.org>
This commit is contained in:
Simon Schampijer 2012-10-25 09:42:00 +00:00
parent 590785f7d1
commit a36ada99fd

View File

@ -29,6 +29,7 @@ from gi.repository import Gdk
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import GObject from gi.repository import GObject
from gi.repository import SugarGestures
from sugar3.graphics import palettegroup from sugar3.graphics import palettegroup
from sugar3.graphics import animator from sugar3.graphics import animator
from sugar3.graphics import style from sugar3.graphics import style
@ -1062,7 +1063,8 @@ class WidgetInvoker(Invoker):
gap[0], gap[1], gap[1] + gap[2]) gap[0], gap[1], gap[1] + gap[2])
def __enter_notify_event_cb(self, widget, event): def __enter_notify_event_cb(self, widget, event):
self.notify_mouse_enter() if event.mode == Gdk.CrossingMode.NORMAL:
self.notify_mouse_enter()
def __leave_notify_event_cb(self, widget, event): def __leave_notify_event_cb(self, widget, event):
if event.mode == Gdk.CrossingMode.NORMAL: if event.mode == Gdk.CrossingMode.NORMAL:
@ -1104,6 +1106,9 @@ class CursorInvoker(Invoker):
self._leave_hid = None self._leave_hid = None
self._release_hid = None self._release_hid = None
self._item = None self._item = None
self._long_pressed_recognized = False
self._long_pressed_hid = None
self._long_pressed_controller = SugarGestures.LongPressController()
if parent: if parent:
self.attach(parent) self.attach(parent)
@ -1118,12 +1123,18 @@ class CursorInvoker(Invoker):
self.__leave_notify_event_cb) self.__leave_notify_event_cb)
self._release_hid = self._item.connect('button-release-event', self._release_hid = self._item.connect('button-release-event',
self.__button_release_event_cb) self.__button_release_event_cb)
self._long_pressed_hid = self._long_pressed_controller.connect('pressed', \
self.__long_pressed_event_cb, self._item)
self._long_pressed_controller.attach(self._item, \
SugarGestures.EventControllerFlags.NONE)
def detach(self): def detach(self):
Invoker.detach(self) Invoker.detach(self)
self._item.disconnect(self._enter_hid) self._item.disconnect(self._enter_hid)
self._item.disconnect(self._leave_hid) self._item.disconnect(self._leave_hid)
self._item.disconnect(self._release_hid) self._item.disconnect(self._release_hid)
self._long_pressed_controller.detach(self._item)
self._long_pressed_controller.disconnect(self._long_pressed_hid)
def get_default_position(self): def get_default_position(self):
return self.AT_CURSOR return self.AT_CURSOR
@ -1138,7 +1149,8 @@ class CursorInvoker(Invoker):
return rect return rect
def __enter_notify_event_cb(self, button, event): def __enter_notify_event_cb(self, button, event):
self.notify_mouse_enter() if event.mode == Gdk.CrossingMode.NORMAL:
self.notify_mouse_enter()
return False return False
def __leave_notify_event_cb(self, button, event): def __leave_notify_event_cb(self, button, event):
@ -1147,6 +1159,9 @@ class CursorInvoker(Invoker):
return False return False
def __button_release_event_cb(self, button, event): def __button_release_event_cb(self, button, event):
if self._long_pressed_recognized:
self._long_pressed_recognized = False
return True
if event.button == 1: if event.button == 1:
if self.props.toggle_palette: if self.props.toggle_palette:
self.notify_toggle_state() self.notify_toggle_state()
@ -1156,6 +1171,10 @@ class CursorInvoker(Invoker):
else: else:
return False return False
def __long_pressed_event_cb(self, controller, x, y, widget):
self._long_pressed_recognized = True
self.notify_right_click()
def get_toplevel(self): def get_toplevel(self):
return self._item.get_toplevel() return self._item.get_toplevel()