style: narrow Optionals for basedpyright diff gate

QLayout.itemAt/QWidget.layout return Optionals; pyright cannot narrow
across repeated method calls, so hold them in locals before use in
tighten_column, _apply_collapsed and _set_visible.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-11 10:35:46 +02:00
co-authored by Claude Fable 5
parent ce0ed20d5a
commit ee7a8356a6
+14 -8
View File
@@ -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)