Skip to content
Snippets Groups Projects
Verified Commit a4923a86 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

[WIP] Turn device list into buttons

parent e50ec570
No related branches found
No related tags found
No related merge requests found
Pipeline #76475 passed
from kivy.app import App
from kivy.logger import Logger
from kivy.properties import ObjectProperty
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from bluetooth import MynitBluetooth
class DeviceListWidget(Widget):
app = ObjectProperty()
device_buttons = None
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._devices_buttons_map = {}
def update_device_buttons(self, devices):
Logger.debug("Updating device buttons")
self._devices_buttons_map = devices
self.device_buttons.clear_widgets()
for label, device in self._devices_buttons_map.items():
Logger.debug("Adding button for %s" % label)
btn = Button(text=label)
self.device_buttons.add_widget(btn)
class MynitCompanionApp(App):
def __init__(self, *args, **kwargs):
......@@ -14,7 +32,8 @@ class MynitCompanionApp(App):
self._bluetooth = MynitBluetooth(self)
def update_device_list(self, devices):
pass
self.widget.update_device_buttons({device.getAddress(): device for device in devices})
def build(self):
return DeviceListWidget(app=self)
self.widget = DeviceListWidget()
return self.widget
......@@ -20,11 +20,12 @@ class MynitBluetooth(BluetoothDispatcher):
self._characteristics = None, None
Logger.info("Starting BLE scanning")
self.start_scan(filters=[ServiceUUIDFilter(_UART_SERVICE_UUID)])
# self.start_scan(filters=[ServiceUUIDFilter(_UART_SERVICE_UUID)])
self.start_scan()
def on_device(self, device, rssi, advertisement):
Logger.debug("BLE device discovered: %s" % device.getAddress())
self.stop_scan()
if device not in self._available_devices:
Logger.info("New BLE device discovered: %s" % device.getAddress())
self._available_devices.add(device)
......
#:kivy 1.0.9
<DeviceListWidget>:
cols: 1
device_buttons: device_buttons
BoxLayout:
Label:
text: "Device List"
BoxLayout:
id: device_buttons
Label:
text: str(root.app._bluetooth._available_devices)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment