<s> """<STR_LIT>""" <EOL> from envisage . api import IExtensionPoint , IServiceRegistry <EOL> from traits . api import Any , Dict , HasTraits , Instance , Int , List <EOL> from traits . api import Property , Str , Undefined <EOL> from traitsui . api import TreeNode <EOL> from traitsui . value_tree import SingleValueTreeNodeObject <EOL> from traitsui . value_tree import value_tree_nodes <EOL> class ServiceModel ( HasTraits ) : <EOL> """<STR_LIT>""" <EOL> id = Int <EOL> obj = Any <EOL> properties = Dict <EOL> class ProtocolModel ( HasTraits ) : <EOL> """<STR_LIT>""" <EOL> name = Str <EOL> services = List ( ServiceModel ) <EOL> class ServiceRegistryModel ( HasTraits ) : <EOL> """<STR_LIT>""" <EOL> service_registry = Instance ( IServiceRegistry ) <EOL> protocols = Property ( List ( ProtocolModel ) ) <EOL> def _get_protocols ( self ) : <EOL> """<STR_LIT>""" <EOL> all_services = list ( self . service_registry . _services . items ( ) ) <EOL> protocols = { } <EOL> for service_id , ( protocol_name , obj , properties ) in all_services : <EOL> protocol = protocols . get ( protocol_name ) <EOL> if protocol is None : <EOL> protocol = ProtocolModel ( name = protocol_name ) <EOL> protocols [ protocol_name ] = protocol <EOL> service_model = ServiceModel ( <EOL> id = service_id , <EOL> obj = obj , <EOL> properties = properties <EOL> ) <EOL> protocol . services . append ( service_model ) <EOL> return list ( protocols . values ( ) ) <EOL> class ProtocolModelTreeNode ( TreeNode ) : <EOL> """<STR_LIT>""" <EOL> def allows_children ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def get_children ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> svtno = SingleValueTreeNodeObject ( ) <EOL> nodes = [ ] <EOL> for service in obj . services : <EOL> node = svtno . node_for ( repr ( service . obj ) , service . obj ) <EOL> node . _protocol_ = obj . name <EOL> node . _service_id_ = service . id <EOL> nodes . append ( node ) <EOL> return nodes <EOL> service_registry_browser_tree_nodes = [ <EOL> TreeNode ( <EOL> node_for = [ ServiceRegistryModel ] , <EOL> auto_open = True , <EOL> label = '<STR_LIT>' , <EOL> children = '<STR_LIT>' , <EOL> rename = False , <EOL> copy = False , <EOL> delete = False , <EOL> insert = False , <EOL> menu = None , <EOL> ) , <EOL> ProtocolModelTreeNode ( <EOL> node_for = [ ProtocolModel ] , <EOL> auto_open = True , <EOL> label = '<STR_LIT:name>' , <EOL> rename = False , <EOL> copy = False , <EOL> delete = False , <EOL> insert = False , <EOL> menu = None , <EOL> ) , <EOL> ] + value_tree_nodes </s>
