title: What's the right way to detect double-click events with python pyglet?
body: <p>I've looked at <a href="http://www.pyglet.org/doc/programming_guide/mouse_events.html" rel="nofollow">pyglet mouse events</a>,
  which nicely deal with common events like clicking, dragging, and releasing the mouse buttons. I want to handle double-click events, but this doesn't seem to be as straightforward.</p>
  
  <p>Should I just monitor for mouse_press and mouse_release events, and compare time intervals and locations to detect double-click events?</p>
  
  <p>I don't want to reinvent the wheel. <strong>Is there a 'best practice' for detecting double-click events with pyglet?</strong></p>
  
  <p>This approach is the best I've got so far:</p>
  
  <pre><code>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] &lt; 0.2:
                          print "Double-click"
  </code></pre>