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

Skip to content

Commit 205e73f

Browse files
committed
gtk: Correctly resize canvas to intended size.
Previously, it was the window that was resized to the intended size, thus making the canvas smaller by the toolbar height. Fixes #10083 for GTK3. Fixes #10566 for GTK3.
1 parent 8feb6d8 commit 205e73f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,18 @@ 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+
canvas_size = self.canvas.get_allocation()
440+
if self.toolbar:
441+
toolbar_size = self.toolbar.size_request()
442+
height += toolbar_size.height
443+
if canvas_size.width == canvas_size.height == 1:
444+
# A canvas size of (1, 1) cannot exist in most cases, because
445+
# window decorations would prevent such a small window. This call
446+
# must be before the window has been mapped and widgets have been
447+
# sized, so just change the window's starting size.
448+
self.window.set_default_size(width, height)
449+
else:
450+
self.window.resize(width, height)
443451

444452

445453
class NavigationToolbar2GTK3(NavigationToolbar2, Gtk.Toolbar):

0 commit comments

Comments
 (0)