SystemMenuDemo Example

import sys, os
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../shared")

from DevMachines import __pyside2__, __pyside6__
from DevMachines import QtitanBase
from DevMachines.QtitanBase import CommonStyle
from DevMachines.QtitanRibbon import RibbonWorkspace, RibbonToolBarControl

if __pyside2__:
    from PySide2 import QtCore
    from PySide2.QtCore import Qt, QPoint
    from PySide2.QtGui import QIcon, QPixmap, QKeySequence
    from PySide2.QtWidgets import QAction, QFileDialog, QApplication, QMenu, QMessageBox

if __pyside6__:
    from PySide6 import QtCore
    from PySide6.QtCore import Qt, QPoint
    from PySide6.QtGui import QAction, QIcon, QPixmap, QKeySequence
    from PySide6.QtWidgets import QFileDialog, QApplication, QMenu, QMessageBox

from DemoRibbonWindow import DemoRibbonWindow

import SystemMenuDemo_rc

class MainWindow(DemoRibbonWindow):
    def __init__(self):
        DemoRibbonWindow.__init__(self)
        self.setWindowTitle(self.tr("Qtitan Ribbon System Menu Sample"))
        self.setCentralWidget(RibbonWorkspace())

        self.createMenuFile()
        self.createQuickAccessBar()
        self.createRibbon()
        self.statusBar()

        self.ribbonBar().setFrameThemeEnabled(True)

        geom = self.screen().availableGeometry()
        self.move(QPoint(200, 200))
        self.resize(2 * geom.width() / 3, 2 * geom.height() / 3)

    def createMenuFile(self):
        iconLogo = QIcon()
        iconLogo.addPixmap(QPixmap(":/res/qtitan.png"))
        iconLogo.addPixmap(QPixmap(":/res/qtitanlogo32x32.png"))
        systemButtonAction = self.ribbonBar().addSystemButton(iconLogo, self.tr("&File"))
        if systemButtonAction:
            systemButtonAction.setToolTip(self.tr("Click here to see everything<br />you can do with your<br />document"))
            systemMenu = self.ribbonBar().systemButton().systemMenu()
            if systemMenu:
                newFile = systemMenu.addAction(QIcon(":/res/new.png"), self.tr("&New"))
                newFile.setShortcut(self.tr("Ctrl+N"))
                newFile.setStatusTip(self.tr("Create a new document"))
                newFile.setToolTip(self.tr("New"))
                newFile.setEnabled(False)

                openFile = systemMenu.addAction(QIcon(":/res/open.png"), self.tr("&Open..."))
                openFile.setShortcut(self.tr("Ctrl+O"))
                openFile.setToolTip(self.tr("Open"))
                openFile.setStatusTip(self.tr("Open an existing document"))
                self.connect(openFile, QtCore.SIGNAL("triggered()"), self.open)

                saveFile = systemMenu.addAction(QIcon(":/res/save.png"), self.tr("&Save"))
                saveFile.setShortcut(self.tr("Ctrl+S"))
                saveFile.setToolTip(self.tr("Save"))
                saveFile.setStatusTip(self.tr("Save the active document"))
                self.connect(saveFile, QtCore.SIGNAL("triggered()"), self.save)

                saveAsFile = systemMenu.addAction(self.tr("Save &As..."))
                saveAsFile.setToolTip(self.tr("Save As"))
                saveAsFile.setStatusTip(self.tr("Save the active document with a new name"))
                self.connect(saveAsFile, QtCore.SIGNAL("triggered()"), self.save)

                systemMenu.addSeparator()

                actionPrint = QAction(QIcon(":/res/print.png"), self.tr("&Print..."), self)
                actionPrint.setToolTip(self.tr("Select a printer, number of copies, and other printing options before printing"))

                actionPagePrint = QAction(actionPrint.icon(), actionPrint.text(), self)
                systemMenu.addAction(actionPagePrint)
                pageSystemPopup = systemMenu.addPageSystemPopup(self.tr("Preview and print the document"), actionPagePrint, True)
                if pageSystemPopup:
                    self.connect(actionPagePrint, QtCore.SIGNAL("triggered()"), actionPrint, QtCore.SIGNAL("triggered()"))
                    pageSystemPopup.setMinimumWidth(296)
                    pageSystemPopup.addAction(actionPrint)
                    actionPrintSetup = QAction(QIcon(":/res/printSetup.png"), self.tr("P&rint Setup"), self)
                    actionPrintSetup.setToolTip(self.tr("Change the printer and printing options"))
                    pageSystemPopup.addAction(actionPrintSetup)
                    actionPrintPreview = QAction(QIcon(":/res/printPreview.png"), self.tr("Print Pre&view..."), self)
                    actionPrintPreview.setToolTip(self.tr("Preview and make changes to pages before printing"))
                    pageSystemPopup.addAction(actionPrintPreview)

                actionPrepare = systemMenu.addAction(QIcon(":/res/prepare.png"), self.tr("Pr&epare"))
                systemMenu.addAction(actionPrepare)
                actionSend = systemMenu.addAction(QIcon(":/res/send.png"), self.tr("Sen&d"))
                systemMenu.addAction(actionSend)
                pageSystemPopup = systemMenu.addPageSystemPopup(self.tr("Preview and print the document"), actionSend, False)
                if pageSystemPopup:
                    pageSystemPopup.setMinimumWidth(296)
                    actionMail = pageSystemPopup.addAction(QIcon(":/res/mail.png"), self.tr("E-Mail"))
                    actionMail.setToolTip(self.tr("Send the active document by e-mail"))
                    pageSystemPopup.addAction(actionMail)
                    actionIntenetFax = pageSystemPopup.addAction(QIcon(":/res/internetfix.png"), self.tr("Intenet Fax"))
                    actionIntenetFax.setToolTip(self.tr("Use an Internet fax service to fax the document"))
                    pageSystemPopup.addAction(actionIntenetFax)

                systemMenu.addSeparator()

                iconClose = QIcon()
                iconClose.addPixmap(QPixmap(":/res/close.png"))
                iconClose.addPixmap(QPixmap(":/res/smallclose.png"))
                actClose = systemMenu.addAction(iconClose, self.tr("&Close"))
                actClose.setShortcut(self.tr("Ctrl+C"))
                actClose.setStatusTip(self.tr("Exit"))
                self.connect(actClose, QtCore.SIGNAL("triggered()"), self.close)
                systemMenu.addPopupBarAction(actClose, Qt.ToolButtonTextBesideIcon)

                option = QAction(QPixmap(":/res/smalloption.png"), self.tr("Opt&ion"), self)
                systemMenu.addPopupBarAction(option, Qt.ToolButtonTextBesideIcon)
                option.setEnabled(False)

                pageRecentFile = systemMenu.addPageRecentFile(self.tr("Recent Documents"))
                if pageRecentFile != None:
                    pageRecentFile.setSize(9)
                    list = []
                    list.append("Document1.txt")
                    list.append("Document2.txt")
                    list.append("Document3.txt")
                    list.append("Document4.txt")
                    list.append("Document5.txt")
                    list.append("Document6.txt")
                    pageRecentFile.updateRecentFileActions(list)

    def createQuickAccessBar(self):
        quickAccessBar = self.ribbonBar().quickAccessBar()
        if quickAccessBar:
            action = quickAccessBar.actionCustomizeButton()
            action.setToolTip(self.tr("Customize Quick Access Bar"))

            smallButton = quickAccessBar.addAction(QIcon(":/res/smallNew.png"), self.tr("New"))
            smallButton.setToolTip(self.tr("Create a new document"))
            self.connect(smallButton, QtCore.SIGNAL("triggered()"), self.pressButton)
            quickAccessBar.setActionVisible(smallButton, False)

            smallButton = quickAccessBar.addAction(QIcon(":/res/smallOpen.png"), self.tr("Open"))
            smallButton.setToolTip(self.tr("Open an existing document"))
            self.connect(smallButton, QtCore.SIGNAL("triggered()"), self.pressButton)
            quickAccessBar.setActionVisible(smallButton, False)

            smallButton = quickAccessBar.addAction(QIcon(":/res/smallSave.png"), self.tr("Save"))
            smallButton.setToolTip(self.tr("Save the active document"))
            self.connect(smallButton, QtCore.SIGNAL("triggered()"), self.pressButton)

            quickAccessBar.addSeparator()

            smallButton = quickAccessBar.addAction(QIcon(":/res/smallUndo.png"), self.tr("&Undo"))
            smallButton.setShortcut(QKeySequence.Undo)
            smallButton.setEnabled(False)

            smallButton = quickAccessBar.addAction(QIcon(":/res/smallRedo.png"), self.tr("&Redo"))
            smallButton.setShortcut(QKeySequence.Redo)
            smallButton.setEnabled(False)

            quickAccessBar.setVisible(True)

    def createRibbon(self):
        pageButtons = self.ribbonBar().addPage(self.tr("&Home"))
        if pageButtons:
            groupClipboard = pageButtons.addGroup(self.tr("Clipboard"))
            if groupClipboard:
                editPaste = QMenu(self)
                actionPaste1 = editPaste.addAction(QIcon(":/res/smallClipboard.png"), self.tr("Paste"))
                actionPaste1.setPriority(QAction.LowPriority)
                actionPaste1.setShortcut(QKeySequence.Paste)

                actionPaste2 = groupClipboard.addAction(QIcon(":/res/clipboard.png"),
                    self.tr("&Paste"), Qt.ToolButtonTextUnderIcon, editPaste)
                actionPaste2.setPriority(QAction.LowPriority)
                actionPaste2.setShortcut(QKeySequence.Paste)

                actionCut = groupClipboard.addAction(QIcon(":/res/smallCut.png"),
                    self.tr("&Cut"), Qt.ToolButtonTextBesideIcon)
                actionCut.setShortcut(QKeySequence.Cut)

                actionCopy = groupClipboard.addAction(QIcon(":/res/smallCopy.png"),
                    self.tr("&Copy"), Qt.ToolButtonTextBesideIcon)
                actionCopy.setShortcut(QKeySequence.Copy)

                groupClipboard.addAction(QIcon(":/res/smallformat.png"),
                    self.tr("F&ormat Pointer"), Qt.ToolButtonTextBesideIcon)

        button = self.ribbonBar().systemButton()
        if button:
            button.setToolButtonStyle(Qt.ToolButtonTextOnly)

    @QtCore.Slot()
    def open(self):
        fileName = QFileDialog.getOpenFileName(self, self.tr("Open"))[0]
        if not fileName:
            return False
        self.statusBar().showMessage(self.tr("File loaded"), 2000)
        return True

    @QtCore.Slot()
    def save(self):
        fileName = QFileDialog.getSaveFileName(self, self.tr("Save As"),self.tr("Document"), "*.txt")[0]
        if not fileName:
            return False
        self.statusBar().showMessage(self.tr("File saved"), 2000)
        return True

    @QtCore.Slot()
    def print(self):
        printer = QPrinter()
        dialog = QPrintDialog(printer, self)
        return dialog.exec() == QDialog.Accepted

    @QtCore.Slot()
    def printSetup(self):
        return

    @QtCore.Slot()
    def pressButton(self):
        QMessageBox.information(self, self.windowTitle(), "Button pressed.", QMessageBox.Ok)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())