BackstageView Example

import sys

from DevMachines import __pyside2__, __pyside6__
from DevMachines.QtitanRibbon import RibbonBackstagePage, RibbonBackstageSeparator, getRibbonVersion

if __pyside2__:
    from PySide2 import QtCore
    from PySide2.QtCore import Qt, QPoint, QRect, QSize
    from PySide2.QtGui import QIcon
    from PySide2.QtWidgets import QAction, QMenu, QActionGroup

if __pyside6__:
    from PySide6 import QtCore
    from PySide6.QtCore import Qt, QPoint, QRect, QSize
    from PySide6.QtGui import QIcon, QActionGroup, QAction
    from PySide6.QtWidgets import QMenu

from ui_infoPage import Ui_InfoPage
from ui_saveemailpage import Ui_SaveEmailPage
from ui_savewebpage import Ui_SaveWebPage
from ui_savepage import Ui_SaveSendPage
from ui_helppage import Ui_AboutPage

class RibbonBackstageInfoPage(RibbonBackstagePage):
    def __init__(self, parent):
        RibbonBackstagePage.__init__(self, parent)
        self.ui = Ui_InfoPage()
        self.ui.setupUi(self)
        self.createActions()
        self.createMenus()

    def createActions(self):
        self.actMark = QAction(self.tr("Mark as &Final"), self)
        self.actMark.setStatusTip(self.tr("Let readers know the document is final and make it read-only."))
        self.actPassword = QAction(QIcon(":/res/ProtectDocument.png"), self.tr("Encrypt with Password"), self)
        self.actMark.setStatusTip(self.tr("Requare a password to open this document"))

        self.actInspect = QAction(self.tr("&Inspect Document"), self)
        self.actMark.setStatusTip(self.tr("Check the document for hidden properties or personal information."))
        self.actAccessibility = QAction(self.tr("Check Accessibility"), self)
        self.actMark.setStatusTip(self.tr("Check the document for content that people with disabilities might find difficult to read."))

    def createMenus(self):
        menu = QMenu(self)
        menu.addAction(self.actMark)
        menu.addAction(self.actPassword)
        self.ui.protectDocumentBut.setMenu(menu)

        menu = QMenu(self)
        menu.addAction(self.actInspect)
        menu.addAction(self.actAccessibility)
        self.ui.checkIssuesBut.setMenu(menu)

        maxWidth = self.ui.protectDocumentBut.sizeHint().width();
        maxWidth = max(maxWidth, self.ui.checkIssuesBut.sizeHint().width());
        maxWidth = max(maxWidth, self.ui.mngVersionsBut.sizeHint().width());
        self.ui.protectDocumentBut.setMinimumWidth(maxWidth);
        self.ui.protectDocumentBut.setMaximumWidth(maxWidth);
        self.ui.checkIssuesBut.setMinimumWidth(maxWidth);
        self.ui.checkIssuesBut.setMaximumWidth(maxWidth);
        self.ui.mngVersionsBut.setMinimumWidth(maxWidth);
        self.ui.mngVersionsBut.setMaximumWidth(maxWidth);

class RibbonBackstageSaveEmailPage(RibbonBackstagePage):
    def __init__(self, parent):
        RibbonBackstagePage.__init__(self, parent)
        self.ui = Ui_SaveEmailPage()
        self.ui.setupUi(self)

class RibbonBackstageSaveWebPage(RibbonBackstagePage):
    def __init__(self, parent):
        RibbonBackstagePage.__init__(self, parent)
        self.ui = Ui_SaveWebPage()
        self.ui.setupUi(self)

class RibbonBackstageSavePage(RibbonBackstagePage):
    def __init__(self, parent):
        RibbonBackstagePage.__init__(self, parent)
        self.separator = RibbonBackstageSeparator(self)
        self.separator.setOrientation(Qt.Vertical)
        self.ui = Ui_SaveSendPage()
        self.ui.setupUi(self)
        self.ui.pageWrapper.setText("")

        self.pageSaveEmail = RibbonBackstageSaveEmailPage(self.ui.pageWrapper)
        self.pageSaveWeb = RibbonBackstageSaveWebPage(self.ui.pageWrapper)
        self.pageSaveWeb.hide()

        actGroup = QActionGroup(self)

        self.actSendEmailButton = actGroup.addAction(self.ui.sendEmailButton.icon(), self.ui.sendEmailButton.text())
        self.actSendEmailButton.setCheckable(True)
        self.actSaveWebButton = actGroup.addAction(self.ui.saveWebButton.icon(), self.ui.saveWebButton.text())
        self.actSaveWebButton.setCheckable(True)
        self.actSharePointButton = actGroup.addAction(self.ui.sharePointButton.icon(), self.ui.sharePointButton.text())
        self.actSharePointButton.setCheckable(True)
        self.actBlogPostButton = actGroup.addAction(self.ui.blogPostButton.icon(), self.ui.blogPostButton.text())
        self.actBlogPostButton.setCheckable(True)
        self.actFileTypeButton = actGroup.addAction(self.ui.fileTypeButton.icon(), self.ui.fileTypeButton.text())
        self.actFileTypeButton.setCheckable(True)
        self.actCreateDocButton = actGroup.addAction(self.ui.createDocButton.icon(), self.ui.createDocButton.text())
        self.actCreateDocButton.setCheckable(True)

        self.ui.sendEmailButton.setDefaultAction(self.actSendEmailButton)
        self.ui.saveWebButton.setDefaultAction(self.actSaveWebButton)
        self.ui.sharePointButton.setDefaultAction(self.actSharePointButton)
        self.ui.blogPostButton.setDefaultAction(self.actBlogPostButton)
        self.ui.fileTypeButton.setDefaultAction(self.actFileTypeButton)
        self.ui.createDocButton.setDefaultAction(self.actCreateDocButton)

        self.actSendEmailButton.setChecked(True)
        self.connect(actGroup, QtCore.SIGNAL("triggered(QAction*)"), self.triggeredPage)

    def triggeredPage(self, action):
        if self.actSendEmailButton == action:
            self.pageSaveWeb.hide()
            self.pageSaveEmail.show()
        elif self.actSaveWebButton == action:
            self.pageSaveWeb.show()
            self.pageSaveEmail.hide()
        else:
            self.pageSaveWeb.hide()
            self.pageSaveEmail.hide()

    def resizeEvent(self, event):
        super(RibbonBackstagePage, self).resizeEvent(event)
        self.pageSaveEmail.setGeometry(QRect(QPoint(0, 0), self.ui.pageWrapper.size()))
        self.pageSaveWeb.setGeometry(QRect(QPoint(0, 0), self.ui.pageWrapper.size()))
        rc = self.ui.verticalLayoutTabs.geometry()
        self.separator.setGeometry(QRect(QPoint(rc.right() - 1, 0), QSize(3, self.size().height())))

class RibbonBackstageAboutPage(RibbonBackstagePage):
    def __init__(self, parent):
        RibbonBackstagePage.__init__(self, parent)
        self.ui = Ui_AboutPage()
        self.ui.setupUi(self)
        s = self.ui.labelVersion.text()
        if s == "":
            version = self.tr("Version:") + getRibbonVersion()
            self.ui.labelVersion.setText(version)