@@ -1372,6 +1372,8 @@ class MouseButton(IntEnum):
1372
1372
LEFT = 1
1373
1373
MIDDLE = 2
1374
1374
RIGHT = 3
1375
+ X1 = 4
1376
+ X2 = 5
1375
1377
1376
1378
1377
1379
class MouseEvent (LocationEvent ):
@@ -2394,6 +2396,17 @@ def _get_uniform_gridstate(ticks):
2394
2396
a .set_navigate (i == n )
2395
2397
2396
2398
2399
+ def button_press_handler (event , canvas , toolbar = None ):
2400
+ """
2401
+ The default Matplotlib button actions for extra mouse buttons.
2402
+ """
2403
+ if toolbar is not None :
2404
+ if event .button is MouseButton .X1 :
2405
+ toolbar .back ()
2406
+ elif event .button is MouseButton .X2 :
2407
+ toolbar .forward ()
2408
+
2409
+
2397
2410
class NonGuiException (Exception ):
2398
2411
pass
2399
2412
@@ -2411,22 +2424,34 @@ class FigureManagerBase(object):
2411
2424
The figure number
2412
2425
2413
2426
key_press_handler_id : int
2414
- The default key handler cid, when using the toolmanager. Can be used
2415
- to disable default key press handling ::
2427
+ The default key handler cid, when using the toolmanager.
2428
+ To disable the default key press handling use ::
2416
2429
2417
2430
figure.canvas.mpl_disconnect(
2418
2431
figure.canvas.manager.key_press_handler_id)
2432
+
2433
+ button_press_handler_id : int
2434
+ The default mouse button handler cid, when using the toolmanager.
2435
+ To disable the default button press handling use::
2436
+
2437
+ figure.canvas.mpl_disconnect(
2438
+ figure.canvas.manager.button_press_handler_id)
2439
+
2419
2440
"""
2420
2441
def __init__ (self , canvas , num ):
2421
2442
self .canvas = canvas
2422
2443
canvas .manager = self # store a pointer to parent
2423
2444
self .num = num
2424
2445
2425
2446
self .key_press_handler_id = None
2447
+ self .button_press_handler_id = None
2426
2448
if rcParams ['toolbar' ] != 'toolmanager' :
2427
2449
self .key_press_handler_id = self .canvas .mpl_connect (
2428
2450
'key_press_event' ,
2429
2451
self .key_press )
2452
+ self .button_press_handler_id = self .canvas .mpl_connect (
2453
+ 'button_press_event' ,
2454
+ self .button_press )
2430
2455
2431
2456
self .toolmanager = None
2432
2457
self .toolbar = None
@@ -2463,6 +2488,13 @@ def key_press(self, event):
2463
2488
if rcParams ['toolbar' ] != 'toolmanager' :
2464
2489
key_press_handler (event , self .canvas , self .canvas .toolbar )
2465
2490
2491
+ def button_press (self , event ):
2492
+ """
2493
+ The default Matplotlib button actions for extra mouse buttons.
2494
+ """
2495
+ if rcParams ['toolbar' ] != 'toolmanager' :
2496
+ button_press_handler (event , self .canvas , self .canvas .toolbar )
2497
+
2466
2498
@cbook .deprecated ("2.2" )
2467
2499
def show_popup (self , msg ):
2468
2500
"""Display message in a popup -- GUI only."""
0 commit comments