|
|
|
@ -15,6 +15,23 @@ class Hui(wx.Frame):
|
|
|
|
|
wx (Frame): Parent class
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def redraw(*args):
|
|
|
|
|
"""Decorator used for redrawing the widgets in the sizer
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
function: The decorated function
|
|
|
|
|
"""
|
|
|
|
|
func = args[0]
|
|
|
|
|
|
|
|
|
|
def wrapper(self, *wrapper_args):
|
|
|
|
|
"""The wrapper function for the decorator
|
|
|
|
|
"""
|
|
|
|
|
self.sizer.Clear(delete_windows=True)
|
|
|
|
|
func(self, *wrapper_args)
|
|
|
|
|
self.sizer.Layout()
|
|
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kw):
|
|
|
|
|
"""Constructor
|
|
|
|
|
"""
|
|
|
|
@ -33,23 +50,6 @@ class Hui(wx.Frame):
|
|
|
|
|
self.pnl.SetSizer(self.sizer)
|
|
|
|
|
self.add_bridges()
|
|
|
|
|
|
|
|
|
|
def redraw(*args):
|
|
|
|
|
"""Decorator used for redrawing the widgets in the sizer
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
function: The decorated function
|
|
|
|
|
"""
|
|
|
|
|
func = args[0]
|
|
|
|
|
|
|
|
|
|
def wrapper(self, *wrapper_args):
|
|
|
|
|
"""The wrapper function for the decorator
|
|
|
|
|
"""
|
|
|
|
|
self.sizer.Clear(delete_windows=True)
|
|
|
|
|
func(self, *wrapper_args)
|
|
|
|
|
self.sizer.Layout()
|
|
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
@redraw
|
|
|
|
|
def add_bridges(self):
|
|
|
|
|
"""Add bridges to sizer, the entry point of the program
|
|
|
|
@ -123,59 +123,11 @@ class Hui(wx.Frame):
|
|
|
|
|
light_btn: wx.Button = wx.Button(self.pnl, label=label, style=wx.BU_LEFT)
|
|
|
|
|
inner_sizer.Add(light_btn, 4, wx.EXPAND)
|
|
|
|
|
self.Bind(wx.EVT_BUTTON,
|
|
|
|
|
lambda event, mlightid=lightid: self.goto_light(mlightid), light_btn)
|
|
|
|
|
lambda event, mlightid=lightid: self.add_single_light(mlightid), light_btn)
|
|
|
|
|
self.sizer.Add(inner_sizer, 0, wx.EXPAND)
|
|
|
|
|
|
|
|
|
|
def goto_bridge(self, bridge: HueBridge):
|
|
|
|
|
"""Call back for a bridge button
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
bridge (HueBridge): The bridge to display
|
|
|
|
|
"""
|
|
|
|
|
self.cur_bridge = bridge
|
|
|
|
|
groups: list[HueGroup] = bridge.get_groups()
|
|
|
|
|
if groups:
|
|
|
|
|
self.add_groups(groups)
|
|
|
|
|
else:
|
|
|
|
|
self.add_lights(bridge.get_lights())
|
|
|
|
|
|
|
|
|
|
def discover_new_bridges(self):
|
|
|
|
|
"""Call back for button that is displayed if no bridges were found
|
|
|
|
|
"""
|
|
|
|
|
self.m_tinge.discover_new_bridges()
|
|
|
|
|
self.add_bridges()
|
|
|
|
|
|
|
|
|
|
def toggle_group(self, groupid: int):
|
|
|
|
|
"""Toggle the lights of a group
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
groupid (int): The group id of the group to toggle
|
|
|
|
|
"""
|
|
|
|
|
self.cur_bridge.get_group_by_id(groupid).toggle()
|
|
|
|
|
self.add_groups(self.cur_bridge.get_groups())
|
|
|
|
|
|
|
|
|
|
def goto_group(self, groupid: int):
|
|
|
|
|
"""Call back for group button
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
groupid (int): The group id of the group to display
|
|
|
|
|
"""
|
|
|
|
|
group = self.cur_bridge.get_group_by_id(groupid)
|
|
|
|
|
self.cur_group = group
|
|
|
|
|
self.add_lights(group.get_lights())
|
|
|
|
|
|
|
|
|
|
def toggle_light_and_goto_group(self, lightid: int, lights: list[HueLight]):
|
|
|
|
|
"""Combo call back for toggle and goto group
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
lightid (int): The light id oof the light to toggle
|
|
|
|
|
lights (list[HueLight]): The lights to display after toggle
|
|
|
|
|
"""
|
|
|
|
|
self.cur_bridge.get_light_by_id(lightid).toggle()
|
|
|
|
|
self.add_lights(lights)
|
|
|
|
|
|
|
|
|
|
@redraw
|
|
|
|
|
def goto_light(self, lightid: int):
|
|
|
|
|
def add_single_light(self, lightid: int):
|
|
|
|
|
"""Call back for light button
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
@ -201,7 +153,7 @@ class Hui(wx.Frame):
|
|
|
|
|
|
|
|
|
|
# Slider for brightness
|
|
|
|
|
if is_on:
|
|
|
|
|
if light.get_brightness() > 0:
|
|
|
|
|
if light.can_set_brightness():
|
|
|
|
|
b_label: wx.StaticText = wx.StaticText(self.pnl, label="Brightness")
|
|
|
|
|
self.sizer.Add(b_label, 0, wx.EXPAND)
|
|
|
|
|
b_slider: wx.Slider = wx.Slider(self.pnl, value=light.get_state().get_brightness(), minValue=1,
|
|
|
|
@ -236,6 +188,35 @@ class Hui(wx.Frame):
|
|
|
|
|
self.Bind(wx.EVT_SCROLL,
|
|
|
|
|
lambda event: self.set_saturation(event, light.get_id()), e_slider)
|
|
|
|
|
|
|
|
|
|
def discover_new_bridges(self):
|
|
|
|
|
"""Call back for button that is displayed if no bridges were found
|
|
|
|
|
"""
|
|
|
|
|
self.m_tinge.discover_new_bridges()
|
|
|
|
|
self.add_bridges()
|
|
|
|
|
|
|
|
|
|
def goto_bridge(self, bridge: HueBridge):
|
|
|
|
|
"""Call back for a bridge button
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
bridge (HueBridge): The bridge to display
|
|
|
|
|
"""
|
|
|
|
|
self.cur_bridge = bridge
|
|
|
|
|
groups: list[HueGroup] = bridge.get_groups()
|
|
|
|
|
if groups:
|
|
|
|
|
self.add_groups(groups)
|
|
|
|
|
else:
|
|
|
|
|
self.add_lights(bridge.get_lights())
|
|
|
|
|
|
|
|
|
|
def goto_group(self, groupid: int):
|
|
|
|
|
"""Call back for group button
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
groupid (int): The group id of the group to display
|
|
|
|
|
"""
|
|
|
|
|
group = self.cur_bridge.get_group_by_id(groupid)
|
|
|
|
|
self.cur_group = group
|
|
|
|
|
self.add_lights(group.get_lights())
|
|
|
|
|
|
|
|
|
|
def set_brightness(self, event: wx.ScrollEvent, lightid: int):
|
|
|
|
|
"""Call back for brightness slider
|
|
|
|
|
|
|
|
|
@ -247,15 +228,6 @@ class Hui(wx.Frame):
|
|
|
|
|
light: HueLight = self.cur_bridge.get_light_by_id(lightid)
|
|
|
|
|
light.set_brightness(bri)
|
|
|
|
|
|
|
|
|
|
def toggle_light_and_goto_light(self, lightid):
|
|
|
|
|
"""Combo call back to toggle a light and display that light again
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
lightid ([type]): The light id of the light to toggle/display
|
|
|
|
|
"""
|
|
|
|
|
self.cur_bridge.get_light_by_id(lightid).toggle()
|
|
|
|
|
self.goto_light(lightid)
|
|
|
|
|
|
|
|
|
|
def set_colortemp(self, event, lightid):
|
|
|
|
|
"""Call back for colortemp slider
|
|
|
|
|
|
|
|
|
@ -268,7 +240,7 @@ class Hui(wx.Frame):
|
|
|
|
|
light.set_ct(ct)
|
|
|
|
|
|
|
|
|
|
def set_hue(self, event, lightid):
|
|
|
|
|
"""Call back for colortemp slider
|
|
|
|
|
"""Call back for hue slider
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
event (wx.ScrollEvent): The scroll event to react to
|
|
|
|
@ -279,15 +251,43 @@ class Hui(wx.Frame):
|
|
|
|
|
light.set_hue(hue)
|
|
|
|
|
|
|
|
|
|
def set_saturation(self, event, lightid):
|
|
|
|
|
"""Call back for colortemp slider
|
|
|
|
|
"""Call back for saturation slider
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
event (wx.ScrollEvent): The scroll event to react to
|
|
|
|
|
lightid (int): The light id of the light to adjust hue of
|
|
|
|
|
lightid (int): The light id of the light to adjust saturation of
|
|
|
|
|
"""
|
|
|
|
|
sat: int = event.GetPosition()
|
|
|
|
|
light: HueLight = self.cur_bridge.get_light_by_id(lightid)
|
|
|
|
|
light.set_hue(sat)
|
|
|
|
|
light.set_sat(sat)
|
|
|
|
|
|
|
|
|
|
def toggle_group(self, groupid: int):
|
|
|
|
|
"""Toggle the lights of a group
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
groupid (int): The group id of the group to toggle
|
|
|
|
|
"""
|
|
|
|
|
self.cur_bridge.get_group_by_id(groupid).toggle()
|
|
|
|
|
self.add_groups(self.cur_bridge.get_groups())
|
|
|
|
|
|
|
|
|
|
def toggle_light_and_goto_light(self, lightid):
|
|
|
|
|
"""Combo call back to toggle a light and display that light again
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
lightid ([type]): The light id of the light to toggle/display
|
|
|
|
|
"""
|
|
|
|
|
self.cur_bridge.get_light_by_id(lightid).toggle()
|
|
|
|
|
self.add_single_light(lightid)
|
|
|
|
|
|
|
|
|
|
def toggle_light_and_goto_group(self, lightid: int, lights: list[HueLight]):
|
|
|
|
|
"""Combo call back for toggle and goto group
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
lightid (int): The light id oof the light to toggle
|
|
|
|
|
lights (list[HueLight]): The lights to display after toggle
|
|
|
|
|
"""
|
|
|
|
|
self.cur_bridge.get_light_by_id(lightid).toggle()
|
|
|
|
|
self.add_lights(lights)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|