style: narrow Optionals for basedpyright diff gate
CI / lint (push) Skipped
CI / test (3.11) (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
CI / test-with-beamline-plugins (pxi_bec) (push) Skipped
CI / test-with-beamline-plugins (pxii_bec) (push) Skipped
CI / test-with-beamline-plugins (pxiii_bec) (push) Skipped
CI / test (3.12) (pull_request) Successful in 45s
CI / test-with-beamline-plugins (pxii_bec) (pull_request) Successful in 44s
CI / test-with-coverage (pull_request) Successful in 59s
CI / coverage-analysis (pull_request) Successful in 4s
CI / test (3.13) (pull_request) Successful in 1m53s
CI / lint (pull_request) Successful in 2m17s
CI / test (3.11) (pull_request) Successful in 2m18s
CI / test-with-beamline-plugins (pxi_bec) (pull_request) Successful in 4m15s
CI / test-with-beamline-plugins (pxiii_bec) (pull_request) Successful in 5m57s
CI / lint (push) Skipped
CI / test (3.11) (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
CI / test-with-beamline-plugins (pxi_bec) (push) Skipped
CI / test-with-beamline-plugins (pxii_bec) (push) Skipped
CI / test-with-beamline-plugins (pxiii_bec) (push) Skipped
CI / test (3.12) (pull_request) Successful in 45s
CI / test-with-beamline-plugins (pxii_bec) (pull_request) Successful in 44s
CI / test-with-coverage (pull_request) Successful in 59s
CI / coverage-analysis (pull_request) Successful in 4s
CI / test (3.13) (pull_request) Successful in 1m53s
CI / lint (pull_request) Successful in 2m17s
CI / test (3.11) (pull_request) Successful in 2m18s
CI / test-with-beamline-plugins (pxi_bec) (pull_request) Successful in 4m15s
CI / test-with-beamline-plugins (pxiii_bec) (pull_request) Successful in 5m57s
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user