✨ feat(dashboard): make Bluetooth and Network tiles toggleable via content area click
This commit is contained in:
3 files changed
+45
-1
No files matched your search
@@ -104,6 +104,9 @@ class Bluetooth(Tile):
|
|||||||
# Initialize state
|
# Initialize state
|
||||||
self._update_tile_state()
|
self._update_tile_state()
|
||||||
|
|
||||||
|
# Override the type_box button behavior to toggle Bluetooth
|
||||||
|
self._setup_content_button()
|
||||||
|
|
||||||
def _update_tile_state(self):
|
def _update_tile_state(self):
|
||||||
"""Update tile visual state based on Bluetooth status."""
|
"""Update tile visual state based on Bluetooth status."""
|
||||||
self.state = self.bluetooth_client.enabled
|
self.state = self.bluetooth_client.enabled
|
||||||
@@ -119,6 +122,19 @@ class Bluetooth(Tile):
|
|||||||
# Update tile icon based on Bluetooth state
|
# Update tile icon based on Bluetooth state
|
||||||
self._update_tile_icon()
|
self._update_tile_icon()
|
||||||
|
|
||||||
|
def _setup_content_button(self):
|
||||||
|
"""Setup the content button to toggle Bluetooth instead of showing menu."""
|
||||||
|
if hasattr(self, 'type_box'):
|
||||||
|
# Disconnect the existing click handler
|
||||||
|
self.type_box.disconnect_by_func(self.handle_click)
|
||||||
|
# Connect to Bluetooth toggle handler
|
||||||
|
self.type_box.connect("clicked", self._on_bluetooth_toggle)
|
||||||
|
|
||||||
|
def _on_bluetooth_toggle(self, *_):
|
||||||
|
"""Handle Bluetooth toggle when clicking on the main content area."""
|
||||||
|
# Toggle Bluetooth state
|
||||||
|
self.bluetooth_client.enabled = not self.bluetooth_client.enabled
|
||||||
|
|
||||||
def _update_tile_icon(self):
|
def _update_tile_icon(self):
|
||||||
"""Update the tile icon based on Bluetooth status and connected devices."""
|
"""Update the tile icon based on Bluetooth status and connected devices."""
|
||||||
if not self.bluetooth_client.enabled:
|
if not self.bluetooth_client.enabled:
|
||||||
|
|||||||
@@ -106,6 +106,9 @@ class Network(Tile):
|
|||||||
if self.network_client.wifi_device:
|
if self.network_client.wifi_device:
|
||||||
self._setup_wifi_device()
|
self._setup_wifi_device()
|
||||||
|
|
||||||
|
# Override the type_box button behavior to toggle WiFi
|
||||||
|
self._setup_content_button()
|
||||||
|
|
||||||
def handle_connection_change(self, *_):
|
def handle_connection_change(self, *_):
|
||||||
"""Handle network connection state changes."""
|
"""Handle network connection state changes."""
|
||||||
self._update_tile_state()
|
self._update_tile_state()
|
||||||
@@ -213,6 +216,20 @@ class Network(Tile):
|
|||||||
self._stop_animation()
|
self._stop_animation()
|
||||||
self.icon.set_markup(icons.wifi_off)
|
self.icon.set_markup(icons.wifi_off)
|
||||||
|
|
||||||
|
def _setup_content_button(self):
|
||||||
|
"""Setup the content button to toggle WiFi instead of showing menu."""
|
||||||
|
if hasattr(self, 'type_box'):
|
||||||
|
# Disconnect the existing click handler
|
||||||
|
self.type_box.disconnect_by_func(self.handle_click)
|
||||||
|
# Connect to WiFi toggle handler
|
||||||
|
self.type_box.connect("clicked", self._on_wifi_toggle)
|
||||||
|
|
||||||
|
def _on_wifi_toggle(self, *_):
|
||||||
|
"""Handle WiFi toggle when clicking on the main content area."""
|
||||||
|
wifi = self.network_client.wifi_device
|
||||||
|
if wifi:
|
||||||
|
# Toggle WiFi state
|
||||||
|
wifi.wireless_enabled = not wifi.wireless_enabled
|
||||||
|
|
||||||
def create_content(self):
|
def create_content(self):
|
||||||
"""Create the detailed network content for the dashboard."""
|
"""Create the detailed network content for the dashboard."""
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class Tile(Box):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Container for label and properties
|
# Container for label and properties
|
||||||
self.type_box = Box(
|
content_box = Box(
|
||||||
style_classes="tile-type",
|
style_classes="tile-type",
|
||||||
orientation="v",
|
orientation="v",
|
||||||
v_expand=True,
|
v_expand=True,
|
||||||
@@ -94,6 +94,17 @@ class Tile(Box):
|
|||||||
children=[self.tile_label, self.props],
|
children=[self.tile_label, self.props],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Make the type_box clickable using a button
|
||||||
|
self.type_box = Button(
|
||||||
|
style_classes="tile-content-button",
|
||||||
|
h_expand=True,
|
||||||
|
v_expand=True,
|
||||||
|
child=content_box,
|
||||||
|
on_clicked=self.handle_click,
|
||||||
|
)
|
||||||
|
# Add hover cursor to the content area
|
||||||
|
add_hover_cursor(self.type_box)
|
||||||
|
|
||||||
def _create_tile_layout(self, has_menu: bool):
|
def _create_tile_layout(self, has_menu: bool):
|
||||||
"""Create the tile's layout structure."""
|
"""Create the tile's layout structure."""
|
||||||
# Create menu button if needed
|
# Create menu button if needed
|
||||||
|
|||||||
Reference in new issue
Block a user