MDIWindowDemo 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 DockMainWindow, DockWidgetPanel

if __pyside2__:
    from PySide2 import QtCore
    from PySide2.QtCore import Qt, QSize, QFile, QTextCodec
    from PySide2.QtGui import QIcon, QKeySequence
    from PySide2.QtWidgets import QAction, QApplication, QTreeWidgetItem, QTreeWidget, QMdiArea, QTextEdit, QLabel

if __pyside6__:
    from PySide6 import QtCore
    from PySide6.QtCore import Qt, QSize, QFile, QTextStream
    from PySide6.QtGui import QAction, QIcon, QKeySequence
    from PySide6.QtWidgets import QApplication, QTreeWidgetItem, QTreeWidget, QMdiArea, QTextEdit, QLabel

from DemoDockWindow import DemoDockWindow
import MDIWindowDemo_rc

class MyDockSubWindow(DockMainWindow):
    def __init__(self, parent = None):
        DockMainWindow.__init__(self, parent)
        self.textEdit = QTextEdit()
        self.setCentralWidget(self.textEdit)
        initialFile = ":/res/example.html";
        self.load(initialFile)
        self.createDockWidget()

    def createDockWidget(self):
        panel = self.addDockPanel("Child DockWidgetPanel", QSize(200, 120), Qtitan.LeftDockPanelArea)
        if panel != None:
            treeWidget = QTreeWidget()
            treeWidget.setAlternatingRowColors(True)
            treeWidget.setMinimumWidth(190)
            treeWidget.setHeaderHidden(True)

            strings = []
            strings.append(self.tr("MainItem"))
            mainItem = QTreeWidgetItem(strings)
            mainItem.setCheckState(0, Qt.Checked)
            mainItem.setExpanded(False)
            mainItem.setIcon(0, QIcon(":/res/open16x16.png"))
            treeWidget.insertTopLevelItem(0, mainItem)

            for i in range(0, 10):
                strings.clear()
                strings.append("Item {0:d}".format(i + 1))
                item = QTreeWidgetItem(mainItem, strings)
                item.setCheckState(0, Qt.Checked)
                item.setIcon(0, QIcon(":/res/open16x16.png"))
                item.setExpanded(True)
                treeWidget.insertTopLevelItem(1, item)

            treeWidget.expandAll()

            panel.setWidget(treeWidget)

            features = panel.features()
            #features &= ~(DockWidgetPanel.DockPanelMenuButton)
            panel.setFeatures(features)

    def minimumSizeHint(self):
        return self.centralWidget().minimumSizeHint().expandedTo(QSize(240, 200))

    def load(self, fileName):
        file = QFile(fileName)
        if not file.open(QFile.ReadOnly):
            return False

        shownName = "untitled.txt";
        self.setWindowTitle("{0:s}[*] - {1:s}".format(shownName, self.tr("Qtitan Docking")))

        if __pyside2__:
            data = file.readAll()
            codec = QTextCodec.codecForLocale()
            text = codec.toUnicode(data)
        if __pyside6__:
            stream = QTextStream(file)
            text = stream.readAll()

        self.textEdit.setText(text)
        return True

class MainWindow(DemoDockWindow):
    def __init__(self):
        DemoDockWindow.__init__(self)
        self.mdiArea = QMdiArea()
        self.mdiArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.mdiArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.setCentralWidget(self.mdiArea)

        self.createActions()
        self.createMenus()
        self.createToolBars()
        self.createStatusBar()
        self.createMdiChild()

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

    def createActions(self):
        self.fileNewAction = QAction(QIcon(":/res/new16x16.png"), self.tr("&New"), self)
        self.fileNewAction.setShortcuts(QKeySequence.New)
        self.fileNewAction.setStatusTip(self.tr("Create a document"))
        #    connect(self.fileNewAction, QtCore.SIGNAL(triggered()), self, QtCore.SLOT(newLetter()))

        self.fileOpenAction = QAction(QIcon(":/res/open16x16.png"), self.tr("&Open"), self)
        self.fileOpenAction.setShortcuts(QKeySequence.Open)
        self.fileOpenAction.setStatusTip(self.tr("Open an existing document"))
        #    connect(self.fileOpenAction, QtCore.SIGNAL(triggered()), self, QtCore.SLOT(newLetter()))

        self.fileSaveAction = QAction(QIcon(":/res/save16x16.png"), self.tr("&Save..."), self)
        self.fileSaveAction.setShortcuts(QKeySequence.Save)
        self.fileSaveAction.setStatusTip(self.tr("Save the active document"))
        #    connect(self.fileSaveAction, QtCore.SIGNAL(triggered()), self, QtCore.SLOT(save()))

        self.filePrintAction = QAction(QIcon(":/res/print16x16.png"), self.tr("Print"), self)
        self.filePrintAction.setStatusTip(self.tr("Print the active document"))
        self.filePrintAction.setDisabled(True)
        self.filePrintAction.setDisabled(True)

        self.editCutAction = QAction(QIcon(":/res/cut16x16.png"), self.tr("&Cut"), self)
        self.editCutAction.setShortcuts(QKeySequence.Cut)
        self.editCutAction.setStatusTip(self.tr("Cut the selection and put it on the Clipboard"))
        self.editCutAction.setDisabled(True)

        self.editCopyAction = QAction(QIcon(":/res/copy16x16.png"), self.tr("&Copy"), self)
        self.editCopyAction.setShortcuts(QKeySequence.Copy)
        self.editCopyAction.setStatusTip(self.tr("Copy the selection and put it on the Clipboard"))
        self.editCopyAction.setDisabled(True)

        self.editUndoAction = QAction(QIcon(":/res/undo16x16.png"), self.tr("Undo"), self)
        self.editUndoAction.setStatusTip(self.tr("Undo the last action"))
        self.editUndoAction.setDisabled(True)

        self.editRedoAction = QAction(QIcon(":/res/redo16x16.png"), self.tr("Redo"), self)
        self.editRedoAction.setStatusTip(self.tr("Redo the previously undone action"))
        self.editRedoAction.setDisabled(True)

    def createMenus(self):
        self.fileMenu = self.menuBar().addMenu(self.tr("&File"))
        self.fileMenu.addAction(self.fileNewAction)
        self.fileMenu.addAction(self.fileSaveAction)
        self.fileMenu.addAction(self.filePrintAction)

        self.editMenu = self.menuBar().addMenu(self.tr("&Edit"))
        self.viewMenu = self.menuBar().addMenu(self.tr("&View"))
        self.createViewMenuStyle(self.viewMenu)
        self.menuBar().addSeparator()
        self.helpMenu = self.menuBar().addMenu(self.tr("&Help"))
        self.helpMenu.addAction(self.aboutAction)

    def createToolBars(self):
        self.fileToolBar = self.addToolBar(self.tr("Standard"), Qtitan.DockBarTop)
        self.fileToolBar.setIconSize(QSize(16, 16))
        self.fileToolBar.addAction(self.fileNewAction)
        self.fileToolBar.addAction(self.fileOpenAction)
        self.fileToolBar.addAction(self.fileSaveAction)
        self.fileToolBar.addSeparator()
        self.fileToolBar.addAction(self.editCutAction)
        self.fileToolBar.addAction(self.editCopyAction)
        self.fileToolBar.addSeparator()
        self.fileToolBar.addAction(self.editUndoAction)
        self.fileToolBar.addAction(self.editRedoAction)
        self.fileToolBar.addSeparator()
        self.fileToolBar.addAction(self.filePrintAction)

        self.fileToolBar.addWidget(QLabel(self.tr("   Style:")))
        self.createComboBoxStyle()
        stylesAction = self.fileToolBar.addWidget(self.styleSwitcher)
        stylesAction.setToolTip(self.tr("Styles switcher"))

        self.fileToolBar.addSeparator()
        self.fileToolBar.addAction(self.aboutAction)

    def createStatusBar(self):
        self.statusBar().showMessage(self.tr("Ready"))

    def createMdiChild(self):
        subWindow = self.mdiArea.addSubWindow(MyDockSubWindow())
        subWindow.resize(640, 480)

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