-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Add a GTK4 backend. #20321
Conversation
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. |
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. |
b09cb0f
to
b3ba921
Compare
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. |
0f0119e
to
fc11e21
Compare
87031fc
to
a06d597
Compare
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. |
There was a problem hiding this 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): |
There was a problem hiding this comment.
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)
Actually I found another bug: with this PR, on gtk3 (not gtk4), if you press |
Ah, I thought the block wasn't working in GTK4, but it was really just a stylistic issue. Adding the |
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. |
@tacaswell The last commit fixes Ctrl+C, but it needs the IPython input hooks to work completely as expected ipython/ipython#13101 |
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.
…321-on-v3.5.x Backport PR #20321 on branch v3.5.x (Add a GTK4 backend.)
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
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).