Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitea9f1e4

Browse files
committed
Added doc and cleaned backend_managers, don't want our new file dirty.
1 parent4df6923 commitea9f1e4

File tree

7 files changed

+145
-46
lines changed

7 files changed

+145
-46
lines changed

‎doc/api/backend_managers_api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
:mod:`matplotlib.backend_managers`
3+
==================================
4+
5+
..automodule::matplotlib.backend_managers
6+
:members:
7+
:undoc-members:
8+
:show-inheritance:

‎doc/api/index_backend_api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ backends
55
..toctree::
66

77
backend_bases_api.rst
8+
backend_managers_api.rst
89
backend_gtkagg_api.rst
910
backend_qt4agg_api.rst
1011
backend_wxagg_api.rst

‎lib/matplotlib/_pylab_helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def show_all(cls, block=None):
6868
it does not block if run inside ipython's "%pylab" mode
6969
it does not block in interactive mode.
7070
"""
71+
7172
managers=cls.get_all_fig_managers()
7273
ifnotmanagers:
7374
return
@@ -77,7 +78,7 @@ def show_all(cls, block=None):
7778

7879
ifblockisnotNone:
7980
ifblock:
80-
manager.mainloop()
81+
manager._mainloop()
8182
return
8283

8384
frommatplotlibimportpyplot
@@ -99,7 +100,7 @@ def show_all(cls, block=None):
99100
block=False
100101

101102
ifnotis_interactive()orget_backend()=='WebAgg':
102-
manager.mainloop()
103+
manager._mainloop()
103104

104105
@classmethod
105106
defdestroy(cls,num):

‎lib/matplotlib/backend_bases.py

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,10 +2503,10 @@ def key_press_handler(event, canvas, toolbar=None):
25032503

25042504
# quit the figure (defaut key 'ctrl+w')
25052505
ifevent.keyinquit_keys:
2506-
ifisinstance(canvas.manager.mainloop,MainLoopBase):# If new no Gcf.
2507-
canvas.manager._destroy('window_destroy_event')
2508-
else:
2506+
ifisinstance(canvas.manager,FigureManagerBase):# Using old figman.
25092507
Gcf.destroy_fig(canvas.figure)
2508+
else:
2509+
canvas.manager._destroy('window_destroy_event')
25102510

25112511
iftoolbarisnotNone:
25122512
# home or reset mnemonic (default key 'h', 'home' and 'r')
@@ -2589,6 +2589,13 @@ def __init__(self, name, window):
25892589

25902590

25912591
classWindowBase(cbook.EventEmitter):
2592+
""" The base class to show a window on screen.
2593+
2594+
Parameters
2595+
----------
2596+
title : str
2597+
The title of the window.
2598+
"""
25922599
def__init__(self,title):
25932600
cbook.EventEmitter.__init__(self)
25942601

@@ -2602,39 +2609,90 @@ def show(self):
26022609
raiseNonGuiException()
26032610

26042611
defdestroy(self):
2612+
"""Destroys the window
2613+
"""
26052614
pass
26062615

26072616
defset_fullscreen(self,fullscreen):
2617+
"""Whether to show the window fullscreen or not, GUI only.
2618+
2619+
Parameters
2620+
----------
2621+
fullscreen : bool
2622+
True for yes, False for no.
2623+
"""
26082624
pass
26092625

2610-
defset_default_size(self,w,h):
2626+
defset_default_size(self,width,height):
2627+
"""Sets the default size of the window, defaults to a simple resize.
2628+
2629+
Parameters
2630+
----------
2631+
width : int
2632+
The default width (in pixels) of the window.
2633+
height : int
2634+
The default height (in pixels) of the window.
2635+
"""
26112636
self.resize(w,h)
26122637

2613-
defresize(self,w,h):
2614-
""""For gui backends, resize the window (in pixels)."""
2638+
defresize(self,width,height):
2639+
""""For gui backends, resizes the window.
2640+
2641+
Parameters
2642+
----------
2643+
width : int
2644+
The new width (in pixels) for the window.
2645+
height : int
2646+
The new height (in pixels) for the window.
2647+
"""
26152648
pass
26162649

26172650
defget_window_title(self):
26182651
"""
26192652
Get the title text of the window containing the figure.
26202653
Return None for non-GUI backends (e.g., a PS backend).
2654+
2655+
Returns
2656+
-------
2657+
str : The window's title.
26212658
"""
26222659
return'image'
26232660

26242661
defset_window_title(self,title):
26252662
"""
26262663
Set the title text of the window containing the figure. Note that
26272664
this has no effect for non-GUI backends (e.g., a PS backend).
2665+
2666+
Parameters
2667+
----------
2668+
title : str
2669+
The title of the window.
26282670
"""
26292671
pass
26302672

26312673
defadd_element_to_window(self,element,expand,fill,pad,side='bottom'):
26322674
""" Adds a gui widget to the window.
2633-
This has no effect for non-GUI backends
2675+
This has no effect for non-GUI backends and properties only apply
2676+
to those backends that support them, or have a suitable workaround.
2677+
2678+
Parameters
2679+
----------
2680+
element : A gui element.
2681+
The element to add to the window
2682+
expand : bool
2683+
Whether the element should auto expand to fill as much space within
2684+
the window as possible.
2685+
fill : bool
2686+
If the element can expand, should it make the element bigger,
2687+
or go into extra padding? True, False respectfully.
2688+
pad : int
2689+
The extra amount of space in pixels to pad the element.
26342690
"""
26352691
pass
26362692

26372693
defdestroy_event(self,*args):
2694+
"""Fires this event when the window wants to destroy itself.
2695+
*args come from the GUI specific event mechanism."""
26382696
s='window_destroy_event'
26392697
event=WindowEvent(s,self)
26402698
self._callbacks.process(s,event)

‎lib/matplotlib/backend_managers.py

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,56 @@
99

1010

1111
classFigureManagerEvent(object):
12-
def__init__(self,s,fm):
13-
self.name=s
14-
self.figure_manager=fm
12+
"""Event for when something happens to this figure manager.
13+
i.e. the figure it controls gets closed
14+
15+
Attributes
16+
----------
17+
signal : str
18+
The name of the signal.
19+
20+
figure_manager : FigureManager
21+
The figure manager that fired the event.
22+
"""
23+
def__init__(self,signal,figure_manager):
24+
self.name=signal
25+
self.figure_manager=figure_manager
1526

1627

1728
classFigureManager(cbook.EventEmitter):
29+
"""
30+
The FigureManager creates and wraps the necessary components to display a
31+
figure, namely the Window, FigureCanvas and Toolbar. It gets used whenever
32+
you want the figure in a standalone window.
33+
34+
Parameters
35+
----------
36+
figure : `matplotlib.figure.Figure`
37+
The figure to manage.
38+
39+
num : int
40+
The figure number.
41+
42+
Attributes
43+
----------
44+
45+
canvas : `matplotlib.backend_bases.FigureCanvasBase`
46+
The GUI element on which we draw.
47+
48+
toolbar : `matplotlib.backend_bases.NavigationToolbar2`
49+
The toolbar used for interacting with the figure.
50+
51+
window : `matplotlib.backend_bases.WindowBase`
52+
The window that holds the canvas and toolbar.
53+
54+
num : int
55+
The figure number.
56+
"""
1857
def__init__(self,figure,num):
1958
cbook.EventEmitter.__init__(self)
2059
self.num=num
2160

22-
self.mainloop=MainLoop()
61+
self._mainloop=MainLoop()
2362
self.window=Window('Figure %d'%num)
2463
self.window.mpl_connect('window_destroy_event',self._destroy)
2564

@@ -63,21 +102,28 @@ def _destroy(self, event=None):
63102
self._callbacks.process(s,event)
64103

65104
defdestroy(self,*args):
105+
"""Called to destroy this FigureManager, gets called by Gcf through
106+
event magic.
107+
"""
66108
self.canvas.destroy()
67109
ifself.toolbar:
68110
self.toolbar.destroy()
69111
self.window.destroy()
70112

71-
self.mainloop.__del__()
113+
self._mainloop.__del__()
72114

73115
defshow(self):
116+
"""Shows the figure"""
74117
self.window.show()
75118

76119
deffull_screen_toggle(self):
120+
"""Toggles whether we show fullscreen, alternatively call
121+
`window.fullscreen()`"""
77122
self._full_screen_flag=notself._full_screen_flag
78123
self.window.set_fullscreen(self._full_screen_flag)
79124

80125
defresize(self,w,h):
126+
""""For gui backends, resize the window (in pixels)."""
81127
self.window.resize(w,h)
82128

83129
defget_window_title(self):
@@ -108,23 +154,3 @@ def show_popup(self, msg):
108154
Display message in a popup -- GUI only
109155
"""
110156
pass
111-
112-
113-
defnew_figure_manager(num,*args,**kwargs):
114-
"""
115-
Create a new figure manager instance
116-
"""
117-
show=kwargs.pop('show',None)
118-
ifold_new_figure_managerisNone:# Test if we can use the new code
119-
FigureClass=kwargs.pop('FigureClass',Figure)
120-
thisFig=FigureClass(*args,**kwargs)
121-
manager=new_figure_manager_given_figure(num,thisFig)
122-
else:# TODO remove once Gcf removed from backends. Default to old code.
123-
manager=old_new_figure_manager(num,*args,**kwargs)
124-
manager.mainloop=MainLoop
125-
returnmanager
126-
127-
128-
defnew_figure_manager_given_figure(num,figure):
129-
manager=FigureManager(figure,num)
130-
returnmanager

‎lib/matplotlib/backends/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ def get_backends():
2323
_temp=__import__(backend_name,globals(),locals(),
2424
['Window','Toolbar2','FigureCanvas','MainLoop',
2525
'new_figure_manager'],0)
26-
FigureCanvas=_temp.FigureCanvas
2726
try:
2827
Window=_temp.Window
2928
Toolbar2=_temp.Toolbar2
29+
FigureCanvas=_temp.FigureCanvas
3030
MainLoop=_temp.MainLoop
3131
old_new_figure_manager=None
3232
exceptAttributeError:
3333
Window=None
3434
Toolbar2=None
35+
FigureCanvas=None
3536
MainLoop=getattr(_temp,'show',do_nothing_show)
3637
old_new_figure_manager=_temp.new_figure_manager
3738

@@ -54,7 +55,7 @@ def pylab_setup():
5455

5556
defdo_nothing(*args,**kwargs):pass
5657
backend_version=getattr(backend_mod,'backend_version','unknown')
57-
show=Noneifhasattr(backend_mod,'show')elsedo_nothing_show
58+
show=getattr(backend_mod,'show',do_nothing_show)
5859
draw_if_interactive=getattr(backend_mod,'draw_if_interactive',do_nothing)
5960

6061
# Additional imports which only happen for certain backends. This section

‎lib/matplotlib/pyplot.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ def show(*args, **kw):
152152
described above.
153153
"""
154154
global_show
155-
if_showisNone:
155+
ifbackend_managers.WindowisnotNone:# Can we use the new code?
156156
return_pylab_helpers.Gcf.show_all(*args,**kw)
157157
else:
158-
_show(*args,**kw)
158+
_show(*args,**kw)
159159

160160

161161
defisinteractive():
@@ -429,14 +429,18 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
429429
ifget_backend().lower()=='ps':
430430
dpi=72
431431

432-
figManager=backend_managers.new_figure_manager(num,figsize=figsize,
433-
dpi=dpi,
434-
facecolor=facecolor,
435-
edgecolor=edgecolor,
436-
frameon=frameon,
437-
FigureClass=FigureClass,
438-
show=_show,
439-
**kwargs)
432+
ifbackend_managers.WindowisnotNone:# Can we use the new code?
433+
fig=FigureClass(figsize=figsize,dpi=dpi,facecolor=facecolor,
434+
edgecolor=edgecolor,frameon=frameon,**kwargs)
435+
figManager=backend_managers.FigureManager(fig,num)
436+
else:
437+
figManager=new_figure_manager(num,figsize=figsize,
438+
dpi=dpi,
439+
facecolor=facecolor,
440+
edgecolor=edgecolor,
441+
frameon=frameon,
442+
FigureClass=FigureClass,
443+
**kwargs)
440444

441445
iffigLabel:
442446
figManager.set_window_title(figLabel)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp