<s> from atom . api import ( <EOL> DefaultValue , Enum , Typed , List , Constant , ForwardTyped , observe <EOL> ) <EOL> from casuarius import ConstraintVariable <EOL> from enaml . core . declarative import d_ <EOL> from enaml . layout . ab_constrainable import ABConstrainable <EOL> from enaml . layout . layout_helpers import expand_constraints <EOL> from . widget import Widget , ProxyWidget <EOL> PolicyEnum = Enum ( '<STR_LIT:ignore>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class ConstraintMember ( Constant ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( ) <EOL> def __init__ ( self ) : <EOL> super ( ConstraintMember , self ) . __init__ ( ) <EOL> mode = DefaultValue . MemberMethod_Object <EOL> self . set_default_value_mode ( mode , "<STR_LIT:default>" ) <EOL> def default ( self , owner ) : <EOL> """<STR_LIT>""" <EOL> return ConstraintVariable ( self . name ) <EOL> class ProxyConstraintsWidget ( ProxyWidget ) : <EOL> """<STR_LIT>""" <EOL> declaration = ForwardTyped ( lambda : ConstraintsWidget ) <EOL> def request_relayout ( self ) : <EOL> raise NotImplementedError <EOL> class ConstraintsWidget ( Widget ) : <EOL> """<STR_LIT>""" <EOL> constraints = d_ ( List ( ) ) <EOL> left = ConstraintMember ( ) <EOL> top = ConstraintMember ( ) <EOL> width = ConstraintMember ( ) <EOL> height = ConstraintMember ( ) <EOL> right = Constant ( ) <EOL> def _default_right ( self ) : <EOL> return self . left + self . width <EOL> bottom = Constant ( ) <EOL> def _default_bottom ( self ) : <EOL> return self . top + self . height <EOL> v_center = Constant ( ) <EOL> def _default_v_center ( self ) : <EOL> return self . top + self . height / <NUM_LIT> <EOL> h_center = Constant ( ) <EOL> def _default_h_center ( self ) : <EOL> return self . left + self . width / <NUM_LIT> <EOL> hug_width = d_ ( PolicyEnum ( '<STR_LIT>' ) ) <EOL> hug_height = d_ ( PolicyEnum ( '<STR_LIT>' ) ) <EOL> resist_width = d_ ( PolicyEnum ( '<STR_LIT>' ) ) <EOL> resist_height = d_ ( PolicyEnum ( '<STR_LIT>' ) ) <EOL> proxy = Typed ( ProxyConstraintsWidget ) <EOL> @ observe ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> def _layout_invalidated ( self , change ) : <EOL> """<STR_LIT>""" <EOL> self . request_relayout ( ) <EOL> def request_relayout ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . proxy_is_active : <EOL> self . proxy . request_relayout ( ) <EOL> def when ( self , switch ) : <EOL> """<STR_LIT>""" <EOL> if switch : <EOL> return self <EOL> def layout_constraints ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . constraints <EOL> ABConstrainable . register ( ConstraintsWidget ) </s>
