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


Python QMenu.exec_方法代码示例

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


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

示例1: showContextMenu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
 def showContextMenu(self, pos):
     self._cachedPos = pos
     menu = QMenu(self.parent())
     menu.addAction("Add Anchor…", self._createAnchor)
     menu.addAction("Add Component…", self._createComponent)
     menu.exec_(self._cachedPos)
     self._cachedPos = None
开发者ID:davelab6,项目名称:trufont,代码行数:9,代码来源:selectionTool.py

示例2: _handle_context_menu_requested

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [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

示例3: database_info_tree_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
 def database_info_tree_menu(self, position):
     indexes = self.ui.database_info_tree.selectedIndexes()
     if(len(indexes) > 0):
         level = self.get_node_level(indexes[0])
         index = indexes[0]
     else:
         level = -1
     tree_menu = QMenu()
     if(level == -1):
         tree_menu.addAction(
             self.tr("Create Table"),
             self.create_table(),
             0
         )
     elif(level == 0):
         tree_menu.addAction(
             self.tr("Delete Table"),
             self.delete_table(index.data()),
             0
         )
     elif(level == 1):
         tree_menu = self.database_info_tree_menu_l1(tree_menu, index)
     elif(level == 2):
         tree_menu = self.database_info_tree_menu_l2(tree_menu, index)
     elif(level == 3):
         tree_menu = self.database_info_tree_menu_l3(tree_menu, index)
     tree_menu.exec_(
         self.ui.database_info_tree.viewport().mapToGlobal(position)
     )
开发者ID:jakegt1,项目名称:db-normalization-project,代码行数:31,代码来源:db_main.py

示例4: create_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
 def create_menu(self, position):
     idx = self.indexAt(position)
     item = self.model().itemFromIndex(idx)
     # TODO use siblingAtColumn when min Qt version is >=5.11
     item_addr = self.model().itemFromIndex(idx.sibling(idx.row(), self.Columns.ADDRESS))
     if not item_addr:
         return
     addr = item_addr.text()
     req = self.wallet.receive_requests.get(addr)
     if req is None:
         self.update()
         return
     column = idx.column()
     column_title = self.model().horizontalHeaderItem(column).text()
     column_data = item.text()
     menu = QMenu(self)
     if column != self.Columns.SIGNATURE:
         if column == self.Columns.AMOUNT:
             column_data = column_data.strip()
         menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
     menu.addAction(_("Copy URI"), lambda: self.parent.view_and_paste('URI', '', self.parent.get_request_URI(addr)))
     menu.addAction(_("Save as BIP70 file"), lambda: self.parent.export_payment_request(addr))
     menu.addAction(_("Delete"), lambda: self.parent.delete_payment_request(addr))
     run_hook('receive_list_menu', menu, addr)
     menu.exec_(self.viewport().mapToGlobal(position))
开发者ID:vialectrum,项目名称:vialectrum,代码行数:27,代码来源:request_list.py

示例5: layercontextmenu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [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

示例6: __showContextMenu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
 def __showContextMenu(self):
     """
     Private slot to show the context menu.
     """
     menu = QMenu()
     act = menu.addAction(self.tr("Object blocked by ClickToFlash"))
     font = act.font()
     font.setBold(True)
     act.setFont(font)
     menu.addAction(
         self.tr("Show information about object"), self.__showInfo)
     menu.addSeparator()
     menu.addAction(self.tr("Load"), self.__load)
     menu.addAction(self.tr("Delete object"), self.__hideAdBlocked)
     menu.addSeparator()
     host = self.__url.host()
     add = menu.addAction(
         self.tr("Add '{0}' to Whitelist").format(host),
         self.__addToWhitelist)
     remove = menu.addAction(
         self.tr("Remove '{0}' from Whitelist").format(host),
         self.__removeFromWhitelist)
     onWhitelist = self.__plugin.onWhitelist(host)
     add.setEnabled(not onWhitelist)
     remove.setEnabled(onWhitelist)
     menu.addSeparator()
     menu.addAction(self.tr("Configure Whitelist"), self.__configure)
     menu.actions()[0].setEnabled(False)
     
     menu.exec_(QCursor.pos())
开发者ID:testmana2,项目名称:test,代码行数:32,代码来源:ClickToFlash.py

示例7: create_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
    def create_menu(self, position):
        menu = QMenu()
        idx = self.indexAt(position)
        column = idx.column() or 0
        selected_keys = []
        for s_idx in self.selected_in_column(0):
            sel_key = self.model().itemFromIndex(s_idx).data(Qt.UserRole)
            selected_keys.append(sel_key)
        if not selected_keys or not idx.isValid():
            menu.addAction(_("New contact"), lambda: self.parent.new_contact_dialog())
            menu.addAction(_("Import file"), lambda: self.import_contacts())
            menu.addAction(_("Export file"), lambda: self.export_contacts())
        else:
            column_title = self.model().horizontalHeaderItem(column).text()
            column_data = '\n'.join(self.model().itemFromIndex(s_idx).text()
                                    for s_idx in self.selected_in_column(column))
            menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
            if column in self.editable_columns:
                item = self.model().itemFromIndex(idx)
                if item.isEditable():
                    # would not be editable if openalias
                    persistent = QPersistentModelIndex(idx)
                    menu.addAction(_("Edit {}").format(column_title), lambda p=persistent: self.edit(QModelIndex(p)))
            menu.addAction(_("Pay to"), lambda: self.parent.payto_contacts(selected_keys))
            menu.addAction(_("Delete"), lambda: self.parent.delete_contacts(selected_keys))
            URLs = [block_explorer_URL(self.config, 'addr', key) for key in filter(is_address, selected_keys)]
            if URLs:
                menu.addAction(_("View on block explorer"), lambda: [webbrowser.open(u) for u in URLs])

        run_hook('create_contact_menu', menu, selected_keys)
        menu.exec_(self.viewport().mapToGlobal(position))
开发者ID:thrasher-,项目名称:electrum-ltc,代码行数:33,代码来源:contact_list.py

示例8: contextMenuEvent

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
    def contextMenuEvent(self, event):
        from_index = self._table.indexAt(event.pos())
        if not (0 <= from_index.row() < self.model.rowCount()):
            return

        # The context menu event is the same regardless of the selected column
        # Therefore ColumnID is set such that the label name is retrieved
        from_index_to_name = self.model.index(from_index.row(), LabelListModel.ColumnID.Name)

        from_name = self.model.data(from_index_to_name, Qt.DisplayRole)
        menu = QMenu(parent=self)
        menu.addAction(
            "Clear {}".format(from_name),
            partial(self.clearRequested.emit, from_index_to_name.row(), str(from_name))
        )

        if self.support_merges and self.allowDelete:
            for to_row in range(self.model.rowCount()):
                to_index = self.model.index(to_row, LabelListModel.ColumnID.Name)
                to_name = self.model.data(to_index, Qt.DisplayRole)
                action = menu.addAction( "Merge {} into {}".format( from_name, to_name ),
                                         partial( self.mergeRequested.emit, from_index_to_name.row(), str(from_name),
                                                                            to_row,           str(to_name)) )
                if to_row == from_index_to_name.row():
                    action.setEnabled(False)

        menu.exec_( self.mapToGlobal(event.pos()) )
开发者ID:DerThorsten,项目名称:ilastik,代码行数:29,代码来源:labelListView.py

示例9: contextMenuEvent

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
    def contextMenuEvent(self, event):
        # Update selection
        self.updateSelection()

        # Set context menu mode
        app = get_app()
        app.context_menu_object = "files"

        menu = QMenu(self)

        menu.addAction(self.win.actionImportFiles)
        menu.addAction(self.win.actionDetailsView)
        if self.selected:
            # If file selected, show file related options
            menu.addSeparator()

            # Add edit title option (if svg file)
            selected_file_id = self.win.selected_files[0]
            file = File.get(id=selected_file_id)
            if file and file.data.get("path").endswith(".svg"):
                menu.addAction(self.win.actionEditTitle)
                menu.addAction(self.win.actionDuplicateTitle)
                menu.addSeparator()

            menu.addAction(self.win.actionPreview_File)
            menu.addAction(self.win.actionSplitClip)
            menu.addAction(self.win.actionAdd_to_Timeline)
            menu.addAction(self.win.actionFile_Properties)
            menu.addSeparator()
            menu.addAction(self.win.actionRemove_from_Project)
            menu.addSeparator()

        # Show menu
        menu.exec_(QCursor.pos())
开发者ID:OpenShot,项目名称:openshot-qt,代码行数:36,代码来源:files_listview.py

示例10: node_context_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
    def node_context_menu(self, point):
        index = self.table_network.indexAt(point)
        model = self.table_network.model()
        if index.isValid() and index.row() < model.rowCount(QModelIndex()):
            source_index = model.mapToSource(index)
            is_root_col = model.sourceModel().columns_types.index('is_root')
            is_root_index = model.sourceModel().index(source_index.row(), is_root_col)
            is_root = model.sourceModel().data(is_root_index, Qt.DisplayRole)

            menu = QMenu()
            if is_root:
                unset_root = QAction(self.tr("Unset root node"), self)
                unset_root.triggered.connect(self.unset_root_node)
                unset_root.setData(self.community.network.root_node_index(source_index.row()))
                if len(self.community.network.root_nodes) > 1:
                    menu.addAction(unset_root)
            else:
                set_root = QAction(self.tr("Set as root node"), self)
                set_root.triggered.connect(self.set_root_node)
                set_root.setData(self.community.network.nodes[source_index.row()])
                menu.addAction(set_root)

            if self.app.preferences['expert_mode']:
                open_in_browser = QAction(self.tr("Open in browser"), self)
                open_in_browser.triggered.connect(self.open_node_in_browser)
                open_in_browser.setData(self.community.network.nodes[source_index.row()])
                menu.addAction(open_in_browser)

            # Show the context menu.
            menu.exec_(QCursor.pos())
开发者ID:c-geek,项目名称:sakia,代码行数:32,代码来源:network_tab.py

示例11: on_header_sectionClicked

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
   def on_header_sectionClicked(self, logicalIndex):
       """opens a dialog to choose between all unique values for this column,
       or revert to 'All'
       """
       self.log.debug("Header clicked: column {}".format(logicalIndex))
       self.logicalIndex = logicalIndex
       menuValues = QMenu(self)
       self.signalMapper = QSignalMapper(self)  
 
       self.filter_cb.setCurrentIndex(self.logicalIndex)
       self.filter_cb.blockSignals(True)
       self.proxy.setFilterKeyColumn(self.logicalIndex)
       
       valuesUnique = [str(self.model.index(row, self.logicalIndex).data())
                       for row in range(self.model.rowCount())
                       ]
       
       actionAll = QAction("All", self)
       actionAll.triggered.connect(self.on_actionAll_triggered)
       menuValues.addAction(actionAll)
       menuValues.addSeparator()
       
       for actionNumber, actionName in enumerate(sorted(list(set(valuesUnique)))):              
           action = QAction(actionName, self)
           self.signalMapper.setMapping(action, actionNumber)  
           action.triggered.connect(self.signalMapper.map)  
           menuValues.addAction(action)
 
       self.signalMapper.mapped.connect(self.on_signalMapper_mapped)  
 
       headerPos = self.table.mapToGlobal(self.header.pos())        
       posY = headerPos.y() + self.header.height()
       posX = headerPos.x() + self.header.sectionViewportPosition(self.logicalIndex)
 
       menuValues.exec_(QPoint(posX, posY))
开发者ID:DKMS-LSL,项目名称:typeloader,代码行数:37,代码来源:GUI_overviews.py

示例12: create_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
    def create_menu(self, position):
        menu = QMenu()
        selected = self.selectedItems()
        if not selected:
            menu.addAction(_("New contact"), lambda: self.parent.new_contact_dialog())
            menu.addAction(_("Import file"), lambda: self.import_contacts())
            menu.addAction(_("Export file"), lambda: self.export_contacts())
        else:
            names = [item.text(0) for item in selected]
            keys = [item.text(1) for item in selected]
            column = self.currentColumn()
            column_title = self.headerItem().text(column)
            column_data = '\n'.join([item.text(column) for item in selected])
            menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
            if column in self.editable_columns:
                item = self.currentItem()
                menu.addAction(_("Edit {}").format(column_title), lambda: self.editItem(item, column))
            menu.addAction(_("Pay to"), lambda: self.parent.payto_contacts(keys))
            menu.addAction(_("Delete"), lambda: self.parent.delete_contacts(keys))
            URLs = [block_explorer_URL(self.config, 'addr', key) for key in filter(is_address, keys)]
            if URLs:
                menu.addAction(_("View on block explorer"), lambda: map(webbrowser.open, URLs))

        run_hook('create_contact_menu', menu, selected)
        menu.exec_(self.viewport().mapToGlobal(position))
开发者ID:asfin,项目名称:electrum,代码行数:27,代码来源:contact_list.py

示例13: contextMenuEvent

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
    def contextMenuEvent(self,event):
        # print(dir(event))
        rightMenu = QMenu(self)
        # rightMenu.setWindowOpacity(0.9); 
        # pos = QGraphicsColorizeEffect(rightMenu)
        # pos.setColor(QColor("red"))
        # pos.setStrength()
        # rightMenu.setGraphicsEffect(pos)
        

        # print(dir(rightMenu))
        rightMenu.setStyleSheet(qss_rightmenu) 
        loveAction = QAction(u"添加收藏", self, triggered=self.noexc)
        delAction = QAction(u"删除文件", self, triggered=self.deleteSongItem)    
        rateAction = QAction(u"我要打分", self, triggered=self.noexc)    
        cmAction = QAction(u"评论", self, triggered=self.noexc)  
        moreAction = QAction(u"歌曲详情", self, triggered=self.noexc)  
        moneyAction = QAction(u"打赏", self, triggered=self.noexc)  
        rightMenu.addAction(loveAction)
        rightMenu.addAction(delAction)
        rightMenu.addAction(rateAction)
        rightMenu.addAction(cmAction)
        rightMenu.addAction(moreAction)
        rightMenu.addAction(moneyAction)
        rightMenu.exec_(QCursor.pos())
开发者ID:codeAB,项目名称:music-player,代码行数:27,代码来源:mywidget.py

示例14: contextMenuEvent

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
    def contextMenuEvent(self, event):
        """
        Reimplemented to show various options depending on location of click.

        :param PyQt5.QtGui.QContextMenuEvent.QContextMenuEvent event:
        :return:
        """
        menu=QMenu(self)

        # if they've set a new root dir, show option to unset
        if self.user_toplevel_dir:
            menu.addAction(self.action_unset_toplevel)

        # get item under cursor
        clikked = self.itemAt(event.pos())

        if not isinstance(clikked, ArchiveItem):
            self.context_menu_item = None
        else:
            self.context_menu_item = clikked

            if clikked.isdir:
                self.context_menu_item = clikked
                menu.addAction(self.action_set_toplevel)

            menu.addAction(self.action_rename)

        menu.addAction(self.action_create_directory)

        menu.exec_(event.globalPos())
开发者ID:Kf4btg,项目名称:SkyModMan,代码行数:32,代码来源:mytreewidget.py

示例15: __customContextMenuRequested

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import exec_ [as 别名]
 def __customContextMenuRequested(self, pos):
     """
     Private slot to handle the context menu request for the bookmarks tree.
     
     @param pos position the context menu was requested (QPoint)
     """
     from .BookmarkNode import BookmarkNode
     
     menu = QMenu()
     idx = self.bookmarksTree.indexAt(pos)
     idx = idx.sibling(idx.row(), 0)
     sourceIndex = self.__proxyModel.mapToSource(idx)
     node = self.__bookmarksModel.node(sourceIndex)
     if idx.isValid() and node.type() != BookmarkNode.Folder:
         menu.addAction(
             self.tr("&Open"), self.__openBookmarkInCurrentTab)
         menu.addAction(
             self.tr("Open in New &Tab"), self.__openBookmarkInNewTab)
         menu.addSeparator()
     act = menu.addAction(self.tr("Edit &Name"), self.__editName)
     act.setEnabled(idx.flags() & Qt.ItemIsEditable)
     if idx.isValid() and node.type() != BookmarkNode.Folder:
         menu.addAction(self.tr("Edit &Address"), self.__editAddress)
     menu.addSeparator()
     act = menu.addAction(
         self.tr("&Delete"), self.bookmarksTree.removeSelected)
     act.setEnabled(idx.flags() & Qt.ItemIsDragEnabled)
     menu.addSeparator()
     act = menu.addAction(self.tr("&Properties..."), self.__edit)
     act.setEnabled(idx.flags() & Qt.ItemIsEditable)
     menu.exec_(QCursor.pos())
开发者ID:pycom,项目名称:EricShort,代码行数:33,代码来源:BookmarksDialog.py


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