Skip to content

Commit da8789b

Browse files
authored
Merge pull request matplotlib#16972 from QuLogic/resize-bugs
Fix resize bugs in GTK
2 parents 98dff87 + 1a7cc4c commit da8789b

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,21 @@ def set_window_title(self, title):
436436

437437
def resize(self, width, height):
438438
"""Set the canvas size in pixels."""
439-
#_, _, cw, ch = self.canvas.allocation
440-
#_, _, ww, wh = self.window.allocation
441-
#self.window.resize (width-cw+ww, height-ch+wh)
442-
self.window.resize(width, height)
439+
if self.toolbar:
440+
toolbar_size = self.toolbar.size_request()
441+
height += toolbar_size.height
442+
if self.statusbar:
443+
statusbar_size = self.statusbar.size_request()
444+
height += statusbar_size.height
445+
canvas_size = self.canvas.get_allocation()
446+
if canvas_size.width == canvas_size.height == 1:
447+
# A canvas size of (1, 1) cannot exist in most cases, because
448+
# window decorations would prevent such a small window. This call
449+
# must be before the window has been mapped and widgets have been
450+
# sized, so just change the window's starting size.
451+
self.window.set_default_size(width, height)
452+
else:
453+
self.window.resize(width, height)
443454

444455

445456
class NavigationToolbar2GTK3(NavigationToolbar2, Gtk.Toolbar):

lib/matplotlib/figure.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ def _set_dpi(self, dpi, forward=True):
442442
forward : bool
443443
Passed on to `~.Figure.set_size_inches`
444444
"""
445+
if dpi == self._dpi:
446+
# We don't want to cause undue events in backends.
447+
return
445448
self._dpi = dpi
446449
self.dpi_scale_trans.clear().scale(dpi)
447450
w, h = self.get_size_inches()

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,5 @@ def crashing_callback(fig, stale):
271271
fig.stale_callback = crashing_callback
272272
# this should not raise
273273
canvas = FigureCanvasQTAgg(fig)
274+
fig.stale = True
274275
assert called

0 commit comments

Comments
 (0)