3333"""
3434
3535from contextlib import contextmanager
36+ from enum import IntEnum
3637import importlib
3738import io
3839import logging
@@ -1367,6 +1368,12 @@ def _update_enter_leave(self):
13671368 LocationEvent .lastevent = self
13681369
13691370
1371+ class MouseButton (IntEnum ):
1372+ LEFT = 1
1373+ MIDDLE = 2
1374+ RIGHT = 3
1375+
1376+
13701377class MouseEvent (LocationEvent ):
13711378 """
13721379 A mouse event ('button_press_event',
@@ -1379,21 +1386,26 @@ class MouseEvent(LocationEvent):
13791386
13801387 Attributes
13811388 ----------
1382- button : {None, 1, 2, 3, 'up', 'down'}
1389+ button : {None, MouseButton.LEFT, MouseButton.MIDDLE, MouseButton.RIGHT, \
1390+ 'up', 'down'}
13831391 The button pressed. 'up' and 'down' are used for scroll events.
13841392 Note that in the nbagg backend, both the middle and right clicks
1385- return 3 since right clicking will bring up the context menu in
1393+ return RIGHT since right clicking will bring up the context menu in
13861394 some browsers.
1395+ Note that LEFT and RIGHT actually refer to the "primary" and
1396+ "secondary" buttons, i.e. if the user inverts their left and right
1397+ buttons ("left-handed setting") then the LEFT button will be the one
1398+ physically on the right.
13871399
13881400 key : None or str
13891401 The key pressed when the mouse event triggered, e.g. 'shift'.
13901402 See `KeyEvent`.
13911403
13921404 step : scalar
1393- The Number of scroll steps (positive for 'up', negative for 'down').
1405+ The number of scroll steps (positive for 'up', negative for 'down').
13941406
13951407 dblclick : bool
1396- *True* if the event is a double-click.
1408+ Whether the event is a double-click.
13971409
13981410 Examples
13991411 --------
@@ -1412,6 +1424,8 @@ def __init__(self, name, canvas, x, y, button=None, key=None,
14121424 button pressed None, 1, 2, 3, 'up', 'down'
14131425 """
14141426 LocationEvent .__init__ (self , name , canvas , x , y , guiEvent = guiEvent )
1427+ if button in MouseButton .__members__ .values ():
1428+ button = MouseButton (button )
14151429 self .button = button
14161430 self .key = key
14171431 self .step = step
0 commit comments