Enh new figure function in backends by tacaswell · Pull Request #18852 · matplotlib/matplotlib · GitHub
Skip to content
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
38 changes: 38 additions & 0 deletions lib/matplotlib/backend_bases.py
6 changes: 5 additions & 1 deletion lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ def __init__(self, canvas, num, window):
super().__init__(canvas, num)
self.window = window
self.window.withdraw()
self.set_window_title("Figure %d" % num)
if isinstance(num, str):
title = num
else:
title = f"Figure {num}"
self.set_window_title(title)
# packing toolbar first, because if space is getting low, last packed
# widget is getting shrunk first (-> the canvas)
self.toolbar = self._get_toolbar()
Expand Down
6 changes: 5 additions & 1 deletion lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ def __init__(self, canvas, num):

self.window = Gtk.Window()
self.window.set_wmclass("matplotlib", "Matplotlib")
self.set_window_title("Figure %d" % num)
if isinstance(num, str):
title = num
else:
title = f"Figure {num}"
self.set_window_title(title)
try:
self.window.set_icon_from_file(window_icon)
except Exception:
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/backends/backend_macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ class FigureManagerMac(_macosx.FigureManager, FigureManagerBase):
"""
def __init__(self, canvas, num):
FigureManagerBase.__init__(self, canvas, num)
title = "Figure %d" % num
if isinstance(num, str):
title = num
else:
title = f"Figure {num}"
_macosx.FigureManager.__init__(self, canvas, title)
if mpl.rcParams['toolbar'] == 'toolbar2':
self.toolbar = NavigationToolbar2Mac(canvas)
Expand Down
7 changes: 5 additions & 2 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,11 @@ def __init__(self, canvas, num):
self.window = MainWindow()
self.window.closing.connect(canvas.close_event)
self.window.closing.connect(self._widgetclosed)

self.window.setWindowTitle("Figure %d" % num)
if isinstance(num, str):
title = num
else:
title = f"Figure {num}"
self.window.setWindowTitle(title)
image = str(cbook._get_data_path('images/matplotlib.svg'))
self.window.setWindowIcon(QtGui.QIcon(image))

Expand Down
8 changes: 6 additions & 2 deletions lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def handle_toolbar_button(self, event):
def handle_refresh(self, event):
figure_label = self.figure.get_label()
if not figure_label:
figure_label = "Figure {0}".format(self.manager.num)
figure_label = self._title
self.send_event('figure_label', label=figure_label)
self._force_full = True
if self.toolbar:
Expand Down Expand Up @@ -410,7 +410,10 @@ class FigureManagerWebAgg(backend_bases.FigureManagerBase):

def __init__(self, canvas, num):
super().__init__(canvas, num)

if isinstance(num, str):
self._title = num
else:
self._title = f"Figure {num}"
self.web_sockets = set()

self.toolbar = self._get_toolbar(canvas)
Expand All @@ -429,6 +432,7 @@ def resize(self, w, h, forward=True):
forward=forward)

def set_window_title(self, title):
self._title = title
self._send_event('figure_label', label=title)

# The following methods are specific to FigureManagerWebAgg
Expand Down
6 changes: 5 additions & 1 deletion lib/matplotlib/backends/backend_wx.py