<s> from atom . api import Int , observe <EOL> from enaml . layout . constrainable import ConstraintMember <EOL> from enaml . layout . layout_helpers import align , vertical , horizontal , spacer <EOL> from enaml . core . declarative import d_ <EOL> from . container import Container <EOL> class Form ( Container ) : <EOL> """<STR_LIT>""" <EOL> midline = ConstraintMember ( ) <EOL> row_spacing = d_ ( Int ( <NUM_LIT:10> ) ) <EOL> column_spacing = d_ ( Int ( <NUM_LIT:10> ) ) <EOL> @ observe ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _layout_invalidated ( self , change ) : <EOL> """<STR_LIT>""" <EOL> super ( Form , self ) . _layout_invalidated ( change ) <EOL> def layout_constraints ( self ) : <EOL> """<STR_LIT>""" <EOL> children = self . visible_widgets ( ) <EOL> labels = children [ : : <NUM_LIT:2> ] <EOL> widgets = children [ <NUM_LIT:1> : : <NUM_LIT:2> ] <EOL> n_labels = len ( labels ) <EOL> n_widgets = len ( widgets ) <EOL> if n_labels != n_widgets : <EOL> if n_labels > n_widgets : <EOL> odd_child = labels . pop ( ) <EOL> else : <EOL> odd_child = widgets . pop ( ) <EOL> else : <EOL> odd_child = None <EOL> b_flx = spacer ( <NUM_LIT:0> ) . flex ( ) <EOL> c_flx = spacer ( max ( <NUM_LIT:0> , self . column_spacing ) ) . flex ( ) <EOL> r_flx = spacer ( max ( <NUM_LIT:0> , self . row_spacing ) ) . flex ( ) <EOL> midline = self . midline <EOL> top = self . contents_top <EOL> left = self . contents_left <EOL> right = self . contents_right <EOL> constraints = self . constraints [ : ] <EOL> column1 = [ top , b_flx ] <EOL> column2 = [ top , b_flx ] <EOL> push = constraints . append <EOL> push_col1 = column1 . append <EOL> push_col2 = column2 . append <EOL> for label , widget in zip ( labels , widgets ) : <EOL> push ( ( widget . left == midline ) | '<STR_LIT>' ) <EOL> push ( align ( '<STR_LIT>' , label , widget ) | '<STR_LIT>' ) <EOL> push ( horizontal ( left , b_flx , label , c_flx , widget , b_flx , right ) ) <EOL> push_col1 ( label ) <EOL> push_col1 ( r_flx ) <EOL> push_col2 ( widget ) <EOL> push_col2 ( r_flx ) <EOL> if odd_child is not None : <EOL> push_col1 ( odd_child ) <EOL> push_col2 ( odd_child ) <EOL> push ( horizontal ( left , b_flx , odd_child , b_flx , right ) ) <EOL> else : <EOL> column1 . pop ( ) <EOL> column2 . pop ( ) <EOL> bottom = self . contents_bottom <EOL> push_col1 ( b_flx ) <EOL> push_col1 ( bottom ) <EOL> push_col2 ( b_flx ) <EOL> push_col2 ( bottom ) <EOL> push ( vertical ( * column1 ) ) <EOL> push ( vertical ( * column2 ) ) <EOL> return constraints </s>
