SimplePanels 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
from DevMachines.QtitanDocking import DockWidgetPanel

if __pyside2__:
    from PySide2 import QtCore
    from PySide2.QtCore import Qt
    from PySide2.QtGui import QPainter
    from PySide2.QtWidgets import QAction, QStyleOption, QApplication, QFrame

if __pyside6__:
    from PySide6 import QtCore
    from PySide6.QtCore import Qt
    from PySide6.QtGui import QPainter, QAction
    from PySide6.QtWidgets import QStyleOption, QApplication, QFrame

from DemoDockWindow import DemoDockWindow

class CustomWidget(QFrame):
    def __init__(self, title, shape = QFrame.NoFrame):
        QFrame.__init__(self)
        self.strTitle = title
        self.setFocusPolicy(Qt.StrongFocus)
        if shape != QFrame.NoFrame:
            self.setFrameShape(shape)
            self.setFrameShadow(QFrame.Sunken)

    def paintEvent(self, event):
        QFrame.paintEvent(self, event)
        if self.strTitle != "":
            painter = QPainter(self)
            opt = QStyleOption()
            opt.initFrom(self)
            painter.fillRect(opt.rect.adjusted(self.lineWidth() + 1, self.lineWidth() + 1, -self.lineWidth() + 1, -self.lineWidth() + 1), Qt.white)
            self.style().drawItemText(painter, opt.rect, Qt.TextShowMnemonic | Qt.AlignCenter, self.palette(), True, self.strTitle)

class MainWindow(DemoDockWindow):
    def __init__(self, parent = None):
        DemoDockWindow.__init__(self, parent)
        self.panel_1 = None
        self.panel_2 = None
        self.panel_3 = None

        self.setCentralWidget(CustomWidget("Central Widget"))
        self.createMenus()

        self.panel_1 = self.dockPanelManager().addDockPanel(self.tr("Panel 1"), Qtitan.LeftDockPanelArea)
        self.panel_1.setWidget(CustomWidget("Custom Widget"))

        self.panel_2 = self.dockPanelManager().addDockPanel(self.tr("Panel 2"), Qtitan.RightDockPanelArea)

        self.panel_3 = self.dockPanelManager().addDockPanel(self.tr("Panel 3"), Qtitan.BottomDockPanelArea)

        self.connect(self.dockPanelManager(), QtCore.SIGNAL("dockPanelActivated(DockWidgetPanel*)"), self, QtCore.SLOT("activationPanel(DockWidgetPanel*)"))
        self.connect(self.dockPanelManager(), QtCore.SIGNAL("dockPanelDeactivated(DockWidgetPanel*)"), self, QtCore.SLOT("deactivationPanel(DockWidgetPanel*)"))
        self.centralWidget().setFocus()

        self.connect(self.dockPanelManager(), QtCore.SIGNAL("aboutToClose(DockPanelBase*, bool&)"), self, QtCore.SLOT("aboutToClosePanel(DockPanelBase*, bool&)"))

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

    def createMenus(self):
        self.panelsMenu = self.menuBar().addMenu(self.tr("&Panels"))
        self.subPanelMenu_1 = self.panelsMenu.addMenu("Panel 1")
        self.subPanelMenu_2 = self.panelsMenu.addMenu("Panel 2")
        self.subPanelMenu_3 = self.panelsMenu.addMenu("Panel 3")
        self.panelsMenu.addSeparator()
        subActionDragging = self.panelsMenu.addAction("Shown Dragging Contents")
        subActionDragging.setCheckable(True)
        subActionDragging.setChecked(False)
        self.connect(subActionDragging, QtCore.SIGNAL("toggled(bool)"), self, QtCore.SLOT("draggingFrameActions(bool)"))

        if self.centralWidget() != None:
            self.panelsMenu.addSeparator()
            actCentralWidget = self.panelsMenu.addAction("Show central widget")
            actCentralWidget.setCheckable(True)
            actCentralWidget.setChecked(not self.centralWidget().isHidden())
            self.connect(actCentralWidget, QtCore.SIGNAL("toggled(bool)"), self, QtCore.SLOT("showCentralWidget(bool)"))

        self.connect(self.panelsMenu, QtCore.SIGNAL("aboutToShow()"), self, QtCore.SLOT("enableActions()"))

        self.panelFloatAction_1 = QAction("Float", self)
        self.subPanelMenu_1.addAction(self.panelFloatAction_1)
        self.connect(self.panelFloatAction_1, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelFloat_1()"))

        self.panelDockAction_1 = QAction("Dock", self)
        self.subPanelMenu_1.addAction(self.panelDockAction_1)
        self.connect(self.panelDockAction_1, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelDock_1()"))

        self.panelAutoHideAction_1 = QAction("Auto Hide", self)
        self.subPanelMenu_1.addAction(self.panelAutoHideAction_1)
        self.connect(self.panelAutoHideAction_1, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelAutoHide_1()"))

        self.panelHideAction_1 = QAction("Hide", self)
        self.subPanelMenu_1.addAction(self.panelHideAction_1)
        self.connect(self.panelHideAction_1, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelHide_1()"))

        self.panelShowAction_1 = QAction("Show", self)
        self.subPanelMenu_1.addAction(self.panelShowAction_1)
        self.connect(self.panelShowAction_1, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelShow_1()"))

        self.panelFloatAction_2 = QAction("Float", self)
        self.subPanelMenu_2.addAction(self.panelFloatAction_2)
        self.connect(self.panelFloatAction_2, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelFloat_2()"))

        self.panelDockAction_2 = QAction("Dock", self)
        self.subPanelMenu_2.addAction(self.panelDockAction_2)
        self.connect(self.panelDockAction_2, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelDock_2()"))

        self.panelAutoHideAction_2 = QAction("Auto Hide", self)
        self.subPanelMenu_2.addAction(self.panelAutoHideAction_2)
        self.connect(self.panelAutoHideAction_2, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelAutoHide_2()"))

        self.panelHideAction_2 = QAction("Hide", self)
        self.subPanelMenu_2.addAction(self.panelHideAction_2)
        self.connect(self.panelHideAction_2, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelHide_2()"))

        self.panelShowAction_2 = QAction("Show", self)
        self.subPanelMenu_2.addAction(self.panelShowAction_2)
        self.connect(self.panelShowAction_2, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelShow_2()"))

        self.panelFloatAction_3 = QAction("Float", self)
        self.subPanelMenu_3.addAction(self.panelFloatAction_3)
        self.connect(self.panelFloatAction_3, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelFloat_3()"))

        self.panelDockAction_3 = QAction("Dock", self)
        self.subPanelMenu_3.addAction(self.panelDockAction_3)
        self.connect(self.panelDockAction_3, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelDock_3()"))

        self.panelAutoHideAction_3 = QAction("Auto Hide", self)
        self.subPanelMenu_3.addAction(self.panelAutoHideAction_3)
        self.connect(self.panelAutoHideAction_3, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelAutoHide_3()"))

        self.panelHideAction_3 = QAction("Hide", self)
        self.subPanelMenu_3.addAction(self.panelHideAction_3)
        self.connect(self.panelHideAction_3, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelHide_3()"))

        self.panelShowAction_3 = QAction("Show", self)
        self.subPanelMenu_3.addAction(self.panelShowAction_3)
        self.connect(self.panelShowAction_3, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("triggeredPanelShow_3()"))

        self.configMenu = self.menuBar().addMenu(self.tr("&Project"))
        self.configMenu.addAction(self.saveStateAction)
        self.configMenu.addAction(self.loadStateAction)
        self.configMenu.addSeparator()
        self.createViewMenuStyle(self.configMenu)

        self.helpMenu = self.menuBar().addMenu(self.tr("&Help"))
        self.helpMenu.addAction(self.aboutAction)

    def enableActions(self):
        if self.panel_1 != None:
            self.panelFloatAction_1.setEnabled(not self.dockPanelManager().isDockPanelFloat(self.panel_1) and not self.dockPanelManager().isDockPanelAutoHide(self.panel_1) and not self.panel_1.isClosed())
            self.panelDockAction_1.setEnabled((self.dockPanelManager().isDockPanelFloat(self.panel_1) or self.dockPanelManager().isDockPanelAutoHide(self.panel_1)) and not self.panel_1.isClosed())
            self.panelAutoHideAction_1.setEnabled((not self.dockPanelManager().isDockPanelAutoHide(self.panel_1) and not self.dockPanelManager().isDockPanelFloat(self.panel_1)) and not self.panel_1.isClosed())
            self.panelHideAction_1.setEnabled(not self.panel_1.isClosed())
            self.panelShowAction_1.setEnabled(self.panel_1.isClosed())

        if self.panel_2 != None:
            self.panelFloatAction_2.setEnabled(not self.dockPanelManager().isDockPanelFloat(self.panel_2) and
                                               not self.dockPanelManager().isDockPanelAutoHide(self.panel_2) and
                                               not self.panel_2.isClosed())
            self.panelDockAction_2.setEnabled((self.dockPanelManager().isDockPanelFloat(self.panel_2) or
                                               self.dockPanelManager().isDockPanelAutoHide(self.panel_2)) and
                                              not self.panel_2.isClosed())
            self.panelAutoHideAction_2.setEnabled((not self.dockPanelManager().isDockPanelAutoHide(self.panel_2) and
                                                   not self.dockPanelManager().isDockPanelFloat(self.panel_2)) and
                                                  not self.panel_2.isClosed())
            self.panelHideAction_2.setEnabled(not self.panel_2.isClosed())
            self.panelShowAction_2.setEnabled(self.panel_2.isClosed())

        if self.panel_3 != None:
            self.panelFloatAction_3.setEnabled(not self.dockPanelManager().isDockPanelFloat(self.panel_3) and
                                               not self.dockPanelManager().isDockPanelAutoHide(self.panel_3) and
                                               not self.panel_3.isClosed())
            self.panelDockAction_3.setEnabled((self.dockPanelManager().isDockPanelFloat(self.panel_3) or
                                               self.dockPanelManager().isDockPanelAutoHide(self.panel_3)) and
                                              not self.panel_3.isClosed())
            self.panelAutoHideAction_3.setEnabled((not self.dockPanelManager().isDockPanelAutoHide(self.panel_3) and
                                                   not self.dockPanelManager().isDockPanelFloat(self.panel_3)) and
                                                  not self.panel_3.isClosed())
            self.panelHideAction_3.setEnabled(not self.panel_3.isClosed())
            self.panelShowAction_3.setEnabled(self.panel_3.isClosed())

    def triggeredPanelFloat_1(self):
        self.dockPanelManager().setDockPanelFloat(self.panel_1, True)

    def triggeredPanelDock_1(self):
        self.dockPanelManager().setDockPanelFloat(self.panel_1, False)

    def triggeredPanelAutoHide_1(self):
        self.dockPanelManager().setDockPanelAutoHide(self.panel_1, True)

    def triggeredPanelHide_1(self):
        if not self.panel_1.isClosed():
            self.panel_1.closePanel()

    def triggeredPanelShow_1(self):
        if self.panel_1.isClosed():
            self.dockPanelManager().showDockPanel(self.panel_1)

    def triggeredPanelFloat_2(self):
        self.dockPanelManager().setDockPanelFloat(self.panel_2, True)

    def triggeredPanelDock_2(self):
        self.dockPanelManager().setDockPanelFloat(self.panel_2, False)

    def triggeredPanelAutoHide_2(self):
        self.dockPanelManager().setDockPanelAutoHide(self.panel_2, True)

    def triggeredPanelHide_2(self):
        if not self.panel_2.isClosed():
            self.panel_2.closePanel()

    def triggeredPanelShow_2(self):
        if self.panel_2.isClosed():
            self.dockPanelManager().showDockPanel(self.panel_2)

    def triggeredPanelFloat_3(self):
        self.dockPanelManager().setDockPanelFloat(self.panel_3, True)

    def triggeredPanelDock_3(self):
        self.dockPanelManager().setDockPanelFloat(self.panel_3, False)

    def triggeredPanelAutoHide_3(self):
        self.dockPanelManager().setDockPanelAutoHide(self.panel_3, True)

    def triggeredPanelHide_3(self):
        if not self.panel_3.isClosed():
            self.panel_3.closePanel()

    def triggeredPanelShow_3(self):
        if self.panel_3.isClosed():
            self.dockPanelManager().showDockPanel(self.panel_3)

    def activationPanel(self, dockWidget):
        titleText = QApplication.applicationName()
        titleText += " - "
        titleText += dockWidget.windowTitle()
        self.setWindowTitle(titleText)

    def deactivationPanel(self, dockWidget):
        titleText = QApplication.applicationName()
        self.setWindowTitle(titleText)

    def draggingFrameActions(self, dragging):
        self.dockPanelManager().setDockPanelTransparentWhileDragging(not dragging)
        self.dockPanelManager().setArrowMarkersShown(not dragging)
        self.dockPanelManager().setDockPanelFullContentsWhileDraggingShown(not dragging)

    def showCentralWidget(self, visible):
        if visible:
            self.dockPanelManager().setCentralWidget(CustomWidget("Central Widget"))
        else:
            self.dockPanelManager().setCentralWidget(None)

    def aboutToClosePanel(self, panel, handled):
        if panel == self.panel_1:
            messageBox = QMessageBox(QMessageBox.Information, self.windowTitle(), "Warning", QMessageBox.Yes | QMessageBox.No, self)
            messageBox.setInformativeText("Are you sure you want to close self panel?")
            handled = messageBox.exec() == QMessageBox.Yes;

    def closeEvent(self, event):
        event.accept()
        self.writeSettings()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setApplicationName("PyQtitanDocking - Simple Dock Panels");
    app.setOrganizationName("Developer Machines");
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())