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.
This commit is contained in:
10 files changed
+60
-79
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import math
|
||||
from fabric.audio import Audio
|
||||
from fabric.utils import get_relative_path
|
||||
from fabric.widgets.svg import Svg
|
||||
from utils.utils import svg_file
|
||||
from fabric.widgets.scale import ScaleMark
|
||||
from .animated_scale import AnimatedScale
|
||||
from .base import BaseOSDContainer
|
||||
@@ -17,8 +16,8 @@ class AudioOSDContainer(BaseOSDContainer):
|
||||
self._connect_specific_signals()
|
||||
|
||||
def _setup_specific_components(self):
|
||||
self.osd_window_image = Svg(
|
||||
get_relative_path("../../../config/assets/icons/volume/audio-volume.svg"),
|
||||
self.osd_window_image = svg_file(
|
||||
"volume/audio-volume.svg",
|
||||
size=(100, 100),
|
||||
name="osd-image",
|
||||
h_align="center",
|
||||
@@ -87,11 +86,7 @@ class AudioOSDContainer(BaseOSDContainer):
|
||||
0 if display_volume == 0 else min(int(math.ceil(display_volume / 33)), 3)
|
||||
)
|
||||
|
||||
self.osd_window_image.set_from_file(
|
||||
get_relative_path(
|
||||
f"../../../config/assets/icons/volume/audio-volume-{level}.svg"
|
||||
)
|
||||
)
|
||||
self.osd_window_image.set_from_file(f"volume/audio-volume-{level}.svg")
|
||||
|
||||
if muted or volume == 0:
|
||||
self.scale.add_style_class("muted")
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import math
|
||||
from services.brightness import Brightness
|
||||
from fabric.utils import get_relative_path
|
||||
from fabric.widgets.svg import Svg
|
||||
from utils.utils import svg_file
|
||||
from fabric.widgets.scale import ScaleMark
|
||||
from .animated_scale import AnimatedScale
|
||||
from .base import BaseOSDContainer
|
||||
@@ -15,8 +14,8 @@ class BrightnessOSDContainer(BaseOSDContainer):
|
||||
self._connect_specific_signals()
|
||||
|
||||
def _setup_specific_components(self):
|
||||
self.osd_window_image = Svg(
|
||||
get_relative_path("../../../config/assets/icons/brightness/brightness.svg"),
|
||||
self.osd_window_image = svg_file(
|
||||
"brightness/brightness.svg",
|
||||
size=(100, 100),
|
||||
name="osd-image",
|
||||
h_align="center",
|
||||
@@ -51,11 +50,7 @@ class BrightnessOSDContainer(BaseOSDContainer):
|
||||
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(
|
||||
get_relative_path(
|
||||
f"../../../config/assets/icons/brightness/brightness-{level}.svg"
|
||||
)
|
||||
)
|
||||
self.osd_window_image.set_from_file(f"brightness/brightness-{level}.svg")
|
||||
|
||||
self.scale.animate_value(normalized)
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from fabric.widgets.label import Label
|
||||
from fabric.widgets.svg import Svg
|
||||
from fabric.utils import get_relative_path
|
||||
from utils.utils import svg_file
|
||||
from .base import BaseOSDContainer
|
||||
from services.capslock import CapsLock
|
||||
|
||||
@@ -13,8 +12,8 @@ class CapsLockOSDContainer(BaseOSDContainer):
|
||||
self._connect_specific_signals()
|
||||
|
||||
def _setup_specific_components(self):
|
||||
self.osd_image = Svg(
|
||||
get_relative_path("../../../assets/icons/misc/caps-lock.svg"),
|
||||
self.osd_image = svg_file(
|
||||
"misc/caps-lock.svg",
|
||||
size=(100, 100),
|
||||
name="osd-image",
|
||||
h_align="center",
|
||||
@@ -35,9 +34,7 @@ class CapsLockOSDContainer(BaseOSDContainer):
|
||||
|
||||
def _update_display(self, is_on: bool):
|
||||
icon_path = "caps-lock.svg" if is_on else "caps-lock-off.svg"
|
||||
self.osd_image.set_from_file(
|
||||
get_relative_path(f"../../../assets/icons/misc/{icon_path}")
|
||||
)
|
||||
self.osd_image.set_from_file(f"misc/{icon_path}")
|
||||
if is_on:
|
||||
self.add_style_class("capslock-on")
|
||||
self.remove_style_class("capslock-off")
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from fabric.widgets.label import Label
|
||||
from fabric.widgets.svg import Svg
|
||||
from fabric.utils import get_relative_path
|
||||
from utils.utils import svg_file
|
||||
from .base import BaseOSDContainer
|
||||
from services.keyboard_layout import KeyboardLayout
|
||||
|
||||
@@ -13,8 +12,8 @@ class KeyboardLayoutOSDContainer(BaseOSDContainer):
|
||||
self._connect_specific_signals()
|
||||
|
||||
def _setup_specific_components(self):
|
||||
self.osd_image = Svg(
|
||||
get_relative_path("../../../assets/icons/misc/keyboard-layout.svg"),
|
||||
self.osd_image = svg_file(
|
||||
"misc/keyboard-layout.svg",
|
||||
size=(100, 100),
|
||||
name="osd-image",
|
||||
h_align="center",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import math
|
||||
from fabric.audio import Audio
|
||||
from fabric.utils import get_relative_path
|
||||
from fabric.widgets.svg import Svg
|
||||
from utils.utils import svg_file
|
||||
from fabric.widgets.scale import ScaleMark
|
||||
from .animated_scale import AnimatedScale
|
||||
from .base import BaseOSDContainer
|
||||
@@ -17,8 +16,8 @@ class MicrophoneOSDContainer(BaseOSDContainer):
|
||||
self._connect_specific_signals()
|
||||
|
||||
def _setup_specific_components(self):
|
||||
self.osd_window_image = Svg(
|
||||
get_relative_path("../../../config/assets/icons/mic/microphone.svg"),
|
||||
self.osd_window_image = svg_file(
|
||||
"mic/microphone.svg",
|
||||
size=(100, 100),
|
||||
name="osd-image",
|
||||
h_align="center",
|
||||
@@ -87,11 +86,7 @@ class MicrophoneOSDContainer(BaseOSDContainer):
|
||||
0 if display_volume == 0 else min(int(math.ceil(display_volume / 33)), 3)
|
||||
)
|
||||
|
||||
self.osd_window_image.set_from_file(
|
||||
get_relative_path(
|
||||
f"../../../config/assets/icons/mic/microphone-{level}.svg"
|
||||
)
|
||||
)
|
||||
self.osd_window_image.set_from_file(f"mic/microphone-{level}.svg")
|
||||
|
||||
if muted or volume == 0:
|
||||
self.scale.add_style_class("muted")
|
||||
|
||||
Reference in new issue
Block a user