feat: support icon color - followup#277
Conversation
…into icon-color
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (88.52%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #277 +/- ##
==========================================
- Coverage 99.78% 99.43% -0.36%
==========================================
Files 31 31
Lines 1879 1931 +52
==========================================
+ Hits 1875 1920 +45
- Misses 4 11 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@brisvag, I think the main reason that PR stalled is because of the problem with theme changes. as mentioned in the first comment:
so, currently here: app = Application("myapp")
app.theme_mode = "dark" # or let it auto-detect
Action(
id="my.action",
title="Do Thing",
icon={"dark": "mdi:some-icon", "color_dark": "#FFFFFF", "color_light": "#000000"},
...
)The icon color is resolved once — at the moment the so, it feels like a partially implemented thing that will pretty quickly have a bug report or feature request |
|
Does something like this make sense? One thing I noticed when testing this out with |
if you try it out and it works for you, it seems fine to me.
i need a bit more context: what did you observe and how did it differ from what you expected? |
|
Ok so I pushed some changes that should make this work as intended. I also updated temporarily the demo so you test it out, with 2 new buttons: the first changes "system theme" by changing the qpalette. The second changes the model's theme between light and dark manually. When you swap theme, you'll see that while the icon theme color overrides (blue and red) apply correctly to the two new buttons, they don't affect the scissors icon as long as it's disabled: that grey-out colopr is hardcoded somewhere else. IMO it should be a desaturated version of the provided color? |
|
@tlambert03 ping in case this slipped through the cracks! |
|
I'll have a look today... but can you make sure that things like pre-commit/pyright are green? That will definitely prevent merge |
|
I was mainly asking for feedback on my last comment above, before I lock in in terms of implementation and solve the remaining tests/issues. Some of the changes I made (mainly the example) are temporary and it's just to make it easier for you to see the issue :) |
|
got it thanks! lemme give you a better review soon |
tlambert03
left a comment
There was a problem hiding this comment.
Looks mostly good to me! A couple comments inline. Main issues are the demo code (useful, but currently incomplete in a confusing way)... and the per-action eventFilter causing a potential performance problem
| types.Action( | ||
| id="switch_theme", | ||
| icon={ | ||
| "dark": "fa6-solid:circle-half-stroke", | ||
| "color_dark": "#ff0000", | ||
| "color_light": "#0000ff", | ||
| }, | ||
| title="Switch dark/light theme", | ||
| status_tip="Switch between dark and light theme.", | ||
| menus=[{"id": MenuId.HELP}], | ||
| callback=MainWindow.switch_theme, | ||
| ), | ||
| types.Action( | ||
| id="switch_theme_model", | ||
| icon={ | ||
| "dark": "fa6-solid:circle-half-stroke", | ||
| "color_dark": "#ff0000", | ||
| "color_light": "#0000ff", | ||
| }, | ||
| title="Switch dark/light theme", | ||
| status_tip="Switch between dark and light theme.", | ||
| menus=[{"id": MenuId.HELP}], | ||
| callback=MainWindow.switch_theme_model, | ||
| ), |
There was a problem hiding this comment.
these two actions are very useful in the demo... but they seem to be copy/paste incomplete. They have the same icon/tooltip/title, etc... but do different things?
please also add docstrings to the two methods switch_theme[_model], so it's actually clear what the methods are supposed to be demoing.
| ) | ||
| if submenu.icon: | ||
| self.setIcon(to_qicon(submenu.icon)) | ||
| self.setIcon( |
There was a problem hiding this comment.
does this need to react to theme_mode_changed like the QCommandAction did?
| color_dark: str | None | ||
| color_light: str | None |
There was a problem hiding this comment.
these may have been the names I used when I took a first stab at implementing this... but I'm realizing now it's a footgun. Do you think that color_dark sounds like "the color of the icon when it should be dark" (e.g. for the light theme) ... rather than "the color of the icon when the theme is dark". If so, maybe let's make it dark_theme_color and light_theme_color? (more verbose, but less confusing)
| self.setIcon(to_qicon(command_rule.icon)) | ||
| self.setIconVisibleInMenu(command_rule.icon_visible_in_menu) | ||
| self._update_icon_theme() | ||
| QApplication.instance().installEventFilter(self) |
There was a problem hiding this comment.
for an app with hundreds of actions, I fear the costs of this per-action eventFilter: every QCommandRuleAction installs its own event filter on the global QApplication. With N actions, every Qt event delivered to QApplication (mouse moves, etc.) traverses N filters... And events are fired all the time.
Can we consider one shared event filter at the Application level that triggers app.theme_mode_changed instead?
|
|
||
|
|
||
| LIGHT_COLOR = "#BCB4B4" | ||
| DARK_COLOR = "#6B6565" |
There was a problem hiding this comment.
just pointing out (for myself). This is an observable change for all users, even if they aren't touching the theme stuff. The old default icon color was black, and will now be gray. Probably not a big deal, but could perhaps be mentioned in the main PR comment for visibility
Trying to pick up #130!
I fixed conflicts and brought it up to date. @tlambert03 was there something specific with that PR that was incomplete or you wanted to finish?