Skip to content
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

toolmanager and tools dont hold figure #8

Open
wants to merge 39 commits into
base: backend-refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e09039f
Refactor pass 1. Refactoring Gcf out of specific backend (backend_gt…
OceanWolf Feb 21, 2015
448b221
Refactor Pass 2. Refactored Gcf out of all backend code.
OceanWolf Feb 22, 2015
2d8423d
Quick fix to figure for safe unpickling.
OceanWolf Feb 25, 2015
00e50f7
GTK3Agg
OceanWolf Feb 26, 2015
3db8f92
Refactored making `FigureManager` a *figure* manager, plus added miss…
OceanWolf Feb 27, 2015
9eee846
keyword
OceanWolf Feb 27, 2015
ee52da4
Make add_element more general, and make sure the code complies with it.
OceanWolf Feb 27, 2015
034e328
Better destroy order.
OceanWolf Feb 27, 2015
2688054
GTK simplifications
OceanWolf Feb 28, 2015
a953930
Added doc and cleaned backend_managers, don't want our new file dirty.
OceanWolf Mar 3, 2015
d148482
Improve layout!
OceanWolf Apr 6, 2015
2ea7d3c
Move knowledge of the backend to the manager.
OceanWolf Apr 7, 2015
130e51d
Incorporate MEP22 into MEP27
OceanWolf Apr 12, 2015
a54bbea
Improved new toolbar and updated tool_manager example accoridingly.
OceanWolf Apr 12, 2015
91f6efb
fullscreen
OceanWolf Apr 13, 2015
1c4ca75
MEP update
OceanWolf Apr 14, 2015
a669d51
Finish MEP22 conversion
OceanWolf Apr 14, 2015
7bc5fa1
rename window method
OceanWolf Apr 17, 2015
76ec60e
Add backend anme to widgets
OceanWolf Apr 17, 2015
6637e60
Handle FigureManager destroy internaly without pyplot.
OceanWolf Jun 4, 2015
d68fbcd
Make functionality more consistant for embedded applications
OceanWolf Jun 7, 2015
32198ad
Backend getter method for FigureManager
OceanWolf Jun 13, 2015
b78cd3b
Improve example after new method
OceanWolf Jun 13, 2015
4c21f4d
Clean up the code a bit
OceanWolf Jun 13, 2015
518f0d0
Remove old code from backend_managers
OceanWolf Jun 15, 2015
722307c
Cleanup
OceanWolf Jun 22, 2015
8109dc7
Explicity get set manager as None if appropiate.
OceanWolf Jun 22, 2015
b412654
figure attribute and canvas property
fariza Jun 22, 2015
8f29e31
Fix FigureCanvasBase
OceanWolf Jun 23, 2015
eae38e5
super
OceanWolf Jun 25, 2015
ca3a560
figure setter
fariza Jun 25, 2015
18a36a3
Merge pull request #6 from fariza/figuremanager-figure-centered
OceanWolf Jun 25, 2015
cc1362a
Improve MEP22 Tool Searching Structure
OceanWolf Jun 25, 2015
f1dfb5d
adding example file
fariza Jun 25, 2015
722df57
super dooper
OceanWolf Jun 26, 2015
5e7eabf
Merge branch 'gui-examples' of https://github.com/fariza/matplotlib i…
OceanWolf Jun 26, 2015
5800fb0
Revert old example and fix new one.
OceanWolf Jun 26, 2015
ba748ce
Merge branch 'fariza-gui-examples' into backend-refactor.
OceanWolf Jun 26, 2015
7372409
toolmanager and tools dont hold figure
fariza Jun 26, 2015
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
30 changes: 17 additions & 13 deletions doc/devel/MEP/MEP27.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

Status
======
**Discussion**
**Progress**

Branches and Pull requests
==========================
Main PR (including GTK3):

+ https://github.com/matplotlib/matplotlib/pull/4143

Backend specific branch diffs:

+ https://github.com/OceanWolf/matplotlib/compare/backend-refactor...OceanWolf:backend-refactor-tkagg
+ https://github.com/OceanWolf/matplotlib/compare/backend-refactor...OceanWolf:backend-refactor-qt
+ https://github.com/OceanWolf/matplotlib/compare/backend-refactor...backend-refactor-wx
Expand Down Expand Up @@ -79,7 +81,7 @@ The description of this MEP gives us most of the solution:
1. To remove the windowing aspect out of ``FigureManagerBase`` letting
it simply wrap this new class along with the other backend classes.
Create a new ``WindowBase`` class that can handle this
functionality, with pass-through methods (:arrow_right:) to
functionality, with pass-through methods (->) to
``WindowBase``. Classes that subclass ``WindowBase`` should also
subclass the GUI specific window class to ensure backward
compatibility (``manager.window == manager.window``).
Expand All @@ -103,30 +105,30 @@ The description of this MEP gives us most of the solution:
|FigureManagerBase(canvas, num) |FigureManager(figure, num) |``WindowBase(title)``|Notes |
| | | | |
+======================================+==============================+=====================+================================+
|show | |show | |
|show |-> |show | |
+--------------------------------------+------------------------------+---------------------+--------------------------------+
|destroy |calls destroy on all |destroy | |
| |components | | |
+--------------------------------------+------------------------------+---------------------+--------------------------------+
|full_screen_toggle |handles logic |set_fullscreen | |
+--------------------------------------+------------------------------+---------------------+--------------------------------+
|resize | |resize | |
|resize |-> |resize | |
+--------------------------------------+------------------------------+---------------------+--------------------------------+
|key_press |key_press | | |
|key_press |key_press |X | |
+--------------------------------------+------------------------------+---------------------+--------------------------------+
|show_popup |show_poup | |Not used anywhere in mpl, and |
|show_popup |show_poup |X |Not used anywhere in mpl, and |
| | | |does nothing. |
+--------------------------------------+------------------------------+---------------------+--------------------------------+
|get_window_title | |get_window_title | |
|get_window_title |-> |get_window_title | |
+--------------------------------------+------------------------------+---------------------+--------------------------------+
|set_window_title | |set_window_title | |
|set_window_title |-> |set_window_title | |
+--------------------------------------+------------------------------+---------------------+--------------------------------+
| |_get_toolbar | |A common method to all |
|X |_get_toolbar |X |A common method to all |
| | | |subclasses of FigureManagerBase |
+--------------------------------------+------------------------------+---------------------+--------------------------------+
| | |set_default_size | |
|X |X |set_default_size | |
+--------------------------------------+------------------------------+---------------------+--------------------------------+
| | |add_element_to_window| |
|X |X |add_element | |
+--------------------------------------+------------------------------+---------------------+--------------------------------+


Expand All @@ -135,14 +137,14 @@ The description of this MEP gives us most of the solution:
+==========+============+=============+
|mainloop |begin | |
+----------+------------+-------------+
| |end |Gets called |
|X |end |Gets called |
| | |automagically|
| | |when no more |
| | |instances of |
| | |the subclass |
| | |exist |
+----------+------------+-------------+
|__call__ | |Method moved |
|__call__ |X |Method moved |
| | |to |
| | |Gcf.show_all |
+----------+------------+-------------+
Expand Down Expand Up @@ -191,6 +193,8 @@ in the same manner as everything else.
| | |window, so this also |
| | |breaks BC. |
+-------------------------+-------------------------+-------------------------+
|WebAgg |canvas | |
+-------------------------+-------------------------+-------------------------+


Alternatives
Expand Down
50 changes: 50 additions & 0 deletions examples/user_interfaces/gui_elements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'''This example demonstrates how to:
* Create new toolbars
* Create new windows
Using `matplotlib.backend_managers.ToolManager`,
`matplotlib.backend_bases.WindowBase` and
`matplotlib.backend_bases.ToolContainerBase`
'''

from __future__ import print_function
import matplotlib
matplotlib.use('GTK3Cairo')
matplotlib.rcParams['toolbar'] = 'toolmanager'
import matplotlib.pyplot as plt

fig = plt.figure()

# Shortcuts to FigureManager and ToolManager
manager = fig.canvas.manager
tool_mgr = manager.toolmanager

# Create a new toolbar
topbar = manager.backend.Toolbar(tool_mgr)
# The options are north, east, west and south
manager.window.add_element(topbar, False, 'north')

# Remove some tools from the main toolbar and add them to the
# new sidebar
for tool in ('home', 'back', 'forward'):
manager.toolbar.remove_toolitem(tool)
topbar.add_tool(tool, None)

plt.plot([1, 2, 3])

# Add a new window
win = manager.backend.Window('Extra tools')
# create a sidebar for the new window
sidebar = manager.backend.Toolbar(tool_mgr)
# set the direction of the sidebar
# the options are horizontal and vertical
sidebar.set_flow('vertical')
# add the sidebar to the new window
win.add_element(sidebar, False, 'west')

# Add some tools to the new sidebar
for tool in ('home', 'back', 'forward', 'zoom', 'pan'):
sidebar.add_tool(tool, None)
# show the new window
win.show()

plt.show()
63 changes: 61 additions & 2 deletions lib/matplotlib/_pylab_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import gc
import atexit

from matplotlib import is_interactive


def error_msg(msg):
print(msg, file=sys.stderr)
Expand All @@ -35,6 +37,16 @@ class Gcf(object):
_activeQue = []
figs = {}

@classmethod
def add_figure_manager(cls, manager):
cls.figs[manager.num] = manager
try: # TODO remove once all backends converted to use the new manager.
manager.mpl_connect('window_destroy_event', cls.destroy_cbk)
except:
pass

cls.set_active(manager)

@classmethod
def get_fig_manager(cls, num):
"""
Expand All @@ -46,6 +58,50 @@ def get_fig_manager(cls, num):
cls.set_active(manager)
return manager

@classmethod
def show_all(cls, block=None):
"""
Show all figures. If *block* is not None, then
it is a boolean that overrides all other factors
determining whether show blocks by calling mainloop().
The other factors are:
it does not block if run inside ipython's "%pylab" mode
it does not block in interactive mode.
"""

managers = cls.get_all_fig_managers()
if not managers:
return

for manager in managers:
manager.show()

if block is not None:
if block:
manager._mainloop()
return

from matplotlib import pyplot
try:
ipython_pylab = not pyplot.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'
# TODO: The above is a hack to get the WebAgg backend
# working with ipython's `%pylab` mode until proper
# integration is implemented.
except AttributeError:
ipython_pylab = False

# Leave the following as a separate step in case we
# want to control this behavior with an rcParam.
if ipython_pylab:
block = False

if not is_interactive() or get_backend() == 'WebAgg':
manager._mainloop()

@classmethod
def destroy(cls, num):
"""
Expand All @@ -68,7 +124,7 @@ def destroy(cls, num):
cls._activeQue.append(f)

del cls.figs[num]
manager.destroy()
manager.destroy() # Unneeded with MEP27 remove later
gc.collect(1)

@classmethod
Expand Down Expand Up @@ -137,7 +193,6 @@ def set_active(cls, manager):
if m != manager:
cls._activeQue.append(m)
cls._activeQue.append(manager)
cls.figs[manager.num] = manager

@classmethod
def draw_all(cls, force=False):
Expand All @@ -150,4 +205,8 @@ def draw_all(cls, force=False):
if force or f_mgr.canvas.figure.stale:
f_mgr.canvas.draw_idle()

@classmethod
def destroy_cbk(cls, event):
cls.destroy(event.figure_manager.num)

atexit.register(Gcf.destroy_all)
Loading