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

Skip to content

Commit cc3a77d

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 cc3a77d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/matplotlib/backends/backend_gtk3.py

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

444450

445451
class NavigationToolbar2GTK3(NavigationToolbar2, Gtk.Toolbar):

0 commit comments

Comments
 (0)