Skip to content

Conversation

Isotech42
Copy link
Contributor

This pull request introduces a new icons option in the YASB ClockWidget configuration. This option enables displaying a different icon (or text) depending on the current hour.

Details:

  • Added the icons parameter in the YAML configuration, allowing a dictionary mapping each hour (clock_01, clock_02, …) to a Unicode character or a custom string.
  • By default, times after 12:00 that are not explicitly defined in the icons revert to their corresponding icons in the interval clock_01 to clock_11.
  • This feature enables richer visual customization of the clock widget, for example to indicate different moods or statuses depending on the hour.
  • Documentation has been updated to explain how to use and configure this new option.
  • No impact on existing widget functionality.

Thank you for your review and feedback!

@amnweb
Copy link
Owner

amnweb commented Jul 15, 2025

That's a great idea, and we can expand on it by adding an extra class for the clock based on the hour. For example

.clock-widget .icon.clock_23 {}
.clock-widget .label.clock_23 {}

so I can get a red clock at 23h :p

@Isotech42
Copy link
Contributor Author

It's actually a good idea that I hadn't even thought of. Now it's done! =D

@amnweb
Copy link
Owner

amnweb commented Jul 16, 2025

Cool thanks, can you clean up the commit history a bit before the merge? To make this more readable in the git log.

@Isotech42
Copy link
Contributor Author

Oc ! I've squashed the commits into a single one for better readability. Let me know if there's anything else to adjust!

@amnweb
Copy link
Owner

amnweb commented Jul 17, 2025

Thanks, looks good to me, but... I just thought, since this widget updates every 1 second, we can slightly optimize it. The idea is: what if we set self.current_hour = None inside __init__ and in the _update_label we have
current_hour = f'{now.hour:02d}'
Then, before doing any processing inside update_label we can compare

if self.current_hour != current_hour:
   self.current_hour = current_hour
   ...

and continue with reloading the CSS and changing icons.

I know this isn’t a big issue, the process is fast anyway, but if we can optimize it without much effort, why not do it?

- Add support for per-hour Unicode icons via `{icon}` placeholder
- Icons loaded from `clock_HH` in the config (00–23); hours 13–23 fallback to 01–12 if not defined
- Add dynamic CSS classes `.clock_HH` on icon and label to allow time-based theming (e.g. a red clock at 23h)
- Add `self.current_hour` check to prevent redundant updates when the hour remains the same, optimizing performance
- Reload QLabel styles at runtime to apply updated classes
- Update documentation with configuration and CSS usage examples
@Isotech42
Copy link
Contributor Author

Thanks for the suggestion! Don't worry, you're absolutely right, it's better to optimize what you can, especially if it's for like 3-4 lines of code.
I've just implemented it in the latest commit.
Now the ClockWidget skips icon and CSS updates when the time hasn't changed, which should avoid unnecessary QLabel refreshes during updates per second.

Let me know if there's anything else you'd like me to tweak or optimize, but I think this is good!

@amnweb
Copy link
Owner

amnweb commented Jul 21, 2025

Looks good, thanks. There were some users who used two clock widgets on the same bar, one for time and another one just for date and calendar. And when you have it on 2 screens, this actually results in 4 updates per second. That's why I was thinking it would be better to have a simple check before processing any label update.

@amnweb amnweb merged commit 3abebb5 into amnweb:main Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants