Skip to content

Commit b059d78

Browse files
committed
Dedupe setting of initial window title in each FigureManager.
... by moving it to FigureManagerBase.
1 parent 327cfcf commit b059d78

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
@@ -2713,6 +2713,7 @@ def __init__(self, canvas, num):
27132713
self.canvas = canvas
27142714
canvas.manager = self # store a pointer to parent
27152715
self.num = num
2716+
self.set_window_title(f"Figure {num:d}")
27162717

27172718
self.key_press_handler_id = None
27182719
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
@@ -418,10 +418,9 @@ class FigureManagerTk(FigureManagerBase):
418418
_owns_mainloop = False
419419

420420
def __init__(self, canvas, num, window):
421-
super().__init__(canvas, num)
422421
self.window = window
422+
super().__init__(canvas, num)
423423
self.window.withdraw()
424-
self.set_window_title("Figure %d" % num)
425424
# packing toolbar first, because if space is getting low, last packed
426425
# widget is getting shrunk first (-> the canvas)
427426
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
@@ -369,11 +369,10 @@ class FigureManagerGTK3(FigureManagerBase):
369369
370370
"""
371371
def __init__(self, canvas, num):
372+
self.window = Gtk.Window()
372373
super().__init__(canvas, num)
373374

374-
self.window = Gtk.Window()
375375
self.window.set_wmclass("matplotlib", "Matplotlib")
376-
self.set_window_title("Figure %d" % num)
377376
try:
378377
self.window.set_icon_from_file(window_icon)
379378
except Exception:

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ class FigureManagerMac(_macosx.FigureManager, FigureManagerBase):
8787
Wrap everything up into a window for the pylab interface
8888
"""
8989
def __init__(self, canvas, num):
90+
_macosx.FigureManager.__init__(self, canvas)
9091
FigureManagerBase.__init__(self, canvas, num)
91-
title = "Figure %d" % num
92-
_macosx.FigureManager.__init__(self, canvas, title)
9392
if mpl.rcParams['toolbar'] == 'toolbar2':
9493
self.toolbar = NavigationToolbar2Mac(canvas)
9594
else:

lib/matplotlib/backends/backend_qt5.py

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

536536
def __init__(self, canvas, num):
537-
super().__init__(canvas, num)
538537
self.window = MainWindow()
538+
super().__init__(canvas, num)
539539
self.window.closing.connect(canvas.close_event)
540540
self.window.closing.connect(self._widgetclosed)
541541

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

lib/matplotlib/backends/backend_webagg_core.py

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

411411
def __init__(self, canvas, num):
412-
super().__init__(canvas, num)
413-
414412
self.web_sockets = set()
415-
413+
super().__init__(canvas, num)
416414
self.toolbar = self._get_toolbar(canvas)
417415

418416
def show(self):

lib/matplotlib/backends/backend_wx.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ def __init__(self, num, fig):
914914
pos = wx.DefaultPosition
915915
else:
916916
pos = wx.Point(20, 20)
917-
super().__init__(parent=None, id=-1, pos=pos, title="Figure %d" % num)
917+
super().__init__(parent=None, id=-1, pos=pos)
918918
# Frame will be sized later by the Fit method
919919
_log.debug("%s - __init__()", type(self))
920920
self.num = num
@@ -1022,9 +1022,10 @@ class FigureManagerWx(FigureManagerBase):
10221022

10231023
def __init__(self, canvas, num, frame):
10241024
_log.debug("%s - __init__()", type(self))
1025+
self.frame = self.window = frame
1026+
self._initializing = True
10251027
super().__init__(canvas, num)
1026-
self.frame = frame
1027-
self.window = frame
1028+
self._initializing = False
10281029

10291030
@property
10301031
def toolbar(self):
@@ -1034,7 +1035,7 @@ def toolbar(self):
10341035
def toolbar(self, value):
10351036
# Never allow this, except that base class inits this to None before
10361037
# the frame is set up.
1037-
if value is not None or hasattr(self, "frame"):
1038+
if not self._initializing:
10381039
raise AttributeError("can't set attribute")
10391040

10401041
def show(self):

src/_macosx.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
664664
NSRect rect;
665665
Window* window;
666666
View* view;
667-
const char* title;
668667
PyObject* size;
669668
int width, height;
670669
PyObject* obj;
@@ -676,7 +675,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
676675
return -1;
677676
}
678677

679-
if(!PyArg_ParseTuple(args, "Os", &obj, &title)) return -1;
678+
if(!PyArg_ParseTuple(args, "O", &obj)) return -1;
680679

681680
canvas = (FigureCanvas*)obj;
682681
view = canvas->view;
@@ -708,9 +707,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
708707
defer: YES
709708
withManager: (PyObject*)self];
710709
window = self->window;
711-
[window setTitle: [NSString stringWithCString: title
712-
encoding: NSASCIIStringEncoding]];
713-
714710
[window setDelegate: view];
715711
[window makeFirstResponder: view];
716712
[[window contentView] addSubview: view];

0 commit comments

Comments
 (0)