Python PyQt5.QtWidgets 模块,QAction() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt5.QtWidgets.QAction()

项目:gpvdm    作者:roderickmackenzie    | 项目源码 | 文件源码
def optics(self):
        toolbar = QToolBar()
        toolbar.setToolButtonStyle( Qt.ToolButtonTextUnderIcon)
        toolbar.setIconSize(QSize(42, 42))

        self.run = QAction(QIcon_load("media-playback-start"), wrap_text(_("Calculate"),5), self)
        toolbar.addAction(self.run)

        self.export = QAction(QIcon_load("document-export"), wrap_text(_("Export spectrum"),5), self)
        #self.export.triggered.connect(self.save_image)
        toolbar.addAction(self.export)

        spacer = QWidget()
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        toolbar.addWidget(spacer)


        self.help = QAction(QIcon_load("help"), _("Help"), self)
        toolbar.addAction(self.help)
        return toolbar
项目:py301    作者:PFLC    | 项目源码 | 文件源码
def initUI(self):               

        textEdit = QTextEdit()
        self.setCentralWidget(textEdit)

        exitAction = QAction(QIcon('exit24.png'), 'Exit', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        exitAction.triggered.connect(self.close)

        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAction)

        toolbar = self.addToolBar('Exit')
        toolbar.addAction(exitAction)

        self.setGeometry(300, 300, 350, 250)
        self.setWindowTitle('Main window')    
        self.show()
项目:binja_dynamics    作者:nccgroup    | 项目源码 | 文件源码
def submit_line(self):
        """ Writes the input to the text browser, adds it to the history, and
        adds it to the message queue to be sent to the binary """
        raw = self._textbox.text()
        line = self.decode(raw)
        if line is None:
            return
        if raw not in self.history:
            self.history.append(raw)
            action = QtWidgets.QAction(str(raw), self)
            action.triggered.connect(partial(self.set_text_box_contents, raw))
            self._hist_menu.insertAction(self._hist_menu.actions()[0], action)
        self._messages.put((line, None))
        self._autoscroll()
        # self._textBrowser.setTextColor(usercolor)
        # self._textBrowser.insertPlainText(line + "\n")
        # self._textBrowser.setTextColor(self.palette().color(QPalette.WindowText))
        self._textbox.clear()
        self._autoscroll()
项目:VIRTUAL-PHONE    作者:SumanKanrar-IEM    | 项目源码 | 文件源码
def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        mainMenu = self.menuBar() 
        fileMenu = mainMenu.addMenu('File')
        editMenu = mainMenu.addMenu('Edit')
        viewMenu = mainMenu.addMenu('View')
        searchMenu = mainMenu.addMenu('Search')
        toolsMenu = mainMenu.addMenu('Tools')
        helpMenu = mainMenu.addMenu('Help')

        exitButton = QAction(QIcon('exit24.png'), 'Exit', self)
        exitButton.setShortcut('Ctrl+Q')
        exitButton.setStatusTip('Exit application')
        exitButton.triggered.connect(self.close)
        fileMenu.addAction(exitButton)

        self.show()
项目:plexdesktop    作者:coryo    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super().__init__(parent)
        """style is relying on object names so make sure they are set
           before registering widgets"""
        self.setObjectName('HubSearch')

        search_action = QtWidgets.QAction(self)
        search_action.setObjectName('search_action')
        close_action = QtWidgets.QAction(self)
        close_action.setObjectName('close_action')
        close_action.triggered.connect(self.cancel.emit)
        close_action.triggered.connect(self.clear)

        self.addAction(search_action, QtWidgets.QLineEdit.LeadingPosition)
        self.addAction(close_action, QtWidgets.QLineEdit.TrailingPosition)

        plexdesktop.style.Style.Instance().widget.register(search_action, 'glyphicons-search')
        plexdesktop.style.Style.Instance().widget.register(close_action, 'cancel')
项目:binja_dynamics    作者:ehennenfent    | 项目源码 | 文件源码
def submit_line(self):
        """ Writes the input to the text browser, adds it to the history, and
        adds it to the message queue to be sent to the binary """
        raw = self._textbox.text()
        line = self.decode(raw)
        if line is None:
            return
        if raw not in self.history:
            self.history.append(raw)
            action = QtWidgets.QAction(str(raw), self)
            action.triggered.connect(partial(self.set_text_box_contents, raw))
            self._hist_menu.insertAction(self._hist_menu.actions()[0], action)
        self._messages.put((line, None))
        self._autoscroll()
        # self._textBrowser.setTextColor(usercolor)
        # self._textBrowser.insertPlainText(line + "\n")
        # self._textBrowser.setTextColor(self.palette().color(QPalette.WindowText))
        self._textbox.clear()
        self._autoscroll()
项目:gpvdm    作者:roderickmackenzie    | 项目源码 | 文件源码
def __init__(self):
        QToolBar.__init__(self)

        self.setToolButtonStyle( Qt.ToolButtonTextUnderIcon)
        self.setIconSize(QSize(42, 42))

        self.materials = QAction(QIcon_load("organic_material"), _("Materials\ndatabase"), self)
        self.materials.triggered.connect(self.callback_view_materials)
        self.addAction(self.materials)

        self.spectra_file = QAction(QIcon_load("spectra_file"), _("Optical\ndatabase"), self)
        self.spectra_file.triggered.connect(self.callback_view_optical)
        self.addAction(self.spectra_file)

        if enable_betafeatures()==True:
            self.tb_import_pvlighthouse = QAction(QIcon_load("sync"), _("Update materials\nfrom PVLighthouse"), self)
            self.tb_import_pvlighthouse.triggered.connect(self.callback_pvlighthouse)
            self.addAction(self.tb_import_pvlighthouse)

            self.tb_import_refractiveindex = QAction(QIcon_load("sync"), _("Update materials\nfrom refractiveindex.info"), self)
            self.tb_import_refractiveindex.triggered.connect(self.callback_refractiveindex)
            self.addAction(self.tb_import_refractiveindex)
项目:gpvdm    作者:roderickmackenzie    | 项目源码 | 文件源码
def file(self):
        toolbar = QToolBar()
        toolbar.setToolButtonStyle( Qt.ToolButtonTextUnderIcon)
        toolbar.setIconSize(QSize(42, 42))

        self.home_new = QAction(QIcon_load("document-new"), _("New simulation").replace(" ","\n"), self)
        #self.home_new.setText(_("New\nsimulation"))
        toolbar.addAction(self.home_new)

        self.home_open = QAction(QIcon_load("document-open"), _("Open\nsimulation"), self)
        toolbar.addAction(self.home_open)

        self.home_export = QAction(QIcon_load("document-export"), _("Export\ndata"), self)
        toolbar.addAction(self.home_export)

        spacer = QWidget()
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        toolbar.addWidget(spacer)

        self.home_help = QAction(QIcon_load("internet-web-browser"), _("Help"), self)
        toolbar.addAction(self.home_help)

        return toolbar
项目:pysport    作者:sportorg    | 项目源码 | 文件源码
def _create_menu(self, parent, actions_list):
        for action_item in actions_list:
            if 'type' in action_item:
                if action_item['type'] == 'separator':
                    parent.addSeparator()
            elif 'action' in action_item:
                action = QtWidgets.QAction(self)
                parent.addAction(action)
                action.setText(action_item['title'])
                action.triggered.connect(action_item['action'])
                if 'shortcut' in action_item:
                    action.setShortcut(action_item['shortcut'])
                if 'icon' in action_item:
                    action.setIcon(QtGui.QIcon(action_item['icon']))
                if 'status_tip' in action_item:
                    action.setStatusTip(action_item['status_tip'])
                if 'property' in action_item:
                    self.menu_property[action_item['property']] = action
            else:
                menu = QtWidgets.QMenu(parent)
                menu.setTitle(action_item['title'])
                self._create_menu(menu, action_item['actions'])
                parent.addAction(menu.menuAction())
项目:opcua-modeler    作者:FreeOpcUa    | 项目源码 | 文件源码
def __init__(self, view):
        QObject.__init__(self, view)
        self.view = view
        self.model = QStandardItemModel()
        self.view.setModel(self.model)
        self.nodesets = []
        self.server_mgr = None
        self._nodeset_to_delete = None
        self.view.header().setSectionResizeMode(1)

        addNodeSetAction = QAction("Add Reference Node Set", self.model)
        addNodeSetAction.triggered.connect(self.add_nodeset)
        self.removeNodeSetAction = QAction("Remove Reference Node Set", self.model)
        self.removeNodeSetAction.triggered.connect(self.remove_nodeset)

        self.view.setContextMenuPolicy(Qt.CustomContextMenu)
        self.view.customContextMenuRequested.connect(self.showContextMenu)
        self._contextMenu = QMenu()
        self._contextMenu.addAction(addNodeSetAction)
        self._contextMenu.addAction(self.removeNodeSetAction)
项目:opcua-modeler    作者:FreeOpcUa    | 项目源码 | 文件源码
def __init__(self, view):
        QObject.__init__(self, view)
        self.view = view
        self.model = QStandardItemModel()
        self.view.setModel(self.model)
        delegate = MyDelegate(self.view, self)
        delegate.error.connect(self.error.emit)
        self.view.setItemDelegate(delegate)
        self.node = None
        self.view.header().setSectionResizeMode(1)

        self.addNamespaceAction = QAction("Add Namespace", self.model)
        self.addNamespaceAction.triggered.connect(self.add_namespace)
        self.removeNamespaceAction = QAction("Remove Namespace", self.model)
        self.removeNamespaceAction.triggered.connect(self.remove_namespace)

        self.view.setContextMenuPolicy(Qt.CustomContextMenu)
        self.view.customContextMenuRequested.connect(self.showContextMenu)
        self._contextMenu = QMenu()
        self._contextMenu.addAction(self.addNamespaceAction)
        self._contextMenu.addAction(self.removeNamespaceAction)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super(ShapedClock, self).__init__(parent,
                Qt.FramelessWindowHint | Qt.WindowSystemMenuHint)

        timer = QTimer(self)
        timer.timeout.connect(self.update)
        timer.start(1000)

        quitAction = QAction("E&xit", self, shortcut="Ctrl+Q",
                triggered=QApplication.instance().quit)
        self.addAction(quitAction)

        self.setContextMenuPolicy(Qt.ActionsContextMenu)
        self.setToolTip("Drag the clock with the left mouse button.\n"
                "Use the right mouse button to open a context menu.")
        self.setWindowTitle(self.tr("Shaped Analog Clock"))
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super(ShapedClock, self).__init__(parent,
                Qt.FramelessWindowHint | Qt.WindowSystemMenuHint)

        timer = QTimer(self)
        timer.timeout.connect(self.update)
        timer.start(1000)

        quitAction = QAction("E&xit", self, shortcut="Ctrl+Q",
                triggered=QApplication.instance().quit)
        self.addAction(quitAction)

        self.setContextMenuPolicy(Qt.ActionsContextMenu)
        self.setToolTip("Drag the clock with the left mouse button.\n"
                "Use the right mouse button to open a context menu.")
        self.setWindowTitle(self.tr("Shaped Analog Clock"))
项目:Worksets    作者:DozyDolphin    | 项目源码 | 文件源码
def build_menu(self, workset_names = None):
        self.menu.clear()
        worksets = self.controller.get_worksets()
        for workset in worksets:
            action = QAction(workset.name, self)
            action.setCheckable(True)

            if workset_names is not None:
                if action.text() in workset_names:
                    action.setChecked(True)
            self.menu.addAction(action)
            action.triggered.connect(functools.partial(
                self.handle_workset,
                action))

        self.menu.addSeparator()

        create_action = self.menu.addAction(_("Manage worksets"))
        create_action.triggered.connect(self.manage_worksets)

        settings_action = self.menu.addAction(_("Settings"))
        settings_action.triggered.connect(self.settings)

        exit_action = self.menu.addAction(_("Quit"))
        exit_action.triggered.connect(self.close)
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def qui_menu(self, action_list_str, menu_str):
        # qui menu creation
        # syntax: self.qui_menu('right_menu_createFolder_atn;Create Folder,Ctrl+D | right_menu_openFolder_atn;Open Folder', 'right_menu')
        if menu_str not in self.uiList.keys():
            self.uiList[menu_str] = QtWidgets.QMenu()
        create_opt_list = [ x.strip() for x in action_list_str.split('|') ]
        for each_creation in create_opt_list:
            ui_info = [ x.strip() for x in each_creation.split(';') ]
            atn_name = ui_info[0]
            atn_title = ''
            atn_hotkey = ''
            if len(ui_info) > 1:
                options = ui_info[1].split(',')
                atn_title = '' if len(options) < 1 else options[0]
                atn_hotkey = '' if len(options) < 2 else options[1]
            if atn_name != '':
                if atn_name == '_':
                    self.uiList[menu_str].addSeparator()
                else:
                    if atn_name not in self.uiList.keys():
                        self.uiList[atn_name] = QtWidgets.QAction(atn_title, self)
                        if atn_hotkey != '':
                            self.uiList[atn_name].setShortcut(QtGui.QKeySequence(atn_hotkey))
                    self.uiList[menu_str].addAction(self.uiList[atn_name])
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setLang(self, langName):
        uiList_lang_read = self.memoData['lang'][langName]
        for ui_name in uiList_lang_read:
            ui_element = self.uiList[ui_name]
            if type(ui_element) in [ QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox ]:
                # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox
                if uiList_lang_read[ui_name] != "":
                    ui_element.setText(uiList_lang_read[ui_name])
            elif type(ui_element) in [ QtWidgets.QGroupBox, QtWidgets.QMenu ]:
                # uiType: QMenu, QGroupBox
                if uiList_lang_read[ui_name] != "":
                    ui_element.setTitle(uiList_lang_read[ui_name])
            elif type(ui_element) in [ QtWidgets.QTabWidget]:
                # uiType: QTabWidget
                tabCnt = ui_element.count()
                if uiList_lang_read[ui_name] != "":
                    tabNameList = uiList_lang_read[ui_name].split(';')
                    if len(tabNameList) == tabCnt:
                        for i in range(tabCnt):
                            if tabNameList[i] != "":
                                ui_element.setTabText(i,tabNameList[i])
            elif type(ui_element) == str:
                # uiType: string for msg
                if uiList_lang_read[ui_name] != "":
                    self.uiList[ui_name] = uiList_lang_read[ui_name]
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setLang(self, langName):
        uiList_lang_read = self.memoData['lang'][langName]
        for ui_name in uiList_lang_read:
            ui_element = self.uiList[ui_name]
            if type(ui_element) in [ QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox ]:
                # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox
                if uiList_lang_read[ui_name] != "":
                    ui_element.setText(uiList_lang_read[ui_name])
            elif type(ui_element) in [ QtWidgets.QGroupBox, QtWidgets.QMenu ]:
                # uiType: QMenu, QGroupBox
                if uiList_lang_read[ui_name] != "":
                    ui_element.setTitle(uiList_lang_read[ui_name])
            elif type(ui_element) in [ QtWidgets.QTabWidget]:
                # uiType: QTabWidget
                tabCnt = ui_element.count()
                if uiList_lang_read[ui_name] != "":
                    tabNameList = uiList_lang_read[ui_name].split(';')
                    if len(tabNameList) == tabCnt:
                        for i in range(tabCnt):
                            if tabNameList[i] != "":
                                ui_element.setTabText(i,tabNameList[i])
            elif type(ui_element) == str:
                # uiType: string for msg
                if uiList_lang_read[ui_name] != "":
                    self.uiList[ui_name] = uiList_lang_read[ui_name]
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setLang(self, langName):
        uiList_lang_read = self.memoData['lang'][langName]
        for ui_name in uiList_lang_read:
            ui_element = self.uiList[ui_name]
            if type(ui_element) in [ QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox ]:
                # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox
                if uiList_lang_read[ui_name] != "":
                    ui_element.setText(uiList_lang_read[ui_name])
            elif type(ui_element) in [ QtWidgets.QGroupBox, QtWidgets.QMenu ]:
                # uiType: QMenu, QGroupBox
                if uiList_lang_read[ui_name] != "":
                    ui_element.setTitle(uiList_lang_read[ui_name])
            elif type(ui_element) in [ QtWidgets.QTabWidget]:
                # uiType: QTabWidget
                tabCnt = ui_element.count()
                if uiList_lang_read[ui_name] != "":
                    tabNameList = uiList_lang_read[ui_name].split(';')
                    if len(tabNameList) == tabCnt:
                        for i in range(tabCnt):
                            if tabNameList[i] != "":
                                ui_element.setTabText(i,tabNameList[i])
            elif type(ui_element) == str:
                # uiType: string for msg
                if uiList_lang_read[ui_name] != "":
                    self.uiList[ui_name] = uiList_lang_read[ui_name]
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setLang(self, langName):
        uiList_lang_read = self.memoData['lang'][langName]
        for ui_name in uiList_lang_read:
            ui_element = self.uiList[ui_name]
            if type(ui_element) in [ QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox ]:
                # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox
                if uiList_lang_read[ui_name] != "":
                    ui_element.setText(uiList_lang_read[ui_name])
            elif type(ui_element) in [ QtWidgets.QGroupBox, QtWidgets.QMenu ]:
                # uiType: QMenu, QGroupBox
                if uiList_lang_read[ui_name] != "":
                    ui_element.setTitle(uiList_lang_read[ui_name])
            elif type(ui_element) in [ QtWidgets.QTabWidget]:
                # uiType: QTabWidget
                tabCnt = ui_element.count()
                if uiList_lang_read[ui_name] != "":
                    tabNameList = uiList_lang_read[ui_name].split(';')
                    if len(tabNameList) == tabCnt:
                        for i in range(tabCnt):
                            if tabNameList[i] != "":
                                ui_element.setTabText(i,tabNameList[i])
            elif type(ui_element) == str:
                # uiType: string for msg
                if uiList_lang_read[ui_name] != "":
                    self.uiList[ui_name] = uiList_lang_read[ui_name]
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def contextMenuEvent(self, event):
        menu = QtWidgets.QMenu()

        listOfLabelsAndFunctions = [
            ("interpolation Type", self.changeInterpolationType),
            ("CC Value", self.changeCCValue),
            ("delete", self.delete), #deletes the last hover item which is of course the current one.
            ]

        for text, function in listOfLabelsAndFunctions:
            if text == "separator":
                self.addSeparator()
            else:
                a = QtWidgets.QAction(text, menu)
                menu.addAction(a)
                a.triggered.connect(function)

        pos = QtGui.QCursor.pos()
        pos.setY(pos.y() + 5)
        self.ungrabMouse() #if we don't ungrab and the user clicks the context menu "away" by clicking in an empty area this will still get registered as mouseclick belonging to the current item and change the value to some insane amount, breaking the point.
        menu.exec_(pos)
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def contextMenuEvent(self, event):
        menu = QtWidgets.QMenu()

        listOfLabelsAndFunctions = [
            ("interpolation type", self.changeInterpolationType),
            ("units per minute", self.changeTempoUnits),
            ("reference note", self.changeTempoReference),
            ]
        if not self.staticExportItem["positionInBlock"] == 0:
            listOfLabelsAndFunctions.append(("delete", lambda: api.removeTempoItem(self.staticExportItem["id"])))

        for text, function in listOfLabelsAndFunctions:
            if text == "separator":
                self.addSeparator()
            else:
                a = QtWidgets.QAction(text, menu)
                menu.addAction(a)
                a.triggered.connect(function)

        pos = QtGui.QCursor.pos()
        pos.setY(pos.y() + 5)
        self.ungrabMouse() #if we don't ungrab and the user clicks the context menu "away" by clicking in an empty area this will still get registered as mouseclick belonging to the current item
        menu.exec_(pos)
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def deactivate_contextMenuEvent(self, event):
        menu = QtWidgets.QMenu()

        listOfLabelsAndFunctions = [
            ("restore to full duration ", self.contextRestore),
            ]

        for text, function in listOfLabelsAndFunctions:
            if text == "separator":
                self.addSeparator()
            else:
                a = QtWidgets.QAction(text, menu)
                menu.addAction(a)
                a.triggered.connect(function)

        pos = QtGui.QCursor.pos()
        pos.setY(pos.y() + 5)
        self.ungrabMouse() #if we don't ungrab and the user clicks the context menu "away" by clicking in an empty area this will still get registered as mouseclick belonging to the current item
        menu.exec_(pos)
项目:PointlessMaker    作者:aboood40091    | 项目源码 | 文件源码
def CreateAction(self, shortname, function, icon, text, statustext, shortcut, toggle=False):
        """
        Helper function to create an action
        From Miyamoto
        """

        if icon is not None:
            act = QtWidgets.QAction(icon, text, self)
        else:
            act = QtWidgets.QAction(text, self)

        if shortcut is not None: act.setShortcut(shortcut)
        if statustext is not None: act.setStatusTip(statustext)
        if toggle:
            act.setCheckable(True)
        if function is not None: act.triggered.connect(function)

        self.actions[shortname] = act
项目:py301    作者:PFLC    | 项目源码 | 文件源码
def initUI(self):               

        exitAction = QAction(QIcon('exit.png'), '&Exit', self)        
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        exitAction.triggered.connect(qApp.quit)

        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAction)

        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Menubar')    
        self.show()
项目:opcua-widgets    作者:FreeOpcUa    | 项目源码 | 文件源码
def __init__(self, view):
        QObject.__init__(self, view)
        self.view = view
        self.model = TreeViewModel()
        self.model.clear()  # FIXME: do we need this?
        self.model.error.connect(self.error)
        self.view.setModel(self.model)

        #self.view.setUniformRowHeights(True)
        self.model.setHorizontalHeaderLabels(['DisplayName', "BrowseName", 'NodeId'])
        self.view.header().setSectionResizeMode(0)
        self.view.header().setStretchLastSection(True)
        self.view.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.settings = QSettings()
        state = self.settings.value("tree_widget_state", None)
        if state is not None:
            self.view.header().restoreState(state)

        self.actionReload = QAction("Reload", self)
        self.actionReload.triggered.connect(self.reload_current)
项目:urh    作者:jopohl    | 项目源码 | 文件源码
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)

        if self.count() > 0:
            edit_all_action = QAction("Edit all", self)
            edit_all_action.triggered.connect(self.on_edit_all_action_triggered)
            menu.addAction(edit_all_action)

        action = menu.exec_(self.mapToGlobal(event.pos()))
        if action == edit_action:
            selected_indx = sel_indexes[0]
            self.item_edit_clicked.emit(selected_indx)
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super().__init__(parent)

        self.verticalHeader().setSectionResizeMode(QHeaderView.Fixed)
        self.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed)

        self.ref_message_action = QAction(self.tr("Mark as reference message"), self)
        self.ref_message_action.setShortcut(QKeySequence("R"))
        self.ref_message_action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        self.ref_message_action.triggered.connect(self.set_ref_message)

        self.hide_row_action = QAction("Hide selected rows", self)
        self.hide_row_action.setShortcut(QKeySequence("H"))
        self.hide_row_action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        self.hide_row_action.triggered.connect(self.hide_row)

        self.addAction(self.ref_message_action)
        self.addAction(self.hide_row_action)
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def get_action(self, parent, undo_stack: QUndoStack, sel_range, protocol: ProtocolAnalyzer, view: int):
        """
        :type parent: QTableView
        :type undo_stack: QUndoStack
        :type protocol_analyzers: list of ProtocolAnalyzer
        """
        min_row, max_row, start, end = sel_range
        if min_row == -1 or max_row == -1 or start == -1 or end == -1:
            return None

        if max_row != min_row:
            QMessageBox.critical(parent, self.tr("Error in MessageBreak"),
                                 self.tr("You can only break one line per action."))
            return None

        end = protocol.convert_index(end, view, 0, True, message_indx=min_row)[0]
        # factor = 1 if view == 0 else 4 if view == 1 else 8

        self.command = MessageBreakAction(protocol, max_row, end)
        action = QAction(self.command.text(), parent)
        action.triggered.connect(self.action_triggered)
        self.undo_stack = undo_stack
        return action
项目:FIRST-plugin-ida    作者:vrtadmin    | 项目源码 | 文件源码
def applied_custom_menu(self, point):
        index = self.applied_tree_view.indexAt(point)
        address = index.data(FIRSTUI.ROLE_ADDRESS)
        if not address:
            return

        menu = QtWidgets.QMenu(self.applied_tree_view)
        goto_action = QtWidgets.QAction('&Go to Function', self.applied_tree_view)
        goto_action.triggered.connect(lambda:IDAW.Jump(address))
        menu.addAction(goto_action)

        metadata_id = index.data(FIRSTUI.ROLE_ID)
        if metadata_id:
            history_action = QtWidgets.QAction('View &History', self.applied_tree_view)
            history_action.triggered.connect(lambda:self._metadata_history(metadata_id))
            menu.addAction(history_action)

        menu.exec_(QtGui.QCursor.pos())
项目:FIRST-plugin-ida    作者:vrtadmin    | 项目源码 | 文件源码
def custom_menu(self, point):
            index = self.tree_view.indexAt(point)
            address = index.data(FIRSTUI.ROLE_ADDRESS)
            if not address:
                return

            menu = QtWidgets.QMenu(self.tree_view)
            goto_action = QtWidgets.QAction('&Go to Function', self.tree_view)
            goto_action.triggered.connect(lambda:IDAW.Jump(address))
            menu.addAction(goto_action)

            metadata_id = index.data(FIRSTUI.ROLE_ID)
            if metadata_id:
                history_action = QtWidgets.QAction('View &History', self.tree_view)
                history_action.triggered.connect(lambda:self.metadata_history(metadata_id))
                menu.addAction(history_action)

            menu.exec_(QtGui.QCursor.pos())
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super(ShapedClock, self).__init__(parent,
                Qt.FramelessWindowHint | Qt.WindowSystemMenuHint)

        timer = QTimer(self)
        timer.timeout.connect(self.update)
        timer.start(1000)

        quitAction = QAction("E&xit", self, shortcut="Ctrl+Q",
                triggered=QApplication.instance().quit)
        self.addAction(quitAction)

        self.setContextMenuPolicy(Qt.ActionsContextMenu)
        self.setToolTip("Drag the clock with the left mouse button.\n"
                "Use the right mouse button to open a context menu.")
        self.setWindowTitle(self.tr("Shaped Analog Clock"))
项目:shadowsocks-pyqt    作者:falseen    | 项目源码 | 文件源码
def Tray_init(self):
        self.tray = QSystemTrayIcon()
        self.icon = self.windowIcon()
        self.tray.setIcon(self.icon)
        self.tray.activated[QSystemTrayIcon.ActivationReason].connect(
            self.TrayEvent)
        self.tray_menu = QtWidgets.QMenu(QtWidgets.QApplication.desktop())
        self.ShowAction = QtWidgets.QAction(
            u'?? ', self, triggered=self.re_build)
        self.ShowLog = QtWidgets.QAction(
            u'???? ', self, triggered=self.logwindow.showlog)
        self.QuitAction = QtWidgets.QAction(
            u'?? ', self, triggered=self.app_quit)
        self.tray_menu.addAction(self.ShowLog)
        self.tray_menu.addAction(self.ShowAction)
        self.tray_menu.addAction(self.QuitAction)
        self.tray.setContextMenu(self.tray_menu)  # ????????
        self.tray.show()
        self.showMessage(u"shadowsocks-pyqt ?????")
项目:RRPam-WDS    作者:asselapathirana    | 项目源码 | 文件源码
def setMenu(self):
        bar = self.menuBar()
        bar.setNativeMenuBar(False)  # disable different treatment in Mac OS
        file = bar.addMenu(self.menuitems.file)
        file.addAction(self.menuitems.new_project)
        self.saveaction = file.addAction(self.menuitems.save_project)
        self.saveasaction = file.addAction(self.menuitems.save_project_as)
        file.addAction(self.menuitems.open_project)
        file.addAction(self.menuitems.new_wlc)
        file.addAction(self.menuitems.show_log)
        self.closeaction = file.addAction(self.menuitems.close_project)
        file.triggered[QAction].connect(self.windowaction)
        file2 = bar.addMenu(self.menuitems.view)
        file2.addAction(self.menuitems.cascade)
        file2.addAction(self.menuitems.tiled)
        file2.triggered[QAction].connect(self.windowaction)
        file3 = bar.addMenu(self.menuitems.help)
        self.aboutaction = file3.addAction(self.menuitems.about)
        self.guideaction = file3.addAction(self.menuitems.guide)
        file3.triggered[QAction].connect(self.windowaction)
项目:notepad    作者:lfsando    | 项目源码 | 文件源码
def preferences_menu(self):

        settings_action = QtWidgets.QAction(QtGui.QIcon('assets/icons/config.png'), '&Settings', self)
        settings_action.setStatusTip('Open Settings')
        settings_action.setShortcut('Ctrl+Shift+P')

        preferences_menu = self.menu_bar.addMenu('Prefere&nces')
        preferences_menu.addAction(settings_action)
项目:notepad    作者:lfsando    | 项目源码 | 文件源码
def format_menu(self):
        """ Add Format Menu """

        font_action = QtWidgets.QAction(QtGui.QIcon('assets/icons/font.png'), '&Font', self)
        font_action.setStatusTip('Change the document font')
        font_action.triggered.connect(self.font_dialog)

        date_action = QtWidgets.QAction(QtGui.QIcon('assets/icons/date.png'), '&Append Date', self)
        date_action.setStatusTip('Insert date and time at cursor location')
        date_action.setShortcut('F5')
        date_action.triggered.connect(self.insert_date)

        self.default_syntax = QtWidgets.QAction('&Default', self)
        self.default_syntax.setStatusTip('Turn off syntax highlighting')

        self.python_syntax = QtWidgets.QAction('&Python', self)
        self.python_syntax.setStatusTip('Turn on syntax highlighting for Python language')

        self.default_syntax.triggered.connect(self.assign_syntax_def)
        self.python_syntax.triggered.connect(self.assign_syntax_py)

        format_menu = self.menu_bar.addMenu('Forma&t')

        syntax_menu = format_menu.addMenu(QtGui.QIcon('assets/icons/synthax.png'), '&Syntax')

        syntax_menu.addAction(self.default_syntax)
        syntax_menu.addAction(self.python_syntax)

        format_menu.addSeparator()
        format_menu.addAction(font_action)
        format_menu.addAction(date_action)

    # Text Finder
项目:activity-browser    作者:LCA-ActivityBrowser    | 项目源码 | 文件源码
def set_project_label(self):
        name = projects.current
        self.project_name_label.setText('Project: {}'.format(name))
        self.project_read_only.setText('')
        if projects.read_only:
            self.project_read_only.setText('Read Only Project')
            self.window.warning("Read Only Project", """Read Only Project.\nAnother Python process is working with this project, no writes are allowed.\nCheck to make sure no other Python interpreters are running, and then re-select this project.""")

    # def get_search_box(self):
    #     search_box = QtWidgets.QLineEdit()
    #     search_box.setMaximumSize(QtCore.QSize(150, 25))

    #     # Search
    #     search_action = QtWidgets.QAction(
    #         QtGui.QIcon(icons.search),
    #         'Search activites (see help for search syntax)',
    #         self.window
    #     )
    #     return search_box

    # def get_key_search(self):
    #     key_search_action = QtWidgets.QAction(
    #         QtGui.QIcon(icons.key),
    #         'Search by key',
    #         self.window
    #     )
    #     # key_search_action.triggered.connect(self.search_by_key)
    #     return key_search_action
项目:activity-browser    作者:LCA-ActivityBrowser    | 项目源码 | 文件源码
def setup_context_menu(self):
        # delete database
        self.delete_database_action = QtWidgets.QAction(
            QtGui.QIcon(icons.delete), "Delete database", None
        )
        self.addAction(self.delete_database_action)
        self.delete_database_action.triggered.connect(
            lambda x: signals.delete_database.emit(
                self.currentItem().db_name
            )
        )

        # copy database
        self.copy_database_action = QtWidgets.QAction(
            QtGui.QIcon(icons.duplicate), "Copy database", None
        )
        self.addAction(self.copy_database_action)
        self.copy_database_action.triggered.connect(
            lambda x: signals.copy_database.emit(
                self.currentItem().db_name
            )
        )
        # add activity (important for empty databases, where the activities table will not show up)
        self.add_activity_action = QtWidgets.QAction(
            QtGui.QIcon(icons.add), "Add new activity", None
        )
        self.addAction(self.add_activity_action)
        self.add_activity_action.triggered.connect(
            lambda x: signals.new_activity.emit(
                self.currentItem().db_name
            )
        )
项目:activity-browser    作者:LCA-ActivityBrowser    | 项目源码 | 文件源码
def setup_context_menu(self):
        self.add_activity_action = QtWidgets.QAction(
            QtGui.QIcon(icons.add), "Add new activity", None
        )
        self.copy_activity_action = QtWidgets.QAction(
            QtGui.QIcon(icons.copy), "Copy activity", None
        )
        self.delete_activity_action = QtWidgets.QAction(
            QtGui.QIcon(icons.delete), "Delete activity", None
        )
        self.open_left_tab_action = QtWidgets.QAction(
            QtGui.QIcon(icons.left), "Open in new tab", None
        )
        self.addAction(self.add_activity_action)
        self.addAction(self.copy_activity_action)
        self.addAction(self.delete_activity_action)
        self.addAction(self.open_left_tab_action)
        self.add_activity_action.triggered.connect(
            lambda: signals.new_activity.emit(self.database.name)
        )
        self.copy_activity_action.triggered.connect(
            lambda x: signals.copy_activity.emit(self.currentItem().key)
        )
        self.delete_activity_action.triggered.connect(
            lambda x: signals.delete_activity.emit(self.currentItem().key)
        )
        self.open_left_tab_action.triggered.connect(
            lambda x: signals.open_activity_tab.emit("activities", self.currentItem().key)
        )
项目:activity-browser    作者:LCA-ActivityBrowser    | 项目源码 | 文件源码
def setup_context_menu(self):
        self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
        self.open_left_tab_action = QtWidgets.QAction(
            QtGui.QIcon(icons.left), "Open in new tab", None
        )
        self.addAction(self.open_left_tab_action)
        self.open_left_tab_action.triggered.connect(
            lambda x: signals.open_activity_tab.emit(
                "activities", self.currentItem().key
            )
        )
项目:activity-browser    作者:LCA-ActivityBrowser    | 项目源码 | 文件源码
def setup_context_menu(self):
        self.delete_row_action = QtWidgets.QAction(
            QtGui.QIcon(icons.delete), "Remove row", None
        )
        self.addAction(self.delete_row_action)
        self.delete_row_action.triggered.connect(self.delete_rows)
项目:activity-browser    作者:LCA-ActivityBrowser    | 项目源码 | 文件源码
def setup_context_menu(self):
        self.delete_exchange_action = QtWidgets.QAction(
            QtGui.QIcon(icons.delete), "Delete exchange(s)", None
        )
        self.addAction(self.delete_exchange_action)
        self.delete_exchange_action.triggered.connect(self.delete_exchanges)
项目:activity-browser    作者:LCA-ActivityBrowser    | 项目源码 | 文件源码
def setup_file_menu(self):
        menu = QtWidgets.QMenu('&File', self.window)
        # Switch BW2 directory
        # switch_bw2_dir = QtWidgets.QAction(QtGui.QIcon('exit.png'), '&Database directory...', self.window)
        # # switch_bw2_dir.setShortcut('Ctrl+Q')
        # switch_bw2_dir.setStatusTip('Change database directory')
        # switch_bw2_dir.triggered.connect(signals.switch_bw2_dir_path.emit)
        # menu.addAction(switch_bw2_dir)
        menu.addAction(
            '&Database directory...',
            signals.switch_bw2_dir_path.emit
        )
        menu.addAction(
            '&Import database...',
            signals.import_database.emit
        )
        return menu

    # def setup_extensions_menu(self):
    #     extensions_menu = QtWidgets.QMenu('&Extensions', self.window)
    #     # extensions_menu.addAction(
    #     #     self.add_metaprocess_menu_item()
    #     # )
    #     return extensions_menu
项目:uPyLoader    作者:BetaRavener    | 项目源码 | 文件源码
def _add_menu_action(self, title, handler):
        action = QAction(title, self.context_menu)
        action.triggered.connect(handler)
        self.context_menu.addAction(action)
        return action
项目:git-annex-metadata-gui    作者:alpernebbi    | 项目源码 | 文件源码
def create_header_menu_action(self, header):
        actions = self.menu_headers.actions()
        headers = [act.text() for act in actions]

        if header in headers:
            return
        idx = bisect.bisect(headers, header)

        action = QtWidgets.QAction(self)
        action.setText(header)
        action.setCheckable(True)
        action.setChecked(True)

        def set_visibility(visible):
            self.view_keys.show_header(header, visible)
            self.view_head.show_header(header, visible)

        action.triggered.connect(set_visibility)

        def visibility_set(header_, visible):
            if header_ == header:
                action.setChecked(visible)

        for view in (self.view_keys, self.view_head):
            view.header_visibility_changed.connect(visibility_set)

        if idx < len(actions):
            before_action = actions[idx]
            self.menu_headers.insertAction(before_action, action)
        else:
            self.menu_headers.addAction(action)

        empty = len(self.menu_headers.actions()) == 0
        self.menu_headers.setDisabled(empty)
项目:Dragonfly    作者:duaneloh    | 项目源码 | 文件源码
def init_UI(self):
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowTitle('Dragonfly Frame Viewer')
        window = QtWidgets.QWidget()

        self.hbox = QtWidgets.QHBoxLayout()
        self.frame_panel = frame_panel.Frame_panel(self, powder=self.do_powder, compare=self.do_compare)
        self.hbox.addWidget(self.frame_panel)

        # Menu items
        menubar = self.menuBar()
        menubar.setNativeMenuBar(False)
        # Theme picker
        thememenu = menubar.addMenu('&Theme')
        self.theme = QtWidgets.QActionGroup(self, exclusive=True)
        for i, s in enumerate(map(str, list(QtWidgets.QStyleFactory.keys()))):
            a = self.theme.addAction(QtWidgets.QAction(s, self, checkable=True))
            if i == 0:
                a.setChecked(True)
            a.triggered.connect(self.theme_changed)
            thememenu.addAction(a)
        # Color map picker
        cmapmenu = menubar.addMenu('&Color Map')
        self.color_map = QtWidgets.QActionGroup(self, exclusive=True)
        for i, s in enumerate(['cubehelix', 'CMRmap', 'gray', 'gray_r', 'jet']):
            a = self.color_map.addAction(QtWidgets.QAction(s, self, checkable=True))
            if i == 0:
                a.setChecked(True)
            a.triggered.connect(self.cmap_changed)
            cmapmenu.addAction(a)

        window.setLayout(self.hbox)
        self.setCentralWidget(window)
        self.show()
项目:bitmask-dev    作者:leapcode    | 项目源码 | 文件源码
def _createActions(self):
        self.quitAction = QAction(
            "&Quit", self,
            triggered=self.closeFromSystray)
项目:VIRTUAL-PHONE    作者:SumanKanrar-IEM    | 项目源码 | 文件源码
def __init__(self):
        super().__init__()

        # Create Menu Bar
        bar = self.menuBar()

        # Create Root Menus
        file = bar.addMenu('File')
        edit = bar.addMenu('Edit')

        # Create Actions for menus
        save_action = QAction('Save', self)
        save_action.setShortcut('Ctrl+S')

        new_action = QAction('New', self)
        new_action.setShortcut('Ctrl+N')

        quit_action = QAction('&Quit', self)
        quit_action.setShortcut('Ctrl+Q')

        find_action = QAction('Find...', self)

        replace_action = QAction('Replace...', self)

        # Add actions to Menus
        file.addAction(new_action)
        file.addAction(save_action)
        file.addAction(quit_action)
        find_menu = edit.addMenu('Find')
        find_menu.addAction(find_action)
        find_menu.addAction(replace_action)

        # Events
        quit_action.triggered.connect(self.quit_trigger)
        file.triggered.connect(self.selected)

        self.setWindowTitle("My Menus")
        self.resize(600, 400)

        self.show()
项目:VIRTUAL-PHONE    作者:SumanKanrar-IEM    | 项目源码 | 文件源码
def init_ui(self):
        bar = self.menuBar()
        file = bar.addMenu('File')
        edit = bar.addMenu('Edit')

        new_action = QAction('New', self)
        new_action.setShortcut('Ctrl+N')

        save_action = QAction('&Save', self)
        save_action.setShortcut('Ctrl+S')

        open_action = QAction('&Open', self)

        quit_action = QAction('&Quit', self)

        font_action = QAction('&Font', self)

        file.addAction(new_action)
        file.addAction(save_action)
        file.addAction(open_action)
        file.addAction(quit_action)
        edit.addAction(font_action)

        quit_action.triggered.connect(self.quit_trigger)
        file.triggered.connect(self.respond)
        font_action.triggered.connect(self.font_changer1)
        self.setWindowTitle("Notepad")
        self.show()
项目:VIRTUAL-PHONE    作者:SumanKanrar-IEM    | 项目源码 | 文件源码
def __init__(self):
        super().__init__()

        self.form_widget = MyTable(10, 5)
        self.setCentralWidget(self.form_widget)
        col_headers = ['Name', 'Phone No.', 'Email', 'Address', 'DOB']
        self.form_widget.setHorizontalHeaderLabels(col_headers)

        # Set up menu
        bar = self.menuBar()
        file = bar.addMenu('File')

        save_action = QAction('&Save', self)
        save_action.setShortcut('Ctrl+S')

        open_action = QAction('&Open', self)

        quit_action = QAction('&Quit', self)

        file.addAction(save_action)
        file.addAction(open_action)
        file.addAction(quit_action)

        quit_action.triggered.connect(self.quit_app)
        save_action.triggered.connect(self.form_widget.save_sheet)
        open_action.triggered.connect(self.form_widget.open_sheet)
        self.show()
项目:VIRTUAL-PHONE    作者:SumanKanrar-IEM    | 项目源码 | 文件源码
def init_ui(self):
        bar = self.menuBar()
        file = bar.addMenu('File')
        edit = bar.addMenu('Edit')

        new_action = QAction('New', self)
        new_action.setShortcut('Ctrl+N')

        save_action = QAction('&Save', self)
        save_action.setShortcut('Ctrl+S')

        open_action = QAction('&Open', self)

        quit_action = QAction('&Quit', self)

        font_action = QAction('&Font', self)

        file.addAction(new_action)
        file.addAction(save_action)
        file.addAction(open_action)
        file.addAction(quit_action)
        edit.addAction(font_action)

        quit_action.triggered.connect(self.quit_trigger)
        file.triggered.connect(self.respond)
        font_action.triggered.connect(self.font_changer1)
        self.setWindowTitle("Notepad")
        self.setWindowIcon(QIcon('notepad.png'))
        self.show()