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


Python QMenu.addAction方法代码示例

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


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

示例1: contextMenuEvent

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [as 别名]
 def contextMenuEvent(self, event):
     menu = QMenu(self)
     local_filename = self.currentItem().text()
     # Get the file extension
     ext = os.path.splitext(local_filename)[1].lower()
     open_internal_action = None
     # Mu micro:bit mode only handles .py & .hex
     if ext == '.py' or ext == '.hex':
         open_internal_action = menu.addAction(_("Open in Mu"))
     # Open outside Mu (things get meta if Mu is the default application)
     open_action = menu.addAction(_("Open"))
     action = menu.exec_(self.mapToGlobal(event.pos()))
     if action == open_action:
         # Get the file's path
         path = os.path.join(self.home, local_filename)
         logger.info("Opening {}".format(path))
         msg = _("Opening '{}'").format(local_filename)
         logger.info(msg)
         self.set_message.emit(msg)
         # Let Qt work out how to open it
         QDesktopServices.openUrl(QUrl.fromLocalFile(path))
     elif action == open_internal_action:
         logger.info("Open {} internally".format(local_filename))
         # Get the file's path
         path = os.path.join(self.home, local_filename)
         # Send the signal bubbling up the tree
         self.open_file.emit(path)
开发者ID:martinohanlon,项目名称:mu,代码行数:29,代码来源:panes.py

示例2: contextMenuEvent

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [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()
            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:Algomorph,项目名称:openshot-qt,代码行数:27,代码来源:files_listview.py

示例3: CurrentPlaylistTable

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [as 别名]
class CurrentPlaylistTable(MusicTable):
    remove_signal = pyqtSignal([int])   # song id

    def __init__(self, app):
        super().__init__(app)
        self._app = app

        self._row = 0

        self.menu = QMenu()
        self.remove = QAction('从当前列表中移除', self)
        self.menu.addAction(self.remove)

        self.remove.triggered.connect(self.remove_song)

    def contextMenuEvent(self, event):
        point = event.pos()
        item = self.itemAt(point)
        if item is not None:
            row = self.row(item)
            self._row = row
            self.menu.exec(event.globalPos())

    def remove_song(self):
        song = self.songs[self._row]
        self.songs.pop(self._row)
        self.removeRow(self._row)
        self.remove_signal.emit(song.mid)
开发者ID:leohazy,项目名称:FeelUOwn,代码行数:30,代码来源:ui.py

示例4: cb_backends

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

        self.cb_backends.addItem('Auto')

        menuLyricSource = QMenu(self.ui.menuEdit)
        menuLyricSource.setTitle('Lyric source')

        self.lyricGroup = QActionGroup(self)

        def addAction(name, checked=False):
            action = QAction(name, self)
            action.setText(name)
            action.setCheckable(True)
            action.setChecked(checked)
            action.setActionGroup(self.lyricGroup)

            return action

        menuLyricSource.addAction(addAction('Auto', True))
        menuLyricSource.addSeparator()
        menuLyricSource.triggered.connect(self._menu_backend_change)

        for backend in Pyrics.get_backends():
            menuLyricSource.addAction(addAction(backend.__name__))
            self.cb_backends.addItem(backend.__name__)

        self.ui.menuEdit.addMenu(menuLyricSource)
        self.ui.toolBar.addWidget(self.cb_backends)

        self.cb_backends.currentIndexChanged.connect(self._cb_backend_change)
开发者ID:xcution,项目名称:pyrics,代码行数:33,代码来源:qpyrics.py

示例5: create_context_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [as 别名]
    def create_context_menu(self) -> QMenu:
        menu = QMenu(self)
        index = self.model().mapToSource(self.currentIndex())  # type: QModelIndex
        if index.isValid():
            current_index_info = self.model().sourceModel().fileInfo(index)  # type: QFileInfo
            if current_index_info.isDir():
                if os.path.isfile(os.path.join(current_index_info.filePath(), constants.PROJECT_FILE)):
                    open_action = menu.addAction("Open project")
                    open_action.setIcon(QIcon(":/icons/data/icons/appicon.png"))
                else:
                    open_action = menu.addAction("Open folder")
                    open_action.setIcon(QIcon.fromTheme("folder-open"))
                open_action.triggered.connect(self.on_open_action_triggered)

        new_dir_action = menu.addAction("New folder")
        new_dir_action.setIcon(QIcon.fromTheme("folder"))
        new_dir_action.triggered.connect(self.create_directory)

        del_action = menu.addAction("Delete")
        del_action.setIcon(QIcon.fromTheme("edit-delete"))
        del_action.triggered.connect(self.remove)

        menu.addSeparator()
        open_in_explorer_action = menu.addAction("Open in file manager...")
        open_in_explorer_action.triggered.connect(self.on_open_explorer_action_triggered)

        return menu
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:29,代码来源:DirectoryTreeView.py

示例6: createSubMenu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [as 别名]
 def createSubMenu(self, menu, view, hitTestResult):
     """
     Public method to create the personal information sub-menu.
     
     @param menu reference to the main menu (QMenu)
     @param view reference to the view (HelpBrowser)
     @param hitTestResult reference to the hit test result
         (QWebHitTestResult)
     """
     self.__view = view
     self.__element = hitTestResult.element()
     
     if not hitTestResult.isContentEditable():
         return
     
     if not self.__loaded:
         self.__loadSettings()
     
     submenu = QMenu(self.tr("Insert Personal Information"), menu)
     submenu.setIcon(UI.PixmapCache.getIcon("pim.png"))
     
     for key, info in sorted(self.__allInfo.items()):
         if info:
             act = submenu.addAction(
                 self.__translations[key], self.__insertData)
             act.setData(info)
     
     submenu.addSeparator()
     submenu.addAction(self.tr("Edit Personal Information"),
                       self.showConfigurationDialog)
     
     menu.addMenu(submenu)
     menu.addSeparator()
开发者ID:testmana2,项目名称:test,代码行数:35,代码来源:PersonalInformationManager.py

示例7: __init__

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

        ui_class, widget_class = uic.loadUiType(os.path.split(__file__)[0] + "/zmqPubSubInfoWidget.ui")
        self.ui = ui_class()
        self.ui.setupUi(self)

        self.status = {
            "pub": {
                "address": None,
                "running": False
            },
            "sub": {
                "address": None,
                "running": False
            }
        }

        self.ui.toggleSubStatus.clicked.connect(partial(self.ui.toggleSubStatus.setEnabled, False))
        self.ui.togglePubStatus.clicked.connect(partial(self.ui.togglePubStatus.setEnabled, False))
        self.ui.toggleSubStatus.clicked.connect(self.subStatusToggled.emit)
        self.ui.togglePubStatus.clicked.connect(self.pubStatusToggled.emit)

        menu = QMenu("options")
        self.change_pub_addr_action = menu.addAction("Change Address", self.changePubAddress.emit)
        self.ui.togglePubStatus.setMenu(menu)

        menu = QMenu("options")
        self.change_sub_addr_action = menu.addAction("Change Address", self.changeSubAddress.emit)
        self.ui.toggleSubStatus.setMenu(menu)

        self.status_style = "background-color: %s; border: 3px inset gray; padding: 5px"
开发者ID:DerThorsten,项目名称:ilastik,代码行数:34,代码来源:zmqPubSubInfoWidget.py

示例8: show_id_context_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [as 别名]
    def show_id_context_menu(self, position):
        current_id = -1
        try:
            current_id = int(self.__ui.lbl_uav_id.text())
        except Exception:
            #print("Don't show the menu")
            return

        menu = QMenu()
        menu.addAction("Show Mission for " + str(current_id))
        menu.addAction("Show Fence for " + str(current_id))

        global_position = self.__ui.lbl_uav_id.mapToGlobal(position)
        selectedItem = menu.exec(global_position)
        
        if selectedItem.text()[0:12] == "Show Mission":
            if self.fetching_mission_for == -1: #prevent concurrent fetches
                self.fetching_mission_for = current_id
                
                self.wpFetchThread = WaypointFetchThread(self, self.__hm_state,
                                                        current_id)
                self.wpFetchThread.start()

            elif self.fetching_mission_for != current_id:
                QMessageBox.error(self, "Still fetching waypoints for " + str(current_id),
                    "Still fetching waypoints for " + str(current_id) + "\n\nCan't fetch multiple waypoints concurrently.  Wait a few more seconds for the previous fetch operation to finish.")
                return
        
        elif selectedItem.text()[0:10] == "Show Fence":
            self.fenFetchThread = FenceFetchThread(self, self.__hm_state,
                                                    current_id)
            self.fenFetchThread.start()
开发者ID:dtdavi1,项目名称:acs_dashboards,代码行数:34,代码来源:health_mon_main_wrapper.py

示例9: PredicateNodeInfo

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [as 别名]
class PredicateNodeInfo(NodeInfo):
    """
    This class implements the information box for predicate nodes.
    """
    def __init__(self, mainwindow, parent=None):
        """
        Initialize the predicate node information box.
        """
        super().__init__(mainwindow, parent)

        self.brushKey = Key('Color', self)
        self.brushMenu = QMenu(self)
        for action in self.mainwindow.actionsChangeNodeBrush:
            self.brushMenu.addAction(action)
        self.brushButton = Button()
        self.brushButton.setMenu(self.brushMenu)
        self.brushButton.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        self.nodePropLayout.addRow(self.brushKey, self.brushButton)

    def updateData(self, node):
        """
        Fetch new information and fill the widget with data.
        :type node: AbstractNode
        """
        super().updateData(node)
        for action in self.mainwindow.actionsChangeNodeBrush:
            color = action.data()
            brush = QBrush(QColor(color.value))
            if node.brush == brush:
                self.brushButton.setIcon(ColoredIcon(12, 12, color.value, '#000000'))
                self.brushButton.setText(color.value)
                break
开发者ID:gitter-badger,项目名称:eddy,代码行数:35,代码来源:info.py

示例10: create_context_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [as 别名]
    def create_context_menu(self):
        menu = QMenu()
        menu.setToolTipsVisible(True)
        self._add_zoom_actions_to_menu(menu)

        if self.something_is_selected:
            filter_bw = Filter.read_configured_filter_bw()
            text = self.tr("Apply bandpass filter (filter bw={0:n})".format(filter_bw))
            create_from_frequency_selection = menu.addAction(text)
            create_from_frequency_selection.triggered.connect(self.on_create_from_frequency_selection_triggered)
            create_from_frequency_selection.setIcon(QIcon.fromTheme("view-filter"))

            try:
                cancel_button = " or ".join(k.toString() for k in QKeySequence.keyBindings(QKeySequence.Cancel))
            except Exception as e:
                logger.debug("Error reading cancel button: " + str(e))
                cancel_button = "Esc"

            create_from_frequency_selection.setToolTip("You can abort filtering with <b>{}</b>.".format(cancel_button))

        configure_filter_bw = menu.addAction(self.tr("Configure filter bandwidth..."))
        configure_filter_bw.triggered.connect(self.on_configure_filter_bw_triggered)
        configure_filter_bw.setIcon(QIcon.fromTheme("configure"))

        menu.addSeparator()

        export_fta_action = menu.addAction("Export spectrogram...")
        export_fta_action.triggered.connect(self.on_export_fta_action_triggered)

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

示例11: ApplicationWindow

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [as 别名]
class ApplicationWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowTitle("application main window")

        self.file_menu = QMenu('&File', self)
        self.file_menu.addAction('&Quit', self.fileQuit,
        QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
        self.menuBar().addMenu(self.file_menu)

        self.help_menu = QMenu('&Help', self)
        self.menuBar().addSeparator()
        self.menuBar().addMenu(self.help_menu)

        self.main_widget = QWidget(self)

        l = QVBoxLayout(self.main_widget)
        sc = MyStaticMplCanvas(self.main_widget, width=5, height=4, dpi=100)
        dc = MyDynamicMplCanvas(self.main_widget, width=5, height=4, dpi=100)
        l.addWidget(sc)
        l.addWidget(dc)

        self.main_widget.setFocus()
        self.setCentralWidget(self.main_widget)

        self.statusBar().showMessage("All hail matplotlib!", 2000)

    def fileQuit(self):
        self.close()

    def closeEvent(self, ce):
        self.fileQuit()
开发者ID:corps-g,项目名称:kivy-miniapps,代码行数:35,代码来源:dynamicgraph.py

示例12: buildWidget

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [as 别名]
    def buildWidget(self):
        layout = QHBoxLayout(self)
        layout.setContentsMargins(0,0,0,0)
        SettingMenu = QMenu()
        exitButton = QAction(QIcon('exit24.png'), 'Set As High', self)
        exitButton.triggered.connect(self.setHigh)
        SettingMenu.addAction(exitButton)
        setlowButton = QAction(QIcon('exit24.png'), 'Set As Low', self)
        setlowButton.triggered.connect(self.setLow)
        SettingMenu.addAction(setlowButton)

        self.tb_down = QToolButton()
        self.tb_down.pressed.connect(self.on_click_down)
        self.tb_down.released.connect(self.on_released)
        self.tb_down.setArrowType(Qt.LeftArrow)

        self.tb_up = QToolButton()
        self.tb_up.pressed.connect(self.on_click_up)
        self.tb_up.released.connect(self.on_released)
        self.tb_up.setArrowType(Qt.RightArrow)

        if self.showToggleButton:
            tb_set = QToolButton()
            tb_set.clicked.connect(self.on_click_set_value)
            tb_set.setText('<>')
            if self.showSettingMenu:
                tb_set.setMenu(SettingMenu)
                tb_set.setPopupMode(QToolButton.DelayedPopup)

        layout.addWidget(self.tb_down)
        layout.addWidget(self.bar)
        layout.addWidget(self.tb_up)
        if self.showToggleButton:
            layout.addWidget(tb_set)
        layout.setSpacing(0)
开发者ID:LinuxCNC,项目名称:linuxcnc,代码行数:37,代码来源:adjustment_bar.py

示例13: Systray

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [as 别名]
class Systray(QObject):
    trayIconMenu = None

    def __init__(self, parent):
        super().__init__(parent)

        self.trayIconMenu = QMenu(None)

        icon = QIcon(":/image/thunder.ico")

        self.trayIcon = CompatSystemTrayIcon(self)
        self.trayIcon.setIcon(icon)
        self.trayIcon.setContextMenu(self.trayIconMenu)
        self.trayIcon.setVisible(True)

        self.trayIcon.activated.connect(self.slotSystrayActivated)
        self.trayIconMenu.addAction(app.mainWin.action_exit)

    @pyqtSlot(QSystemTrayIcon.ActivationReason)
    def slotSystrayActivated(self, reason):
        if reason == QSystemTrayIcon.Context:  # right
            pass
        elif reason == QSystemTrayIcon.MiddleClick:  # middle
            pass
        elif reason == QSystemTrayIcon.DoubleClick:  # double click
            pass
        elif reason == QSystemTrayIcon.Trigger:  # left
            if app.mainWin.isHidden() or app.mainWin.isMinimized():
                app.mainWin.restore()
            else:
                app.mainWin.minimize()
开发者ID:0rient,项目名称:XwareDesktop,代码行数:33,代码来源:systray.py

示例14: contextMenuEvent

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

示例15: addShowActions

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import addAction [as 别名]
    def addShowActions(self):
        """Adds a submenu giving access to the (other)
        opened viewer documents"""
        mds = self._actionCollection.viewer_document_select
        docs = mds.viewdocs()
        document_actions = {}
        multi_docs = len(docs) > 1
        if self._panel.widget().currentViewdoc():
            current_doc_filename = self._panel.widget().currentViewdoc().filename()

        m = self._menu
        sm = QMenu(m)
        sm.setTitle(_("Show..."))
        sm.setEnabled(multi_docs)
        ag = QActionGroup(m)
        ag.triggered.connect(self._panel.slotShowViewdoc)

        for d in docs:
            action = QAction(sm)
            action.setText(d.name())
            action._document_filename = d.filename()
            # TODO: Tooltips aren't shown by Qt (it seems)
            action.setToolTip(d.filename())
            action.setCheckable(True)
            action.setChecked(d.filename() == current_doc_filename)

            ag.addAction(action)
            sm.addAction(action)

        m.addSeparator()
        m.addMenu(sm)
开发者ID:19joho66,项目名称:frescobaldi,代码行数:33,代码来源:contextmenu.py


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