#NEWLINE# def constraints( self , component ) : #NEWLINE# #INDENT# ' Generate the grid constraints for the given component.\n\n        Parameters\n        ----------\n        component : Constrainable or None\n            The constrainable object which represents the conceptual\n            owner of the generated constraints.\n\n        Returns\n        -------\n        result : list\n            The list of Constraint objects for the given component.\n\n        ' #NEWLINE# cns = self . box_constraints ( component ) #NEWLINE# cells = [ ] #NEWLINE# cell_map = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# num_cols = 0 #NEWLINE# num_rows = len ( self . rows ) #NEWLINE# for ( row_idx , row ) in enumerate ( self . rows ) : #NEWLINE# #INDENT# num_cols = max ( num_cols , len ( row ) ) #NEWLINE# for ( col_idx , item ) in enumerate ( row ) : #NEWLINE# #INDENT# if ( item is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( item in cell_map ) : #NEWLINE# #INDENT# cell_map [ item ] . expand_to ( row_idx , col_idx ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cell = self . _Cell ( item , row_idx , col_idx ) #NEWLINE# cell_map [ item ] = cell #NEWLINE# cells . append ( cell ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# row_vars = [ ] #NEWLINE# col_vars = [ ] #NEWLINE# for idx in xrange ( ( num_rows + 1 ) ) : #NEWLINE# #INDENT# var = kiwi . Variable ( ( 'row%d' % idx ) ) #NEWLINE# row_vars . append ( var ) #NEWLINE# cns . append ( ( var >= 0 ) ) #NEWLINE# #UNINDENT# for idx in xrange ( ( num_cols + 1 ) ) : #NEWLINE# #INDENT# var = kiwi . Variable ( ( 'col%d' % idx ) ) #NEWLINE# col_vars . append ( var ) #NEWLINE# cns . append ( ( var >= 0 ) ) #NEWLINE# #UNINDENT# for ( r1 , r2 ) in zip ( row_vars [ : ( - 1 ) ] , row_vars [ 1 : ] ) : #NEWLINE# #INDENT# cns . append ( ( r1 <= r2 ) ) #NEWLINE# #UNINDENT# for ( c1 , c2 ) in zip ( col_vars [ : ( - 1 ) ] , col_vars [ 1 : ] ) : #NEWLINE# #INDENT# cns . append ( ( c1 <= c2 ) ) #NEWLINE# #UNINDENT# firsts = ( self . top , col_vars [ ( - 1 ) ] , row_vars [ ( - 1 ) ] , self . left ) #NEWLINE# seconds = ( row_vars [ 0 ] , self . right , self . bottom , col_vars [ 0 ] ) #NEWLINE# for ( size , first , second ) in zip ( self . margins , firsts , seconds ) : #NEWLINE# #INDENT# cns . extend ( EqSpacer ( size ) . create_constraints ( first , second ) ) #NEWLINE# #UNINDENT# row_spacer = FlexSpacer ( ( self . row_spacing / 2 ) ) #NEWLINE# col_spacer = FlexSpacer ( ( self . column_spacing / 2 ) ) #NEWLINE# rspace = ( [ row_spacer ] * len ( row_vars ) ) #NEWLINE# cspace = ( [ col_spacer ] * len ( col_vars ) ) #NEWLINE# rspace [ 0 ] = rspace [ ( - 1 ) ] = cspace [ 0 ] = cspace [ ( - 1 ) ] = 0 #NEWLINE# helpers = [ ] #NEWLINE# for cell in cells : #NEWLINE# #INDENT# sr = cell . start_row #NEWLINE# er = ( cell . end_row + 1 ) #NEWLINE# sc = cell . start_column #NEWLINE# ec = ( cell . end_column + 1 ) #NEWLINE# item = cell . item #NEWLINE# ritems = ( row_vars [ sr ] , rspace [ sr ] , item , rspace [ er ] , row_vars [ er ] ) #NEWLINE# citems = ( col_vars [ sc ] , cspace [ sc ] , item , cspace [ ec ] , col_vars [ ec ] ) #NEWLINE# rhelper = SequenceHelper ( 'bottom' , 'top' , ( ) ) #NEWLINE# chelper = SequenceHelper ( 'right' , 'left' , ( ) ) #NEWLINE# rhelper . items = ritems #NEWLINE# chelper . items = citems #NEWLINE# helpers . extend ( ( row_map , chelper ) ) #NEWLINE# if isinstance ( item , ConstraintHelper ) : #NEWLINE# #INDENT# helpers . append ( item ) #NEWLINE# #UNINDENT# #UNINDENT# anchor = self . row_align #NEWLINE# if anchor : #NEWLINE# #INDENT# row_map = defaultdict ( list ) #NEWLINE# for cell in cells : #NEWLINE# #INDENT# if ( cell . start_row == cell . end_row ) : #NEWLINE# #INDENT# row_map [ cell . start_row ] . append ( cell . item ) #NEWLINE# #UNINDENT# #UNINDENT# for items in row_map . itervalues ( ) : #NEWLINE# #INDENT# if ( len ( items ) > 1 ) : #NEWLINE# #INDENT# helper = SequenceHelper ( anchor , anchor , ( ) , 0 ) #NEWLINE# helper . items = tuple ( items ) #NEWLINE# helpers . append ( helper ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# anchor = self . column_align #NEWLINE# if anchor : #NEWLINE# #INDENT# col_map = defaultdict ( list ) #NEWLINE# for cell in cells : #NEWLINE# #INDENT# if ( cell . start_column == cell . end_column ) : #NEWLINE# #INDENT# col_map [ cell . start_column ] . append ( cell . item ) #NEWLINE# #UNINDENT# #UNINDENT# for items in col_map . itervalues ( ) : #NEWLINE# #INDENT# if ( len ( items ) > 1 ) : #NEWLINE# #INDENT# helper = SequenceHelper ( anchor , anchor , ( ) , 0 ) #NEWLINE# helper . items = tuple ( items ) #NEWLINE# helpers . append ( helper ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for helper in helpers : #NEWLINE# #INDENT# cns . extend ( helper . create_constraints ( None ) ) #NEWLINE# #UNINDENT# return cns