diff --git a/src/aare/gui/widgets/title_label.py b/src/aare/gui/widgets/title_label.py index 237df236..2d128825 100644 --- a/src/aare/gui/widgets/title_label.py +++ b/src/aare/gui/widgets/title_label.py @@ -16,10 +16,12 @@ def tighten_column(layout: QLayout) -> None: """ layout.setSpacing(PANEL_VSPACING) for i in range(layout.count()): - w = layout.itemAt(i).widget() - if w is not None and w.layout() is not None: - m = w.layout().contentsMargins() - w.layout().setContentsMargins(m.left(), PANEL_VMARGIN, m.right(), PANEL_VMARGIN) + item = layout.itemAt(i) + widget = item.widget() if item is not None else None + child_layout = widget.layout() if widget is not None else None + if child_layout is not None: + m = child_layout.contentsMargins() + child_layout.setContentsMargins(m.left(), PANEL_VMARGIN, m.right(), PANEL_VMARGIN) class TitleLabel(QLabel): @@ -91,9 +93,10 @@ class TitleLabel(QLabel): def _apply_collapsed(self) -> None: parent = self.parentWidget() - if parent is None or parent.layout() is None: + parent_layout = parent.layout() if parent is not None else None + if parent_layout is None: return - self._set_visible(parent.layout(), not self._collapsed) + self._set_visible(parent_layout, not self._collapsed) self.toggle_button.setText("+" if self._collapsed else "−") self.toggle_button.setToolTip("Restore panel" if self._collapsed else "Minimise panel") @@ -101,9 +104,12 @@ class TitleLabel(QLabel): # Recursive: panels like SamcamPanel nest sub-layouts via addLayout. for i in range(layout.count()): item = layout.itemAt(i) + if item is None: + continue widget = item.widget() + child_layout = item.layout() if widget is not None: if widget is not self: widget.setVisible(visible) - elif item.layout() is not None: - self._set_visible(item.layout(), visible) + elif child_layout is not None: + self._set_visible(child_layout, visible)