Skip to content

Instantly share code, notes, and snippets.

@almarklein
Last active December 17, 2015 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almarklein/5543119 to your computer and use it in GitHub Desktop.
Save almarklein/5543119 to your computer and use it in GitHub Desktop.
class MouseEvent(Event):
""" Class describing mouse events.
Input arguments
---------------
source : object
The visualization object that this event is created from or applies to.
type : str
string indicating the event type (e.g. mouse_press, key_release)
kwds : keyword arguments
Any additional keyword arguments are stored as attributes on the event.
"""
def __init__(self, source, subtype, x, y, button=None, modifiers=None):
Event.__init__(self, source, 'mouse_'+subtype)
self._x = x
self._y = y
self._button = int(button)
self._modifiers = tuple( modifiers or () )
@property
def x(self):
""" The x-position of the mouse (in screen coordinates).
"""
return self._x
@property
def y(self):
""" The y-position of the mouse (in screen coordinates).
"""
return self._y
@property
def button(self):
""" The button that this event applies to (can be None).
Left=1, right=2, middle=3.
"""
return self._button
@property
def modifiers(self):
""" Tuple that specifies which modifier keys wee pressed down at the
time of the event (shift, control, alt).
"""
return self._modifiers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment