예제 #1
0
파일: selection.py 프로젝트: mjr129/groot
def show_selection_menu( control: QAbstractButton,
                         default: object,
                         mode: type = object,
                         ) -> object:
    """
    Shows the selection menu.
    
    :param control:     Button to drop the menu down from. 
    :param default:     Currently selected item
    :param mode:        What we are capable of selecting (as a `type`).
    :return:            The selection made. This will have already been committed to `actions` if `actions` is a `GuiActions` object. 
    """
    model = groot.global_view.current_model()
    
    selection = default
    
    alive = []
    
    root = QMenu()
    root.setTitle( "Make selection" )
    
    # Sequences
    _add_submenu( "Genes", mode, alive, model.genes, root, selection, resources.black_gene )
    
    # Edges
    _add_submenu( "Edges", mode, alive, model.genes, root, selection, resources.black_edge, expand_functions = [groot.Gene.iter_edges] )
    
    # Components
    _add_submenu( "Components", mode, alive, model.components, root, selection, resources.black_major )
    
    # Components - FASTA (unaligned)
    _add_submenu( "Component FASTA (unaligned)", mode, alive, (x.named_unaligned_fasta for x in model.components), root, selection, resources.black_alignment )
    
    # Domains
    _add_submenu( "Domains", mode, alive, model.genes, root, selection, resources.black_domain, expand_functions = [groot.Gene.iter_userdomains] )
    
    # Components - FASTA (aligned)
    _add_submenu( "Component FASTA (aligned)", mode, alive, (x.named_aligned_fasta for x in model.components), root, selection, resources.black_alignment )
    
    # Components - trees (rooted)
    _add_submenu( "Component trees (rooted)", mode, alive, (x.named_tree for x in model.components), root, selection, resources.black_tree )
    
    # Components - trees (unrooted)
    _add_submenu( "Component trees (unrooted)", mode, alive, (x.named_tree_unrooted for x in model.components), root, selection, resources.black_tree )
    
    # Fusions
    _add_submenu( "Fusion events", mode, alive, model.fusions, root, selection, resources.black_fusion )
    
    # Fusion formations
    _add_submenu( "Fusion formations", mode, alive, model.fusions, root, selection, resources.black_fusion, expand_functions = [lambda x: x.formations] )
    
    # Fusion points
    _add_submenu( "Fusion points", mode, alive, model.fusions, root, selection, resources.black_fusion, expand_functions = [lambda x: x.formations, lambda x: x.points] )
    
    #  Splits
    _add_submenu( "Splits", mode, alive, model.splits, root, selection, resources.black_split, create_index = True )
    
    # Consensus
    _add_submenu( "Consensus", mode, alive, model.consensus, root, selection, resources.black_consensus, create_index = True )
    
    # Subsets
    _add_submenu( "Subsets", mode, alive, model.subsets, root, selection, resources.black_subset )
    
    # Pregraphs
    _add_submenu( "Pregraphs", mode, alive, model.iter_pregraphs(), root, selection, resources.black_pregraph )
    
    # Subgraphs
    _add_submenu( "Supertrees", mode, alive, model.subgraphs, root, selection, resources.black_subgraph )
    
    # NRFG - clean
    _add_submenu( "Fusion graphs", mode, alive, (model.fusion_graph_unclean, model.fusion_graph_clean), root, selection, resources.black_nrfg )
    
    # NRFG - report
    _add_submenu( "Reports", mode, alive, (model.report,), root, selection, resources.black_check )
    
    # Usergraphs
    _add_submenu( "User graphs", mode, alive, model.user_graphs, root, selection, resources.black_nrfg )
    
    # Usergraphs
    _add_submenu( "User reports", mode, alive, model.user_reports, root, selection, resources.black_check )
    
    # Special
    if len( root.actions() ) == 0:
        act = QAction()
        act.setText( "List is empty" )
        act.setEnabled( False )
        act.tag = None
        alive.append( act )
        root.addAction( act )
    elif len( root.actions() ) == 1:
        root = root.actions()[0].menu()
    
    # Show menu
    orig = control.text()
    control.setText( root.title() )
    root.setStyleSheet( _MENU_CSS )
    selected = root.exec_( control.mapToGlobal( QPoint( 0, control.height() ) ) )
    control.setText( orig )
    
    if selected is None:
        return None
    
    return selected.tag