Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fef9502

Browse files
authored
Merge pull request #15212 from anntzer/set_window_title
Dedupe window-title setting by moving it to FigureManagerBase.
2 parents 28efb11 + b059d78 commit fef9502

File tree

8 files changed

+12
-20
lines changed

8 files changed

+12
-20
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,7 @@ def __init__(self, canvas, num):
27162716
self.canvas = canvas
27172717
canvas.manager = self # store a pointer to parent
27182718
self.num = num
2719+
self.set_window_title(f"Figure {num:d}")
27192720

27202721
self.key_press_handler_id = None
27212722
self.button_press_handler_id = None

lib/matplotlib/backends/_backend_tk.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,9 @@ class FigureManagerTk(FigureManagerBase):
394394
_owns_mainloop = False
395395

396396
def __init__(self, canvas, num, window):
397-
super().__init__(canvas, num)
398397
self.window = window
398+
super().__init__(canvas, num)
399399
self.window.withdraw()
400-
self.set_window_title("Figure %d" % num)
401400
# packing toolbar first, because if space is getting low, last packed
402401
# widget is getting shrunk first (-> the canvas)
403402
self.toolbar = self._get_toolbar()

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,10 @@ class FigureManagerGTK3(FigureManagerBase):
312312
313313
"""
314314
def __init__(self, canvas, num):
315+
self.window = Gtk.Window()
315316
super().__init__(canvas, num)
316317

317-
self.window = Gtk.Window()
318318
self.window.set_wmclass("matplotlib", "Matplotlib")
319-
self.set_window_title("Figure %d" % num)
320319
try:
321320
self.window.set_icon_from_file(window_icon)
322321
except Exception:

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ class FigureManagerMac(_macosx.FigureManager, FigureManagerBase):
7171
Wrap everything up into a window for the pylab interface
7272
"""
7373
def __init__(self, canvas, num):
74+
_macosx.FigureManager.__init__(self, canvas)
7475
FigureManagerBase.__init__(self, canvas, num)
75-
title = "Figure %d" % num
76-
_macosx.FigureManager.__init__(self, canvas, title)
7776
if mpl.rcParams['toolbar'] == 'toolbar2':
7877
self.toolbar = NavigationToolbar2Mac(canvas)
7978
else:

lib/matplotlib/backends/backend_qt5.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,11 @@ class FigureManagerQT(FigureManagerBase):
536536
"""
537537

538538
def __init__(self, canvas, num):
539-
super().__init__(canvas, num)
540539
self.window = MainWindow()
540+
super().__init__(canvas, num)
541541
self.window.closing.connect(canvas.close_event)
542542
self.window.closing.connect(self._widgetclosed)
543543

544-
self.window.setWindowTitle("Figure %d" % num)
545544
image = str(cbook._get_data_path('images/matplotlib.svg'))
546545
self.window.setWindowIcon(QtGui.QIcon(image))
547546

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,8 @@ class FigureManagerWebAgg(backend_bases.FigureManagerBase):
446446
ToolbarCls = NavigationToolbar2WebAgg
447447

448448
def __init__(self, canvas, num):
449-
super().__init__(canvas, num)
450-
451449
self.web_sockets = set()
452-
450+
super().__init__(canvas, num)
453451
self.toolbar = self._get_toolbar(canvas)
454452

455453
def show(self):

lib/matplotlib/backends/backend_wx.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ def __init__(self, num, fig):
902902
pos = wx.DefaultPosition
903903
else:
904904
pos = wx.Point(20, 20)
905-
super().__init__(parent=None, id=-1, pos=pos, title="Figure %d" % num)
905+
super().__init__(parent=None, id=-1, pos=pos)
906906
# Frame will be sized later by the Fit method
907907
_log.debug("%s - __init__()", type(self))
908908
self.num = num
@@ -1011,9 +1011,10 @@ class FigureManagerWx(FigureManagerBase):
10111011

10121012
def __init__(self, canvas, num, frame):
10131013
_log.debug("%s - __init__()", type(self))
1014+
self.frame = self.window = frame
1015+
self._initializing = True
10141016
super().__init__(canvas, num)
1015-
self.frame = frame
1016-
self.window = frame
1017+
self._initializing = False
10171018

10181019
@property
10191020
def toolbar(self):
@@ -1023,7 +1024,7 @@ def toolbar(self):
10231024
def toolbar(self, value):
10241025
# Never allow this, except that base class inits this to None before
10251026
# the frame is set up.
1026-
if value is not None or hasattr(self, "frame"):
1027+
if not self._initializing:
10271028
raise AttributeError("can't set attribute")
10281029

10291030
def show(self):

src/_macosx.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
660660
NSRect rect;
661661
Window* window;
662662
View* view;
663-
const char* title;
664663
PyObject* size;
665664
int width, height;
666665
PyObject* obj;
@@ -672,7 +671,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
672671
return -1;
673672
}
674673

675-
if(!PyArg_ParseTuple(args, "Os", &obj, &title)) return -1;
674+
if(!PyArg_ParseTuple(args, "O", &obj)) return -1;
676675

677676
canvas = (FigureCanvas*)obj;
678677
view = canvas->view;
@@ -704,9 +703,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
704703
defer: YES
705704
withManager: (PyObject*)self];
706705
window = self->window;
707-
[window setTitle: [NSString stringWithCString: title
708-
encoding: NSASCIIStringEncoding]];
709-
710706
[window setDelegate: view];
711707
[window makeFirstResponder: view];
712708
[[window contentView] addSubview: view];

0 commit comments

Comments
 (0)