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


Python QMenu.isEmpty方法代码示例

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


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

示例1: contextMenuEvent

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

示例2: contextMenuEvent

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import isEmpty [as 别名]
 def contextMenuEvent(self, event):
     cursor = self._neditor.cursorForPosition(QPoint(0, event.pos().y()))
     menu = QMenu(self)
     self.sidebarContextMenuRequested.emit(cursor.blockNumber(), menu)
     if not menu.isEmpty():
         menu.exec_(event.globalPos())
     menu.deleteLater()
     event.accept()
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:10,代码来源:__init__.py

示例3: _fill_context_menu_with_model_item_actions

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import isEmpty [as 别名]
    def _fill_context_menu_with_model_item_actions(self, context_menu: QMenu):
        """
        Find all model items that should be available in the context menu and create QActions for each, by
        using the available logic in popupmenu.PopupMenu.
        """
        # Get phrase folders to add to main menu
        logger.info("Rebuilding model item actions, adding all items marked for access through the tray icon.")
        folders = [folder for folder in self.config_manager.allFolders if folder.show_in_tray_menu]
        items = [item for item in self.config_manager.allItems if item.show_in_tray_menu]
        # Only extract the QActions, but discard the PopupMenu instance.
        # This is done, because the PopupMenu class is not directly usable as a context menu here.
        menu = popupmenu.PopupMenu(self.app.service, folders, items, False, "AutoKey")
        new_item_actions = menu.actions()
        context_menu.addActions(new_item_actions)
        for action in new_item_actions:  # type: QAction
            # QMenu does not take the ownership when adding QActions, so manually re-parent all actions.
            # This causes the QActions to be destroyed when the context menu is cleared or re-created.
            action.setParent(context_menu)

        if not context_menu.isEmpty():
            # Avoid a stray separator line, if no items are marked for display in the context menu.
            context_menu.addSeparator()
开发者ID:autokey,项目名称:autokey,代码行数:24,代码来源:notifier.py

示例4: __addExtensionsMenu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import isEmpty [as 别名]
 def __addExtensionsMenu(self, menu, key):
     """
     Private method to add an extension menu entry.
     
     @param menu menu to add it to (QMenu)
     @param key menu key (string, one of 'mainMenu', 'multiMenu',
         'backMenu', 'dirMenu' or 'dirMultiMenu')
     @return reference to the menu action (QAction)
     """
     act = None
     if key in ['mainMenu', 'multiMenu', 'backMenu', 'dirMenu',
                'dirMultiMenu']:
         extensionsMenu = QMenu(self.tr("Extensions"), menu)
         extensionsMenu.setTearOffEnabled(True)
         for extensionMenuTitle in sorted(self.__extensionMenuTitles):
             extensionName = self.__extensionMenuTitles[extensionMenuTitle]
             if key in self.__extensionMenus[extensionName]:
                 extensionsMenu.addMenu(
                     self.__extensionMenus[extensionName][key])
         if not extensionsMenu.isEmpty():
             if not menu.isEmpty():
                 menu.addSeparator()
             act = menu.addMenu(extensionsMenu)
     return act
开发者ID:Darriall,项目名称:eric,代码行数:26,代码来源:ProjectBrowserHelper.py

示例5: CommandButton

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import isEmpty [as 别名]
class CommandButton(QToolButton):
    def __init__(self, parent):
        super().__init__(parent)
        self.mMenu = QMenu(self)

        self.setIcon(QIcon(":images/24x24/system-run.png"))
        Utils.setThemeIcon(self, "system-run")
        self.retranslateUi()
        self.setPopupMode(QToolButton.MenuButtonPopup)
        self.setMenu(self.mMenu)
        self.mMenu.aboutToShow.connect(self.populateMenu)
        self.clicked.connect(self.runCommand)

    def changeEvent(self, event):
        super().changeEvent(event)
        x = event.type()
        if x==QEvent.LanguageChange:
            self.retranslateUi()
        else:
            pass

    def runCommand(self):
        command = Command()
        action = self.sender()
        if (type(action)==QAction and action.data()):
            #run the command passed by the action
            command = Command.fromQVariant(action.data())
        else:
            #run the default command
            command = CommandDataModel(self).firstEnabledCommand()
            if (not command.isEnabled):
                msgBox = QMessageBox(self.window())
                msgBox.setIcon(QMessageBox.Warning)
                msgBox.setWindowTitle(self.tr("Error Executing Command"))
                msgBox.setText(self.tr("You do not have any commands setup."))
                msgBox.addButton(QMessageBox.Ok)
                msgBox.addButton(self.tr("Edit commands..."), QMessageBox.ActionRole)
                msgBox.setDefaultButton(QMessageBox.Ok)
                msgBox.setEscapeButton(QMessageBox.Ok)
                button = msgBox.buttons()[-1]
                button.clicked.connect(self.showDialog)
                msgBox.exec()
                return

        command.execute()

    def showDialog(self):
        dialog = CommandDialog(self.window())
        dialog.exec()

    def populateMenu(self):
        self.mMenu.clear()
        # Use a data model for getting the command list to avoid having to
        # manually parse the settings
        model = CommandDataModel(self)
        commands = model.allCommands()
        for command in commands:
            if (not command.isEnabled):
                continue
            action = self.mMenu.addAction(command.name)
            action.setStatusTip(command.command)
            action.setData(command.toQVariant())
            action.triggered.connect(self.runCommand)

        if (not self.mMenu.isEmpty()):
            self.mMenu.addSeparator()
        # Add "Edit Commands..." action
        action = self.mMenu.addAction(self.tr("Edit Commands..."))
        action.triggered.connect(self.showDialog)

    def retranslateUi(self):
        self.setToolTip(self.tr("Execute Command"))
        self.setShortcut(QKeySequence(self.tr("F5")))
开发者ID:theall,项目名称:Python-Tiled,代码行数:75,代码来源:commandbutton.py


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