|
|
|
@ -1,13 +1,15 @@
|
|
|
|
|
from logging import disable
|
|
|
|
|
import kivy
|
|
|
|
|
|
|
|
|
|
kivy.require('2.2.1')
|
|
|
|
|
|
|
|
|
|
from kivy.app import App
|
|
|
|
|
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 tinge import HueBridge, Tinge
|
|
|
|
|
from src.tinge import HueBridge, Tinge
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HueApp(App):
|
|
|
|
@ -27,29 +29,35 @@ class BridgeScreen(Screen):
|
|
|
|
|
def __init__(self, tinge, **kwargs):
|
|
|
|
|
super(BridgeScreen, self).__init__(**kwargs)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
def press_button(self, bridge, button):
|
|
|
|
|
print(bridge.get_ipaddress())
|
|
|
|
|
|
|
|
|
|
def manually_add(self, button):
|
|
|
|
|
print('hello')
|
|
|
|
|
|
|
|
|
|
def get_bridge_buttons(self):
|
|
|
|
|
bridges = self.tinge.discover_new_bridges()
|
|
|
|
|
buttons = []
|
|
|
|
|
if bridges:
|
|
|
|
|
for bridge in bridges:
|
|
|
|
|
bridge_button = Button(
|
|
|
|
|
text=str(bridge.get_ipaddress()),
|
|
|
|
|
on_press=lambda button: self.press_button(bridge, button))
|
|
|
|
|
buttons.append(bridge_button)
|
|
|
|
|
else:
|
|
|
|
|
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:
|
|
|
|
|
bridge_button = Button(
|
|
|
|
|
text='Manually add bridge',
|
|
|
|
|
on_press=lambda button: self.manually_add(button))
|
|
|
|
|
text=str(bridge.get_ipaddress()),
|
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
|
on_press=lambda button: self.press_button(bridge, button))
|
|
|
|
|
buttons.append(bridge_button)
|
|
|
|
|
bridge_button = Button(
|
|
|
|
|
text='Discover Bridges',
|
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
|
on_press=lambda button: self.manually_add(button))
|
|
|
|
|
buttons.append(bridge_button)
|
|
|
|
|
sizer = Label(disabled = True)
|
|
|
|
|
buttons.append(sizer)
|
|
|
|
|
return buttons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|