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


Python QAction.setEnabled方法代码示例

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


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

示例1: layercontextmenu

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

示例2: fetchAction

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
 def fetchAction(self, text, callback=None, shortcut=None):
     if shortcut is None:
         shortcut = _shortcuts.get(text)
     text = _trMenuString(text)
     action = None
     # cache lookup
     action = None
     for action_ in self.actions():
         if action_.text() == text:
             action = action_
     # spawn
     if action is None:
         action = QAction(text, self)
         if self.shouldSpawnElements():
             self.addAction(action)
     # connect
     action.setEnabled(True)
     try:
         action.triggered.disconnect()
     except TypeError:
         pass
     if callback is not None:
         action.triggered.connect(lambda: callback())
     action.setShortcut(QKeySequence(shortcut))
     return action
开发者ID:anthrotype,项目名称:trufont,代码行数:27,代码来源:menu.py

示例3: eventFilter

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
    def eventFilter(self, o, e):
        if o == self.m_lineEdit and e.type() == QEvent.ContextMenu:
            c = e
            menu = self.m_lineEdit.createStandardContextMenu()
            actions = menu.actions()
            for action in actions:
                action.setShortcut(QKeySequence())
                actionString = action.text()
                pos = actionString.rfind('\t')
                if (pos > 0):
                    actionString = actionString[:pos]
                action.setText(actionString)

            actionBefore = None
            if (len(actions) > 0):
                actionBefore = actions[0]
            clearAction = QAction(self.tr("Clear Shortcut"), menu)
            menu.insertAction(actionBefore, clearAction)
            menu.insertSeparator(actionBefore)
            clearAction.setEnabled(not len(self.m_keySequence)<=0)
            clearAction.triggered.connect(self.slotClearShortcut)
            menu.exec(c.globalPos())
            e.accept()
            return True

        return super(QtKeySequenceEdit, self).eventFilter(o, e)
开发者ID:theall,项目名称:Python-Tiled,代码行数:28,代码来源:qtpropertybrowserutils.py

示例4: add_action

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
    def add_action(
            self,
            icon_path,
            text,
            callback,
            enabled_flag=True,
            add_to_menu=True,
            add_to_toolbar=True,
            status_tip=None,
            whats_this=None,
            parent=None):
        """Add a toolbar icon to the toolbar."""

        icon = QIcon(icon_path)
        action = QAction(icon, text, parent)
        action.triggered.connect(callback)
        action.setEnabled(enabled_flag)

        if status_tip is not None:
            action.setStatusTip(status_tip)

        if whats_this is not None:
            action.setWhatsThis(whats_this)

        if add_to_toolbar:
            self.toolbar.addAction(action)

        if add_to_menu:
            self.iface.addPluginToMenu(
                self.menu,
                action)

        self.actions.append(action)

        return action
开发者ID:mattkernow,项目名称:ZoomToPostcode-QGIS-Plugin,代码行数:37,代码来源:zoom_to_postcode.py

示例5: addBranch

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
 def addBranch(self, branch):
     a = QAction(self)
     a.setCheckable(True)
     if branch == vcs.app_repo.current_branch():
         a.setChecked(True)
         a.setEnabled(False)
     self._acts[branch] = a
     self.setBranchStatus(branch)
开发者ID:dliessi,项目名称:frescobaldi,代码行数:10,代码来源:menu.py

示例6: ActionSelector

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
class ActionSelector(TitledToolbar):

    def __init__(self, parent):
        TitledToolbar.__init__(self, parent, 'Actions')
 
        toolbar = QToolBar(self)
        toolbar.setFloatable(False)
        toolbar.setMovable(False)

        self.saveAction = QAction(QIcon(":/icons/file-save.png"), "Save (Ctrl-S)", toolbar)
        self.saveAction.setShortcut(Qt.CTRL + Qt.Key_S);
        self.saveAction.triggered.connect(parent.save)
        toolbar.addAction(self.saveAction)

        self.nonprintableAction = QAction(QIcon(":/icons/view-nonprintable.png"), "View nonprintable chars", toolbar)
        self.nonprintableAction.setCheckable(True);
        self.nonprintableAction.triggered.connect(parent.toggleNonprintable)
        toolbar.addAction(self.nonprintableAction)

        self.undoAction = QAction(QIcon(":/icons/edit-undo.png"), "Undo (Ctrl-Z)", toolbar)
        # saveAction.setShortcut(Qt.CTRL + Qt.Key_Z);
        self.undoAction.triggered.connect(parent.undo)
        toolbar.addAction(self.undoAction)

        self.redoAction = QAction(QIcon(":/icons/edit-redo.png"), "Redo (Ctrl-Y)", toolbar)
        # saveAction.setShortcut(Qt.CTRL + Qt.Key_Y);
        self.redoAction.triggered.connect(parent.redo)
        toolbar.addAction(self.redoAction)

        self.backAction = QAction(QIcon(":/icons/view-back.png"), "Back", toolbar)
        self.backAction.setEnabled(False)
        self.backAction.triggered.connect(parent.navigateBack)
        toolbar.addAction(self.backAction)

        self.forwardAction = QAction(QIcon(":/icons/view-forward.png"), "Forward", toolbar)
        self.forwardAction.setEnabled(False)
        self.forwardAction.triggered.connect(parent.navigateForward)
        toolbar.addAction(self.forwardAction)

        insertImageAction = QAction(QIcon(":/icons/edit-insert-image.png"), "Insert Image", toolbar)
        insertImageAction.triggered.connect(parent.insertImage)
        toolbar.addAction(insertImageAction)

        insertFormulaAction = QAction("f(x)", toolbar)
        insertFormulaAction.triggered.connect(parent.insertFormula)
        toolbar.addAction(insertFormulaAction)

        findInPageAction = QAction(QIcon(":/icons/edit-find.png"), "Find in page (CTRL-F)", toolbar)
        findInPageAction.setShortcut(Qt.CTRL + Qt.Key_F);
        findInPageAction.triggered.connect(parent.findInPage)
        toolbar.addAction(findInPageAction)

        self.addWidget(toolbar)
开发者ID:afester,项目名称:CodeSamples,代码行数:55,代码来源:Toolbars.py

示例7: create_undo_action

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
 def create_undo_action(self, parent):
     """Create a :class:`~PyQt5.QtWidgets.QAction` for an "Undo" button."""
     from PyQt5.QtWidgets import QAction, QStyle
     from PyQt5.QtGui import QKeySequence
     icon = parent.style().standardIcon(QStyle.SP_ArrowBack)
     action = QAction(icon, "Undo", parent)
     action.setShortcut(QKeySequence.Undo)
     action.setStatusTip("Undo")
     action.triggered.connect(self.undo)
     action.setEnabled(self.can_undo())
     self.changed.connect(lambda: action.setEnabled(self.can_undo()))
     return action
开发者ID:hibtc,项目名称:madgui,代码行数:14,代码来源:history.py

示例8: tree_context_menu

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
    def tree_context_menu(self, point):
        mapped = self.view.splitter.mapFromParent(point)
        index = self.view.tree_view.indexAt(mapped)
        raw_data = self.view.tree_view.model().data(index, GenericTreeModel.ROLE_RAW_DATA)
        if raw_data:
            menu = QMenu(self.view)
            if raw_data['misc']['connection'].uid:
                action_view_in_wot = QAction(self.tr("View in Web of Trust"), menu)
                menu.addAction(action_view_in_wot)
                action_view_in_wot.triggered.connect(lambda c:
                                                        self.model.view_in_wot(raw_data['misc']['connection']))

                action_gen_revokation = QAction(self.tr("Save revokation document"), menu)
                menu.addAction(action_gen_revokation)
                action_gen_revokation.triggered.connect(lambda c:
                                                        self.action_save_revokation(raw_data['misc']['connection']))

                action_publish_uid = QAction(self.tr("Publish UID"), menu)
                menu.addAction(action_publish_uid)
                action_publish_uid.triggered.connect(lambda c:
                                                        self.publish_uid(raw_data['misc']['connection']))
                identity_published = self.model.identity_published(raw_data['misc']['connection'])
                action_publish_uid.setEnabled(not identity_published)

                action_export_identity = QAction(self.tr("Export identity document"), menu)
                menu.addAction(action_export_identity)
                action_export_identity.triggered.connect(lambda c:
                                                        self.export_identity_document(raw_data['misc']['connection']))

                action_leave = QAction(self.tr("Leave the currency"), menu)
                menu.addAction(action_leave)
                action_leave.triggered.connect(lambda c: self.send_leave(raw_data['misc']['connection']))
                action_leave.setEnabled(self.model.identity_is_member(raw_data['misc']['connection']))

            copy_pubkey = QAction(menu.tr("Copy pubkey to clipboard"), menu.parent())
            copy_pubkey.triggered.connect(lambda checked,
                                                 c=raw_data['misc']['connection']: \
                                                 NavigationModel.copy_pubkey_to_clipboard(c))
            menu.addAction(copy_pubkey)

            copy_pubkey_crc = QAction(menu.tr("Copy pubkey to clipboard (with CRC)"), menu.parent())
            copy_pubkey_crc.triggered.connect(lambda checked,
                                                     c=raw_data['misc']['connection']: \
                                              NavigationModel.copy_pubkey_to_clipboard_with_crc(c))
            menu.addAction(copy_pubkey_crc)

            action_remove = QAction(self.tr("Remove the connection"), menu)
            menu.addAction(action_remove)
            action_remove.triggered.connect(lambda c: self.remove_connection(raw_data['misc']['connection']))
            # Show the context menu.

            menu.popup(QCursor.pos())
开发者ID:duniter,项目名称:sakia,代码行数:54,代码来源:controller.py

示例9: contextMenuEvent

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
    def contextMenuEvent(self, event: QContextMenuEvent):
        menu = QMenu()
        sel_indexes = [index.row() for index in self.selectedIndexes()]
        edit_action = QAction("Edit", self)
        if len(sel_indexes) == 0:
            edit_action.setEnabled(False)

        menu.addAction(edit_action)

        action = menu.exec_(self.mapToGlobal(event.pos()))
        if action == edit_action:
            selected_indx = sel_indexes[0]
            self.item_edit_clicked.emit(selected_indx)
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:15,代码来源:GeneratorListWidget.py

示例10: generateMenu

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
    def generateMenu(self):
        m = QMenu()

        for i in [
            self.tr("Show Plots"),
            self.tr("Show Characters"),
            self.tr("Show Objects"),
        ]:
            a = QAction(i, m)
            a.setCheckable(True)
            a.setEnabled(False)
            m.addAction(a)

        self.btnSettings.setMenu(m)
开发者ID:georgehank,项目名称:manuskript,代码行数:16,代码来源:storylineView.py

示例11: Undo

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
class Undo(QObject):
    def __init__(self, spectrum, redraw):
        QObject.__init__(self)
        self.redraw = redraw
        self.undo_action = QAction(QIcon(":/undo_20.png"), "Undo", self)
        self.redo_action = QAction(QIcon(":/redo_20.png"), "Redo", self)
        self.undo_action.triggered.connect(self.undo)
        self.redo_action.triggered.connect(self.redo)
        self.set_spectrum(spectrum)
        
    def undo(self):
        data = self.undo_buffer.pop()
        self.__append_to_buffer(self.__current_data(), self.redo_buffer)
        self.__reset_data(data)
        
    def redo(self):
        data = self.redo_buffer.pop()
        self.__append_to_buffer(self.__current_data(), self.undo_buffer)
        self.__reset_data(data)
        
    def save_undo(self):
        self.__append_to_buffer( self.__current_data(), self.undo_buffer)
        self.redo_buffer.clear()
        self.__enable_actions()
        
    def __reset_data(self, data):
        self.spectrum.wavelengths = data[0]
        self.spectrum.fluxes = data[1]
        self.__enable_actions()
        self.redraw()
        
    def set_spectrum(self, spectrum):
        self.spectrum = spectrum
        self.undo_buffer = deque(maxlen=20)
        self.redo_buffer = deque(maxlen=20)
        self.__enable_actions()
        
    def __enable_actions(self):
        self.undo_action.setEnabled(len(self.undo_buffer)>0)
        self.redo_action.setEnabled(len(self.redo_buffer)>0)
        
    def __append_to_buffer(self, data, buffer):
        buffer.append((np.copy(data[0]), np.copy(data[1])))
        
    def __current_data(self):
        return self.spectrum.wavelengths, self.spectrum.fluxes
    
    def add_actions(self, container):
        container.addAction(self.undo_action)
        container.addAction(self.redo_action)
开发者ID:GuLinux,项目名称:PySpectrum,代码行数:52,代码来源:undo.py

示例12: on_right_click_file_item

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
    def on_right_click_file_item(self, pos):
        num_selected = len(self.window().download_files_list.selectedItems())
        if num_selected == 0:
            return

        item_infos = []  # Array of (item, included, is_selected)
        selected_files_info = []

        for i in range(self.window().download_files_list.topLevelItemCount()):
            item = self.window().download_files_list.topLevelItem(i)
            is_selected = item in self.window().download_files_list.selectedItems()
            item_infos.append((item, item.file_info["included"], is_selected))

            if is_selected:
                selected_files_info.append(item.file_info)

        item_clicked = self.window().download_files_list.itemAt(pos)
        if not item_clicked or not item_clicked in self.window().download_files_list.selectedItems():
            return

        # Check whether we should enable the 'exclude' button
        num_excludes = 0
        num_includes_selected = 0
        for item_info in item_infos:
            if item_info[1] and item_info[0] in self.window().download_files_list.selectedItems():
                num_includes_selected += 1
            if not item_info[1]:
                num_excludes += 1

        menu = TriblerActionMenu(self)

        include_action = QAction('Include file' + ('(s)' if num_selected > 1 else ''), self)
        exclude_action = QAction('Exclude file' + ('(s)' if num_selected > 1 else ''), self)

        include_action.triggered.connect(lambda: self.on_files_included(selected_files_info))
        include_action.setEnabled(True)
        exclude_action.triggered.connect(lambda: self.on_files_excluded(selected_files_info))
        exclude_action.setEnabled(not (num_excludes + num_includes_selected == len(item_infos)))

        menu.addAction(include_action)
        menu.addAction(exclude_action)

        if len(selected_files_info) == 1 and is_video_file(selected_files_info[0]['name'])\
                and self.window().vlc_available:
            play_action = QAction('Play', self)
            play_action.triggered.connect(lambda: self.on_play_file(selected_files_info[0]))
            menu.addAction(play_action)

        menu.exec_(self.window().download_files_list.mapToGlobal(pos))
开发者ID:synctext,项目名称:tribler,代码行数:51,代码来源:downloadsdetailstabwidget.py

示例13: __init__

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
    def __init__(self, home_url):
        super().__init__()

        # store home url
        self.home_url = home_url

        # create and add tool bar on top (non floatable or movable)
        tool_bar = QToolBar(self)

        # create actions, connect to methods, add to tool bar
        action_home = QAction(self)
        action_home.setIcon(QIcon('icon.home.png'))
        action_home.setToolTip('Home')
        action_home.triggered.connect(self.actionHomeTriggered)
        tool_bar.addAction(action_home)

        action_backward = QAction(self)
        action_backward.setEnabled(False)
        action_backward.setIcon(QIcon('icon.backward.png'))
        action_backward.triggered.connect(self.actionBackwardTriggered)
        tool_bar.addAction(action_backward)
        self.action_backward = action_backward

        action_forward = QAction(self)
        action_forward.setEnabled(False)
        action_forward.setIcon(QIcon('icon.forward.png'))
        action_forward.triggered.connect(self.actionForwardTriggered)
        tool_bar.addAction(action_forward)
        self.action_forward = action_forward

        # create and add web view, connect linkClicked signal with our newPage method
        web_view = QWebView()
        # must set DelegationPolicy to include all links
        web_view.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        web_view.linkClicked.connect(self.newPage)
        self.web_view = web_view

        # set Layout
        layout = QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(tool_bar)
        layout.addWidget(web_view)

        # Initialize history (initially there is no current page)
        self.history = []
        self.current_page_index = -1

        # Finally set the home page
        self.actionHomeTriggered()
开发者ID:wkoot,项目名称:imperialism-remake,代码行数:51,代码来源:browser.py

示例14: handleCustomContextMenuRequested

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
    def handleCustomContextMenuRequested(self, pos):
        col = self.columnAt( pos.x() )
        row = self.rowAt( pos.y() )
        
        if 0 <= col < self.model().columnCount() and \
                0 <= row < self.model().rowCount() - 1: # last row is a button
            menu = QMenu(parent=self)
            editSharedPropertiesAction = QAction( "Edit shared properties...", menu )
            editPropertiesAction = QAction( "Edit properties...", menu )
            replaceWithFileAction = QAction( "Replace with file...", menu )
            replaceWithStackAction = QAction( "Replace with stack...", menu )
            
            if self.model().getNumRoles() > 1:
                resetSelectedAction = QAction( "Reset", menu )
            else:
                resetSelectedAction = QAction( "Remove", menu )

            if row in self.selectedLanes and len(self.selectedLanes) > 1:
                editable = True
                for lane in self.selectedLanes:
                    editable &= self.model().isEditable(lane)

                # Show the multi-lane menu, which allows for editing but not replacing
                menu.addAction( editSharedPropertiesAction )
                editSharedPropertiesAction.setEnabled(editable)
                menu.addAction( resetSelectedAction )
            else:
                menu.addAction( editPropertiesAction )
                editPropertiesAction.setEnabled(self.model().isEditable(row))
                menu.addAction( replaceWithFileAction )
                menu.addAction( replaceWithStackAction )
                menu.addAction( resetSelectedAction )
    
            globalPos = self.viewport().mapToGlobal( pos )
            selection = menu.exec_( globalPos )
            if selection is None:
                return
            if selection is editSharedPropertiesAction:
                self.editRequested.emit( self.selectedLanes )
            if selection is editPropertiesAction:
                self.editRequested.emit( [row] )
            if selection is replaceWithFileAction:
                self.replaceWithFileRequested.emit( row )
            if selection is replaceWithStackAction:
                self.replaceWithStackRequested.emit( row )
            if selection is resetSelectedAction:
                self.resetRequested.emit( self.selectedLanes )
开发者ID:ilastik,项目名称:ilastik,代码行数:49,代码来源:datasetDetailedInfoTableView.py

示例15: popupPath

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setEnabled [as 别名]
    def popupPath(self, item):
        m = QMenu()
        def gen_cb(i):
            return lambda: self.editor.switchToItem(i)

        for i in item.siblings():
            a = QAction(i.title(), m)
            if i == item:
                a.setIcon(QIcon.fromTheme("stock_yes"))
                a.setEnabled(False)
            elif self.editor.firstTextItem(i) is None:
                a.setEnabled(False)
            else:
                a.triggered.connect(gen_cb(i))
            m.addAction(a)
        m.popup(QCursor.pos())
        self._m = m
开发者ID:olivierkes,项目名称:manuskript,代码行数:19,代码来源:fullScreenEditor.py


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