Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1e3fd4

Browse files
committed
Describe FigureManager
1 parent 64ba969 commit c1e3fd4

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,20 +2463,53 @@ def button_press_handler(event, canvas, toolbar=None):
24632463

24642464

24652465
class NonGuiException(Exception):
2466+
"""Raised when trying show a figure in a non-GUI backend."""
24662467
pass
24672468

24682469

24692470
class FigureManagerBase:
24702471
"""
2471-
Helper class for pyplot mode, wraps everything up into a neat bundle.
2472+
A backend-independent abstraction of a figure container and controller.
2473+
2474+
The figure manager is used by pyplot to interact with the window in a
2475+
backend-independent way. It's an adapter for the real (GUI) framework that
2476+
represents the visual figure on screen.
2477+
2478+
GUI backends define from this class to translate common operations such
2479+
as *show* or *resize* to the GUI-specific code. Non-GUI backends do not
2480+
support these operations an can just use the base class.
2481+
2482+
This following basic operations are accessible:
2483+
2484+
**Window operations**
2485+
2486+
- `~.FigureManagerBase.show`
2487+
- `~.FigureManagerBase.destroy`
2488+
- `~.FigureManagerBase.full_screen_toggle`
2489+
- `~.FigureManagerBase.resize`
2490+
- `~.FigureManagerBase.get_window_title`
2491+
- `~.FigureManagerBase.set_window_title`
2492+
2493+
**Key and mouse button press handling**
2494+
2495+
The figure manager sets up default key and mouse button press handling by
2496+
hooking up the `.key_press_handler` to the matplotlib event system. This
2497+
ensures the same shortcuts and mouse actions across backends.
2498+
2499+
**Other operations**
2500+
2501+
Subclasses will have additional attributes and functions to access
2502+
additional functionality. This is of course backend-specific. For example,
2503+
most GUI backends have ``window`` and ``toolbar`` attributes that give
2504+
access to the native GUI widgets of the respective framework.
24722505
24732506
Attributes
24742507
----------
24752508
canvas : :class:`FigureCanvasBase`
2476-
The backend-specific canvas instance
2509+
The backend-specific canvas instance.
24772510
24782511
num : int or str
2479-
The figure number
2512+
The figure number.
24802513
24812514
key_press_handler_id : int
24822515
The default key handler cid, when using the toolmanager.
@@ -2491,7 +2524,6 @@ class FigureManagerBase:
24912524
24922525
figure.canvas.mpl_disconnect(
24932526
figure.canvas.manager.button_press_handler_id)
2494-
24952527
"""
24962528
def __init__(self, canvas, num):
24972529
self.canvas = canvas
@@ -2533,7 +2565,7 @@ def full_screen_toggle(self):
25332565
pass
25342566

25352567
def resize(self, w, h):
2536-
""""For GUI backends, resize the window (in pixels)."""
2568+
"""For GUI backends, resize the window (in pixels)."""
25372569

25382570
def key_press(self, event):
25392571
"""
@@ -2544,9 +2576,7 @@ def key_press(self, event):
25442576
key_press_handler(event, self.canvas, self.canvas.toolbar)
25452577

25462578
def button_press(self, event):
2547-
"""
2548-
The default Matplotlib button actions for extra mouse buttons.
2549-
"""
2579+
"""The default Matplotlib button actions for extra mouse buttons."""
25502580
if rcParams['toolbar'] != 'toolmanager':
25512581
button_press_handler(event, self.canvas, self.canvas.toolbar)
25522582

0 commit comments

Comments
 (0)