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

Skip to content

Commit da078ca

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 da078ca

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-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):

0 commit comments

Comments
 (0)