<s> """<STR_LIT>""" <EOL> import sys <EOL> import urwid <EOL> class LogWidget ( urwid . ListBox ) : <EOL> _selectable = False <EOL> def __init__ ( self ) : <EOL> super ( ) . __init__ ( urwid . SimpleListWalker ( [ ] ) ) <EOL> def add_log_line ( self , line ) : <EOL> text = urwid . Text ( ( '<STR_LIT>' , line ) ) <EOL> self . body . append ( text ) <EOL> self . focus_position = len ( self . body ) - <NUM_LIT:1> <EOL> class ToggleableOverlay ( urwid . Overlay ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , bottom_w ) : <EOL> super ( ) . __init__ ( <EOL> None , bottom_w , <EOL> align = '<STR_LIT>' , valign = '<STR_LIT>' , height = '<STR_LIT>' , width = '<STR_LIT>' , <EOL> ) <EOL> def selectable ( self ) : <EOL> return self . focus . selectable ( ) <EOL> def keypress ( self , size , key ) : <EOL> if self . top_w : <EOL> return super ( ) . keypress ( size , key ) <EOL> else : <EOL> return self . bottom_w . keypress ( size , key ) <EOL> @ property <EOL> def focus ( self ) : <EOL> if self . top_w : <EOL> return self . top_w <EOL> else : <EOL> return self . bottom_w <EOL> @ property <EOL> def focus_position ( self ) : <EOL> if self . top_w : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return <NUM_LIT:0> <EOL> @ focus_position . setter <EOL> def focus_position ( self , position ) : <EOL> if position == <NUM_LIT:0> : <EOL> self . top_w = None <EOL> else : <EOL> super ( ) . focus_position = position <EOL> def render ( self , size , focus = False ) : <EOL> if self . top_w : <EOL> return super ( ) . render ( size , focus ) <EOL> else : <EOL> return self . bottom_w . render ( size , focus ) <EOL> def _close_handler ( self , widget , * args ) : <EOL> urwid . disconnect_signal ( widget , '<STR_LIT>' , self . _close_handler ) <EOL> if self . _onclose : <EOL> self . _onclose ( * args ) <EOL> self . change_overlay ( None ) <EOL> _onclose = None <EOL> def change_overlay ( self , widget , onclose = None , ** kwargs ) : <EOL> self . _onclose = onclose <EOL> if widget : <EOL> urwid . disconnect_signal ( widget , '<STR_LIT>' , self . _close_handler ) <EOL> urwid . connect_signal ( widget , '<STR_LIT>' , self . _close_handler ) <EOL> if '<STR_LIT>' in widget . sizing ( ) : <EOL> defaults = dict ( <EOL> align = '<STR_LIT>' , <EOL> valign = '<STR_LIT>' , <EOL> width = ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> height = ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ) <EOL> else : <EOL> defaults = dict ( <EOL> align = '<STR_LIT:left>' , <EOL> valign = '<STR_LIT>' , <EOL> width = ( '<STR_LIT>' , <NUM_LIT:100> ) , <EOL> height = '<STR_LIT>' , <EOL> ) <EOL> defaults . update ( kwargs ) <EOL> self . set_overlay_parameters ( ** defaults ) <EOL> self . top_w = widget <EOL> self . _invalidate ( ) </s>
