<s> from cStringIO import StringIO <EOL> import sys <EOL> from traits . api import Either , Enum , HasStrictTraits , Int , Instance , List , Str <EOL> class LayoutItem ( HasStrictTraits ) : <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> return self . pformat ( ) <EOL> def iterleaves ( self ) : <EOL> yield self <EOL> def pargs ( self ) : <EOL> return [ ] <EOL> def pformat ( self , indent = <NUM_LIT:0> , multiline = False ) : <EOL> """<STR_LIT>""" <EOL> stream = StringIO ( ) <EOL> self . pstream ( stream , indent , multiline ) <EOL> return stream . getvalue ( ) <EOL> def pprint ( self , indent = <NUM_LIT:0> , multiline = False ) : <EOL> """<STR_LIT>""" <EOL> self . pstream ( sys . stdout , indent , multiline ) <EOL> def pstream ( self , stream , indent = <NUM_LIT:0> , multiline = False ) : <EOL> """<STR_LIT>""" <EOL> call = self . __class__ . __name__ + '<STR_LIT:(>' <EOL> indent += len ( call ) <EOL> stream . write ( call ) <EOL> args = [ ( None , arg ) for arg in self . pargs ( ) ] <EOL> traits = [ ] <EOL> for name , trait in sorted ( self . traits ( ) . iteritems ( ) ) : <EOL> if not trait . pretty_skip and not trait . transient : <EOL> value = getattr ( self , name ) <EOL> if trait . default != value : <EOL> traits . append ( ( name , value ) ) <EOL> traits . sort ( ) <EOL> args . extend ( traits ) <EOL> for i , ( name , value ) in enumerate ( args ) : <EOL> arg_indent = indent <EOL> if name : <EOL> arg_indent += len ( name ) + <NUM_LIT:1> <EOL> stream . write ( name + '<STR_LIT:=>' ) <EOL> if isinstance ( value , LayoutItem ) : <EOL> value . pstream ( stream , arg_indent , multiline ) <EOL> else : <EOL> stream . write ( repr ( value ) ) <EOL> if i < len ( args ) - <NUM_LIT:1> : <EOL> stream . write ( '<STR_LIT:U+002C>' ) <EOL> if multiline : <EOL> stream . write ( '<STR_LIT:\n>' + indent * '<STR_LIT:U+0020>' ) <EOL> else : <EOL> stream . write ( '<STR_LIT:U+0020>' ) <EOL> stream . write ( '<STR_LIT:)>' ) <EOL> class LayoutContainer ( LayoutItem ) : <EOL> """<STR_LIT>""" <EOL> items = List ( pretty_skip = True ) <EOL> def __init__ ( self , * items , ** traits ) : <EOL> if items : <EOL> if '<STR_LIT>' in traits : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> else : <EOL> traits [ '<STR_LIT>' ] = list ( items ) <EOL> super ( LayoutContainer , self ) . __init__ ( ** traits ) <EOL> def iterleaves ( self ) : <EOL> for item in self . items : <EOL> for leaf in item . iterleaves ( ) : <EOL> yield leaf <EOL> def pargs ( self ) : <EOL> return self . items <EOL> class PaneItem ( LayoutItem ) : <EOL> """<STR_LIT>""" <EOL> id = Either ( Str , Int , default = '<STR_LIT>' , pretty_skip = True ) <EOL> width = Int ( - <NUM_LIT:1> ) <EOL> height = Int ( - <NUM_LIT:1> ) <EOL> def __init__ ( self , id = '<STR_LIT>' , ** traits ) : <EOL> super ( PaneItem , self ) . __init__ ( ** traits ) <EOL> self . id = id <EOL> def pargs ( self ) : <EOL> return [ self . id ] <EOL> class Tabbed ( LayoutContainer ) : <EOL> """<STR_LIT>""" <EOL> items = List ( PaneItem , pretty_skip = True ) <EOL> active_tab = Either ( Str , Int , default = '<STR_LIT>' ) <EOL> class Splitter ( LayoutContainer ) : <EOL> """<STR_LIT>""" <EOL> orientation = Enum ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> items = List ( Either ( <EOL> PaneItem , <EOL> Tabbed , <EOL> Instance ( '<STR_LIT>' ) ) , pretty_skip = True ) <EOL> class HSplitter ( Splitter ) : <EOL> """<STR_LIT>""" <EOL> orientation = Str ( '<STR_LIT>' ) <EOL> class VSplitter ( Splitter ) : <EOL> """<STR_LIT>""" <EOL> orientation = Str ( '<STR_LIT>' ) <EOL> class DockLayout ( LayoutItem ) : <EOL> """<STR_LIT>""" <EOL> left = Either ( PaneItem , Tabbed , Splitter ) <EOL> right = Either ( PaneItem , Tabbed , Splitter ) <EOL> top = Either ( PaneItem , Tabbed , Splitter ) <EOL> bottom = Either ( PaneItem , Tabbed , Splitter ) <EOL> top_left_corner = Enum ( '<STR_LIT>' , '<STR_LIT:left>' ) <EOL> top_right_corner = Enum ( '<STR_LIT>' , '<STR_LIT:right>' ) <EOL> bottom_left_corner = Enum ( '<STR_LIT>' , '<STR_LIT:left>' ) <EOL> bottom_right_corner = Enum ( '<STR_LIT>' , '<STR_LIT:right>' ) <EOL> class TaskLayout ( DockLayout ) : <EOL> """<STR_LIT>""" <EOL> id = Str </s>
