CommandBar Example

from DevMachines import __pyside2__, __pyside6__
from DevMachines.QtitanBase import Qtitan, ColorPickerButton
from DevMachines.QtitanStyle import ColorizedStyle
from DevMachines.QtitanNavigationDesignUI import NavigationMainWindow

if __pyside2__:
    from PySide2 import QtCore
    from PySide2.QtCore import Qt
    from PySide2.QtWidgets import QWidget, QComboBox, QLabel, QHBoxLayout, QVBoxLayout, QLayout

if __pyside6__:
    from PySide6 import QtCore
    from PySide6.QtCore import Qt
    from PySide6.QtWidgets import QWidget, QComboBox, QLabel, QHBoxLayout, QVBoxLayout, QLayout

class SettingsWidget(QWidget):
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        l = QVBoxLayout(self)
        l.setSizeConstraint(QLayout.SetNoConstraint)
        l.setAlignment(Qt.AlignCenter)
        l.setSpacing(20)

        style = qApp.style()
        if not isinstance(style, ColorizedStyle):
            return

        label = QLabel(self)
        label.setText(self.tr("Navigation Theme:"))
        themeComboBox = QComboBox(self)
        themeComboBox.addItem("Light")
        themeComboBox.addItem("Dark")
        themeComboBox.addItem("Blue")
        themeComboBox.addItem("Light Blue")
        themeComboBox.addItem("Red")
        themeComboBox.addItem("Custom")
        self.connect(themeComboBox, QtCore.SIGNAL("activated(int)"), self.themeActivated)
        label.setBuddy(themeComboBox)
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(themeComboBox)
        l.addLayout(hl)

        label = QLabel(self)
        label.setText(self.tr("Navigation Area:"))
        areComboBox = QComboBox(self)
        areComboBox.addItem("Top")
        areComboBox.addItem("Left")
        areComboBox.addItem("Right")
        areComboBox.addItem("Bottom")
        self.connect(areComboBox, QtCore.SIGNAL("activated(int)"), self.areaActivated)
        label.setBuddy(areComboBox)
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(areComboBox)
        l.addLayout(hl)

        label = QLabel(self)
        label.setText(self.tr("Window Color:"))
        self.windowColorPicker = ColorPickerButton()
        self.connect(self.windowColorPicker, QtCore.SIGNAL("colorSelected(const QColor&)"),
            style, QtCore.SLOT("setWindowColor(const QColor&)"))
        label.setBuddy(self.windowColorPicker)
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(self.windowColorPicker)
        l.addLayout(hl)

        label = QLabel(self)
        label.setText(self.tr("Window Text Color:"))
        self.windowTextColorPicker = ColorPickerButton()
        self.connect(self.windowTextColorPicker, QtCore.SIGNAL("colorSelected(const QColor&)"),
            style, QtCore.SLOT("setWindowTextColor(const QColor&)"))
        label.setBuddy(self.windowTextColorPicker)
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(self.windowTextColorPicker)
        l.addLayout(hl)

        label = QLabel(self)
        label.setText(self.tr("Material Color:"))
        self.materialColorColorPicker = ColorPickerButton()
        self.connect(self.materialColorColorPicker, QtCore.SIGNAL("colorSelected(const QColor&)"),
            style, QtCore.SLOT("setMaterialColor(const QColor&)"))
        label.setBuddy(self.materialColorColorPicker)
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(self.materialColorColorPicker)
        l.addLayout(hl)

        label = QLabel(self)
        label.setText(self.tr("Tile Menu Color:"))
        self.tileMenuColorPicker = ColorPickerButton()
        self.connect(self.tileMenuColorPicker, QtCore.SIGNAL("colorSelected(const QColor&)"),
            style, QtCore.SLOT("setTileMenuColor(const QColor&)"))
        label.setBuddy(self.tileMenuColorPicker)
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(self.tileMenuColorPicker)
        l.addLayout(hl)

        label = QLabel(self)
        label.setText(self.tr("Menu Color:"))
        self.menuColorPicker = ColorPickerButton()
        self.connect(self.menuColorPicker, QtCore.SIGNAL("colorSelected(const QColor&)"),
            style, QtCore.SLOT("setMenuColor(const QColor&)"))
        label.setBuddy(self.menuColorPicker)
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(self.menuColorPicker)
        l.addLayout(hl)

        label = QLabel(self)
        label.setText(self.tr("Link Color:"))
        self.linkColorPicker = ColorPickerButton()
        self.connect(self.linkColorPicker, QtCore.SIGNAL("colorSelected(const QColor&)"),
            style, QtCore.SLOT("setLinkColor(const QColor&)"))
        label.setBuddy(self.linkColorPicker)
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(self.linkColorPicker)
        l.addLayout(hl)

        label = QLabel(self)
        label.setText(self.tr("Item Color:"))
        self.itemColorPicker = ColorPickerButton()
        self.connect(self.itemColorPicker, QtCore.SIGNAL("colorSelected(const QColor&)"),
            style, QtCore.SLOT("setItemColor(const QColor&)"))
        label.setBuddy(self.itemColorPicker)
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(self.itemColorPicker)
        l.addLayout(hl)

        label = QLabel(self)
        label.setText(self.tr("Item Text Color:"))
        self.itemTextColorPicker = ColorPickerButton()
        self.connect(self.itemTextColorPicker, QtCore.SIGNAL("colorSelected(const QColor&)"),
            style, QtCore.SLOT("setItemTextColor(const QColor&)"))
        label.setBuddy(self.itemTextColorPicker)
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(self.itemTextColorPicker)
        l.addLayout(hl)

        label = QLabel(self)
        label.setText(self.tr("Caption Color:"))
        self.captionColorPicker = ColorPickerButton()
        self.connect(self.captionColorPicker, QtCore.SIGNAL("colorSelected(const QColor&)"),
            style, QtCore.SLOT("setCaptionColor(const QColor&)"))
        label.setBuddy(self.captionColorPicker)
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(self.captionColorPicker)
        l.addLayout(hl)

    def updateSettings(self):
        style = qApp.style()
        if not isinstance(style, ColorizedStyle):
            return
        self.windowColorPicker.setColor(style.windowColor())
        self.windowTextColorPicker.setColor(style.windowTextColor())
        self.materialColorColorPicker.setColor(style.materialColor())
        self.tileMenuColorPicker.setColor(style.tileMenuColor())
        self.menuColorPicker.setColor(style.menuColor())
        self.linkColorPicker.setColor(style.linkColor())
        self.itemColorPicker.setColor(style.itemColor())
        self.itemTextColorPicker.setColor(style.itemTextColor())
        self.captionColorPicker.setColor(style.captionColor())

    @QtCore.Slot(int)
    def themeActivated(self, index):
        style = qApp.style()
        if not isinstance(style, ColorizedStyle):
            return
        style.setTheme(ColorizedStyle.Theme(index))
        self.updateSettings()

    @QtCore.Slot(int)
    def areaActivated(self, index):
        w = self.window()
        if not isinstance(w, NavigationMainWindow):
            return

        if index == 0:
            w.setNavigationBarArea(Qtitan.TopArea)
        elif index == 1:
            w.setNavigationBarArea(Qtitan.LeftArea)
        elif index == 2:
            w.setNavigationBarArea(Qtitan.RightArea)
        else:
            w.setNavigationBarArea(Qtitan.BottomArea)