Position palette based on event coords, fixes #4897

Instead of getting the position of the mouse later in the code,
this commit uses the coords given to sugar by Gtk that say where
the event happened.  This means that if the system is busy, or
the user is fast with the mouse, the palette will pop up where
they originally clicked.
This commit is contained in:
Sam Parkinson 2015-10-10 12:02:28 +11:00 committed by Martin Abente Lahaye
parent 639b2e85c2
commit 739dacbd01

View File

@ -1008,14 +1008,33 @@ class Invoker(GObject.GObject):
def notify_mouse_leave(self): def notify_mouse_leave(self):
self.emit('mouse-leave') self.emit('mouse-leave')
def notify_right_click(self): def notify_right_click(self, x=None, y=None):
'''
Notify the palette invoker of a right click and expand the
palette as required. The x and y args should be that of
where the event happened, relative to the root of the screen.
Args
x (float): the x coord of the event relative to the root
of the screen, eg. :class:`Gdk.EventTouch.x_root`
y (float): the y coord of the event relative to the root
of the screen, eg. :class:`Gdk.EventTouch.y_root`
'''
self._ensure_palette_exists() self._ensure_palette_exists()
self._process_event(x, y)
self.emit('right-click') self.emit('right-click')
def notify_toggle_state(self): def notify_toggle_state(self):
self._ensure_palette_exists() self._ensure_palette_exists()
self.emit('toggle-state') self.emit('toggle-state')
def _process_event(self, x, y):
if x is None or y is None:
return
self._cursor_x = x
self._cursor_y = y
def get_palette(self): def get_palette(self):
return self._palette return self._palette
@ -1231,14 +1250,14 @@ class WidgetInvoker(Invoker):
if self.props.toggle_palette: if self.props.toggle_palette:
self.notify_toggle_state() self.notify_toggle_state()
elif event.button == 3: elif event.button == 3:
self.notify_right_click() self.notify_right_click(event.x_root, event.y_root)
return True return True
else: else:
return False return False
def __long_pressed_event_cb(self, controller, x, y, widget): def __long_pressed_event_cb(self, controller, x, y, widget):
self._long_pressed_recognized = True self._long_pressed_recognized = True
self.notify_right_click() self.notify_right_click(x, y)
def get_toplevel(self): def get_toplevel(self):
return self._widget.get_toplevel() return self._widget.get_toplevel()
@ -1348,14 +1367,14 @@ class CursorInvoker(Invoker):
if self.props.toggle_palette: if self.props.toggle_palette:
self.notify_toggle_state() self.notify_toggle_state()
if event.button == 3: if event.button == 3:
self.notify_right_click() self.notify_right_click(event.x_root, event.y_root)
return True return True
else: else:
return False return False
def __long_pressed_event_cb(self, controller, x, y, widget): def __long_pressed_event_cb(self, controller, x, y, widget):
self._long_pressed_recognized = True self._long_pressed_recognized = True
self.notify_right_click() self.notify_right_click(x, y)
def get_toplevel(self): def get_toplevel(self):
return self._item.get_toplevel() return self._item.get_toplevel()
@ -1497,7 +1516,7 @@ class TreeViewInvoker(Invoker):
# right mouse button # right mouse button
self._mouse_detector.stop() self._mouse_detector.stop()
self._change_palette() self._change_palette()
self.notify_right_click() self.notify_right_click(event.x_root, event.y_root)
return True return True
else: else:
return False return False
@ -1507,7 +1526,7 @@ class TreeViewInvoker(Invoker):
self._path = path self._path = path
self._column = column self._column = column
self._change_palette() self._change_palette()
self.notify_right_click() self.notify_right_click(x, y)
def __mouse_slow_cb(self, widget): def __mouse_slow_cb(self, widget):
self._mouse_detector.stop() self._mouse_detector.stop()