Skip to content

Dock restoreState fails silently if a dock object is the only item in a V- or HContainer #2887

@UsYer

Description

@UsYer

Short description

Calling restoreState() on a dockArea where a dock is the only object inside a container leads to the state being not correctly restored.
I don't know how it happened that a dock could appear as the only item in a container but one user managed to do that.
I couldn't find out how to trigger that.
Anyway, in that case way too many container are apoptose'd and the state is nor correctly restored

Code to reproduce

import json
import sys

import pyqtgraph as pg
from PySide6.QtWidgets import QMainWindow
from pyqtgraph.dockarea import Dock, DockArea


class DockApp(QMainWindow):
    def __init__(self, title):
        super().__init__()
        self.dock_area = DockArea()
        self.setCentralWidget(self.dock_area)
        self.dock_area.addDock(Dock(name="Plot 1", closable=False), 'left')
        self.dock_area.addDock(Dock(name="Plot 2", closable=False), 'left')
        self.dock_area.addDock(Dock(name="Plot 4", closable=False), 'left')
        self.dock_area.addDock(Dock(name="Table 1", closable=False), 'left')
        self.dock_area.addDock(Dock(name="Table 2", closable=False), 'left')
        self.dock_area.addDock(Dock(name="Table 3", closable=False), 'left')

        state = json.loads("""{
          "main": [
            "vertical",
            [
              [
                "horizontal",
                [
                  [
                    "vertical",
                    [
                      [
                        "vertical",
                        [
                          [
                            "dock",
                            "Plot 1",
                            {}
                          ]
                        ],
                        {
                          "sizes": [
                            314
                          ]
                        }
                      ],
                      [
                        "dock",
                        "Plot 2",
                        {}
                      ]
                    ],
                    {
                      "sizes": [
                        314,
                        313
                      ]
                    }
                  ],
                  [
                    "vertical",
                    [
                      [
                        "dock",
                        "Table 3",
                        {}
                      ],
                      [
                        "dock",
                        "Table 2",
                        {}
                      ],
                      [
                        "dock",
                        "Table 1",
                        {}
                      ]
                    ],
                    {
                      "sizes": [
                        208,
                        207,
                        208
                      ]
                    }
                  ]
                ],
                {
                  "sizes": [
                    784,
                    783
                  ]
                }
              ],
              [
                "dock",
                "Plot 4",
                {}
              ]
            ],
            {
              "sizes": [
                631,
                210
              ]
            }
          ],
          "float": []
        }""")
        self.dock_area.restoreState(state)


if __name__ == '__main__':
    app = pg.Qt.mkQApp("LiveTrace")
    window = DockApp(title='Test')
    window.show()
    sys.exit(app.exec())

Expected behavior

All 6 docks should be restored like this:
image

Real behavior

Only 2 docks are visible. All other docks are missing.
image

Note: No exception is thrown

Tested environment(s)

  • PyQtGraph version: 0.13.3
  • Qt Python binding: PySide6 6.6.0 Qt 6.6.0
  • Python version: 3.10.11 AMD64
  • NumPy version: 1.26.2
  • Operating system: Windows 10 22H2
  • Installation method: pip

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions