BackstageView 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 Qtitan, CommonStyle
from DevMachines.QtitanRibbon import RibbonWorkspace, RibbonBackstageView

if __pyside2__:
    from PySide2 import QtCore
    from PySide2.QtCore import Qt, QPoint, QSettings
    from PySide2.QtGui import QIcon, QPixmap, QKeySequence
    from PySide2.QtWidgets import (QWidget, QApplication, QAction, QMenu, QListWidget,
           QCheckBox, QDockWidget, QGroupBox, QVBoxLayout, QMessageBox, QListWidgetItem)

if __pyside6__:
    from PySide6 import QtCore
    from PySide6.QtCore import Qt, QPoint, QSettings
    from PySide6.QtGui import QIcon, QPixmap, QKeySequence, QAction
    from PySide6.QtWidgets import (QWidget, QApplication, QMenu, QListWidget,
           QCheckBox, QDockWidget, QGroupBox, QVBoxLayout, QMessageBox, QListWidgetItem)

from DemoRibbonWindow import DemoRibbonWindow

from backstagepages import (RibbonBackstageInfoPage, RibbonBackstageSaveEmailPage,
    RibbonBackstageSaveWebPage, RibbonBackstageSavePage, RibbonBackstageAboutPage)

import BackstageView_rc

class MainWindow(DemoRibbonWindow):
    def __init__(self):
        DemoRibbonWindow.__init__(self)
        self.setWindowTitle(self.tr("PyQtitanRibbon Backstage Sample"))
        self.setCentralWidget(RibbonWorkspace())
        self.createBackstageView()
        self.createQuickAccessBar()
        self.createRibbon()
        self.createDockWindows()
        self.statusBar()
        self.ribbonBar().setTitleBackground(QPixmap(":/res/background.png"))
        self.move(QPoint(200, 200))
        geom = self.screen().availableGeometry()
        self.resize(2 * geom.width() / 3, 2 * geom.height() / 3)

        settings = QSettings(QSettings.UserScope, "Developer Machines")
        files = settings.value("recentFileList")
        settings.setValue("recentFileList", files)
        #emit updateRecentFileActions(files)
        self.ribbonBar().systemButton().setToolButtonStyle(Qt.ToolButtonTextOnly)

    def createBackstageView(self):
        iconLogo = QIcon()
        iconLogo.addPixmap(QPixmap(":/res/file.png"))
        iconLogo.addPixmap(QPixmap(":/res/qtitanlogo32x32.png"))
        actionFile = self.ribbonBar().addSystemButton(iconLogo, self.tr("&File"))
        actionFile.setToolTip(self.tr("Click here to see everything<br />you can do with your<br />document"))

        backstage = RibbonBackstageView(self)
        #connect(backstage, SIGNAL(aboutToShow()), this, SLOT(showBackstage()));
        #connect(backstage, SIGNAL(aboutToHide()), this, SLOT(hideBackstage()));

        saveFile = backstage.addAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Save), self.tr("&Save"))
        saveFile.setShortcut(self.tr("Ctrl+S"))
        saveFile.setToolTip(self.tr("Save"))
        saveFile.setStatusTip(self.tr("Save the active document"))
        #connect(saveFile, SIGNAL(triggered()), this, SLOT(save()));

        saveAsFile = backstage.addAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_SaveAs), self.tr("Save &As"))
        saveAsFile.setToolTip(self.tr("Save As"))
        saveAsFile.setStatusTip(self.tr("Save the active document with a new name"))
        #connect(saveAsFile, SIGNAL(triggered()), this, SLOT(save()))

        openFile = backstage.addAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Open), self.tr("&Open"))
        openFile.setShortcut(self.tr("Ctrl+O"))
        openFile.setToolTip(self.tr("Open"))
        openFile.setStatusTip(self.tr("Open an existing document"))
        #connect(openFile, SIGNAL(triggered()), this, SLOT(open()));

        infoPage = RibbonBackstageInfoPage(self)
        backstage.addPage(infoPage)

        savePage = RibbonBackstageSavePage(self)
        backstage.addPage(savePage)

        aboutPage = RibbonBackstageAboutPage(self)
        backstage.addPage(aboutPage)

        actOptions = backstage.addAction(QIcon(":/res/smallOptions.png"), self.tr("Options"))
        #connect(actOptions, SIGNAL(triggered()), this, SLOT(pressButton()));

        backstage.addSeparator()

        actExit = backstage.addAction(QIcon(":/res/smallClose.png"), self.tr("Exit"))
       # connect(actExit, SIGNAL(triggered()), this, SLOT(close()));

        sysButton = self.ribbonBar().systemButton()
        if sysButton != None:
            sysButton.setBackstage(backstage)

        backstage.open()

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

            smallButton = quickAccessBar.addAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_New),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(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Open), 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(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Save), self.tr("Save"))
            smallButton.setToolTip(self.tr("Save the active document"))
            self.connect(smallButton, QtCore.SIGNAL("triggered()"), self.pressButton)

            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("&Buttons"))
        if pageButtons != None:
            splitPopup = QMenu(self)
            splitPopup.addAction(self.tr("Option 1"))
            splitPopup.addAction(self.tr("Option 2"))
            splitPopup.addAction(self.tr("Option 3"))
            groupClipboard = pageButtons.addGroup(self.tr("Clipboard"))
            if groupClipboard != None:
                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/smallFormatPainter.png"), self.tr("F&ormat Pointer"), Qt.ToolButtonTextBesideIcon)
                groupClipboard.setEnabled(False)

            groupView = pageButtons.addGroup(self.tr("View"))
            if groupView != None:
                checkStatusBar = QCheckBox(self.tr("Status Bar"))
                checkStatusBar.setToolTip(self.tr("CheckBox 1"))
                checkStatusBar.setCheckState(Qt.Checked)
                groupView.addWidget(checkStatusBar)
                #connect(checkStatusBar, SIGNAL(stateChanged(int)), this, SLOT(hideStatusBar(int)));

        pageWindow = self.ribbonBar().addPage(self.tr("&Window"))
        pageContext = self.ribbonBar().addPage(self.tr("&Context Tab"))
        if pageContext != None:
            pageContext.setContextColor(Qtitan.ContextColorGreen)

        self.ribbonBar().setFrameThemeEnabled()

    def createDockWindows(self):
        dock = QDockWidget(self.tr("Styles"), self)
        dock.setAllowedAreas(Qt.AllDockWidgetAreas)

        styleWidget = QWidget()
        styleGroup = QWidget()
        listLayout = QVBoxLayout()
        listLayout.setContentsMargins(0, 0, 0, 0)

        customerList = QListWidget()
        for i in range(0, 10):
            customerList.insertItem(i, QListWidgetItem(self.tr("Item ") + str(i+1)))

        listLayout.addWidget(customerList)
        styleGroup.setLayout(listLayout)

        optionsGroup = QGroupBox(self.tr("Preview"))
        optionsLayout = QVBoxLayout()
        showPreviewBox = QCheckBox(self.tr("Show Preview"))
        showPreviewBox.setEnabled(False)
        linkedStylesBox = QCheckBox(self.tr("Disable Linked Styles"))
        optionsLayout.addWidget(showPreviewBox)
        optionsLayout.addWidget(linkedStylesBox)
        optionsGroup.setLayout(optionsLayout)

        mainLayout = QVBoxLayout()
        mainLayout.addWidget(styleGroup)
        mainLayout.addWidget(optionsGroup)
        styleWidget.setLayout(mainLayout)

        dock.setWidget(styleWidget)
        self.addDockWidget(Qt.LeftDockWidgetArea, dock)

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

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

    def openRecentFile(self, file):
        QMessageBox.information(self, self.windowTitle(),
                                "Open Recent File. " + file, QMessageBox.Ok)

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

    def printSetup(self):
        self = self

    def hideStatusBar(self, state):
        self.statusBar().setVisible(Qt.CheckState(state) == Qt.Checked)

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

    def showBackstage(self):
        quickAccessBar = self.ribbonBar().quickAccessBar()
        if quickAccessBar != None:
            quickAccessBar.setEnabled(False)
        self.actionRibbonMinimize.setEnabled(False)
        self.menuOptions.setEnabled(False)

    def hideBackstage(self):
        quickAccessBar = self.ribbonBar().quickAccessBar()
        if quickAccessBar != None:
            quickAccessBar.setEnabled(True)
        self.actionRibbonMinimize.setEnabled(True)
        self.menuOptions.setEnabled(True)

    def setDPIToggled(self, on_):
        #self.ribbonStyle.setDPIAware(on_)
        on_ = on_

    def setCurrentFile(self, fileName):
        self.setWindowFilePath(fileName)
        settings = QSettings(QSettings.UserScope, "Developer Machines")
        files = settings.value("recentFileList").toStringList()
        files.removeAll(fileName)
        files.prepend(fileName)
        while files.size() > 9:
            files.removeLast()
        settings.setValue("recentFileList", files)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setApplicationName("PyQtitanRibbon Backstage Sample");
    app.setOrganizationName("Developer Machines");
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())