8000 Normalized GTK click events so that the same pattern of events is sen… · jonovik/matplotlib@3597218 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3597218

Browse files
committed
Normalized GTK click events so that the same pattern of events is sent, on
double click, as the other backends. DOWN-UP-DBLCLICK-UP.
1 parent 135555a commit 3597218

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

examples/event_handling/test_mouseclicks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ def OnClick(event):
1515
if event.dblclick:
1616
print "DBLCLICK",event
1717
else:
18-
print "DOWN",event
18+
print "DOWN ",event
1919

2020
def OnRelease(event):
21-
print "UP",event
21+
print "UP ",event
2222

2323

2424
fig = plt.gcf()

lib/matplotlib/backends/backend_gtk.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import division
22

33
import os, sys
4+
import time
45
def fn_name(): return sys._getframe(1).f_code.co_name
56

67
try:
@@ -224,6 +225,8 @@ def __init__(self, figure):
224225

225226
self._idle_event_id = gobject.idle_add(self.idle_event)
226227

228+
self.last_downclick = {}
229+
227230
def destroy(self):
228231
#gtk.DrawingArea.destroy(self)
229232
self.close_event()
@@ -249,6 +252,21 @@ def button_press_event(self, widget, event):
249252
# flipy so y=0 is bottom of canvas
250253
y = self.allocation.height - event.y
251254
dblclick = (event.type == gdk._2BUTTON_PRESS)
255+
if not dblclick:
256+
# GTK is the only backend that generates a DOWN-UP-DOWN-DBLCLICK-UP event
257+
# sequence for a double click. All other backends have a DOWN-UP-DBLCLICK-UP
258+
# sequence. In order to provide consistency to matplotlib users, we will
259+
# eat the extra DOWN event in the case that we detect it is part of a double
260+
# click.
261+
# first, get the double click time in milliseconds.
262+
current_time = time.time()
263+
last_time = self.last_downclick.get(event.button,0.0)
264+
dblclick_time = gtk.settings_get_for_screen(gdk.screen_get_default()).get_property('gtk-double-click-time')
265+
delta_time = int((current_time-last_time)*1000.0)
266+
if delta_time < dblclick_time:
267+
del self.last_downclick[event.button] # we do not want to eat more than one event.
268+
return False # eat.
269+
self.last_downclick[event.button] = current_time
252270
FigureCanvasBase.button_press_event(self, x, y, event.button, dblclick=dblclick, guiEvent=event)
253271
return False # finish event propagation?
254272

0 commit comments

Comments
 (0)
0