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


Python QtWidgets.QAction类代码示例

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


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

示例1: add

    def add(self, recent):
        remove_action = None
        for a in self.qactions:
            if a.recent == recent:
                remove_action = a
                break

        a = QAction("1: " + recent, self.filemenu, triggered=(lambda r=recent : lambda :self.open_wrapper(r))())
        a.recent = recent
        self.filemenu.insertAction (self.next_element, a)
        self.qactions.insert(0, a)
        self.next_element = a
        if remove_action:
            self.qactions.remove(remove_action)
            self.filemenu.removeAction(remove_action)

        for i, a in enumerate(self.qactions, 1):
            a.setText("%d: %s" % (i, a.recent))

        recent_lst = self.parent.load_setting('recent_lst', "").split(";")
        recent_lst.insert(0, recent)
        self.parent.save_setting('recent_lst', ";".join(recent_lst[:3]))
        if len(self.qactions) > self.max:
            a = self.qactions.pop()
            self.filemenu.removeAction(a)
开发者ID:madsmpedersen,项目名称:MMPE,代码行数:25,代码来源:recent_menu.py

示例2: func_wrapper

            def func_wrapper(plugin, workspace, *args, **kwargs):
                """
                Wrapper function that, when called, causes the plugin to be
                loaded into a specific workspace.
                """

                if workspace is None:
                    return

                parent = workspace.main_tool_bar
                action = QAction(parent)
                action.setText(name)

                if icon is not None:
                    action.setIcon(icon)

                if location is not None and isinstance(location, str):
                    for level in location.split('/'):
                        parent = self.get_action(parent, level)

                if isinstance(location, int):
                    parent.insertAction(parent.actions()[location], action)
                else:
                    parent.addAction(action)

                action.triggered.connect(lambda: func(plugin, *args, **kwargs))
开发者ID:nmearl,项目名称:specviz,代码行数:26,代码来源:plugin.py

示例3: _init_toolbar

 def _init_toolbar(self):
     a = QAction(getIcon('ruler'), 'Scale bar', self)
     a.setToolTip('Add scale bar')
     a.setCheckable(True)
     a.triggered.connect(self.scalebar)
     self._actions['scalebar'] = a
     self.insertAction(self._actions['configure_subplots'], a)
开发者ID:pyhmsa,项目名称:pyhmsa-gui,代码行数:7,代码来源:toolbar.py

示例4: __init__

 def __init__(self, parent, filemenu, open_func, next_element, max=10):
     self.parent = parent
     self.filemenu = filemenu
     self.open_func = open_func
     self.next_element = next_element
     self.max = max
     self.qactions = []
     for i, recent in enumerate([r for r in self.parent.load_setting('recent_lst', "").split(";") if r], 1):
         a = QAction("%d: %s" % (i, recent), self.filemenu, triggered=(lambda r=recent : lambda :self.open_wrapper(r))())
         a.recent = recent
         self.qactions.append(a)
         self.filemenu.insertAction (self.next_element, a)
     if self.qactions:
         self.next_element = self.qactions[0]
开发者ID:madsmpedersen,项目名称:MMPE,代码行数:14,代码来源:recent_menu.py

示例5: file_menu

            def file_menu():

                """Create a file submenu"""
                self.file_sub_menu = self.menubar.addMenu('File')

                self.open_action = QAction('Open File', self)
                self.open_action.setStatusTip('Open a new design')
                self.open_action.setShortcut('CTRL+O')
                # self.open_action.triggered.connect(self.open_file)

                self.exit_action = QAction('Exit', self)
                self.exit_action.setStatusTip('Exit the application.')
                self.exit_action.setShortcut('CTRL+Q')
                self.exit_action.triggered.connect(QApplication.quit)

                self.file_sub_menu.addAction(self.open_action)
                self.file_sub_menu.addAction(self.exit_action)
开发者ID:tuxxi,项目名称:OpenBurn,代码行数:17,代码来源:mainwindow.py

示例6: help_menu

 def help_menu():
     """Create help submenu"""
     self.help_sub_menu = self.menubar.addMenu('Help')
     self.about_action = QAction('About', self)
     self.about_action.setStatusTip('About the application.')
     self.about_action.setShortcut('CTRL+H')
     self.about_action.triggered.connect(self.about_dialog.exec_)
     self.help_sub_menu.addAction(self.about_action)
开发者ID:tuxxi,项目名称:OpenBurn,代码行数:8,代码来源:mainwindow.py

示例7: _init_menu_buttons

    def _init_menu_buttons(self):
        """
        Add the two menu buttons to the tool bar. Currently two are defined:
            View - for changing the view of the active window
            Data Processing - for applying a data processing step to the data.

        :return:
        """
        self._option_buttons = [
            self.ui.view_option_button,
            self.ui.cube_option_button
        ]

        # Create the View Menu
        view_menu = self._dict_to_menu(OrderedDict([
            ('Hide Axes', ['checkable', self._toggle_viewer_axes]),
            ('Hide Toolbars', ['checkable', self._toggle_toolbars]),
            ('Hide Spaxel Value Tooltip', ['checkable', self._toggle_hover_value]),
            ('Hide Stats', ['checkable', self._toggle_stats_display]),
            ('Flux Units', OrderedDict([
                ('Convert Displayed Units', lambda: self._open_dialog('Convert Displayed Units', None)),
                ('Convert Data Values', lambda: self._open_dialog('Convert Data Values', None)),
                ])
             ),
            ('Wavelength Units/Redshift', lambda: self._open_dialog('Wavelength Units/Redshift', None))
        ]))

        # Add toggle RA-DEC format:
        format_menu = view_menu.addMenu("RA-DEC Format")
        format_action_group = QActionGroup(format_menu)
        self.ra_dec_format_menu = format_menu

        # Make sure to change all instances of the the names
        # of the formats if modifications are made to them.
        for format_name in ["Sexagesimal", "Decimal Degrees"]:
            act = QAction(format_name, format_menu)
            act.triggered.connect(self._toggle_all_coords_in_degrees)
            act.setActionGroup(format_action_group)
            act.setCheckable(True)
            act.setChecked(True) if format == "Sexagesimal" else act.setChecked(False)
            format_menu.addAction(act)

        self.ui.view_option_button.setMenu(view_menu)

        # Create the Data Processing Menu
        cube_menu = self._dict_to_menu(OrderedDict([
            ('Collapse Cube', lambda: self._open_dialog('Collapse Cube', None)),
            ('Spatial Smoothing', lambda: self._open_dialog('Spatial Smoothing', None)),
            ('Moment Maps', lambda: self._open_dialog('Moment Maps', None)),
            ('Arithmetic Operations', lambda: self._open_dialog('Arithmetic Operations', None))
        ]))
        self.ui.cube_option_button.setMenu(cube_menu)
开发者ID:spacetelescope,项目名称:cube-tools,代码行数:52,代码来源:layout.py

示例8: _dict_to_menu

    def _dict_to_menu(self, menu_dict,  menu_widget=None):
        '''Stolen shamelessly from specviz. Thanks!'''
        if not menu_widget:
            menu_widget = QMenu()
        for k, v in menu_dict.items():
            if isinstance(v, dict):
                new_menu = menu_widget.addMenu(k)
                self._dict_to_menu(v, menu_widget=new_menu)
            else:
                act = QAction(k, menu_widget)

                if isinstance(v, list):
                    if v[0] == 'checkable':
                        v = v[1]
                        act.setCheckable(True)
                        act.setChecked(False)

                act.triggered.connect(v)
                menu_widget.addAction(act)
        return menu_widget
开发者ID:spacetelescope,项目名称:cube-tools,代码行数:20,代码来源:layout.py

示例9: SpyderAction

class SpyderAction(QAction):
    """Spyder QAction class wrapper to handle cross platform patches."""

    def __init__(self, *args, **kwargs):
        """Spyder QAction class wrapper to handle cross platform patches."""
        super(SpyderAction, self).__init__(*args, **kwargs)
        self._action_no_icon = None

        if sys.platform == 'darwin':
            self._action_no_icon = QAction(*args, **kwargs)
            self._action_no_icon.setIcon(QIcon())
            self._action_no_icon.triggered.connect(self.triggered)
            self._action_no_icon.toggled.connect(self.toggled)
            self._action_no_icon.changed.connect(self.changed)
            self._action_no_icon.hovered.connect(self.hovered)
        else:
            self._action_no_icon = self

    def __getattribute__(self, name):
        """Intercept method calls and apply to both actions, except signals."""
        attr = super(SpyderAction, self).__getattribute__(name)

        if hasattr(attr, '__call__') and name not in ['triggered', 'toggled',
                                                      'changed', 'hovered']:
            def newfunc(*args, **kwargs):
                result = attr(*args, **kwargs)
                if name not in ['setIcon']:
                    action_no_icon = self.__dict__['_action_no_icon']
                    attr_no_icon = super(QAction,
                                         action_no_icon).__getattribute__(name)
                    attr_no_icon(*args, **kwargs)
                return result
            return newfunc
        else:
            return attr

    @property
    def no_icon_action(self):
        """Return the action without an Icon."""
        return self._action_no_icon
开发者ID:silentquasar,项目名称:spyder,代码行数:40,代码来源:qthelpers.py

示例10: create_menus

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

        menubar = self.menuBar()

        file_menu = menubar.addMenu('&File')
        open_menu = file_menu.addMenu('&Open')

        open_file_action = QAction('&File', self)
        open_file_action.triggered.connect(self.openFile)

        open_dir_action = QAction('&Directory', self)
        open_dir_action.triggered.connect(self.openDirDialog)

        open_menu.addAction(open_file_action)
        open_menu.addAction(open_dir_action)

        file_menu.addAction(exit_action)
开发者ID:janpipek,项目名称:boadata,代码行数:22,代码来源:main_window.py

示例11: __init__

    def __init__(self, *args, **kwargs):
        """Spyder QAction class wrapper to handle cross platform patches."""
        super(SpyderAction, self).__init__(*args, **kwargs)
        self._action_no_icon = None

        if sys.platform == 'darwin':
            self._action_no_icon = QAction(*args, **kwargs)
            self._action_no_icon.setIcon(QIcon())
            self._action_no_icon.triggered.connect(self.triggered)
            self._action_no_icon.toggled.connect(self.toggled)
            self._action_no_icon.changed.connect(self.changed)
            self._action_no_icon.hovered.connect(self.hovered)
        else:
            self._action_no_icon = self
开发者ID:silentquasar,项目名称:spyder,代码行数:14,代码来源:qthelpers.py

示例12: set_context_menu_actions

    def set_context_menu_actions(self, table):
        """
        Sets up the context menu actions for the table
        :type table: QTableView
        :param table: The table whose context menu actions will be set up.
        :param ws_read_function: The read function used to efficiently retrieve data directly from the workspace
        """
        copy_action = QAction(self.COPY_ICON, "Copy", table)
        # sets the first (table) parameter of the copy action callback
        # so that each context menu can copy the data from the correct table
        decorated_copy_action_with_correct_table = partial(self.presenter.action_copy_cells, table)
        copy_action.triggered.connect(decorated_copy_action_with_correct_table)

        table.setContextMenuPolicy(Qt.ActionsContextMenu)
        table.addAction(copy_action)

        horizontalHeader = table.horizontalHeader()
        horizontalHeader.setContextMenuPolicy(Qt.ActionsContextMenu)
        horizontalHeader.setSectionResizeMode(QHeaderView.Fixed)

        copy_bin_values = QAction(self.COPY_ICON, "Copy", horizontalHeader)
        copy_bin_values.triggered.connect(partial(self.presenter.action_copy_bin_values, table))

        plot_bin_action = QAction(self.GRAPH_ICON, "Plot bin (values only)", horizontalHeader)
        plot_bin_action.triggered.connect(partial(self.presenter.action_plot_bin, table))
        plot_bin_with_errors_action = QAction(self.GRAPH_ICON, "Plot bin (values + errors)", horizontalHeader)
        plot_bin_with_errors_action.triggered.connect(partial(self.presenter.action_plot_bin_with_errors, table))
        separator1 = QAction(horizontalHeader)
        separator1.setSeparator(True)

        horizontalHeader.addAction(copy_bin_values)
        horizontalHeader.addAction(separator1)
        horizontalHeader.addAction(plot_bin_action)
        horizontalHeader.addAction(plot_bin_with_errors_action)

        verticalHeader = table.verticalHeader()
        verticalHeader.setContextMenuPolicy(Qt.ActionsContextMenu)
        verticalHeader.setSectionResizeMode(QHeaderView.Fixed)

        copy_spectrum_values = QAction(self.COPY_ICON, "Copy", verticalHeader)
        copy_spectrum_values.triggered.connect(
            partial(self.presenter.action_copy_spectrum_values, table))

        plot_spectrum_action = QAction(self.GRAPH_ICON, "Plot spectrum (values only)", verticalHeader)
        plot_spectrum_action.triggered.connect(partial(self.presenter.action_plot_spectrum, table))
        plot_spectrum_with_errors_action = QAction(self.GRAPH_ICON, "Plot spectrum (values + errors)",
                                                   verticalHeader)
        plot_spectrum_with_errors_action.triggered.connect(
            partial(self.presenter.action_plot_spectrum_with_errors, table))
        separator1 = QAction(verticalHeader)
        separator1.setSeparator(True)

        verticalHeader.addAction(copy_spectrum_values)
        verticalHeader.addAction(separator1)
        verticalHeader.addAction(plot_spectrum_action)
        verticalHeader.addAction(plot_spectrum_with_errors_action)
开发者ID:mantidproject,项目名称:mantid,代码行数:56,代码来源:view.py

示例13: get_action

    def get_action(parent, level=None):
        """
        Creates nested menu actions depending on the user-created plugin
        decorator location values.
        """
        for action in parent.actions():
            if action.text() == level:
                if isinstance(parent, QToolBar):
                    button = parent.widgetForAction(action)
                    button.setPopupMode(QToolButton.InstantPopup)
                elif isinstance(parent, QMenu):
                    button = action

                if button.menu():
                    menu = button.menu()
                else:
                    menu = QMenu(parent)
                    button.setMenu(menu)

                return menu
        else:
            action = QAction(parent)
            action.setText(level)

            if isinstance(parent, QToolBar):
                parent.addAction(action)
                button = parent.widgetForAction(action)
                button.setPopupMode(QToolButton.InstantPopup)
            elif isinstance(parent, QMenu):
                parent.addAction(action)
                button = action

            menu = QMenu(parent)
            button.setMenu(menu)

            return menu
开发者ID:nmearl,项目名称:specviz,代码行数:36,代码来源:plugin.py

示例14: __init__

    def __init__(self):
        super(TourTestWindow, self).__init__()
        self.setGeometry(300, 100, 400, 600)
        self.setWindowTitle('Exploring QMainWindow')

        self.exit = QAction('Exit', self)
        self.exit.setStatusTip('Exit program')

        # create the menu bar
        menubar = self.menuBar()
        file_ = menubar.addMenu('&File')
        file_.addAction(self.exit)

        # create the status bar
        self.statusBar()

        # QWidget or its instance needed for box layout
        self.widget = QWidget(self)

        self.button = QPushButton('test')
        self.button1 = QPushButton('1')
        self.button2 = QPushButton('2')

        effect = QGraphicsOpacityEffect(self.button2)
        self.button2.setGraphicsEffect(effect)
        self.anim = QPropertyAnimation(effect, to_binary_string("opacity"))
        self.anim.setStartValue(0.01)
        self.anim.setEndValue(1.0)
        self.anim.setDuration(500)

        lay = QVBoxLayout()
        lay.addWidget(self.button)
        lay.addStretch()
        lay.addWidget(self.button1)
        lay.addWidget(self.button2)

        self.widget.setLayout(lay)

        self.setCentralWidget(self.widget)
        self.button.clicked.connect(self.action1)
        self.button1.clicked.connect(self.action2)

        self.tour = AnimatedTour(self)
开发者ID:0xBADCA7,项目名称:spyder,代码行数:43,代码来源:tour.py

示例15: __init__

    def __init__(self, parent=None):
        super(ManiWindow, self).__init__(parent)
        self.canvas = qtViewer3d(self)
        # self.setWindowTitle("pythonOCC-%s 3d viewer" % VERSION)
        self.canvas.InitDriver()

        bar = self.menuBar()
        file = bar.addMenu("&File")

        _new = QAction(QIcon('icons/exit.png'), '&New', self)
        _new.setStatusTip("New application")
        _new.triggered.connect(self.my_process)
        # self.connect(_new, SIGNAL("triggered()"), self.my_process)
        file.addAction(_new)

        _exit = QAction(QIcon('icons/exit.png'), '&Exit', self)
        _exit.setShortcut('Ctrl+Q')
        _exit.setStatusTip('Exit application')
        _exit.triggered.connect(qApp.quit)
        file.addAction(_exit)
        self.statusBar()
        self.setCentralWidget(self.canvas)
        self.resize(800, 600)
开发者ID:kozintsev,项目名称:ResearchPythonOCC,代码行数:23,代码来源:TestQtBackendNative.py


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