<s> from atom . api import Atom , Range <EOL> import kiwisolver as kiwi <EOL> from . strength_member import StrengthMember <EOL> class Spacer ( Atom ) : <EOL> """<STR_LIT>""" <EOL> size = Range ( low = <NUM_LIT:0> ) <EOL> strength = StrengthMember ( ) <EOL> def __init__ ( self , size , strength = None ) : <EOL> """<STR_LIT>""" <EOL> self . size = size <EOL> self . strength = strength <EOL> def __or__ ( self , strength ) : <EOL> """<STR_LIT>""" <EOL> self . strength = strength <EOL> return self <EOL> def when ( self , switch ) : <EOL> """<STR_LIT>""" <EOL> return self if switch else None <EOL> def create_constraints ( self , first , second ) : <EOL> """<STR_LIT>""" <EOL> cns = self . constraints ( first , second ) <EOL> strength = self . strength <EOL> if strength is not None : <EOL> cns = [ cn | strength for cn in cns ] <EOL> return cns <EOL> def constraints ( self , first , second ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class EqSpacer ( Spacer ) : <EOL> """<STR_LIT>""" <EOL> def constraints ( self , first , second ) : <EOL> """<STR_LIT>""" <EOL> return [ ( second - first ) == self . size ] <EOL> class LeSpacer ( Spacer ) : <EOL> """<STR_LIT>""" <EOL> def constraints ( self , first , second ) : <EOL> """<STR_LIT>""" <EOL> return [ ( second - first ) <= self . size , ( second - first ) >= <NUM_LIT:0> ] <EOL> class GeSpacer ( Spacer ) : <EOL> """<STR_LIT>""" <EOL> def constraints ( self , first , second ) : <EOL> """<STR_LIT>""" <EOL> return [ ( second - first ) >= self . size ] <EOL> class FlexSpacer ( Spacer ) : <EOL> """<STR_LIT>""" <EOL> min_strength = StrengthMember ( kiwi . strength . required ) <EOL> eq_strength = StrengthMember ( kiwi . strength . medium * <NUM_LIT> ) <EOL> def __init__ ( self , size , min_strength = None , eq_strength = None ) : <EOL> """<STR_LIT>""" <EOL> self . size = size <EOL> if min_strength is not None : <EOL> self . min_strength = min_strength <EOL> if eq_strength is not None : <EOL> self . eq_strength = eq_strength <EOL> def constraints ( self , first , second ) : <EOL> """<STR_LIT>""" <EOL> min_cn = ( ( second - first ) >= self . size ) | self . min_strength <EOL> eq_cn = ( ( second - first ) == self . size ) | self . eq_strength <EOL> return [ min_cn , eq_cn ] <EOL> class LayoutSpacer ( Spacer ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return type ( self ) ( * args , ** kwargs ) <EOL> def __or__ ( self , strength ) : <EOL> """<STR_LIT>""" <EOL> return type ( self ) ( self . size , strength ) <EOL> def __eq__ ( self , size ) : <EOL> """<STR_LIT>""" <EOL> return EqSpacer ( size , self . strength ) <EOL> def __le__ ( self , size ) : <EOL> """<STR_LIT>""" <EOL> return LeSpacer ( size , self . strength ) <EOL> def __ge__ ( self , size ) : <EOL> """<STR_LIT>""" <EOL> return GeSpacer ( size , self . strength ) <EOL> def flex ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return FlexSpacer ( self . size , ** kwargs ) <EOL> def constraints ( self , first , second ) : <EOL> """<STR_LIT>""" <EOL> return GeSpacer ( self . size , self . strength ) . constraints ( first , second ) </s>
