✨ feat(panel): add show_window option to indicators to conditionally render control centers

This commit is contained in:
sankalp committed 2025-08-09 14:55:50 +05:45
1 parent 76b241328d
commit 31a0e1dd25
1 file changed
+92 -69
+92 -69
View File
@@ -14,8 +14,9 @@ from widgets.wayland import WaylandWindow as Window
class BluetoothIndicator(Box): class BluetoothIndicator(Box):
def __init__(self, **kwargs): def __init__(self, show_window=True, **kwargs):
super().__init__(name="bluetooth-indicator", orientation="h", **kwargs) super().__init__(name="bluetooth-indicator", orientation="h", **kwargs)
self.show_window = show_window
self.bluetooth = BluetoothClient() self.bluetooth = BluetoothClient()
self.bt_icon = Svg( self.bt_icon = Svg(
@@ -32,25 +33,30 @@ class BluetoothIndicator(Box):
self.add(self.bt_button) self.add(self.bt_button)
# Create Bluetooth control center widget # Create Bluetooth control center widget only if show_window is True
self.bluetooth_window = Window( if self.show_window:
layer="overlay", self.bluetooth_window = Window(
title="modus", layer="overlay",
anchor="top right", title="modus",
margin="2px 10px 0px 0px", anchor="top right",
exclusivity="auto", margin="2px 10px 0px 0px",
keyboard_mode="on-demand", exclusivity="auto",
name="bluetooth-control-window", keyboard_mode="on-demand",
visible=False, name="bluetooth-control-window",
) visible=False,
)
self.bluetooth_widget = BluetoothConnections(self, show_back_button=False) self.bluetooth_widget = BluetoothConnections(self, show_back_button=False)
self.bluetooth_window.children = [self.bluetooth_widget] self.bluetooth_window.children = [self.bluetooth_widget]
# Create mouse capture for Bluetooth widget # Create mouse capture for Bluetooth widget
self.bluetooth_mousecapture = DropDownMouseCapture( self.bluetooth_mousecapture = DropDownMouseCapture(
layer="top", child_window=self.bluetooth_window layer="top", child_window=self.bluetooth_window
) )
else:
self.bluetooth_window = None
self.bluetooth_widget = None
self.bluetooth_mousecapture = None
modus_service.connect("bluetooth-changed", self.on_bluetooth_changed) modus_service.connect("bluetooth-changed", self.on_bluetooth_changed)
self.bluetooth.connect("changed", self.on_bluetooth_direct_changed) self.bluetooth.connect("changed", self.on_bluetooth_direct_changed)
@@ -136,20 +142,24 @@ class BluetoothIndicator(Box):
def on_bluetooth_clicked(self, *args): def on_bluetooth_clicked(self, *args):
"""Handle Bluetooth indicator click""" """Handle Bluetooth indicator click"""
self.bluetooth_mousecapture.toggle_mousecapture() if self.show_window and self.bluetooth_mousecapture:
self.bluetooth_mousecapture.toggle_mousecapture()
def close_bluetooth(self, *args): def close_bluetooth(self, *args):
"""Close Bluetooth control center""" """Close Bluetooth control center"""
self.bluetooth_mousecapture.hide_child_window() if self.show_window and self.bluetooth_mousecapture:
self.bluetooth_mousecapture.hide_child_window()
def hide_controlcenter(self, *args): def hide_controlcenter(self, *args):
"""Hide Bluetooth control center""" """Hide Bluetooth control center"""
self.bluetooth_mousecapture.hide_child_window() if self.show_window and self.bluetooth_mousecapture:
self.bluetooth_mousecapture.hide_child_window()
class NetworkIndicator(Box): class NetworkIndicator(Box):
def __init__(self, **kwargs): def __init__(self, show_window=True, **kwargs):
super().__init__(name="network-indicator", orientation="h", **kwargs) super().__init__(name="network-indicator", orientation="h", **kwargs)
self.show_window = show_window
self.network_service = NetworkClient() self.network_service = NetworkClient()
@@ -169,25 +179,30 @@ class NetworkIndicator(Box):
self.add(self.network_button) self.add(self.network_button)
# Create WiFi control center widget # Create WiFi control center widget only if show_window is True
self.wifi_window = Window( if self.show_window:
layer="overlay", self.wifi_window = Window(
title="modus", layer="overlay",
anchor="top right", title="modus",
margin="2px 10px 0px 0px", anchor="top right",
exclusivity="auto", margin="2px 10px 0px 0px",
keyboard_mode="on-demand", exclusivity="auto",
name="wifi-control-window", keyboard_mode="on-demand",
visible=False, name="wifi-control-window",
) visible=False,
)
self.wifi_widget = WifiConnections(self, show_back_button=False) self.wifi_widget = WifiConnections(self, show_back_button=False)
self.wifi_window.children = [self.wifi_widget] self.wifi_window.children = [self.wifi_widget]
# Create mouse capture for WiFi widget # Create mouse capture for WiFi widget
self.wifi_mousecapture = DropDownMouseCapture( self.wifi_mousecapture = DropDownMouseCapture(
layer="top", child_window=self.wifi_window layer="top", child_window=self.wifi_window
) )
else:
self.wifi_window = None
self.wifi_widget = None
self.wifi_mousecapture = None
modus_service.connect("wlan-changed", self.on_wlan_changed) modus_service.connect("wlan-changed", self.on_wlan_changed)
self.network_service.connect("wifi-device-added", self.on_wifi_device_added) self.network_service.connect("wifi-device-added", self.on_wifi_device_added)
@@ -300,20 +315,24 @@ class NetworkIndicator(Box):
def on_wifi_clicked(self, *args): def on_wifi_clicked(self, *args):
"""Handle WiFi indicator click""" """Handle WiFi indicator click"""
self.wifi_mousecapture.toggle_mousecapture() if self.show_window and self.wifi_mousecapture:
self.wifi_mousecapture.toggle_mousecapture()
def close_wifi(self, *args): def close_wifi(self, *args):
"""Close WiFi control center""" """Close WiFi control center"""
self.wifi_mousecapture.hide_child_window() if self.show_window and self.wifi_mousecapture:
self.wifi_mousecapture.hide_child_window()
def hide_controlcenter(self, *args): def hide_controlcenter(self, *args):
"""Hide WiFi control center""" """Hide WiFi control center"""
self.wifi_mousecapture.hide_child_window() if self.show_window and self.wifi_mousecapture:
self.wifi_mousecapture.hide_child_window()
class BatteryIndicator(Box): class BatteryIndicator(Box):
def __init__(self, **kwargs): def __init__(self, show_window=True, **kwargs):
super().__init__(name="battery-indicator", orientation="h", **kwargs) super().__init__(name="battery-indicator", orientation="h", **kwargs)
self.show_window = show_window
self.battery_service = Battery() self.battery_service = Battery()
@@ -328,30 +347,35 @@ class BatteryIndicator(Box):
self.battery_button = Button( self.battery_button = Button(
name="battery-button", name="battery-button",
child=self.battery_icon, child=self.battery_icon,
on_clicked=self.on_battery_clicked on_clicked=self.on_battery_clicked,
) )
self.add(self.battery_button) self.add(self.battery_button)
# Create Battery control center widget # Create Battery control center widget only if show_window is True
self.battery_window = Window( if self.show_window:
layer="overlay", self.battery_window = Window(
title="modus", layer="overlay",
anchor="top right", title="modus",
margin="2px 200px 0px 0px", anchor="top right",
exclusivity="auto", margin="2px 200px 0px 0px",
keyboard_mode="on-demand", exclusivity="auto",
name="battery-control-window", keyboard_mode="on-demand",
visible=False, name="battery-control-window",
) visible=False,
)
self.battery_widget = BatteryControl(self, show_back_button=False) self.battery_widget = BatteryControl(self, show_back_button=False)
self.battery_window.children = [self.battery_widget] self.battery_window.children = [self.battery_widget]
# Create mouse capture for Battery widget # Create mouse capture for Battery widget
self.battery_mousecapture = DropDownMouseCapture( self.battery_mousecapture = DropDownMouseCapture(
layer="top", child_window=self.battery_window layer="top", child_window=self.battery_window
) )
else:
self.battery_window = None
self.battery_widget = None
self.battery_mousecapture = None
modus_service.connect("battery-changed", self.on_battery_changed) modus_service.connect("battery-changed", self.on_battery_changed)
self.battery_service.connect("changed", self.on_battery_direct_changed) self.battery_service.connect("changed", self.on_battery_direct_changed)
@@ -386,8 +410,6 @@ class BatteryIndicator(Box):
modus_service.battery = battery_state modus_service.battery = battery_state
def get_battery_tooltip(self, percentage, state): def get_battery_tooltip(self, percentage, state):
tooltip = f"Battery: {percentage}%" tooltip = f"Battery: {percentage}%"
@@ -415,9 +437,7 @@ class BatteryIndicator(Box):
is_charging = state in ["CHARGING", "FULLY_CHARGED"] is_charging = state in ["CHARGING", "FULLY_CHARGED"]
icon_file = Battery.get_battery_icon_file( icon_file = Battery.get_battery_icon_file(
percentage, percentage, is_charging, base_path="../../../config/assets/icons/"
is_charging,
base_path="../../../config/assets/icons/"
) )
tooltip = self.get_battery_tooltip(percentage, state) tooltip = self.get_battery_tooltip(percentage, state)
@@ -427,12 +447,15 @@ class BatteryIndicator(Box):
def on_battery_clicked(self, *args): def on_battery_clicked(self, *args):
"""Handle Battery indicator click""" """Handle Battery indicator click"""
self.battery_mousecapture.toggle_mousecapture() if self.show_window and self.battery_mousecapture:
self.battery_mousecapture.toggle_mousecapture()
def close_battery(self, *args): def close_battery(self, *args):
"""Close Battery control center""" """Close Battery control center"""
self.battery_mousecapture.hide_child_window() if self.show_window and self.battery_mousecapture:
self.battery_mousecapture.hide_child_window()
def hide_controlcenter(self, *args): def hide_controlcenter(self, *args):
"""Hide Battery control center""" """Hide Battery control center"""
self.battery_mousecapture.hide_child_window() if self.show_window and self.battery_mousecapture:
self.battery_mousecapture.hide_child_window()