8000 MEP27 Decouple pyplot from backends (refactoring Gcf out of backend code) by OceanWolf · Pull Request #4143 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

MEP27 Decouple pyplot from backends (refactoring Gcf out of backend code) #4143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
24caf2b
Refactor pass 1. Refactoring Gcf out of specific backend (backend_gt…
OceanWolf Feb 21, 2015
2b05d38
Refactor Pass 2. Refactored Gcf out of all backend code.
OceanWolf Feb 22, 2015
f4fc354
Quick fix to figure for safe unpickling.
OceanWolf Feb 25, 2015
0b31e3a
GTK3Agg
OceanWolf Feb 26, 2015
6fb452e
Refactored making `FigureManager` a *figure* manager, plus added miss…
OceanWolf Feb 27, 2015
0a868a2
keyword
OceanWolf Feb 27, 2015
61ba2b4
Make add_element more general, and make sure the code complies with it.
OceanWolf Feb 27, 2015
f0eb84c
Better destroy order.
OceanWolf Feb 27, 2015
8fe9cd7
GTK simplifications
OceanWolf Feb 28, 2015
494e5f1
Added doc and cleaned backend_managers, don't want our new file dirty.
OceanWolf Mar 3, 2015
ed16178
Improve layout!
OceanWolf Apr 6, 2015
21b8f58
Move knowledge of the backend to the manager.
OceanWolf Apr 7, 2015
cf42e3b
Incorporate MEP22 into MEP27
OceanWolf Apr 12, 2015
f027b16
Improved new toolbar and updated tool_manager example accoridingly.
OceanWolf Apr 12, 2015
24b7b73
fullscreen
OceanWolf Apr 13, 2015
bc99129
MEP update
OceanWolf Apr 14, 2015
7f7f05e
Finish MEP22 conversion
OceanWolf Apr 14, 2015
713abcb
rename window method
OceanWolf Apr 17, 2015
80adaaf
Add backend anme to widgets
OceanWolf Apr 17, 2015
4e5f69d
Handle FigureManager destroy internaly without pyplot.
OceanWolf Jun 4, 2015
160ef57
Make functionality more consistant for embedded applications
OceanWolf Jun 7, 2015
b6d6acc
Backend getter method for FigureManager
OceanWolf Jun 13, 2015
ecd5038
Improve example after new method
OceanWolf Jun 13, 2015
f8e83fe
Clean up the code a bit
OceanWolf Jun 13, 2015
c53b79a
Remove old code from backend_managers
OceanWolf Jun 15, 2015
34c6b12
Cleanup
OceanWolf Jun 22, 2015
8a4268a
Explicity get set manager as None if appropiate.
OceanWolf Jun 22, 2015
44df199
figure attribute and canvas property
fariza Jun 22, 2015
860a8ed
Fix FigureCanvasBase
OceanWolf Jun 23, 2015
c44e744
super
OceanWolf Jun 25, 2015
2fe9215
figure setter
fariza Jun 25, 2015
3b434ef
Improve MEP22 Tool Searching Structure
OceanWolf Jun 25, 2015
490629f
adding example file
fariza Jun 25, 2015
8eb987b
super dooper
OceanWolf Jun 26, 2015
224a4f3
Revert old example and fix new one.
OceanWolf Jun 26, 2015
cdbd51b
Improve MEP22 tool-searching method.
OceanWolf Jun 27, 2015
50e3719
MEP22 Save Figure Tool
OceanWolf Jun 27, 2015
85be519
pep8
OceanWolf Jun 27, 2015
7edaf5a
Make ToolConfigureSubplots a generic tool
OceanWolf Jun 28, 2015
8e6e252
Improve flow handling and make it a lot more generic
OceanWolf Jun 28, 2015
72575cb
Missing resize method
OceanWolf Jun 28, 2015
4a78246
Convert to new structure for finding tools
OceanWolf Jun 28, 2015
e300707
doc
OceanWolf Jun 29, 2015
ee76451
Add ExpandableBase
OceanWolf Jun 29, 2015
6f0c7ab
Template Backend plus fix FigManager for non-GUI backends and add gen…
OceanWolf Jun 29, 2015
ae9bf5b
rcParam and Travis
OceanWolf Jul 19, 2015
fb004e0
test
OceanWolf Jul 20, 2015
1d2095b
test always MEP27
OceanWolf Jul 20, 2015
24e43b3
Fix FigureManager to allow pyplot to work for non GUI backends
OceanWolf Jul 27, 2015
208c3be
Fix Gcf.show_all()
OceanWolf Jul 27, 2015
a44ebd9
doc
OceanWolf Jul 27, 2015
f8f9cf2
pep8
OceanWolf Jul 27, 2015
0e09a54
remove show_popup
OceanWolf Jul 27, 2015
a38b6d7
AttributeError
OceanWolf Sep 22, 2015
64f0c61
Fixes for MEP27
OceanWolf Aug 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Gcf.show_all()
  • Loading branch information
OceanWolf committed Aug 4, 2016
commit 208c3be13338330b4efbefa5bb99713acfd93233
15 changes: 9 additions & 6 deletions lib/matplotlib/_pylab_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,21 @@ def show_all(cls, block=None):
for manager in managers:
manager.show()

if block is not None:
if block:
manager._mainloop()
if block is True:
manager._mainloop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who is this manager? the last one of managers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because calling mainloop will pause execution here... we only want one to pause it once we have shown all of the managers.

return
elif block is False:
return

# Hack: determine at runtime whether we are
# inside ipython in pylab mode.
from matplotlib import pyplot
try:
ipython_pylab = not p 8000 yplot.show._needmain
# IPython versions >= 0.10 tack the _needmain
# attribute onto pyplot.show, and always set
# it to False, when in %pylab mode.
ipython_pylab = ipython_pylab and get_backend() != 'WebAgg'
ipython_pylab = ipython_pylab and manager.backend_name != 'webagg'
# TODO: The above is a hack to get the WebAgg backend
# working with ipython's `%pylab` mode until proper
# integration is implemented.
Expand All @@ -97,9 +100,9 @@ def show_all(cls, block=None):
# Leave the following as a separate step in case we
# want to control this behavior with an rcParam.
if ipython_pylab:
block = False
return

if not is_interactive() or get_backend() == 'WebAgg':
if not is_interactive() or manager.backend_name == 'webagg':
manager._mainloop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh? if it isn't interactive, then start a mainloop?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this method I just copy pasted from the ShowBase. The mainloop blocks execution, which prevents the script from dying. If not interactive we don't need it as the code won't die. Anyway, as I said, just a copy-paste... saying which, I copy-pasted a bit too much, i.e. get_backend doesn't exist in this scope... it should get it from the manager...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably be good to explain that in a comment


@classmethod
Expand Down
8 changes: 6 additions & 2 deletions lib/matplotlib/backend_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from matplotlib import is_interactive
from matplotlib import rcParams
from matplotlib.figure import Figure
from matplotlib.backends import get_backend
from matplotlib.backends import get_backend, backend as backend_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this one of the sources of the global state that needs to be pushed back into pyplot.py

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_backend, no, as a function, but I think yes to backend as backend_name, but no different from existing behaviour (I think) from when I wrote it. After we had more backends converted to test with, we (me and @fariza) planned to test and improve the backend switching ability of matplotlib, and more than just switching, but having multiple backends active at the same time.



class FigureManagerEvent(object):
Expand Down Expand Up @@ -75,7 +75,7 @@ class FigureManager(cbook.EventEmitter):
"""
def __init__(self, figure, num, **kwargs):
super(FigureManager, self).__init__(**kwargs)
self._backend = get_backend()
self._backend_name, self._backend = get_backend()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you ask the figure instance what backend it is? (might have to add that to it's API?).


self.num = num
self.figure = figure
Expand Down Expand Up @@ -193,6 +193,10 @@ def set_window_title(self, title):
def backend(self):
return self._backend

@property
def backend_name(self):
return self._backend_name

def _get_toolbar(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not put it as a property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because you did it like this in MEP22, so I just copy and paste it over :P.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups... I think it would look better as a property don't you?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also it ain't getting the toolbar, it creates a new one... I think I remember disliking this function name...

which reminds me, we only store the first toolbar in the manager, if we create extra toolbars they don't go here (though they do get added to the window naturally).

What do you think about making the example a bit simpler with

topbar = manager.new_toolbar('north')

# create new toolbar without adding it to the main window
sidebar = manager.new_toolbar()
win.add_element(sidebar, 'west')

or too complicated...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to keep track of other toolbars, if you create it you have the handler.
Most of the time we create the first toolbar automatically for you, so you need to be able to access it, that is why we give the .toolbar attribute.

The example we can fix in other smaller PRs, at this moment it just has to work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so yes, definitely not a property for this I think... as we create a new toolbar...

do you think I should rename it just for clarity? We keep it private for now so no worries about BC later if we change our mind.

try:
# must be inited after the window, drawingArea and figure
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_backend(name=None):
# the last argument is specifies whether to use absolute or relative
# imports. 0 means only perform absolute imports.
backend_name = get_backend_name(name)
return __import__(backend_name, globals(), locals(),
return backend_name, __import__(backend_name, globals(), locals(),
[backend_name], 0)


Expand Down Expand Up @@ -68,7 +68,7 @@ def pylab_setup(name=None):

'''
# Import the requested backend into a generic module object
backend_mod = get_backend(name)
backend_mod = get_backend(name)[1]

# Things we pull in from all backends
new_figure_manager = getattr(backend_mod, 'new_figure_manager', None)
Expand Down
0