kivy
Micke Nordin 1 year ago
parent 25a2d75ae3
commit 9d3856f91b

@ -1,13 +1,15 @@
from logging import disable
import kivy import kivy
kivy.require('2.2.1') kivy.require('2.2.1')
from kivy.app import App from kivy.app import App
from kivy.uix.boxlayout import BoxLayout from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button from kivy.uix.button import Button, ColorProperty
from kivy.uix.label import Label
from kivy.uix.screenmanager import Screen, ScreenManager from kivy.uix.screenmanager import Screen, ScreenManager
from tinge import HueBridge, Tinge from src.tinge import HueBridge, Tinge
class HueApp(App): class HueApp(App):
@ -27,29 +29,35 @@ class BridgeScreen(Screen):
def __init__(self, tinge, **kwargs): def __init__(self, tinge, **kwargs):
super(BridgeScreen, self).__init__(**kwargs) super(BridgeScreen, self).__init__(**kwargs)
self.tinge = tinge self.tinge = tinge
for bridge_button in self.get_bridge_buttons(): for bridge_button in self.set_bridge_buttons():
self.layout.add_widget(bridge_button) self.layout.add_widget(bridge_button)
def press_button(self, bridge, button): def press_button(self, bridge, button):
print(bridge.get_ipaddress()) print(bridge.get_ipaddress())
def manually_add(self, button): def manually_add(self, button):
print('hello')
def get_bridge_buttons(self):
bridges = self.tinge.discover_new_bridges() bridges = self.tinge.discover_new_bridges()
buttons = []
if bridges: if bridges:
for bridge in bridges:
if not bridge in self.tinge.get_bridges():
self.tinge.append_bridge(bridge)
def set_bridge_buttons(self):
buttons = []
bridges = self.tinge.get_bridges()
for bridge in bridges: for bridge in bridges:
bridge_button = Button( bridge_button = Button(
text=str(bridge.get_ipaddress()), text=str(bridge.get_ipaddress()),
size_hint=(1, 0.1),
on_press=lambda button: self.press_button(bridge, button)) on_press=lambda button: self.press_button(bridge, button))
buttons.append(bridge_button) buttons.append(bridge_button)
else:
bridge_button = Button( bridge_button = Button(
text='Manually add bridge', text='Discover Bridges',
size_hint=(1, 0.1),
on_press=lambda button: self.manually_add(button)) on_press=lambda button: self.manually_add(button))
buttons.append(bridge_button) buttons.append(bridge_button)
sizer = Label(disabled = True)
buttons.append(sizer)
return buttons return buttons

@ -48,6 +48,7 @@ class Tinge:
""" """
upnp: UPnP = UPnP() upnp: UPnP = UPnP()
discovered_devices = list() discovered_devices = list()
print("Discovering new bridges")
try: try:
discovered_devices = upnp.discover() discovered_devices = upnp.discover()
except http.client.BadStatusLine: except http.client.BadStatusLine:

Loading…
Cancel
Save