@ -38,6 +38,7 @@ class Hui(wx.Frame):
super ( ) . __init__ ( * args , * * kw )
self . m_on_icon : str = ' ☼ '
self . m_off_icon : str = ' ☾ '
self . m_unreachable_icon : str = ' ⚠ '
self . m_tinge : Tinge = Tinge ( )
self . m_bridges : list [ HueBridge ] = self . m_tinge . get_bridges ( )
self . cur_bridge : Union [ None , HueBridge ] = None
@ -114,6 +115,8 @@ class Hui(wx.Frame):
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 ,
@ -145,6 +148,8 @@ class Hui(wx.Frame):
icon : str = self . m_off_icon
if 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 )
self . sizer . Add ( toggle_btn , 0 , wx . EXPAND )
self . Bind ( wx . EVT_BUTTON ,
@ -187,6 +192,30 @@ class Hui(wx.Frame):
self . sizer . Add ( e_slider , 0 , wx . EXPAND )
self . Bind ( wx . EVT_SCROLL ,
lambda event : self . set_saturation ( event , light . get_id ( ) ) , e_slider )
rename_btn : wx . Button = wx . Button ( self . pnl , label = " Rename " )
self . sizer . Add ( rename_btn , 0 , wx . EXPAND )
self . Bind ( wx . EVT_BUTTON ,
lambda event , mlightid = lightid : self . rename_light_and_goto_light ( mlightid ) ,
rename_btn )
delete_btn : wx . Button = wx . Button ( self . pnl , label = " Delete " )
self . sizer . Add ( delete_btn , 0 , wx . EXPAND )
self . Bind ( wx . EVT_BUTTON ,
lambda event , mlightid = lightid : self . delete_light_and_goto_group ( mlightid ) ,
delete_btn )
def delete_light_and_goto_group ( self , lightid ) :
""" Combo call back for delete and goto group
Args :
lightid ( int ) : The light id of the light to delete
"""
if self . get_ok_cancel_answer_from_modal ( " Are you sure you want to delete this light? " ) :
light : HueLight = self . cur_bridge . get_light_by_id ( lightid )
light . delete ( )
self . cur_bridge . remove_light ( light )
self . add_lights ( self . cur_group . get_lights ( ) )
else :
self . add_single_light ( lightid )
def discover_new_bridges ( self ) :
""" Call back for button that is displayed if no bridges were found
@ -194,6 +223,34 @@ class Hui(wx.Frame):
self . m_tinge . discover_new_bridges ( )
self . add_bridges ( )
def get_ok_cancel_answer_from_modal ( self , message : str ) - > bool :
""" Display a message dialog and return ok or cancel
Args :
message ( str ) : The message to display
Returns :
bool : The response from the user
"""
with wx . MessageDialog ( self . pnl , message , style = wx . OK | wx . CANCEL | wx . CANCEL_DEFAULT ) as dlg :
return dlg . ShowModal ( ) == wx . ID_OK
def get_text_answer_from_modal ( self , message : str , cap : str , val : str = " " ) - > str :
""" Display a text entry and return the content
Args :
message ( str ) : The message to display
cap ( str ) : The caption to display
val ( str , optional ) : The default value to display , defaults to the empty string
Returns :
str : The response from the user
"""
with wx . TextEntryDialog ( self . pnl , message , caption = cap , value = val ) as dlg :
dlg . ShowModal ( )
answer : str = dlg . GetValue ( )
return answer
def goto_bridge ( self , bridge : HueBridge ) :
""" Call back for a bridge button
@ -217,6 +274,17 @@ class Hui(wx.Frame):
self . cur_group = group
self . add_lights ( group . get_lights ( ) )
def rename_light_and_goto_light ( self , lightid ) :
""" Combo call back to rename a light and display that light again
Args :
lightid ( [ type ] ) : The light id of the light to rename / display
"""
newname : str = self . get_text_answer_from_modal ( " Set new name " , " New name: " )
if newname :
self . cur_bridge . get_light_by_id ( lightid ) . rename ( newname )
self . add_single_light ( lightid )
def set_brightness ( self , event : wx . ScrollEvent , lightid : int ) :
""" Call back for brightness slider
@ -283,7 +351,7 @@ class Hui(wx.Frame):
""" Combo call back for toggle and goto group
Args :
lightid ( int ) : The light id o o f the light to toggle
lightid ( int ) : The light id o f the light to toggle
lights ( list [ HueLight ] ) : The lights to display after toggle
"""
self . cur_bridge . get_light_by_id ( lightid ) . toggle ( )