You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tinge/main.py

58 lines
1.5 KiB

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.screenmanager import Screen, ScreenManager
from tinge import HueBridge, Tinge
class HueApp(App):
def build(self):
self.tinge = Tinge()
sm = ScreenManager()
sm.add_widget(BridgeScreen(self.tinge))
return sm
class BridgeScreen(Screen):
bridges = []
layout = BoxLayout()
def __init__(self, tinge, **kwargs):
super(BridgeScreen, self).__init__(**kwargs)
self.tinge = tinge
for bridge_button in self.get_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:
bridge_button = Button(
text='Manually add bridge',
on_press=lambda button: self.manually_add(button))
buttons.append(bridge_button)
return buttons
if __name__ == '__main__':
HueApp().run()