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 GObject
from gi.repository import SugarGestures
from sugar3.graphics import palettegroup
from sugar3.graphics import animator
from sugar3.graphics import style
@ -1062,6 +1063,7 @@ class WidgetInvoker(Invoker):
gap[0], gap[1], gap[1] + gap[2])
def __enter_notify_event_cb(self, widget, event):
if event.mode == Gdk.CrossingMode.NORMAL:
self.notify_mouse_enter()
def __leave_notify_event_cb(self, widget, event):
@ -1104,6 +1106,9 @@ class CursorInvoker(Invoker):
self._leave_hid = None
self._release_hid = None
self._item = None
self._long_pressed_recognized = False
self._long_pressed_hid = None
self._long_pressed_controller = SugarGestures.LongPressController()
if parent:
self.attach(parent)
@ -1118,12 +1123,18 @@ class CursorInvoker(Invoker):
self.__leave_notify_event_cb)
self._release_hid = self._item.connect('button-release-event',
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):
Invoker.detach(self)
self._item.disconnect(self._enter_hid)
self._item.disconnect(self._leave_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):
return self.AT_CURSOR
@ -1138,6 +1149,7 @@ class CursorInvoker(Invoker):
return rect
def __enter_notify_event_cb(self, button, event):
if event.mode == Gdk.CrossingMode.NORMAL:
self.notify_mouse_enter()
return False
@ -1147,6 +1159,9 @@ class CursorInvoker(Invoker):
return False
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 self.props.toggle_palette:
self.notify_toggle_state()
@ -1156,6 +1171,10 @@ class CursorInvoker(Invoker):
else:
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):
return self._item.get_toplevel()