<s> from traits . api import HasTraits , Str , Regex , List , Instance <EOL> from traitsui . api import TreeEditor , TreeNode , View , Item , VSplit , HGroup , Handler <EOL> from traitsui . menu import Menu , Action , Separator <EOL> from traitsui . wx . tree_editor import NewAction , CopyAction , CutAction , PasteAction , DeleteAction , RenameAction <EOL> class Employee ( HasTraits ) : <EOL> name = Str ( '<STR_LIT>' ) <EOL> title = Str <EOL> phone = Regex ( regex = r'<STR_LIT>' ) <EOL> def default_title ( self ) : <EOL> self . title = '<STR_LIT>' <EOL> class Department ( HasTraits ) : <EOL> name = Str ( '<STR_LIT>' ) <EOL> employees = List ( Employee ) <EOL> class Company ( HasTraits ) : <EOL> name = Str ( '<STR_LIT>' ) <EOL> departments = List ( Department ) <EOL> employees = List ( Employee ) <EOL> class Partner ( HasTraits ) : <EOL> name = Str ( '<STR_LIT>' ) <EOL> company = Instance ( Company ) <EOL> jason = Employee ( <EOL> name = '<STR_LIT>' , <EOL> title = '<STR_LIT>' , <EOL> phone = '<STR_LIT>' ) <EOL> mike = Employee ( <EOL> name = '<STR_LIT>' , <EOL> title = '<STR_LIT>' , <EOL> phone = '<STR_LIT>' ) <EOL> dave = Employee ( <EOL> name = '<STR_LIT>' , <EOL> title = '<STR_LIT>' , <EOL> phone = '<STR_LIT>' ) <EOL> martin = Employee ( <EOL> name = '<STR_LIT>' , <EOL> title = '<STR_LIT>' , <EOL> phone = '<STR_LIT>' ) <EOL> duncan = Employee ( <EOL> name = '<STR_LIT>' , <EOL> title = '<STR_LIT>' ) <EOL> partner = Partner ( <EOL> name = '<STR_LIT>' , <EOL> company = Company ( <EOL> name = '<STR_LIT>' , <EOL> departments = [ <EOL> Department ( <EOL> name = '<STR_LIT>' , <EOL> employees = [ jason , mike ] <EOL> ) , <EOL> Department ( <EOL> name = '<STR_LIT>' , <EOL> employees = [ dave , martin , duncan ] <EOL> ) <EOL> ] , <EOL> employees = [ dave , martin , mike , duncan , jason ] <EOL> ) <EOL> ) <EOL> no_view = View ( ) <EOL> tree_editor = TreeEditor ( <EOL> nodes = [ <EOL> TreeNode ( node_for = [ Company ] , <EOL> auto_open = True , <EOL> children = '<STR_LIT>' , <EOL> label = '<STR_LIT:name>' , <EOL> view = View ( [ '<STR_LIT:name>' , '<STR_LIT>' ] ) ) , <EOL> TreeNode ( node_for = [ Company ] , <EOL> auto_open = True , <EOL> children = '<STR_LIT>' , <EOL> label = '<STR_LIT>' , <EOL> view = no_view , <EOL> add = [ Department ] ) , <EOL> TreeNode ( node_for = [ Company ] , <EOL> auto_open = True , <EOL> children = '<STR_LIT>' , <EOL> label = '<STR_LIT>' , <EOL> view = no_view , <EOL> add = [ Employee ] ) , <EOL> TreeNode ( node_for = [ Department ] , <EOL> auto_open = True , <EOL> children = '<STR_LIT>' , <EOL> label = '<STR_LIT:name>' , <EOL> menu = Menu ( NewAction , <EOL> Separator ( ) , <EOL> DeleteAction , <EOL> Separator ( ) , <EOL> RenameAction , <EOL> Separator ( ) , <EOL> CopyAction , <EOL> CutAction , <EOL> PasteAction ) , <EOL> view = View ( [ '<STR_LIT:name>' , '<STR_LIT>' ] ) , <EOL> add = [ Employee ] ) , <EOL> TreeNode ( node_for = [ Employee ] , <EOL> auto_open = True , <EOL> label = '<STR_LIT:name>' , <EOL> menu = Menu ( NewAction , <EOL> Separator ( ) , <EOL> Action ( name = '<STR_LIT>' , <EOL> action = '<STR_LIT>' ) , <EOL> Action ( name = '<STR_LIT>' , <EOL> action = '<STR_LIT>' ) , <EOL> Separator ( ) , <EOL> CopyAction , <EOL> CutAction , <EOL> PasteAction , <EOL> Separator ( ) , <EOL> DeleteAction , <EOL> Separator ( ) , <EOL> RenameAction ) , <EOL> view = View ( VSplit ( HGroup ( '<STR_LIT:3>' , '<STR_LIT:name>' ) , <EOL> HGroup ( '<STR_LIT>' , '<STR_LIT:title>' ) , <EOL> HGroup ( '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' , <EOL> dock = '<STR_LIT>' ) ) <EOL> ] <EOL> ) <EOL> class TreeHandler ( Handler ) : <EOL> def employee_department ( self , editor , object ) : <EOL> dept = editor . get_parent ( object ) <EOL> print '<STR_LIT>' % ( object . name , dept . name ) <EOL> view = View ( [ Item ( name = '<STR_LIT>' , <EOL> id = '<STR_LIT>' , <EOL> editor = tree_editor , <EOL> resizable = True ) , '<STR_LIT>' ] , <EOL> title = '<STR_LIT>' , <EOL> id = '<STR_LIT>' , <EOL> dock = '<STR_LIT>' , <EOL> drop_class = HasTraits , <EOL> handler = TreeHandler ( ) , <EOL> buttons = [ '<STR_LIT>' , '<STR_LIT:OK>' , '<STR_LIT>' ] , <EOL> resizable = True , <EOL> width = <NUM_LIT> , <EOL> height = <NUM_LIT> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> partner . configure_traits ( view = view ) </s>
