From ddacdea3eb5db75f44b64bd3e5baaf0b1e40a60b Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Tue, 14 Jul 2026 23:26:21 +0545 Subject: [PATCH] refactor(src/window/controlcenter): replace svg_file imports with Image and simplify battery icon handling --- src/window/controlcenter/bluetooth.py | 42 +++++++++++++++------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/window/controlcenter/bluetooth.py b/src/window/controlcenter/bluetooth.py index d3f2bb0..2b7735d 100644 --- a/src/window/controlcenter/bluetooth.py +++ b/src/window/controlcenter/bluetooth.py @@ -12,7 +12,6 @@ from services.bluetooth import BluetoothClient, BluetoothDevice from shared.widgets.smooth_switch import SmoothSwitch from shared.window.animated_scrollwindow import AnimatedScrollable from utils.functions import spawn_detached -from utils.gtk_utils import svg_file def get_battery_icon_file( @@ -35,6 +34,17 @@ def get_battery_icon_file( return f"battery/{filename}" +def get_battery_theme_icon(percentage: float, charging: bool = False) -> str: + level = round(percentage / 10.0) * 10 + if level <= 0: + return ( + "battery-empty-charging-symbolic" if charging else "battery-empty-symbolic" + ) + if level >= 100: + return "battery-full-charged-symbolic" if charging else "battery-full-symbolic" + return f"battery-level-{level:02d}{'-charging' if charging else ''}-symbolic" + + def set_bluetooth_enabled_with_fallback(client, enabled: bool): if enabled: command = "rfkill unblock bluetooth" @@ -85,14 +95,14 @@ class BluetoothDeviceSlot(Box): self.dimage = Image( icon_name=self._get_icon_for_device(self.device), - size=5, + pixel_size=20, name="device-icon", style_classes=" ".join(self.styles), ) self.status_icon = Image( icon_name="process-working-symbolic", - size=5, + pixel_size=16, name="device-icon", ) self.status_icon.set_visible(False) @@ -100,12 +110,9 @@ class BluetoothDeviceSlot(Box): self.battery_icon = None self.battery_label = None if hasattr(device, "battery_percentage") and device.battery_percentage > 0: - self.battery_icon = svg_file( - get_battery_icon_file( - device.battery_percentage, - False, - ), - size=24, + self.battery_icon = Image( + icon_name=get_battery_theme_icon(device.battery_percentage, False), + pixel_size=16, ) self.battery_label = Label( label=f"{device.battery_percentage:.0f}%", name="battery-label" @@ -208,20 +215,17 @@ class BluetoothDeviceSlot(Box): if self.battery_icon and self.battery_label: self.battery_icon.set_visible(True) self.battery_label.set_visible(True) - self.battery_icon.dynamic_file( - get_battery_icon_file( - self.device.battery_percentage, - False, - ) + self.battery_icon.set_property( + "icon-name", + get_battery_theme_icon(self.device.battery_percentage, False), ) self.battery_label.set_label(f"{self.device.battery_percentage:.0f}%") else: - self.battery_icon = svg_file( - get_battery_icon_file( - self.device.battery_percentage, - False, + self.battery_icon = Image( + icon_name=get_battery_theme_icon( + self.device.battery_percentage, False ), - size=12, + pixel_size=16, ) self.battery_label = Label( label=f"{self.device.battery_percentage:.0f}%",