Files
Modus/modules/osd/components/brightness.py
T
sankalp c22ea5dfda refactor(modules): simplify SVG asset handling across modules
Enhancements:
- Add optimized night‑variant detection for weather icons using a predefined list
- Replace `Svg` usage with direct `svg_file` calls throughout the todo widget, removing redundant relative‑path logic
- Update dock and battery modules to load assets via direct paths, eliminating unnecessary `get_relative_path` calls- Introduce `WEATHER_CACHE_TIMEOUT` constant and tidy up unused imports (`WEATHER_EMOJI_MAP` removed)
- Minor formatting and structural clean‑ups that improve code readability

Bug Fixes:
- Remove dead import of `WEATHER_EMOJI_MAP` and unused constant `WEATHER_EMOJI_MAP`
- Correct syntax of `condition_em` initialization to avoid potential rendering issues

New Features:
- None.
2026-04-02 23:13:47 +05:45

60 lines
1.8 KiB
Python

import math
from services.brightness import Brightness
from utils.utils import svg_file
from fabric.widgets.scale import ScaleMark
from .animated_scale import AnimatedScale
from .base import BaseOSDContainer
class BrightnessOSDContainer(BaseOSDContainer):
def __init__(self, window, **kwargs):
super().__init__(window, **kwargs)
self.brightness_service = Brightness.get_initial()
self._setup_specific_components()
self._connect_specific_signals()
def _setup_specific_components(self):
self.osd_window_image = svg_file(
"brightness/brightness.svg",
size=(100, 100),
name="osd-image",
h_align="center",
v_align="center",
h_expand=True,
v_expand=True,
)
self.scale = AnimatedScale(
marks=(ScaleMark(value=i) for i in range(0, 101, 10)),
value=70,
min_value=0,
max_value=100,
increments=(1, 1),
orientation="h",
)
self.add(self.osd_window_image)
self.add(self.scale)
def _connect_specific_signals(self):
self.brightness_service.connect("screen", self._on_screen_brightness_changed)
def _on_screen_brightness_changed(self, _sender, value, *_args):
self.update()
def _get_normalized_brightness(self):
return (
self.brightness_service.screen_brightness
/ self.brightness_service.max_screen
) * 100
def _update_display(self):
normalized = self._get_normalized_brightness()
level = 0 if normalized == 0 else min(int(math.ceil(normalized / 33)), 3)
self.osd_window_image.set_from_file(f"brightness/brightness-{level}.svg")
self.scale.animate_value(normalized)
def update(self, *_):
self._update_display()
super().update()