<s> from traits . api import HasStrictTraits , Str , Int , Regex , List , Instance <EOL> from traitsui . api import View , Group , Item , TableEditor , EnumEditor <EOL> from traitsui . table_column import ObjectColumn <EOL> from traitsui . table_filter import TableFilter , RuleTableFilter , RuleFilterTemplate , MenuFilterTemplate , EvalFilterTemplate <EOL> class Person ( HasStrictTraits ) : <EOL> name = Str <EOL> age = Int <EOL> phone = Regex ( value = '<STR_LIT>' , regex = '<STR_LIT>' ) <EOL> state = Str <EOL> traits_view = View ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:state>' , <EOL> title = '<STR_LIT>' , <EOL> width = <NUM_LIT> , <EOL> buttons = [ '<STR_LIT:OK>' , '<STR_LIT>' ] ) <EOL> people = [ <EOL> Person ( name = '<STR_LIT>' , age = <NUM_LIT> , phone = '<STR_LIT>' ) , <EOL> Person ( name = '<STR_LIT>' , age = <NUM_LIT> , phone = '<STR_LIT>' ) , <EOL> Person ( name = '<STR_LIT>' , age = <NUM_LIT> , phone = '<STR_LIT>' ) , <EOL> Person ( name = '<STR_LIT>' , age = <NUM_LIT> , phone = '<STR_LIT>' ) , <EOL> Person ( name = '<STR_LIT>' , age = <NUM_LIT> , phone = '<STR_LIT>' ) , <EOL> Person ( name = '<STR_LIT>' , age = <NUM_LIT> , phone = '<STR_LIT>' ) , <EOL> Person ( name = '<STR_LIT>' , age = <NUM_LIT> , phone = '<STR_LIT>' ) , <EOL> Person ( name = '<STR_LIT>' , age = <NUM_LIT> , phone = '<STR_LIT>' ) <EOL> ] <EOL> class AgeFilter ( TableFilter ) : <EOL> name = "<STR_LIT>" <EOL> _name = "<STR_LIT>" <EOL> age = Int ( <NUM_LIT:0> ) <EOL> def filter ( self , person ) : <EOL> """<STR_LIT>""" <EOL> return ( person . age >= self . age ) <EOL> def description ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % self . age <EOL> def _age_changed ( self , old , new ) : <EOL> self . name = self . description ( ) <EOL> print '<STR_LIT>' , self . name <EOL> class NameFilter ( TableFilter ) : <EOL> mname = Str <EOL> filter_view = Group ( '<STR_LIT>' ) <EOL> def filter ( self , person ) : <EOL> """<STR_LIT>""" <EOL> return ( person . name . lower ( ) . find ( self . mname . lower ( ) ) >= <NUM_LIT:0> ) <EOL> def description ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % self . mname <EOL> filters = [ AgeFilter ( age = <NUM_LIT:30> ) , NameFilter ( mname = '<STR_LIT:d>' ) , EvalFilterTemplate , MenuFilterTemplate , RuleFilterTemplate , <EOL> ] <EOL> def evaluate_value ( v ) : <EOL> print '<STR_LIT>' , v <EOL> return str ( v ) <EOL> class TableTest ( HasStrictTraits ) : <EOL> people = List ( Person ) <EOL> _valid_states = List ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> _state_editor = EnumEditor ( <EOL> name = "<STR_LIT>" , <EOL> evaluate = evaluate_value , <EOL> object = '<STR_LIT>' <EOL> ) <EOL> table_editor = TableEditor ( <EOL> columns = [ ObjectColumn ( name = '<STR_LIT:name>' ) , <EOL> ObjectColumn ( name = '<STR_LIT>' ) , <EOL> ObjectColumn ( name = '<STR_LIT>' ) , <EOL> ObjectColumn ( name = '<STR_LIT:state>' , <EOL> editor = _state_editor ) , ] , <EOL> editable = True , <EOL> deletable = True , <EOL> sortable = True , <EOL> sort_model = True , <EOL> show_lines = True , <EOL> orientation = '<STR_LIT>' , <EOL> show_column_labels = True , <EOL> edit_view = View ( [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:state>' , '<STR_LIT>' ] , <EOL> resizable = True ) , <EOL> filter = None , <EOL> filters = filters , <EOL> row_factory = Person <EOL> ) <EOL> traits_view = View ( <EOL> [ Item ( '<STR_LIT>' , <EOL> id = '<STR_LIT>' , <EOL> editor = table_editor ) , <EOL> '<STR_LIT>' ] , <EOL> title = '<STR_LIT>' , <EOL> id = '<STR_LIT>' , <EOL> dock = '<STR_LIT>' , <EOL> width = <NUM_LIT> , <EOL> height = <NUM_LIT> , <EOL> resizable = True , <EOL> kind = '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> tt = TableTest ( people = people ) <EOL> tt . configure_traits ( ) <EOL> for p in tt . people : <EOL> p . print_traits ( ) <EOL> print '<STR_LIT>' </s>
