Merge branch '2016-190-enter-notify' of https://github.com/quozl/sugar-toolkit-gtk3
This commit is contained in:
commit
d60989cd92
@ -38,6 +38,18 @@ from sugar3.graphics import style
|
|||||||
from sugar3.graphics.icon import CellRendererIcon
|
from sugar3.graphics.icon import CellRendererIcon
|
||||||
|
|
||||||
|
|
||||||
|
_pointer = None
|
||||||
|
|
||||||
|
def _get_pointer_position(widget):
|
||||||
|
global _pointer
|
||||||
|
|
||||||
|
if _pointer is None:
|
||||||
|
display = widget.get_display()
|
||||||
|
manager = display.get_device_manager()
|
||||||
|
_pointer = manager.get_client_pointer()
|
||||||
|
screen, x, y = _pointer.get_position()
|
||||||
|
return (x, y)
|
||||||
|
|
||||||
def _calculate_gap(a, b):
|
def _calculate_gap(a, b):
|
||||||
"""Helper function to find the gap position and size of widget a"""
|
"""Helper function to find the gap position and size of widget a"""
|
||||||
# Test for each side if the palette and invoker are
|
# Test for each side if the palette and invoker are
|
||||||
@ -394,7 +406,6 @@ class _PaletteWindowWidget(Gtk.Window):
|
|||||||
|
|
||||||
def popup(self, invoker):
|
def popup(self, invoker):
|
||||||
if self.get_visible():
|
if self.get_visible():
|
||||||
logging.error('PaletteWindowWidget popup get_visible True')
|
|
||||||
return
|
return
|
||||||
self.connect('enter-notify-event', self.__enter_notify_event_cb)
|
self.connect('enter-notify-event', self.__enter_notify_event_cb)
|
||||||
self.connect('leave-notify-event', self.__leave_notify_event_cb)
|
self.connect('leave-notify-event', self.__leave_notify_event_cb)
|
||||||
@ -437,7 +448,7 @@ class MouseSpeedDetector(GObject.GObject):
|
|||||||
def start(self):
|
def start(self):
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
self._mouse_pos = self._get_mouse_position()
|
self._mouse_pos = _get_pointer_position(self.parent)
|
||||||
self._timeout_hid = GLib.timeout_add(self._delay, self._timer_cb)
|
self._timeout_hid = GLib.timeout_add(self._delay, self._timer_cb)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
@ -446,19 +457,9 @@ class MouseSpeedDetector(GObject.GObject):
|
|||||||
self._timeout_hid = None
|
self._timeout_hid = None
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
def _get_mouse_position(self):
|
|
||||||
if hasattr(self.parent, 'get_display'):
|
|
||||||
display = self.parent.get_display()
|
|
||||||
else:
|
|
||||||
display = Gdk.Display.get_default()
|
|
||||||
manager = display.get_device_manager()
|
|
||||||
pointer_device = manager.get_client_pointer()
|
|
||||||
screen, x, y = pointer_device.get_position()
|
|
||||||
return (x, y)
|
|
||||||
|
|
||||||
def _detect_motion(self):
|
def _detect_motion(self):
|
||||||
oldx, oldy = self._mouse_pos
|
oldx, oldy = self._mouse_pos
|
||||||
(x, y) = self._get_mouse_position()
|
(x, y) = _get_pointer_position(self.parent)
|
||||||
self._mouse_pos = (x, y)
|
self._mouse_pos = (x, y)
|
||||||
|
|
||||||
dist2 = (oldx - x) ** 2 + (oldy - y) ** 2
|
dist2 = (oldx - x) ** 2 + (oldy - y) ** 2
|
||||||
@ -845,15 +846,8 @@ class Invoker(GObject.GObject):
|
|||||||
invoker_valign = alignment[3]
|
invoker_valign = alignment[3]
|
||||||
|
|
||||||
if self._cursor_x == -1 or self._cursor_y == -1:
|
if self._cursor_x == -1 or self._cursor_y == -1:
|
||||||
if hasattr(self.parent, 'get_display'):
|
position = _get_pointer_position(self.parent)
|
||||||
display = self.parent.get_display()
|
(self._cursor_x, self._cursor_y) = position
|
||||||
else:
|
|
||||||
display = Gdk.Display.get_default()
|
|
||||||
manager = display.get_device_manager()
|
|
||||||
pointer_device = manager.get_client_pointer()
|
|
||||||
screen, x, y = pointer_device.get_position()
|
|
||||||
self._cursor_x = x
|
|
||||||
self._cursor_y = y
|
|
||||||
|
|
||||||
if self._position_hint is self.ANCHORED:
|
if self._position_hint is self.ANCHORED:
|
||||||
rect = self.get_rect()
|
rect = self.get_rect()
|
||||||
@ -1117,6 +1111,7 @@ class WidgetInvoker(Invoker):
|
|||||||
|
|
||||||
self._widget = None
|
self._widget = None
|
||||||
self._expanded = False
|
self._expanded = False
|
||||||
|
self._pointer_position = (-1, -1)
|
||||||
self._enter_hid = None
|
self._enter_hid = None
|
||||||
self._leave_hid = None
|
self._leave_hid = None
|
||||||
self._release_hid = None
|
self._release_hid = None
|
||||||
@ -1136,6 +1131,8 @@ class WidgetInvoker(Invoker):
|
|||||||
else:
|
else:
|
||||||
self._widget = parent
|
self._widget = parent
|
||||||
|
|
||||||
|
self._pointer_position = _get_pointer_position(self._widget)
|
||||||
|
|
||||||
self.notify('widget')
|
self.notify('widget')
|
||||||
|
|
||||||
self._enter_hid = self._widget.connect('enter-notify-event',
|
self._enter_hid = self._widget.connect('enter-notify-event',
|
||||||
@ -1212,6 +1209,9 @@ 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):
|
||||||
|
if (event.x_root, event.y_root) == self._pointer_position:
|
||||||
|
self._pointer_position = (-1, -1)
|
||||||
|
return False
|
||||||
if event.mode == Gdk.CrossingMode.NORMAL:
|
if event.mode == Gdk.CrossingMode.NORMAL:
|
||||||
self.notify_mouse_enter()
|
self.notify_mouse_enter()
|
||||||
|
|
||||||
@ -1303,6 +1303,7 @@ class CursorInvoker(Invoker):
|
|||||||
Invoker.__init__(self)
|
Invoker.__init__(self)
|
||||||
|
|
||||||
self._position_hint = self.AT_CURSOR
|
self._position_hint = self.AT_CURSOR
|
||||||
|
self._pointer_position = (-1, -1)
|
||||||
self._enter_hid = None
|
self._enter_hid = None
|
||||||
self._leave_hid = None
|
self._leave_hid = None
|
||||||
self._release_hid = None
|
self._release_hid = None
|
||||||
@ -1318,6 +1319,9 @@ class CursorInvoker(Invoker):
|
|||||||
Invoker.attach(self, parent)
|
Invoker.attach(self, parent)
|
||||||
|
|
||||||
self._item = parent
|
self._item = parent
|
||||||
|
|
||||||
|
self._pointer_position = _get_pointer_position(self.parent)
|
||||||
|
|
||||||
self._enter_hid = self._item.connect('enter-notify-event',
|
self._enter_hid = self._item.connect('enter-notify-event',
|
||||||
self.__enter_notify_event_cb)
|
self.__enter_notify_event_cb)
|
||||||
self._leave_hid = self._item.connect('leave-notify-event',
|
self._leave_hid = self._item.connect('leave-notify-event',
|
||||||
@ -1352,6 +1356,9 @@ class CursorInvoker(Invoker):
|
|||||||
return rect
|
return rect
|
||||||
|
|
||||||
def __enter_notify_event_cb(self, button, event):
|
def __enter_notify_event_cb(self, button, event):
|
||||||
|
if (event.x_root, event.y_root) == self._pointer_position:
|
||||||
|
self._pointer_position = (-1, -1)
|
||||||
|
return False
|
||||||
if event.mode == Gdk.CrossingMode.NORMAL:
|
if event.mode == Gdk.CrossingMode.NORMAL:
|
||||||
self.notify_mouse_enter()
|
self.notify_mouse_enter()
|
||||||
return False
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user