refactor(src/window/controlcenter): replace svg_file imports with Image and simplify battery icon handling

This commit is contained in:
sankalp committed 2026-07-14 23:26:21 +05:45
1 parent f2517ee9f3
commit ddacdea3eb
1 file changed
+23 -19
+23 -19
View File
@@ -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}%",