The Wayback Machine - https://web.archive.org/web/20210905053650/https://github.com/matplotlib/matplotlib/pull/20321
Skip to content
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

Add a GTK4 backend. #20321

Merged
merged 7 commits into from Sep 1, 2021
Merged

Add a GTK4 backend. #20321

merged 7 commits into from Sep 1, 2021

Conversation

@QuLogic
Copy link
Member

@QuLogic QuLogic commented May 28, 2021

PR Summary

This is currently sufficient to open a window, do the usual things, like handle key presses, or zoom/pan, but there are still some kinks to work out. The zoom/pan buttons do not stay pressed, the canvas does not resize, and there are probably several other smaller things that are broken.

It is also in a separate file, but several of the changes can be cross-ported to the GTK3 backend, which I will do separately. When that is done, I can likely remove a lot of duplication, and possibly put it all together like Qt5/Qt6 is aiming to do.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
@QuLogic QuLogic added this to the v3.5.0 milestone Jul 13, 2021
@QuLogic QuLogic added this to High Priority in v3.5 Milestone Jul 13, 2021
@QuLogic QuLogic mentioned this pull request Jul 20, 2021
3 tasks done
@QuLogic QuLogic force-pushed the QuLogic:gtk4 branch from 4ca9501 to a7ea649 Jul 29, 2021
@QuLogic
Copy link
Member Author

@QuLogic QuLogic commented Jul 29, 2021

I've now fixed resizing, which was easier to fix than I first thought, so it's just the toolbar button setup that needs fixing. Then there's lots of shared code between 2 and 3 that could be refactored out.

@QuLogic QuLogic force-pushed the QuLogic:gtk4 branch from a7ea649 to 8ae34a6 Jul 31, 2021
@QuLogic
Copy link
Member Author

@QuLogic QuLogic commented Jul 31, 2021

OK, I've fixed the toolbar, as well as tool manager, a focus issue, and this seems to be working in general. I haven't done the refactor or updated CI yet, but it is in a testable state.

@QuLogic QuLogic force-pushed the QuLogic:gtk4 branch 2 times, most recently from b09cb0f to b3ba921 Jul 31, 2021
@QuLogic
Copy link
Member Author

@QuLogic QuLogic commented Aug 5, 2021

OK, I noticed some more bugs and have fixed them now. The tool manager copy button works now, and save figure uses the native dialog.

I moved common code into a separate file. I'm debating whether the canvas and manager should be refactored together. The event handling is quite a bit different, so this may not save much. Really only the draw event handling (with a rubberband) is common on the canvas.

IPython does not have an entry for gtk4, so does not set up event loop integration. I don't know if there's anything we can do on our side to get that working.

@QuLogic QuLogic marked this pull request as ready for review Aug 5, 2021
@QuLogic QuLogic force-pushed the QuLogic:gtk4 branch 3 times, most recently from 0f0119e to fc11e21 Aug 5, 2021
@QuLogic QuLogic force-pushed the QuLogic:gtk4 branch 2 times, most recently from 87031fc to a06d597 Aug 6, 2021
@QuLogic
Copy link
Member Author

@QuLogic QuLogic commented Aug 6, 2021

Fixed, and I also added docs and example updates. Since we don't need to support GTK 3.0.0, I used the latest recommended style for the embedding examples.

Copy link
Contributor

@anntzer anntzer left a comment

Modulo rebase, CI, and clarifying #20321 (comment).

# TODO: Only update the rubberband area.
self.queue_draw()

def draw_func(self, drawing_area, ctx, width, height):

This comment has been minimized.

@anntzer

anntzer Aug 6, 2021
Contributor

Keep this private? (this makes is slightly clearer that 3rd party renderers (i.e., mplcairo.gtk) can keep on overriding on_draw_event as in gtk3, not something else)

@anntzer
Copy link
Contributor

@anntzer anntzer commented Aug 6, 2021

Actually I found another bug: with this PR, on gtk3 (not gtk4), if you press o to toggle the zoom tool, you get an infinite recursion error (repeatedly going between _update_buttons_checked() and zoom()).

@anntzer anntzer dismissed their stale review Aug 6, 2021

recursion error needs fix

@QuLogic
Copy link
Member Author

@QuLogic QuLogic commented Aug 6, 2021

Ah, I thought the block wasn't working in GTK4, but it was really just a stylistic issue. Adding the flat class made the changes correctly visible, so we can go back to the same blocking implementation that worked on GTK3.

@QuLogic QuLogic force-pushed the QuLogic:gtk4 branch from ba87787 to a8d6d77 Aug 6, 2021
@anntzer
Copy link
Contributor

@anntzer anntzer commented Aug 16, 2021

I can't say I checked everything, but this seems good enough to go for now and we can always fix anything else we find later.

@QuLogic
Copy link
Member Author

@QuLogic QuLogic commented Aug 20, 2021

@tacaswell The last commit fixes Ctrl+C, but it needs the IPython input hooks to work completely as expected ipython/ipython#13101

@tacaswell
Copy link
Member

@tacaswell tacaswell commented Sep 1, 2021

I @QuLogic can self-merge this after a rebase and CI green.

QuLogic added 7 commits Jul 31, 2021
According to the docs, this function was added in GTK 2.2, so probably
was only needed when we supported GTK2.

It also no longer exists in GTK4.
Since these examples don't need to support the very oldest GTK3, I took
the opportunity to rewrite them using the recommended Application-styled
model.
The `Gtk.Window.destroy` doesn't work, but `.close` correctly triggers
our cleanup.
@QuLogic QuLogic force-pushed the QuLogic:gtk4 branch from f678514 to d3804c2 Sep 1, 2021
@QuLogic QuLogic merged commit d3da54a into matplotlib:master Sep 1, 2021
27 of 28 checks passed
27 of 28 checks passed
@github-actions
flake8
Details
@github-actions
greeting
Details
@github-actions
Python 3.7 on ubuntu-18.04 (Minimum Versions)
Details
@github-actions
Python 3.7 on ubuntu-18.04
Details
@github-actions
Python 3.8 on ubuntu-18.04
Details
@github-actions
Python 3.9 on ubuntu-20.04
Details
@github-actions
Python 3.10-dev on ubuntu-20.04 Python 3.10-dev on ubuntu-20.04
Details
@github-actions
Python 3.8 on macos-latest
Details
@github-actions
eslint
Details
@codecov
codecov/patch 18.78% of diff hit (target 50.00%)
Details
@lgtm-com
LGTM analysis: JavaScript No code changes detected
Details
@github-actions
Check the rendered docs here! Link to 0/doc/build/html/index.html
Details
@lgtm-com
LGTM analysis: Python 9 new alerts
Details
ci/circleci: docs-python38 Your tests passed on CircleCI!
Details
@codecov
codecov/project/library 80.15% (target 50.00%)
Details
@codecov
codecov/project/tests 98.85% (+0.00%) compared to a142369
Details
@appveyor
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@azure-pipelines
matplotlib.matplotlib Build #20210901.17 succeeded
Details
@azure-pipelines
matplotlib.matplotlib (Check Skip) Check Skip succeeded
Details
@azure-pipelines
matplotlib.matplotlib (Main Pytest Linux_py37) Main Pytest Linux_py37 succeeded
Details
@azure-pipelines
matplotlib.matplotlib (Main Pytest Linux_py38) Main Pytest Linux_py38 succeeded
Details
@azure-pipelines
matplotlib.matplotlib (Main Pytest Linux_py39) Main Pytest Linux_py39 succeeded
Details
@azure-pipelines
matplotlib.matplotlib (Main Pytest Windows_py37) Main Pytest Windows_py37 succeeded
Details
@azure-pipelines
matplotlib.matplotlib (Main Pytest Windows_py38) Main Pytest Windows_py38 succeeded
Details
@azure-pipelines
matplotlib.matplotlib (Main Pytest Windows_py39) Main Pytest Windows_py39 succeeded
Details
@azure-pipelines
matplotlib.matplotlib (Main Pytest macOS_py37) Main Pytest macOS_py37 succeeded
Details
@azure-pipelines
matplotlib.matplotlib (Main Pytest macOS_py38) Main Pytest macOS_py38 succeeded
Details
@azure-pipelines
matplotlib.matplotlib (Main Pytest macOS_py39) Main Pytest macOS_py39 succeeded
Details
v3.5 Milestone automation moved this from High Priority to Done Sep 1, 2021
@QuLogic QuLogic deleted the QuLogic:gtk4 branch Sep 1, 2021
meeseeksmachine added a commit to meeseeksmachine/matplotlib that referenced this pull request Sep 1, 2021
QuLogic added a commit that referenced this pull request Sep 1, 2021
…321-on-v3.5.x

Backport PR #20321 on branch v3.5.x (Add a GTK4 backend.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants