@ -88,9 +88,15 @@ class Hui(wx.Frame):
"""
"""
self . SetTitle ( " Tinge - {} " . format ( self . cur_bridge . m_name ) )
self . SetTitle ( " Tinge - {} " . format ( self . cur_bridge . m_name ) )
bridge_btn : wx . Button = wx . Button ( self . pnl , label = " All Bridges " )
bridge_btn : wx . Button = wx . Button ( self . pnl , label = " All Bridges " )
group_label : wx . StaticText = wx . StaticText ( self . pnl , label = " ⚯ Groups ⚯ " , style = wx . ALIGN_CENTER )
unattached_label : wx . StaticText = wx . StaticText ( self . pnl , label = " ⚬ Unattached lights ⚬ " , style = wx . ALIGN_CENTER )
has_unattached : bool = len ( self . cur_bridge . unattached_lights ) > 0
self . sizer . Add ( bridge_btn , 0 , wx . EXPAND )
self . sizer . Add ( bridge_btn , 0 , wx . EXPAND )
self . Bind ( wx . EVT_BUTTON ,
self . Bind ( wx . EVT_BUTTON ,
lambda event : self . add_bridges ( ) , bridge_btn )
lambda event : self . add_bridges ( ) , bridge_btn )
if has_unattached :
self . sizer . Add ( group_label , 0 , wx . EXPAND )
for group in groups :
for group in groups :
inner_sizer : wx . BoxSizer = wx . BoxSizer ( orient = wx . HORIZONTAL )
inner_sizer : wx . BoxSizer = wx . BoxSizer ( orient = wx . HORIZONTAL )
groupid : int = group . get_id ( )
groupid : int = group . get_id ( )
@ -101,12 +107,33 @@ class Hui(wx.Frame):
inner_sizer . Add ( toggle_btn , 1 , wx . EXPAND )
inner_sizer . Add ( toggle_btn , 1 , wx . EXPAND )
self . Bind ( wx . EVT_BUTTON ,
self . Bind ( wx . EVT_BUTTON ,
lambda event , mgroupid = groupid : self . toggle_group ( mgroupid ) , toggle_btn )
lambda event , mgroupid = groupid : self . toggle_group ( mgroupid ) , toggle_btn )
label : str = str ( group )
label : str = " {} " . format ( str ( group ) )
group_btn : wx . Button = wx . Button ( self . pnl , label = label , style = wx . BU_LEFT )
group_btn : wx . Button = wx . Button ( self . pnl , label = label , style = wx . BU_LEFT )
inner_sizer . Add ( group_btn , 4 , wx . EXPAND )
inner_sizer . Add ( group_btn , 4 , wx . EXPAND )
self . Bind ( wx . EVT_BUTTON ,
self . Bind ( wx . EVT_BUTTON ,
lambda event , mgroupid = groupid : self . goto_group ( mgroupid ) , group_btn )
lambda event , mgroupid = groupid : self . goto_group ( mgroupid ) , group_btn )
self . sizer . Add ( inner_sizer , 0 , wx . EXPAND )
self . sizer . Add ( inner_sizer , 0 , wx . EXPAND )
if has_unattached :
self . sizer . Add ( unattached_label , 0 , wx . EXPAND )
for light in self . cur_bridge . unattached_lights :
inner_sizer = wx . BoxSizer ( orient = wx . HORIZONTAL )
lightid : int = light . get_id ( )
icon : str = self . m_off_icon
if light . is_on ( ) :
icon = self . m_on_icon
elif not light . is_reachable ( ) :
icon = self . m_unreachable_icon
toggle_btn : wx . Button = wx . Button ( self . pnl , label = icon )
inner_sizer . Add ( toggle_btn , 1 , wx . EXPAND )
self . Bind ( wx . EVT_BUTTON ,
lambda event , mlightid = lightid : self . toggle_light_and_goto_group ( mlightid , lights ) ,
toggle_btn )
label : str = " {} " . format ( light )
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 . add_single_light ( mlightid , True ) , light_btn )
self . sizer . Add ( inner_sizer , 0 , wx . EXPAND )
def add_manual_discovery_dialog ( self ) - > bool :
def add_manual_discovery_dialog ( self ) - > bool :
self . sizer . Clear ( delete_windows = True )
self . sizer . Clear ( delete_windows = True )
@ -164,20 +191,27 @@ class Hui(wx.Frame):
self . sizer . Add ( inner_sizer , 0 , wx . EXPAND )
self . sizer . Add ( inner_sizer , 0 , wx . EXPAND )
@redraw
@redraw
def add_single_light ( self , lightid : int ):
def add_single_light ( self , lightid : int , unattached : bool = False ):
""" Call back for light button
""" Call back for light button
Args :
Args :
lightid ( int ) : The light id of the light to display
lightid ( int ) : The light id of the light to display
unattached ( bool , optional ) : Is the light unattached to any group ?
"""
"""
light : HueLight = self . cur_bridge . get_light_by_id ( lightid )
light : HueLight = self . cur_bridge . get_light_by_id ( lightid )
self . SetTitle ( " Tinge - {} " . format ( light ) )
self . SetTitle ( " Tinge - {} " . format ( light ) )
is_on : bool = light . is_on ( )
is_on : bool = light . is_on ( )
group : HueGroup = self . cur_group
if unattached :
group_btn : wx . Button = wx . Button ( self . pnl , label = str ( group ) )
group_btn : wx . Button = wx . Button ( self . pnl , label = str ( self . cur_bridge ) )
self . sizer . Add ( group_btn , 0 , wx . EXPAND )
self . sizer . Add ( group_btn , 0 , wx . EXPAND )
self . Bind ( wx . EVT_BUTTON ,
self . Bind ( wx . EVT_BUTTON ,
lambda event : self . goto_group ( self . cur_group . get_id ( ) ) , group_btn )
lambda event : self . add_groups ( self . cur_bridge . get_groups ( ) ) , group_btn )
else :
group : HueGroup = self . cur_group
group_btn : wx . Button = wx . Button ( self . pnl , label = str ( group ) )
self . sizer . Add ( group_btn , 0 , wx . EXPAND )
self . Bind ( wx . EVT_BUTTON ,
lambda event : self . goto_group ( self . cur_group . get_id ( ) ) , group_btn )
# Toggle
# Toggle
icon : str = self . m_off_icon
icon : str = self . m_off_icon
if is_on :
if is_on :
@ -229,7 +263,7 @@ class Hui(wx.Frame):
rename_btn : wx . Button = wx . Button ( self . pnl , label = " Rename " )
rename_btn : wx . Button = wx . Button ( self . pnl , label = " Rename " )
self . sizer . Add ( rename_btn , 0 , wx . EXPAND )
self . sizer . Add ( rename_btn , 0 , wx . EXPAND )
self . Bind ( wx . EVT_BUTTON ,
self . Bind ( wx . EVT_BUTTON ,
lambda event , mlightid = lightid : self . rename_light_and_goto_light ( mlightid ),
lambda event , mlightid = lightid : self . rename_light_and_goto_light ( mlightid , unattached ),
rename_btn )
rename_btn )
delete_btn : wx . Button = wx . Button ( self . pnl , label = " Delete " )
delete_btn : wx . Button = wx . Button ( self . pnl , label = " Delete " )
self . sizer . Add ( delete_btn , 0 , wx . EXPAND )
self . sizer . Add ( delete_btn , 0 , wx . EXPAND )
@ -324,7 +358,7 @@ class Hui(wx.Frame):
self . cur_group = group
self . cur_group = group
self . add_lights ( group . get_lights ( ) )
self . add_lights ( group . get_lights ( ) )
def rename_light_and_goto_light ( self , lightid ):
def rename_light_and_goto_light ( self , lightid , unattached : bool = False ):
""" Combo call back to rename a light and display that light again
""" Combo call back to rename a light and display that light again
Args :
Args :
@ -333,7 +367,7 @@ class Hui(wx.Frame):
newname : str = self . get_text_answer_from_modal ( " Set new name " , " New name: " )
newname : str = self . get_text_answer_from_modal ( " Set new name " , " New name: " )
if newname :
if newname :
self . cur_bridge . get_light_by_id ( lightid ) . rename ( newname )
self . cur_bridge . get_light_by_id ( lightid ) . rename ( newname )
self . add_single_light ( lightid )
self . add_single_light ( lightid , unattached )
def set_brightness ( self , event : wx . ScrollEvent , lightid : int ) :
def set_brightness ( self , event : wx . ScrollEvent , lightid : int ) :
""" Call back for brightness slider
""" Call back for brightness slider