Skip to content

factor the pyplot dependence out of the figure_manager classes #2617

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2439,7 +2439,7 @@ def key_press_handler(event, canvas, toolbar=None):

# quit the figure (defaut key 'ctrl+w')
if event.key in quit_keys:
Gcf.destroy_fig(canvas.figure)
canvas.manager.destroy()

if toolbar is not None:
# home or reset mnemonic (default key 'h', 'home' and 'r')
Expand Down Expand Up @@ -2525,10 +2525,9 @@ class FigureManagerBase:
*num*
The figure number
"""
def __init__(self, canvas, num):
def __init__(self, canvas):
Copy link
Member

Choose a reason for hiding this comment

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

You could avoid this change to the base API, and thereby avoid quite a few other changes, by changing the num argument to a kwarg with default None. In addition to simplifying the changeset, this would avoid breaking any user-written backends that might be in use.

self.canvas = canvas
canvas.manager = self # store a pointer to parent
self.num = num

self.key_press_handler_id = self.canvas.mpl_connect('key_press_event',
self.key_press)
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ def new_figure_manager_given_figure(num, figure):
Create a new figure manager instance for the given figure.
"""
canvas = FigureCanvasAgg(figure)
manager = FigureManagerBase(canvas, num)
manager = FigureManagerBase(canvas)
manager.num = num
return manager


Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ def new_figure_manager_given_figure(num, figure):
Create a new figure manager instance for the given figure.
"""
canvas = FigureCanvasCairo(figure)
manager = FigureManagerBase(canvas, num)
manager = FigureManagerBase(canvas)
manager.num = num
return manager


Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/backend_cocoaagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ def startWithBundle_(self, bundle):

class FigureManagerCocoaAgg(FigureManagerBase):
def __init__(self, canvas, num):
FigureManagerBase.__init__(self, canvas, num)
FigureManagerBase.__init__(self, canvas)
self.num = num

try:
WMEnable('Matplotlib')
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/backend_gdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ def new_figure_manager_given_figure(num, figure):
Create a new figure manager instance for the given figure.
"""
canvas = FigureCanvasGDK(figure)
manager = FigureManagerBase(canvas, num)
manager = FigureManagerBase(canvas)
manager.num = num
return manager


Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ class FigureManagerGTK(FigureManagerBase):
"""
def __init__(self, canvas, num):
if _debug: print('FigureManagerGTK.%s' % fn_name())
FigureManagerBase.__init__(self, canvas, num)

FigureManagerBase.__init__(self, canvas)
self.num = num
self.window = gtk.Window()
self.set_window_title("Figure %d" % num)
if (window_icon):
Expand Down
Loading