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


Python QtWidgets.QMenu类代码示例

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


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

示例1: ApplicationWindow

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,代码行数:33,代码来源:dynamicgraph.py

示例2: PredicateNodeInfo

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,代码行数:33,代码来源:info.py

示例3: buildWidget

    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,代码行数:35,代码来源:adjustment_bar.py

示例4: right_click

    def right_click(self, type, champ):
        "Retourne une fonction qui sera executée lors d'un clic droit sur le champ 'champ'."
        champ.setFocus()
        plusieurs = isinstance(type, list)
        if plusieurs:
            type = type[0]
        liste_objets = self.onglet_actuel.feuille_actuelle.objets.lister(False, type = type)
        liste_objets.sort(key = attrgetter('nom')) # ordre alphabétique
        if not liste_objets:
            return
        menu = QMenu()

        for obj in liste_objets:
            action = menu.addAction(obj.nom_complet)
            action.nom = obj.nom

        action = menu.exec_(QCursor.pos())
        if action:
            if plusieurs:
                # le champ doit contenir non pas un objet, mais une liste d'objets
                val = champ.text().strip()
                if val:
                    if not val.endswith(","):
                        val += ","
                    val += " "
                champ.setText(val + action.nom)
            else:
                # le champ contient un seul objet
                champ.setText(action.nom)
开发者ID:wxgeo,项目名称:geophar,代码行数:29,代码来源:dialogues_geometrie.py

示例5: Systray

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,代码行数:31,代码来源:systray.py

示例6: _handle_context_menu_requested

    def _handle_context_menu_requested(self, qpoint):
        index = self.treeView.indexAt(qpoint)
        item = index.internalPointer()

        def add_action(menu, text, handler, icon=None):
            a = None
            if icon is None:
                a = QAction(text, self)
            else:
                a = QAction(icon, text, self)
            a.triggered.connect(handler)
            menu.addAction(a)

        menu = QMenu(self)

        action = None
        if self._is_item_colored(item):
            add_action(menu, "De-color item", lambda: self._handle_clear_color_item(item))
        else:
            add_action(menu, "Color item", lambda: self._handle_color_item(item))
            color_menu = menu.addMenu("Color item...")

            # need to escape the closure capture on the color loop variable below
            # hint from: http://stackoverflow.com/a/6035865/87207
            def make_color_item_handler(item, color):
                return lambda: self._handle_color_item(item, color=color)

            for color in QT_COLORS:
                add_action(color_menu, "{:s}".format(color.name),
                           make_color_item_handler(item, color.qcolor), make_color_icon(color.qcolor))

        add_action(menu, "Set name...", lambda: self._handle_set_name(item))

        menu.exec_(self.treeView.mapToGlobal(qpoint))
开发者ID:HerbDavisY2K,项目名称:python-pyqt5-vstructui,代码行数:34,代码来源:vstructui.py

示例7: ValueDomainNodeInfo

class ValueDomainNodeInfo(PredicateNodeInfo):
    """
    This class implements the information box for the Value Domain node.
    """
    def __init__(self, mainwindow, parent=None):
        """
        Initialize the Value Domain node information box.
        """
        super().__init__(mainwindow, parent)

        self.datatypeKey = Key('Datatype', self)
        self.datatypeMenu = QMenu(self)
        for action in self.mainwindow.actionsChangeValueDomainDatatype:
            self.datatypeMenu.addAction(action)
        self.datatypeButton = Button()
        self.datatypeButton.setMenu(self.datatypeMenu)
        self.datatypeButton.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)

        self.nodePropLayout.addRow(self.datatypeKey, self.datatypeButton)

    def updateData(self, node):
        """
        Fetch new information and fill the widget with data.
        :type node: AbstractNode
        """
        super().updateData(node)
        datatype = node.datatype
        for action in self.mainwindow.actionsChangeValueDomainDatatype:
            action.setChecked(action.data() is datatype)
        self.datatypeButton.setText(datatype.value)
开发者ID:gitter-badger,项目名称:eddy,代码行数:30,代码来源:info.py

示例8: __init__

    def __init__(self, index, isPlaylistEmpty, hasUndo, hasRedo, parent=None):
        QMenu.__init__(self, parent)

        self.trackIndex = index
        self.w = PlaylistMenuWidget()

        if index.row() != -1:
            self.addAction(self.w.play)
            self.w.play.triggered.connect(self._onPlay)
            self.addAction(self.w.remove)
            self.w.remove.triggered.connect(self._onRemove)

        if not isPlaylistEmpty:
            self.addAction(self.w.clear)
            self.w.clear.triggered.connect(self._onClear)

            self.addAction(self.w.save)
            self.w.save.triggered.connect(self._onSave)

        if hasUndo:
            self.addAction(self.w.undo)
            self.w.undo.triggered.connect(self._onUndo)

        if hasRedo:
            self.addAction(self.w.redo)
            self.w.redo.triggered.connect(self._onRedo)

        self.addAction(self.w.reconnect)
        self.w.reconnect.triggered.connect(self._onReconnect)
开发者ID:petrushev,项目名称:txplaya,代码行数:29,代码来源:playlist.py

示例9: init_stat_bar

	def init_stat_bar(self):
		self.status_bar = self.statusBar()
		self.status_bar.setMaximumHeight(20)
		self.status_bar.setSizeGripEnabled(False)
		self.stat_info = QLabel()
		self.stat_info.setIndent(5)
		self.sort_main = QAction("Asc", self)
		sort_menu = QMenu()
		self.sort_main.setMenu(sort_menu)
		s_by_title = QAction("Title", sort_menu)
		s_by_artist = QAction("Artist", sort_menu)
		sort_menu.addAction(s_by_title)
		sort_menu.addAction(s_by_artist)
		self.status_bar.addPermanentWidget(self.stat_info)
		#self.status_bar.addAction(self.sort_main)
		self.temp_msg = QLabel()
		self.temp_timer = QTimer()

		self.manga_list_view.gallery_model.ROWCOUNT_CHANGE.connect(self.stat_row_info)
		self.manga_list_view.gallery_model.db_emitter.COUNT_CHANGE.connect(self.stat_row_info)
		self.manga_list_view.gallery_model.STATUSBAR_MSG.connect(self.stat_temp_msg)
		self.manga_list_view.STATUS_BAR_MSG.connect(self.stat_temp_msg)
		self.manga_table_view.STATUS_BAR_MSG.connect(self.stat_temp_msg)
		self.stat_row_info()
		app_constants.STAT_MSG_METHOD = self.stat_temp_msg
开发者ID:darmstard,项目名称:happypanda,代码行数:25,代码来源:app.py

示例10: __init__

    def __init__(self, titre='', liste=None, fonction=None, aide=''):
        QMenu.__init__(self, titre)
#        self.parent = parent
        self.fonction = None
#        self.titre = titre
#        self.setTitle(titre)
        self.update(liste, fonction, aide)
开发者ID:wxgeo,项目名称:geophar,代码行数:7,代码来源:menu.py

示例11: _get_menu

 def _get_menu(self):
     # main menu
     menu = QMenu()
     main_menu_action_group = QActionGroup(menu)
     main_menu_action_group.setObjectName("main")
     # character menu
     map_action = QAction(menu)
     map_action.setText("Toggle Map")
     main_menu_action_group.addAction(map_action)
     separator = QAction(menu)
     separator.setSeparator(True)
     main_menu_action_group.addAction(separator)
     characters_action = QAction(menu)
     characters_action.setText("Switch Characters")
     main_menu_action_group.addAction(characters_action)
     separator = QAction(menu)
     separator.setSeparator(True)
     main_menu_action_group.addAction(separator)
     settings_action = QAction(menu)
     settings_action.setText("Settings")
     main_menu_action_group.addAction(settings_action)
     quit_action = QAction(menu)
     quit_action.setText("Quit")
     main_menu_action_group.addAction(quit_action)
     menu.addActions(main_menu_action_group.actions())
     menu.triggered[QAction].connect(self._menu_actions)
     return menu
开发者ID:nomns,项目名称:Parse99,代码行数:27,代码来源:parse99.py

示例12: slot_transportViewMenu

    def slot_transportViewMenu(self):
        menu = QMenu(self)
        actHMS    = menu.addAction("Hours:Minutes:Seconds")
        actBBT    = menu.addAction("Beat:Bar:Tick")
        actFrames = menu.addAction("Frames")

        actHMS.setCheckable(True)
        actBBT.setCheckable(True)
        actFrames.setCheckable(True)

        if self.fCurTransportView == TRANSPORT_VIEW_HMS:
            actHMS.setChecked(True)
        elif self.fCurTransportView == TRANSPORT_VIEW_BBT:
            actBBT.setChecked(True)
        elif self.fCurTransportView == TRANSPORT_VIEW_FRAMES:
            actFrames.setChecked(True)

        actSelected = menu.exec_(QCursor().pos())

        if actSelected == actHMS:
            self.setTransportView(TRANSPORT_VIEW_HMS)
        elif actSelected == actBBT:
            self.setTransportView(TRANSPORT_VIEW_BBT)
        elif actSelected == actFrames:
            self.setTransportView(TRANSPORT_VIEW_FRAMES)
开发者ID:Houston4444,项目名称:Cadence,代码行数:25,代码来源:shared_canvasjack.py

示例13: getCustomContextMenu

 def getCustomContextMenu(self, point: QPoint):
     """
     Args:
         point: the point to place the context menu
     """
     sgv = self.slice_graphics_view
     do_show = False
     menu = None
     if len(self.selection_set) > 0:
         menu = QMenu(sgv)
         copy_act = QAction("copy selection", sgv)
         copy_act.setStatusTip("copy selection")
         copy_act.triggered.connect(self.copySelection)
         menu.addAction(copy_act)
         delete_act = QAction("delete selection", sgv)
         delete_act.setStatusTip("delete selection")
         delete_act.triggered.connect(self.deleteSelection)
         menu.addAction(delete_act)
         do_show = True
     if self.clip_board is not None:
         if menu is None:
             menu = QMenu(sgv)
         copy_act = QAction("paste", sgv)
         copy_act.setStatusTip("paste from clip board")
         copy_act.triggered.connect(self.pasteClipboard)
         menu.addAction(copy_act)
         do_show = True
     if do_show:
         # def menuClickSet(event):
         #     self.menu_pos = event.globalPos()
         #     return QMenu.mousePressEvent(menu, event)
         # menu.mousePressEvent = menuClickSet
         menu.exec_(sgv.mapToGlobal(point))
开发者ID:cadnano,项目名称:cadnano2.5,代码行数:33,代码来源:selectgridtool.py

示例14: __init__

    def __init__(self, project, settings):
        QWidget.__init__(self)
        self.ui = Ui_ProjectWidget()
        self.ui.setupUi(self)
        self.project = project
        self.project.filesChanged.connect(self.refresh)
        self.toolbar = QToolBar()
        import_image = lambda: ImportImage.pick(lambda f: self.import_image.emit(f[0]), settings)
        self.toolbar.addAction(ImportImage.icon(), ImportImage.ACTION_TEXT, import_image)
        self.ui.import_image.clicked.connect(import_image)
        self.raw_spectra_model = QStandardItemModel()
        self.calibrated_spectra_model = QStandardItemModel()
        self.finished_spectra_model = QStandardItemModel()

        def button_action(button, signal, widget, model):
            button.clicked.connect(lambda: signal.emit(model.item(widget.selectionModel().selectedRows()[0].row()).data() ) )
            widget.selectionModel().selectionChanged.connect(lambda sel, unsel: button.setEnabled(len(sel.indexes())>0))
            
        for model, widget in [(self.raw_spectra_model, self.ui.raw_spectra), (self.calibrated_spectra_model, self.ui.calibrated_spectra), (self.finished_spectra_model, self.ui.finished_spectra)]:
            widget.setModel(model)
            widget.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
            
        button_action(self.ui.calibrate, self.calibrate, self.ui.raw_spectra, self.raw_spectra_model)
        button_action(self.ui.math, self.math, self.ui.calibrated_spectra, self.calibrated_spectra_model)
        button_action(self.ui.finish, self.finish, self.ui.calibrated_spectra, self.calibrated_spectra_model)
        button_action(self.ui.open_finished, self.finish, self.ui.finished_spectra, self.finished_spectra_model)
        open_finished_menu = QMenu()
        self.ui.open_finished_dirs.setMenu(open_finished_menu)
        open_finished_menu.addAction(QIcon(':/image_20'), 'Exported Images folder', lambda: QDesktopServices.openUrl(QUrl.fromLocalFile(project.directory_path(Project.EXPORTED_IMAGES))))
        open_finished_menu.addAction(QIcon(':/done_20'), 'Finished Spectra folder', lambda: QDesktopServices.openUrl(QUrl.fromLocalFile(project.directory_path(Project.FINISHED_PROFILES))))
        

            
        self.refresh()
开发者ID:GuLinux,项目名称:PySpectrum,代码行数:34,代码来源:project_widget.py

示例15: __init__

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

        fileMenu = QMenu("&File", self)
        openAction = fileMenu.addAction("&Open...")
        openAction.setShortcut("Ctrl+O")
        saveAction = fileMenu.addAction("&Save As...")
        saveAction.setShortcut("Ctrl+S")
        quitAction = fileMenu.addAction("E&xit")
        quitAction.setShortcut("Ctrl+Q")

        self.setupModel()
        self.setupViews()

        openAction.triggered.connect(self.openFile)
        saveAction.triggered.connect(self.saveFile)
        quitAction.triggered.connect(QApplication.instance().quit)

        self.menuBar().addMenu(fileMenu)
        self.statusBar()

        self.openFile(':/Charts/qtdata.cht')

        self.setWindowTitle("Chart")
        self.resize(870, 550)
开发者ID:PWilsonUofC,项目名称:VGenes,代码行数:25,代码来源:chart.py


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