What's the right way to detect double-click events with python pyglet? -


i've looked @ pyglet mouse events, nicely deal common events clicking, dragging, , releasing mouse buttons. want handle double-click events, doesn't seem straightforward.

should monitor mouse_press , mouse_release events, , compare time intervals , locations detect double-click events?

i don't want reinvent wheel. is there 'best practice' detecting double-click events pyglet?

this approach best i've got far:

import time import pyglet  class mydisplay:     def __init__(self):         self.window = pyglet.window.window(100, 100)          @self.window.event         def on_mouse_release(x, y, button, modifiers):             self.last_mouse_release = (x, y, button, time.clock())          @self.window.event         def on_mouse_press(x, y, button, modifiers):             if hasattr(self, 'last_mouse_release'):                 if (x, y, button) == self.last_mouse_release[:-1]:                     """same place, same button"""                     if time.clock() - self.last_mouse_release[-1] < 0.2:                         print "double-click" 

looking @ source code, seems pyglet measures time between clicks using time.time().

to describe talking about, here small excerpt pyglet's source code:

t = time.time() if t - self._click_time < 0.25:     self._click_count += 1 else:     self._click_count = 1     self._click_time = time.time() 

(the full version of function can found here. please note in full version code geared towards selecting text.)

the source code hints @ using gui toolkit can monitor click events.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -