1
1
from __future__ import division
2
2
3
3
import os , sys
4
+ import time
4
5
def fn_name (): return sys ._getframe (1 ).f_code .co_name
5
6
6
7
try :
@@ -224,6 +225,8 @@ def __init__(self, figure):
224
225
225
226
self ._idle_event_id = gobject .idle_add (self .idle_event )
226
227
228
+ self .last_downclick = {}
229
+
227
230
def destroy (self ):
228
231
#gtk.DrawingArea.destroy(self)
229
232
self .close_event ()
@@ -249,6 +252,21 @@ def button_press_event(self, widget, event):
249
252
# flipy so y=0 is bottom of canvas
250
253
y = self .allocation .height - event .y
251
254
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
252
270
FigureCanvasBase .button_press_event (self , x , y , event .button , dblclick = dblclick , guiEvent = event )
253
271
return False # finish event propagation?
254
272
0 commit comments