<s> """<STR_LIT>""" <EOL> import wx <EOL> from wx . lib . scrolledpanel import ScrolledPanel <EOL> from itertools import chain , izip_longest <EOL> from gooey . gui . util import wx_util <EOL> from gooey . gui . lang import i18n <EOL> from gooey . gui . widgets import components <EOL> PADDING = <NUM_LIT:10> <EOL> class WidgetContainer ( wx . Panel ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , parent , section_name , * args , ** kwargs ) : <EOL> wx . Panel . __init__ ( self , parent , * args , ** kwargs ) <EOL> self . section_name = section_name <EOL> self . title = None <EOL> self . widgets = [ ] <EOL> self . container = wx . BoxSizer ( wx . VERTICAL ) <EOL> self . SetSizer ( self . container ) <EOL> def layout ( self ) : <EOL> STD_LAYOUT = ( <NUM_LIT:0> , wx . LEFT | wx . RIGHT | wx . EXPAND , PADDING ) <EOL> if self . title : <EOL> self . container . Add ( wx_util . h0 ( self , self . title ) , <NUM_LIT:0> , wx . LEFT | wx . RIGHT , PADDING ) <EOL> self . container . AddSpacer ( <NUM_LIT:30> ) <EOL> if self . widgets : <EOL> self . container . Add ( wx_util . h1 ( self , self . section_name ) , <NUM_LIT:0> , wx . LEFT | wx . RIGHT , PADDING ) <EOL> self . container . AddSpacer ( <NUM_LIT:5> ) <EOL> self . container . Add ( wx_util . horizontal_rule ( self ) , * STD_LAYOUT ) <EOL> self . container . AddSpacer ( <NUM_LIT:20> ) <EOL> self . create_component_grid ( self . container , self . widgets , cols = <NUM_LIT:2> ) <EOL> self . container . AddSpacer ( <NUM_LIT:10> ) <EOL> def populate ( self , widgets ) : <EOL> for index , widget in enumerate ( widgets ) : <EOL> widget_class = getattr ( components , widget . type ) <EOL> widget_instance = widget_class ( self , widget . title , widget . help , widget . choices ) <EOL> self . widgets . append ( widget_instance ) <EOL> self . layout ( ) <EOL> def get_values ( self ) : <EOL> return [ x . get_value ( ) for x in self . widgets ] <EOL> def clear ( self ) : <EOL> self . container . Clear ( True ) <EOL> self . widgets = [ ] <EOL> def create_component_grid ( self , parent_sizer , components , cols = <NUM_LIT:2> ) : <EOL> for row in self . chunk ( components , cols ) : <EOL> hsizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> for widget in filter ( None , row ) : <EOL> hsizer . Add ( widget . panel , <NUM_LIT:1> , wx . EXPAND | wx . LEFT | wx . RIGHT , <NUM_LIT:10> ) <EOL> parent_sizer . Add ( hsizer , <NUM_LIT:0> , wx . EXPAND ) <EOL> parent_sizer . AddSpacer ( <NUM_LIT:20> ) <EOL> def chunk ( self , iterable , n , fillvalue = None ) : <EOL> "<STR_LIT>" <EOL> args = [ iter ( iterable ) ] * n <EOL> return izip_longest ( fillvalue = fillvalue , * args ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . widgets ) <EOL> class ConfigPanel ( ScrolledPanel ) : <EOL> def __init__ ( self , parent , req_cols = <NUM_LIT:1> , opt_cols = <NUM_LIT:3> , title = None , ** kwargs ) : <EOL> ScrolledPanel . __init__ ( self , parent , ** kwargs ) <EOL> self . SetupScrolling ( scroll_x = False , scrollToTop = False ) <EOL> self . SetDoubleBuffered ( True ) <EOL> self . title = title <EOL> self . _num_req_cols = req_cols <EOL> self . _num_opt_cols = opt_cols <EOL> self . required_section = WidgetContainer ( self , i18n . _ ( "<STR_LIT>" ) ) <EOL> self . optional_section = WidgetContainer ( self , i18n . _ ( "<STR_LIT>" ) ) <EOL> self . _do_layout ( ) <EOL> self . Bind ( wx . EVT_SIZE , self . OnResize ) <EOL> def _do_layout ( self ) : <EOL> STD_LAYOUT = ( <NUM_LIT:0> , wx . LEFT | wx . RIGHT | wx . EXPAND , PADDING ) <EOL> container = wx . BoxSizer ( wx . VERTICAL ) <EOL> container . AddSpacer ( <NUM_LIT:15> ) <EOL> container . Add ( self . required_section , * STD_LAYOUT ) <EOL> container . Add ( self . optional_section , * STD_LAYOUT ) <EOL> self . SetSizer ( container ) <EOL> def OnResize ( self , evt ) : <EOL> self . SetupScrolling ( scroll_x = False , scrollToTop = False ) <EOL> evt . Skip ( ) <EOL> def clear ( self ) : <EOL> self . required_section . clear ( ) <EOL> self . optional_section . clear ( ) </s>
