Skip to content

Use light icons on dark themes for wx and gtk, too. #17459

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 1 commit into from
May 31, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 20, 2020

These can be tried e.g. by setting GTK_THEME to Adwaita:dark.
I couldn't find how to get the foreground color in GTK3 so the check for
dark themes is just looking at the luminance of the background, and the
icon color is set to white. (Better approaches welcome...)
I made the _icon API "consistent" across qt, wx, and gtk.

(Qt already supports this, and I don't think Tk supports this kind of theming out of the box anyways.)

before:
old
after:
new

PR Summary

PR Checklist

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

# See wx.Colour.GetLuminance.
bg_lum = (.299 * bg.red + .587 * bg.green + .114 * bg.blue) / 255
fg_lum = (.299 * fg.red + .587 * fg.green + .114 * fg.blue) / 255
dark = fg_lum - bg_lum > .2
Copy link
Member

Choose a reason for hiding this comment

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

Why calculate this differently from GTK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is copypasted from the implementation of wx's IsUsingDarkBackground (which is not available on older wx), so at least it's internally consistent across wx versions.

Also I was not able to figure out how to get the text color on gtk...

Copy link
Member

Choose a reason for hiding this comment

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

I think there's a better way to do it on GTK, but it would be a much more substantial re-write.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not actually a gtk expert at all (tbh I find its docs much harder to follow than wx, which I'm not that familiar with either (I (used to) use qt fairly regularly) but find much easier to follow), so I'll leave it up to you whether we want the "complicated" solution here.

Copy link
Member

Choose a reason for hiding this comment

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

OK, I think I've figured it out and it's actually not as complicated as I thought, but it's a bit of a hack right now. I'll try and figure out how to be less hacky and open a PR.

@anntzer
Copy link
Contributor Author

anntzer commented May 22, 2020

rebased

@QuLogic
Copy link
Member

QuLogic commented May 29, 2020

So to be clear on the problem here, in dark mode, the buttons in GTK do not reflect their state. So if back/forward are disabled, they look the same as the rest of the buttons. When GtkImage comes from a file, GTK seems to handle changing appearances for you, but not when it comes from a surface.

My original thought was to switch GtkImage to GtkDrawingArea and do the drawing based on current style's colours. However, that seemed to be a lot of work for little gain, when GTK has support for symbolic icons already. Symbolic icons work essentially the way we have already, with a single-colour icon that is styled by the theme. The only problem is this is triggered by the file name. So I debating what we should do here:

  • Copy *.png to *.symbolic.png
  • Rename *.png to *.symbolic.png
  • Copy *.svg to *-symbolic.svg
  • Rename *.svg to *-symbolic.svg

Currently, every backend uses *.png, so maybe we don't want to rename those. I'm not super happy about copying things. Nothing uses *.svg, so maybe rename those? I just don't know if those files qualify as public API.

@anntzer
Copy link
Contributor Author

anntzer commented May 29, 2020

Symlink them? The number of people using matplotlib + gtk on windows and without the ability to create symlinks is likely, uh, limited.

@QuLogic
Copy link
Member

QuLogic commented May 29, 2020

Wasn't sure if that might cause trouble in wheels? Since they're zips, do they preserve them?

@anntzer
Copy link
Contributor Author

anntzer commented May 29, 2020

From a very quick check, looks like the symlink just gets replaced by a regular file in the wheel, but that's fine? That just means that whoever installs from a wheel will get a copy instead of a symlink, but that's fine?

@timhoffm
Copy link
Member

GTK handling must be removed because that's handled now via #17539.

@anntzer
Copy link
Contributor Author

anntzer commented May 31, 2020

done

This can be tried e.g. by setting `GTK_THEME` to `Adwaita:dark`.
I made the `_icon` API "consistent" across qt and wx, too.
@timhoffm timhoffm merged commit 7021730 into matplotlib:master May 31, 2020
@anntzer anntzer deleted the gtkwxdark branch June 1, 2020 08:01
@QuLogic QuLogic added this to the v3.3.0 milestone Jun 1, 2020
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.

3 participants