<s> """<STR_LIT>""" <EOL> from traits . api import * <EOL> from traitsui . api import * <EOL> from traitsui . table_column import * <EOL> class Player ( HasTraits ) : <EOL> name = Str ( '<STR_LIT>' ) <EOL> hits = Int <EOL> class Team ( HasTraits ) : <EOL> name = Str ( '<STR_LIT>' ) <EOL> players = List ( Player ) <EOL> num_players = Property ( depends_on = '<STR_LIT>' ) <EOL> def _get_num_players ( self ) : <EOL> """<STR_LIT>""" <EOL> return len ( self . players ) <EOL> class League ( HasTraits ) : <EOL> name = Str ( '<STR_LIT>' ) <EOL> teams = List ( Team ) <EOL> class LeagueModelView ( ModelView ) : <EOL> team = Instance ( Team ) <EOL> player = Instance ( Player ) <EOL> got_hit = Button ( '<STR_LIT>' ) <EOL> total_hits = Property ( depends_on = '<STR_LIT>' ) <EOL> @ cached_property <EOL> def _get_total_hits ( self ) : <EOL> """<STR_LIT>""" <EOL> return reduce ( add , [ reduce ( add , [ p . hits for p in t . players ] , <NUM_LIT:0> ) <EOL> for t in self . model . teams ] , <NUM_LIT:0> ) <EOL> view = View ( <EOL> VGroup ( <EOL> HGroup ( <EOL> Item ( '<STR_LIT>' , style = '<STR_LIT>' ) , <EOL> label = '<STR_LIT>' , <EOL> show_border = True , <EOL> ) , <EOL> VGroup ( <EOL> Item ( '<STR_LIT>' , <EOL> show_label = False , <EOL> editor = TableEditor ( <EOL> columns = [ ObjectColumn ( name = '<STR_LIT:name>' , <EOL> width = <NUM_LIT> ) , <EOL> ObjectColumn ( name = '<STR_LIT>' , <EOL> label = '<STR_LIT>' , <EOL> editable = False , <EOL> width = <NUM_LIT> ) ] , <EOL> selected = '<STR_LIT>' , <EOL> auto_add = True , <EOL> row_factory = Team , <EOL> configurable = False , <EOL> sortable = False ) <EOL> ) , <EOL> label = '<STR_LIT>' , <EOL> show_border = True , <EOL> ) , <EOL> VGroup ( <EOL> Item ( '<STR_LIT>' , <EOL> show_label = False , <EOL> editor = TableEditor ( <EOL> columns = [ ObjectColumn ( name = '<STR_LIT:name>' , <EOL> width = <NUM_LIT> ) , <EOL> ObjectColumn ( name = '<STR_LIT>' , <EOL> editable = False , <EOL> width = <NUM_LIT> ) ] , <EOL> selected = '<STR_LIT>' , <EOL> auto_add = True , <EOL> row_factory = Player , <EOL> configurable = False , <EOL> sortable = False ) , <EOL> ) , <EOL> '<STR_LIT:_>' , <EOL> HGroup ( <EOL> Item ( '<STR_LIT>' , <EOL> show_label = False , <EOL> enabled_when = '<STR_LIT>' , <EOL> ) , <EOL> ) , <EOL> label = '<STR_LIT>' , <EOL> show_labels = False , <EOL> show_border = True , <EOL> ) , <EOL> ) , <EOL> resizable = True , <EOL> ) <EOL> def _model_changed ( self , model ) : <EOL> """<STR_LIT>""" <EOL> if len ( model . teams ) > <NUM_LIT:0> : <EOL> self . team = model . teams [ <NUM_LIT:0> ] <EOL> def _got_hit_changed ( self ) : <EOL> """<STR_LIT>""" <EOL> self . player . hits += <NUM_LIT:1> <EOL> def _team_changed ( self , team ) : <EOL> """<STR_LIT>""" <EOL> if len ( team . players ) > <NUM_LIT:0> : <EOL> self . player = team . players [ <NUM_LIT:0> ] <EOL> else : <EOL> self . player = None <EOL> add = lambda a , b : a + b <EOL> blue_birds = Team ( name = '<STR_LIT>' , players = [ <EOL> Player ( name = '<STR_LIT>' , hits = <NUM_LIT> ) , <EOL> Player ( name = '<STR_LIT>' , hits = <NUM_LIT> ) , <EOL> Player ( name = '<STR_LIT>' , hits = <NUM_LIT> ) ] ) <EOL> chicken_hawks = Team ( name = '<STR_LIT>' , players = [ <EOL> Player ( name = '<STR_LIT>' , hits = <NUM_LIT> ) , <EOL> Player ( name = '<STR_LIT>' , hits = <NUM_LIT:16> ) , <EOL> Player ( name = '<STR_LIT>' , hits = <NUM_LIT> ) ] ) <EOL> eagles = Team ( name = '<STR_LIT>' , players = [ <EOL> Player ( name = '<STR_LIT>' , hits = <NUM_LIT> ) , <EOL> Player ( name = '<STR_LIT>' , hits = <NUM_LIT:12> ) , <EOL> Player ( name = '<STR_LIT>' , hits = <NUM_LIT> ) ] ) <EOL> demo = LeagueModelView ( <EOL> League ( name = '<STR_LIT>' , <EOL> teams = [ blue_birds , chicken_hawks , eagles ] ) ) </s>
