当前位置: 首页>>代码示例>>Python>>正文


Python QMenu.addMenu方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QMenu.addMenu方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.addMenu方法的具体用法?Python QMenu.addMenu怎么用?Python QMenu.addMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QMenu的用法示例。


在下文中一共展示了QMenu.addMenu方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: show_context_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def show_context_menu(self, position):
        items = []
        for class_ in sorted(self._context_items.keys(), key=lambda i: str(i)):
            if isinstance(self.get_context_cue(), class_):
                items.extend(self._context_items[class_])

        if len(items) > 0:
            menu = QMenu(self)

            for item in items:
                if isinstance(item, QAction):
                    menu.addAction(item)
                elif isinstance(item, QMenu):
                    menu.addMenu(item)

            menu.move(position)
            menu.show()

            # Adjust the menu position
            desktop = qApp.desktop().availableGeometry()
            menu_rect = menu.geometry()

            if menu_rect.bottom() > desktop.bottom():
                menu.move(menu.x(), menu.y() - menu.height())
            if menu_rect.right() > desktop.right():
                menu.move(menu.x() - menu.width(), menu.y())
开发者ID:tornel,项目名称:linux-show-player,代码行数:28,代码来源:cue_layout.py

示例2: initMenu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def initMenu(self, mainMenu):
        """
        Public method to generate the extension menu.
        
        @param mainMenu reference to the main menu (QMenu)
        @return populated menu (QMenu)
        """
        menu = QMenu(self.menuTitle(), mainMenu)
        menu.setTearOffEnabled(True)

        self.__adminMenu = QMenu(self.tr("Administration"), menu)
        self.__adminMenu.setTearOffEnabled(True)
        self.__adminMenu.addAction(self.hgVerifyLargeAct)
        self.__adminMenu.addAction(self.hgVerifyLfaAct)
        self.__adminMenu.addAction(self.hgVerifyLfcAct)

        menu.addAction(self.hgConvertToLargefilesAct)
        menu.addAction(self.hgConvertToNormalAct)
        menu.addSeparator()
        menu.addAction(self.hgLfPullAct)
        menu.addSeparator()
        menu.addAction(self.hgLfSummaryAct)
        menu.addSeparator()
        menu.addMenu(self.__adminMenu)

        return menu
开发者ID:testmana2,项目名称:eric,代码行数:28,代码来源:ProjectHelper.py

示例3: layercontextmenu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
def layercontextmenu(layer, pos, parent=None):
    """Show a context menu to manipulate properties of layer.

    layer -- a volumina layer instance
    pos -- QPoint

    """
    menu = QMenu("Menu", parent)

    # Title
    title = QAction("%s" % layer.name, menu)
    title.setEnabled(False)
    menu.addAction(title)

    # Export
    global _has_lazyflow
    if _has_lazyflow:
        export = QAction("Export...", menu)
        export.setStatusTip("Export Layer...")
        export.triggered.connect(partial(prompt_export_settings_and_export_layer, layer, menu))
        menu.addAction(export)

    menu.addSeparator()
    _add_actions(layer, menu)

    # Layer-custom context menu items
    menu.addSeparator()
    for item in layer.contexts:
        if isinstance(item, QAction):
            menu.addAction(item)
        elif isinstance(item, QMenu):
            menu.addMenu(item)

    menu.exec_(pos)
开发者ID:ilastik,项目名称:volumina,代码行数:36,代码来源:layercontextmenu.py

示例4: updatePlotPersoButton

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def updatePlotPersoButton(self):
        menu = QMenu(self.mw)

        menus = []
        for i in [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]:
            m = QMenu(i, menu)
            menus.append(m)
            menu.addMenu(m)

        mpr = QSignalMapper(menu)
        for i in range(self.mw.mdlCharacter.rowCount()):
            a = QAction(self.mw.mdlCharacter.name(i), menu)
            a.setIcon(self.mw.mdlCharacter.icon(i))
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, int(self.mw.mdlCharacter.ID(i)))

            imp = toInt(self.mw.mdlCharacter.importance(i))

            menus[2 - imp].addAction(a)

        # Disabling empty menus
        for m in menus:
            if not m.actions():
                m.setEnabled(False)

        mpr.mapped.connect(self.addPlotPerso)
        self.mw.btnAddPlotPerso.setMenu(menu)
开发者ID:olivierkes,项目名称:manuskript,代码行数:29,代码来源:plotModel.py

示例5: contextMenuEvent

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
 def contextMenuEvent (self, event):
     menu = QMenu()
     if self.isselected():
         window = FlGlob.mainwindow
         menu.addAction(window.actions["collapse"])
         menu.addMenu(window.addmenu)
     if not menu.isEmpty():
         menu.exec_(event.screenPos())
开发者ID:bucaneer,项目名称:flint,代码行数:10,代码来源:nodeitems.py

示例6: get_context_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def get_context_menu(self, qpoint):
        """ override this method to customize the context menu """
        menu = QMenu(self)
        index = self.view.indexAt(qpoint)

        def add_action(menu, text, handler, icon=None):
            a = None
            if icon is None:
                a = QAction(text, self)
            else:
                a = QAction(icon, text, self)
            a.triggered.connect(handler)
            menu.addAction(a)

        add_action(menu, "Color selection", self._handle_color_selection)

        # duplication here with vstructui
        color_menu = menu.addMenu("Color selection...")

        # need to escape the closure capture on the color loop variable below
        # hint from: http://stackoverflow.com/a/6035865/87207
        def make_color_selection_handler(color):
            return lambda: self._handle_color_selection(color=color)

        for color in QT_COLORS:
            add_action(color_menu, "{:s}".format(color.name),
                       make_color_selection_handler(color.qcolor), make_color_icon(color.qcolor))

        start = self._hsm.start
        end = self._hsm.end
        cm = self.getColorModel()
        if (start == end and cm.is_index_colored(start)) or cm.is_region_colored(start, end):
            def make_remove_color_handler(r):
                return lambda: self._handle_remove_color_range(r)

            remove_color_menu = menu.addMenu("Remove color...")
            for cr in cm.get_region_colors(start, end):
                pixmap = QPixmap(10, 10)
                pixmap.fill(cr.color)
                icon = QIcon(pixmap)
                add_action(remove_color_menu,
                       "Remove color [{:s}, {:s}], len: {:s}".format(h(cr.begin), h(cr.end), h(cr.end - cr.begin)),
                       make_remove_color_handler(cr), make_color_icon(cr.color))

        menu.addSeparator()  # -----------------------------------------------------------------

        add_action(menu, "Copy selection (binary)", self._handle_copy_binary)
        copy_menu = menu.addMenu("Copy...")
        add_action(copy_menu, "Copy selection (binary)", self._handle_copy_binary)
        add_action(copy_menu, "Copy selection (text)", self._handle_copy_text)
        add_action(copy_menu, "Copy selection (hex)", self._handle_copy_hex)
        add_action(copy_menu, "Copy selection (hexdump)", self._handle_copy_hexdump)
        add_action(copy_menu, "Copy selection (base64)", self._handle_copy_base64)

        menu.addSeparator()  # -----------------------------------------------------------------

        add_action(menu, "Add origin", lambda: self._handle_add_origin(index))
        return menu
开发者ID:williballenthin,项目名称:python-pyqt5-hexview,代码行数:60,代码来源:hexview.py

示例7: generateViewMenu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def generateViewMenu(self):

        values = [
            (self.tr("Nothing"), "Nothing"),
            (self.tr("POV"), "POV"),
            (self.tr("Label"), "Label"),
            (self.tr("Progress"), "Progress"),
            (self.tr("Compile"), "Compile"),
        ]

        menus = [
            (self.tr("Tree"), "Tree"),
            (self.tr("Index cards"), "Cork"),
            (self.tr("Outline"), "Outline")
        ]

        submenus = {
            "Tree": [
                (self.tr("Icon color"), "Icon"),
                (self.tr("Text color"), "Text"),
                (self.tr("Background color"), "Background"),
            ],
            "Cork": [
                (self.tr("Icon"), "Icon"),
                (self.tr("Text"), "Text"),
                (self.tr("Background"), "Background"),
                (self.tr("Border"), "Border"),
                (self.tr("Corner"), "Corner"),
            ],
            "Outline": [
                (self.tr("Icon color"), "Icon"),
                (self.tr("Text color"), "Text"),
                (self.tr("Background color"), "Background"),
            ],
        }

        self.menuView.clear()
        self.menuView.addMenu(self.menuMode)
        self.menuView.addSeparator()

        # print("Generating menus with", settings.viewSettings)

        for mnu, mnud in menus:
            m = QMenu(mnu, self.menuView)
            for s, sd in submenus[mnud]:
                m2 = QMenu(s, m)
                agp = QActionGroup(m2)
                for v, vd in values:
                    a = QAction(v, m)
                    a.setCheckable(True)
                    a.setData("{},{},{}".format(mnud, sd, vd))
                    if settings.viewSettings[mnud][sd] == vd:
                        a.setChecked(True)
                    a.triggered.connect(self.setViewSettingsAction, AUC)
                    agp.addAction(a)
                    m2.addAction(a)
                m.addMenu(m2)
            self.menuView.addMenu(m)
开发者ID:TenKeyAngle,项目名称:manuskript,代码行数:60,代码来源:mainWindow.py

示例8: open_context_menu_parameter_tree

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def open_context_menu_parameter_tree(self, position):
        """
        This callback function is called to create a context menu
        for the parameter tree

        :param position:
        :return:
        """

        index = self.parameterTree.indexAt(position)

        if index.isValid() is False:
            return None

        if self.parameterTree.isIndexHidden(index):
            return

        index_sibling = index.sibling(index.row(), index.column()-1)

        if index_sibling.isValid():
            index = index_sibling

        dparameter = self.parameterTree.model().data(index, Qt.UserRole)
        dplugin = self.pluginTree.model().data(self.pluginTree.currentIndex(), Qt.UserRole)

        sub_menu = QMenu('Control by')

        dplugin_ids = self.dgui.get_all_plugins()

        for dplugin_id in dplugin_ids:
            dplugin_pcp = dplugin_ids[dplugin_id]

            if len(dplugin_pcp.get_devent()) > 0:
                # action = QAction(self.tr(dplugin.uname), self)
                # sub_menu.addAction(action)
                pcp_menu = QMenu(self.tr(dplugin_pcp.uname), sub_menu)
                sub_menu.addMenu(pcp_menu)

                dblock_pcp_ids = dplugin_pcp.get_dblocks()

                for dblock_pcp_id in dblock_pcp_ids:
                    dblock_pcp = dblock_pcp_ids[dblock_pcp_id]

                    count = len(dblock_pcp.get_subscribers())

                    action = QAction(self.tr(dblock_pcp.name)+' ('+str(count)+')', pcp_menu)
                    pcp_menu.addAction(action)

                    action.triggered.connect(lambda ignore, p1=dplugin, p2=dparameter, p3=dplugin_pcp, p4=dblock_pcp:
                                             self.add_pcp_subscription_action(p1, p2, p3, p4))

        menu = QMenu()
        menu.addMenu(sub_menu)

        menu.exec_(self.parameterTree.viewport().mapToGlobal(position))
开发者ID:TUB-Control,项目名称:PaPI,代码行数:57,代码来源:OverviewPluginMenu.py

示例9: annotationMenu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def annotationMenu(self):
        global annotations, classLabels
        global startTimeToPlay, endTimeToPlay, overlap, isAbove
        global text1, text2

        speakers = []
        passAppend = True

        annotation = QMenu()

        for index in range(len(annotations)):
            if startTimeToPlay==annotations[index][0] and endTimeToPlay==annotations[index][1]:
                if not overlap:
                    delete = annotation.addAction('Delete')
                    delete.triggered.connect(self.delete)
                elif overlap and isAbove:
                    delete = annotation.addMenu('Delete')
                    delete.addAction(text1)
                    delete.addAction(text2)
                    delete.triggered.connect(self.deleteFromOverlap)
                    isAbove = False
                elif overlap:
                    delete = annotation.addAction('Delete')
                    delete.triggered.connect(self.delete)
                    overlap = False
        self.subMenu = annotation.addMenu('Annotate')
        
        #Define Labels
        #----------------------
        for i in range(len(classLabels)):
            self.subMenu.addAction(classLabels[i])

        #Define Speakers
        #----------------------
        speakerMenu = self.subMenu.addMenu('Speech')
        for i in range(len(annotations)):
            if annotations[i][2][:8] == 'Speech::':
                remove = annotations[i][2].index(':')
                remove = remove + 2
                length = len(annotations[i][2])
                sub = length - remove
                if not annotations[i][2][-sub:] in speakers:
                    speakers.append(annotations[i][2][-sub:])
                #speakerMenu.addAction(speaker)
        #new speaker...
        for index in range(len(speakers)):
            speakerMenu.addAction(speakers[index])
        addNew = speakerMenu.addAction('Add New Speaker')

        self.subMenu.triggered.connect(self.chooseAnnotation)
        speakerMenu.triggered.connect(self.Speakers)

        annotation.exec_(self.mapToGlobal(self.pos()) + QtCore.QPoint(xPos, yPos))
开发者ID:ElenaDiamantidou,项目名称:audioGraph,代码行数:55,代码来源:gui.py

示例10: __init__

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def __init__(self, parent):
        super().__init__(parent)
        self.setupUi(self)

        tool_menu = QMenu(self.tr("Tools"), self.toolbutton_menu)
        self.toolbutton_menu.setMenu(tool_menu)

        self.action_add_connection = QAction(self.tr("Add a connection"), tool_menu)
        tool_menu.addAction(self.action_add_connection)

        self.action_revoke_uid = QAction(self.tr(ToolbarView._action_revoke_uid_text), self)
        tool_menu.addAction(self.action_revoke_uid)

        self.action_parameters = QAction(self.tr("Settings"), tool_menu)
        tool_menu.addAction(self.action_parameters)

        self.action_plugins = QAction(self.tr("Plugins manager"), tool_menu)
        tool_menu.addAction(self.action_plugins)

        tool_menu.addSeparator()

        about_menu = QMenu(self.tr("About"), tool_menu)
        tool_menu.addMenu(about_menu)

        self.action_about_money = QAction(self.tr("About Money"), about_menu)
        about_menu.addAction(self.action_about_money)

        self.action_about_referentials = QAction(self.tr("About Referentials"), about_menu)
        about_menu.addAction(self.action_about_referentials)

        self.action_about_wot = QAction(self.tr("About Web of Trust"), about_menu)
        about_menu.addAction(self.action_about_wot)

        self.action_about = QAction(self.tr("About Sakia"), about_menu)
        about_menu.addAction(self.action_about)

        self.action_exit = QAction(self.tr("Exit"), tool_menu)
        tool_menu.addAction(self.action_exit)

        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Minimum)
        self.setMaximumHeight(60)
        self.button_network.setIconSize(self.button_network.iconSize()*dpi_ratio())
        self.button_contacts.setIconSize(self.button_contacts.iconSize()*dpi_ratio())
        self.button_identity.setIconSize(self.button_identity.iconSize()*dpi_ratio())
        self.button_explore.setIconSize(self.button_explore.iconSize()*dpi_ratio())
        self.toolbutton_menu.setIconSize(self.toolbutton_menu.iconSize()*dpi_ratio())
        self.button_network.setFixedHeight(self.button_network.height()*dpi_ratio()+5*dpi_ratio())
        self.button_contacts.setFixedHeight(self.button_contacts.height()*dpi_ratio()+5*dpi_ratio())
        self.button_identity.setFixedHeight(self.button_identity.height()*dpi_ratio()+5*dpi_ratio())
        self.button_explore.setFixedHeight(self.button_explore.height()*dpi_ratio()+5*dpi_ratio())
        self.toolbutton_menu.setFixedHeight(self.toolbutton_menu.height()*dpi_ratio()+5*dpi_ratio())
开发者ID:duniter,项目名称:sakia,代码行数:53,代码来源:view.py

示例11: context_menu_for_root

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def context_menu_for_root(self):
        if not self.current_tree:
            # en vez de un mensaje, colorear el area de projecto...
            # el area de projecto debería decir 'Sin Projectos'/'without Projects'
            # QMessageBox.information(self, translations.TR_INFO_TITLE_PROJECT_PROPERTIES,
            #     translations.TR_INFO_MESSAGE_PROJECT_PROPERTIES)
            return
        menu = QMenu(self)
        path = self.current_tree.project.path
        action_add_file = menu.addAction(QIcon(":img/new"),
                                         translations.TR_ADD_NEW_FILE)
        action_add_folder = menu.addAction(QIcon(
            ":img/openProj"), translations.TR_ADD_NEW_FOLDER)
        action_create_init = menu.addAction(translations.TR_CREATE_INIT)
        action_add_file.triggered['bool'].connect(lambda s,_path=path: self.current_tree._add_new_file(_path))
        action_add_folder.triggered['bool'].connect(lambda s,_path=path: self.current_tree._add_new_folder(_path))
        action_create_init.triggered['bool'].connect(lambda s,_path=path: self.current_tree._create_init(_path))
        menu.addSeparator()
        actionRunProject = menu.addAction(QIcon(
            ":img/play"), translations.TR_RUN_PROJECT)
        actionRunProject.triggered['bool'].connect(lambda s: self.current_tree._execute_project())
        if self.current_tree._added_to_console:
            actionRemoveFromConsole = menu.addAction(
                translations.TR_REMOVE_PROJECT_FROM_PYTHON_CONSOLE)
            actionRemoveFromConsole.triggered['bool'].connect(lambda s: self.current_tree._remove_project_from_console())
        else:
            actionAdd2Console = menu.addAction(
                translations.TR_ADD_PROJECT_TO_PYTHON_CONSOLE)
            actionAdd2Console.triggered['bool'].connect(lambda s: self.current_tree._add_project_to_console())
        actionShowFileSizeInfo = menu.addAction(translations.TR_SHOW_FILESIZE)
        actionShowFileSizeInfo.triggered['bool'].connect(lambda s: self.current_tree.show_filesize_info())
        actionProperties = menu.addAction(QIcon(":img/pref"),
                                          translations.TR_PROJECT_PROPERTIES)
        actionProperties.triggered['bool'].connect(lambda s: self.current_tree.open_project_properties())

        menu.addSeparator()
        action_close = menu.addAction(
            self.style().standardIcon(QStyle.SP_DialogCloseButton),
            translations.TR_CLOSE_PROJECT)
        action_close.triggered['bool'].connect(lambda s: self.current_tree._close_project())
        #menu for the project
        for m in self.current_tree.extra_menus_by_scope['project']:
            if isinstance(m, QMenu):
                menu.addSeparator()
                menu.addMenu(m)

        #show the menu!
        menu.exec_(QCursor.pos())
开发者ID:Salmista-94,项目名称:Ninja_3.0_PyQt5,代码行数:50,代码来源:tree_projects_widget.py

示例12: showContextMenu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def showContextMenu(self, clickedObjectItem, screenPos):
        selection = self.mMapScene.selectedObjectItems()
        if (clickedObjectItem and not selection.contains(clickedObjectItem)):
            selection.clear()
            selection.insert(clickedObjectItem)
            self.mMapScene.setSelectedObjectItems(selection)
        if selection.isEmpty():
            return

        selectedObjects = self.mapDocument().selectedObjects()
        objectGroups = self.mapDocument().map().objectGroups()

        menu = QMenu()
        duplicateAction = menu.addAction(self.tr("Duplicate %n Object(s)", "", selection.size()), self.duplicateObjects)
        removeAction = menu.addAction(self.tr("Remove %n Object(s)", "", selection.size()), self.removeObjects)

        duplicateAction.setIcon(QIcon("/images/16x16/stock-duplicate-16.png"))
        removeAction.setIcon(QIcon("/images/16x16/edit-delete.png"))

        menu.addSeparator()
        menu.addAction(self.tr("Flip Horizontally"), self.flipHorizontally, QKeySequence(self.tr("X")))
        menu.addAction(self.tr("Flip Vertically"), self.flipVertically, QKeySequence(self.tr("Y")))

        objectGroup = RaiseLowerHelper.sameObjectGroup(selection)
        if (objectGroup and objectGroup.drawOrder() == ObjectGroup.DrawOrder.IndexOrder):
            menu.addSeparator()
            menu.addAction(self.tr("Raise Object"), self.raise_, QKeySequence(self.tr("PgUp")))
            menu.addAction(self.tr("Lower Object"), self.lower, QKeySequence(self.tr("PgDown")))
            menu.addAction(self.tr("Raise Object to Top"), self.raiseToTop, QKeySequence(self.tr("Home")))
            menu.addAction(self.tr("Lower Object to Bottom"), self.lowerToBottom, QKeySequence(self.tr("End")))

        if (objectGroups.size() > 1):
            menu.addSeparator()
            moveToLayerMenu = menu.addMenu(self.tr("Move %n Object(s) to Layer", "", selectedObjects.size()))
            for objectGroup in objectGroups:
                action = moveToLayerMenu.addAction(objectGroup.name())
                action.setData(objectGroup)

        menu.addSeparator()
        propIcon = QIcon("images/16x16/document-properties.png")
        propertiesAction = menu.addAction(propIcon, self.tr("Object &Properties..."))
        # TODO Implement editing of properties for multiple objects
        propertiesAction.setEnabled(selectedObjects.size() == 1)

        Utils.setThemeIcon(removeAction, "edit-delete")
        Utils.setThemeIcon(propertiesAction, "document-properties")

        action = menu.exec(screenPos)
        if not action:
            return

        if action == propertiesAction:
            mapObject = selectedObjects.first()
            self.mapDocument().setCurrentObject(mapObject)
            self.mapDocument().emitEditCurrentObject()
            return
        
        objectGroup = action.data()
        if type(objectGroup) == ObjectGroup:
            self.mapDocument().moveObjectsToGroup(self.mapDocument().selectedObjects(), objectGroup)
开发者ID:theall,项目名称:Python-Tiled,代码行数:62,代码来源:abstractobjecttool.py

示例13: create_context_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def create_context_menu(self) -> QMenu:
        menu = QMenu()
        if self.context_menu_pos is None:
            return menu

        selected_label_index = self.model().get_selected_label_index(row=self.rowAt(self.context_menu_pos.y()),
                                                                     column=self.columnAt(self.context_menu_pos.x()))

        if self.model().row_count > 0:
            if selected_label_index == -1:
                label_action = menu.addAction("Create label...")
                label_action.setIcon(QIcon.fromTheme("list-add"))
            else:
                label_action = menu.addAction("Edit label...")
                label_action.setIcon(QIcon.fromTheme("configure"))

            label_action.triggered.connect(self.on_create_or_edit_label_action_triggered)
            menu.addSeparator()

            zoom_menu = menu.addMenu("Zoom font size")
            zoom_menu.addAction(self.zoom_in_action)
            zoom_menu.addAction(self.zoom_out_action)
            zoom_menu.addAction(self.zoom_original_action)
            menu.addSeparator()

        return menu
开发者ID:jopohl,项目名称:urh,代码行数:28,代码来源:TableView.py

示例14: _handle_context_menu_requested

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def _handle_context_menu_requested(self, qpoint):
        index = self.treeView.indexAt(qpoint)
        item = index.internalPointer()

        def add_action(menu, text, handler, icon=None):
            a = None
            if icon is None:
                a = QAction(text, self)
            else:
                a = QAction(icon, text, self)
            a.triggered.connect(handler)
            menu.addAction(a)

        menu = QMenu(self)

        action = None
        if self._is_item_colored(item):
            add_action(menu, "De-color item", lambda: self._handle_clear_color_item(item))
        else:
            add_action(menu, "Color item", lambda: self._handle_color_item(item))
            color_menu = menu.addMenu("Color item...")

            # need to escape the closure capture on the color loop variable below
            # hint from: http://stackoverflow.com/a/6035865/87207
            def make_color_item_handler(item, color):
                return lambda: self._handle_color_item(item, color=color)

            for color in QT_COLORS:
                add_action(color_menu, "{:s}".format(color.name),
                           make_color_item_handler(item, color.qcolor), make_color_icon(color.qcolor))

        add_action(menu, "Set name...", lambda: self._handle_set_name(item))

        menu.exec_(self.treeView.mapToGlobal(qpoint))
开发者ID:HerbDavisY2K,项目名称:python-pyqt5-vstructui,代码行数:36,代码来源:vstructui.py

示例15: open_context_menu_dplugin_tree

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addMenu [as 别名]
    def open_context_menu_dplugin_tree(self, position):
        """
        This callback function is called to create a context menu for the dplugin tree.
        It is triggered by use

        :param position:
        :return:
        """
        index = self.pluginTree.indexAt(position)

        if index.parent().isValid() is False:
            return None

        if index.isValid() is False:
            return None

        if self.pluginTree.isIndexHidden(index):
            return

        dplugin = self.pluginTree.model().data(index, Qt.UserRole)

        menu = QMenu('Menu')

        submenu = QMenu('Action')
        menu.addMenu(submenu)
        action = QAction('Remove plugin', self)
        submenu.addAction(action)

        action.triggered.connect(lambda ignore, p=dplugin.id: self.gui_api.do_delete_plugin(p))

        action = QAction('Copy plugin', self)
        submenu.addAction(action)

        action.triggered.connect(lambda ignore, p=dplugin: self.show_create_plugin_dialog(p))

        actionCollapsAll = QAction('Collapse all',self)
        actionCollapsAll.triggered.connect(self.pluginTree.collapseAll)

        actionExpandAll = QAction('Expand all',self)
        actionExpandAll.triggered.connect(self.pluginTree.expandAll)

        menu.addAction(actionCollapsAll)
        menu.addAction(actionExpandAll)

        menu.exec_(self.pluginTree.viewport().mapToGlobal(position))
开发者ID:TUB-Control,项目名称:PaPI,代码行数:47,代码来源:OverviewPluginMenu.py


注:本文中的PyQt5.QtWidgets.QMenu.addMenu方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。