8000 Add a GTK4 backend. by QuLogic · Pull Request #20321 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add a GTK4 backend. #20321

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 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 mentioned this pull request Jul 20, 2021
3 tasks
@QuLogic
Copy link
Member Author
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
Copy link
Member Author
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 gtk4 branch 2 times, most recently from b09cb0f to b3ba921 Compare August 5, 2021 00:22
@QuLogic
Copy link
Member Author
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 August 5, 2021 00:33
@QuLogic QuLogic force-pushed the gtk4 branch 3 times, most recently from 0f0119e to fc11e21 Compare August 5, 2021 06:28
@QuLogic QuLogic force-pushed the gtk4 branch 2 times, most recently from 87031fc to a06d597 Compare August 6, 2021 03:05
@QuLogic
Copy link
Member Author
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.

anntzer
anntzer previously approved these changes Aug 6, 2021
Copy link
Contributor
@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

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):
Copy link
Contributor

Choose a reason for hiding this comment

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

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 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 August 6, 2021 18:37

recursion error needs fix

@QuLogic
Copy link
Member Author
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.

@anntzer
Copy link
Contributor
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 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

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

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 merged commit d3da54a into matplotlib:master Sep 1, 2021
@QuLogic QuLogic deleted the gtk4 branch September 1, 2021 22:18
meeseeksmachine pushed 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.)
tacaswell pushed a commit that referenced this pull request Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0