mouse_events.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """
  2. Mouse events.
  3. How it works
  4. ------------
  5. The renderer has a 2 dimensional grid of mouse event handlers.
  6. (`prompt_toolkit.layout.MouseHandlers`.) When the layout is rendered, the
  7. `Window` class will make sure that this grid will also be filled with
  8. callbacks. For vt100 terminals, mouse events are received through stdin, just
  9. like any other key press. There is a handler among the key bindings that
  10. catches these events and forwards them to such a mouse event handler. It passes
  11. through the `Window` class where the coordinates are translated from absolute
  12. coordinates to coordinates relative to the user control, and there
  13. `UIControl.mouse_handler` is called.
  14. """
  15. from __future__ import unicode_literals
  16. __all__ = (
  17. 'MouseEventType',
  18. 'MouseEvent'
  19. )
  20. class MouseEventType:
  21. MOUSE_UP = 'MOUSE_UP'
  22. MOUSE_DOWN = 'MOUSE_DOWN'
  23. SCROLL_UP = 'SCROLL_UP'
  24. SCROLL_DOWN = 'SCROLL_DOWN'
  25. MouseEventTypes = MouseEventType # Deprecated: plural for backwards compatibility.
  26. class MouseEvent(object):
  27. """
  28. Mouse event, sent to `UIControl.mouse_handler`.
  29. :param position: `Point` instance.
  30. :param event_type: `MouseEventType`.
  31. """
  32. def __init__(self, position, event_type):
  33. self.position = position
  34. self.event_type = event_type
  35. def __repr__(self):
  36. return 'MouseEvent(%r, %r)' % (self.position, self.event_type)