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

Skip to content

Fix resize bugs in GTK #16972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 4, 2020
Merged

Fix resize bugs in GTK #16972

merged 3 commits into from
Apr 4, 2020

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Mar 31, 2020

PR Summary

This fixes #16934 by essentially reverting the Text.get_window_extent change, but in a more general way. Avoiding redundant event signals for changing DPI is somewhat safer for all backends as we can't really control whether a backend will trigger another draw on resize or not (ok, we could block their signals, but this is simpler). By doing it in the Figure.set_dpi method, it covers all cases that might come up in the future, and not just the Text one.

The second commit also fixes #10083 and #10566 for GTK.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • [n/a] New features are documented, with examples if plot related
  • [n/a] Documentation is sphinx and numpydoc compliant
  • [n/a] Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • [n/a] Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

This is essentially a revert of the `Text.get_window_extent` change to
its dpi handling, but applies in _all_ cases.

Depending on backend, we want to avoid this extraneous dpi change,
because it can cause recursive event signals. For example, with GTK3, a
resize will trigger its event loop, which eventually causes a re-draw.
The re-draw would get to `Text.get_window_extent`, change the dpi (to
the same value), and call `Figure.set_size_inches`, which would resize
the window again. Depending on how much of the GTK event loop was
processed, this may or may not trigger another draw, recursing again and
again.

Fixes matplotlib#16934.
Previously, it was the window that was resized to the intended size,
thus making the canvas smaller by the toolbar height.

Fixes matplotlib#10083 for GTK3.
Fixes matplotlib#10566 for GTK3.
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change makes sense and tested that this fixes the problem locally.

The figure is no longer set stale because `resize` is no longer called.
There's no reason the figure should be stale until it's ready to be
drawn, but we don't really need a whole main loop for this test.
@QuLogic
Copy link
Member Author

QuLogic commented Mar 31, 2020

I'm not 100% on that last test fix as I'm not sure what it's trying to trigger.

@QuLogic
Copy link
Member Author

QuLogic commented Apr 4, 2020

This also fixes some kind of refresh loop in nbagg.

@anntzer
Copy link
Contributor

anntzer commented Apr 4, 2020

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gtk3 window immediately resizes down to zero-height upon showing up. Wrong figure height after set_size_inches within event handler
3 participants