Skip to content

Commit e0f19b2

Browse files
committed
Bluetooth scanning
1 parent 9798214 commit e0f19b2

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

modules/bluetooth.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ def __init__(self, **kwargs):
7171
self.bt_menu_label = self.buttons.bluetooth_menu_label
7272

7373
self.client = BluetoothClient(on_device_added=self.on_device_added)
74+
self.scan_label = Label(name="bluetooth-scan-label", markup=icons.radar)
7475
self.scan_button = Button(
7576
name="bluetooth-scan",
76-
label="Scan",
77+
child=self.scan_label,
78+
tooltip_text="Scan for Bluetooth devices",
7779
on_clicked=lambda *_: self.client.toggle_scan()
7880
)
7981
self.back_button = Button(
@@ -85,7 +87,7 @@ def __init__(self, **kwargs):
8587
self.client.connect("notify::enabled", lambda *_: self.status_label())
8688
self.client.connect(
8789
"notify::scanning",
88-
lambda *_: self.scan_button.set_label("Stop" if self.client.scanning else "Scan")
90+
lambda *_: self.update_scan_label()
8991
)
9092

9193
self.paired_box = Box(spacing=2, orientation="vertical")
@@ -138,3 +140,13 @@ def on_device_added(self, client: BluetoothClient, address: str):
138140
if device.paired:
139141
return self.paired_box.add(slot)
140142
return self.available_box.add(slot)
143+
144+
def update_scan_label(self):
145+
if self.client.scanning:
146+
self.scan_label.add_style_class("scanning")
147+
self.scan_button.add_style_class("scanning")
148+
self.scan_button.set_tooltip_text("Stop scanning for Bluetooth devices")
149+
else:
150+
self.scan_label.remove_style_class("scanning")
151+
self.scan_button.remove_style_class("scanning")
152+
self.scan_button.set_tooltip_text("Scan for Bluetooth devices")

modules/icons.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
palette: str = ""
140140
cloud_off: str = ""
141141
loader: str = ""
142+
radar: str = ""
142143

143144
exceptions: list[str] = ['font_family', 'font_weight', 'span']
144145

styles/bluetooth.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,31 @@
6969
/*background-color: var(--surface);*/
7070
/*margin: 0 16px;*/
7171
}
72+
73+
#bluetooth-scan-label {
74+
font-size: 20px;
75+
color: var(--primary);
76+
}
77+
78+
#bluetooth-scan.scanning {
79+
animation: blink 0.5s ease infinite;
80+
}
81+
82+
#bluetooth-scan-label.scanning {
83+
animation: blink 0.5s ease infinite;
84+
}
85+
86+
@keyframes blink {
87+
0% {
88+
background-color: var(--blue);
89+
color: var(--shadow);
90+
}
91+
50% {
92+
background-color: var(--shadow);
93+
color: var(--blue);
94+
}
95+
100% {
96+
background-color: var(--blue);
97+
color: var(--shadow);
98+
}
99+
}

0 commit comments

Comments
 (0)