diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 2f34248837dc..60537cf6443a 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -436,10 +436,21 @@ def set_window_title(self, title): def resize(self, width, height): """Set the canvas size in pixels.""" - #_, _, cw, ch = self.canvas.allocation - #_, _, ww, wh = self.window.allocation - #self.window.resize (width-cw+ww, height-ch+wh) - self.window.resize(width, height) + if self.toolbar: + toolbar_size = self.toolbar.size_request() + height += toolbar_size.height + if self.statusbar: + statusbar_size = self.statusbar.size_request() + height += statusbar_size.height + canvas_size = self.canvas.get_allocation() + if canvas_size.width == canvas_size.height == 1: + # A canvas size of (1, 1) cannot exist in most cases, because + # window decorations would prevent such a small window. This call + # must be before the window has been mapped and widgets have been + # sized, so just change the window's starting size. + self.window.set_default_size(width, height) + else: + self.window.resize(width, height) class NavigationToolbar2GTK3(NavigationToolbar2, Gtk.Toolbar): diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 69b22df4528d..299e893993f8 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -442,6 +442,9 @@ def _set_dpi(self, dpi, forward=True): forward : bool Passed on to `~.Figure.set_size_inches` """ + if dpi == self._dpi: + # We don't want to cause undue events in backends. + return self._dpi = dpi self.dpi_scale_trans.clear().scale(dpi) w, h = self.get_size_inches() diff --git a/lib/matplotlib/tests/test_backend_qt.py b/lib/matplotlib/tests/test_backend_qt.py index 1f4798e25498..2545c3c68923 100644 --- a/lib/matplotlib/tests/test_backend_qt.py +++ b/lib/matplotlib/tests/test_backend_qt.py @@ -271,4 +271,5 @@ def crashing_callback(fig, stale): fig.stale_callback = crashing_callback # this should not raise canvas = FigureCanvasQTAgg(fig) + fig.stale = True assert called