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


Python QMenu.insertAction方法代码示例

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


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

示例1: MainWindow

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import insertAction [as 别名]

#.........这里部分代码省略.........
            if menu_rect.bottom() > desktop.bottom():
                self.menuEdit.move(self.menuEdit.x(),
                                   self.menuEdit.y() - self.menuEdit.height())
            if menu_rect.right() > desktop.right():
                self.menuEdit.move(self.menuEdit.x() - self.menuEdit.width(),
                                   self.menuEdit.y())

    def closeEvent(self, event):
        self._exit()
        event.ignore()

    def register_cue_menu_action(self, name, function, category='', shortcut=''):
        """Register a new-cue choice for the edit-menu

        param name: The name for the MenuAction
        param function: The function that add the new cue(s)
        param category: The optional menu where insert the MenuAction
        param shortcut: An optional shortcut for the MenuAction
        """
        action = QAction(self)
        action.setText(name)
        action.triggered.connect(function)
        if shortcut != '':
            action.setShortcut(shortcut)

        if category != '':
            if category not in self._cue_add_menu:
                menu = QMenu(category, self)
                self._cue_add_menu[category] = menu
                self.menuEdit.insertMenu(self.cueSeparator, menu)

            self._cue_add_menu[category].addAction(action)
        else:
            self.menuEdit.insertAction(self.cueSeparator, action)

    def update_window_title(self):
        saved = MainActionsHandler().is_saved()
        if not saved and not self.windowTitle()[0] == '*':
            self.setWindowTitle('*' + self.windowTitle())
        elif saved and self.windowTitle()[0] == '*':
            self.setWindowTitle(self.windowTitle()[1:])

    def _action_done(self, action):
        self.statusBar.showMessage(action.log())
        self.update_window_title()

    def _action_undone(self, action):
        self.statusBar.showMessage('Undone: ' + action.log())
        self.update_window_title()

    def _action_redone(self, action):
        self.statusBar.showMessage('Redone: ' + action.log())
        self.update_window_title()

    def _save(self):
        if self.filename == '':
            self._save_with_name()
        else:
            self.save_session.emit(self.filename)

    def _save_with_name(self):
        filename, _ = QFileDialog.getSaveFileName(parent=self,
                                                  filter='*.lsp',
                                                  directory=os.getenv('HOME'))
        if filename != '':
            if not filename.endswith('.lsp'):
开发者ID:chippey,项目名称:linux-show-player,代码行数:70,代码来源:mainwindow.py

示例2: MainWindow

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import insertAction [as 别名]

#.........这里部分代码省略.........
        if(prefUi.result() == QDialog.Accepted):
            configuration.update_config_from_dict(prefUi.get_configuraton())

    def exit(self):
        confirm = QMessageBox.Yes
        if not ActionsHandler().is_saved():
            confirm = QMessageBox.question(self, 'Exit',
                                           'The current session is not saved. '
                                           'Exit anyway?')

        if confirm == QMessageBox.Yes:
            qApp.quit()

    def closeEvent(self, event):
        self.exit()
        event.ignore()

    def register_cue_options_ui(self, name, options_ui, category='',
                                shortcut=''):
        '''
            Register a new-cue choice for the edit-menu

            @param name: The name for the MenuAction
            @param options_ui: A method that provide the options for the new
                               cue(s) (e.g. show a file-dialog)
            @param category: The optional menu where insert the MenuAction
            @param shortcut: An optional shortcut for the MenuAction
        '''
        action = QAction(self)
        action.setText(name)
        action.triggered.connect(lambda: self._add_cues(options_ui()))
        if shortcut != '':
            action.setShortcut(shortcut)

        if category != '':
            if category not in self._cue_add_menus:
                menu = QMenu(category, self)
                self._cue_add_menus[category] = menu
                self.menuEdit.insertMenu(self.cueSeparator, menu)

            self._cue_add_menus[category].addAction(action)
        else:
            self.menuEdit.insertAction(self.cueSeparator, action)

    def update_window_title(self):
        saved = ActionsHandler().is_saved()
        if not saved and not self.windowTitle()[0] == '*':
            self.setWindowTitle('*' + self.windowTitle())
        elif saved and self.windowTitle()[0] == '*':
            self.setWindowTitle(self.windowTitle()[1:])

    def _action_done(self, action):
        self.statusBar.showMessage(action.log())
        self.update_window_title()

    def _action_undone(self, action):
        self.statusBar.showMessage('Undone' + action.log())
        self.update_window_title()

    def _action_redone(self, action):
        self.statusBar.showMessage('Redone' + action.log())
        self.update_window_title()

    def _add_cues(self, options_list):
        for options in options_list:
            try:
                cue = CueFactory.create_cue(options)
                self.layout.add_cue(cue)
            except Exception as e:
                message = ' '.join([str(i) for i in e.args])
                QMessageBox.critical(None, 'Error', message)

    def _load_from_file(self):
        if self._new_session_confirm():
            path = QFileDialog.getOpenFileName(parent=self, filter='*.lsp',
                                               directory=os.getenv('HOME'))[0]

            if os.path.exists(path):
                self.open_session.emit(path)
                self.file = path
                return True

        return False

    def _new_session_confirm(self):
        confirm = QMessageBox.question(self, 'New session',
                                       'The current session will be lost. '
                                       'Continue?')

        return confirm == QMessageBox.Yes

    def _startup(self):
        if self._new_session_confirm():
            self.new_session.emit()

    def _fullscreen(self, enable):
        if enable:
            self.showFullScreen()
        else:
            self.showMaximized()
开发者ID:tornel,项目名称:linux-show-player,代码行数:104,代码来源:mainwindow.py


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