コード例 #1
0
ファイル: misc.py プロジェクト: r0k3/jigna
def Menu_from_QMenu(qmenu):
    """ Create a TraitsUI Menu from a native Qt QMenu.
    Submenus are currently not supported, separators are supported.
    """
    qactions = qmenu.actions()
    groups = []
    grp_actions = []
    for action in reversed(qactions):
        action = Action_from_QAction(action)
        if isinstance(action, Separator):
            if len(grp_actions) > 0:
                groups.append(Group(*reversed(grp_actions)))
                grp_actions = []
            else:
                continue
        else:
            grp_actions.append(action)
    if len(grp_actions) > 0:
        groups.append(Group(*reversed(grp_actions)))
    menu = Menu(*groups)
    # Keep a reference to the original menu to prevent actions from being
    # destroyed then the menu is deleted.
    menu._qmenu = qmenu
    return menu