spacr.qt.widget_cleanup

Ownership-scoped cleanup for Qt objects libraries leave parentless.

Qt normally destroys a widget tree with its parent. pyqtgraph context menus are an exception: PlotItem and ViewBox intentionally create them as top-level windows and keep them through Python references. Closing a screen therefore used to leave hundreds of live menu widgets behind, all of which a later palette change had to visit.

The helper below walks only graphics scenes owned by the widget being closed. It never sweeps QApplication and never invokes Python’s cycle collector, so it cannot collect an unrelated live QThread wrapper.

Functions

retire_pyqtgraph_menus(→ int)

Queue deletion of parentless pyqtgraph menus owned by owner.

Module Contents

spacr.qt.widget_cleanup.retire_pyqtgraph_menus(owner: Any) → int[source]

Queue deletion of parentless pyqtgraph menus owned by owner.

Parameters:

owner – widget whose child QGraphicsView objects are searched for pyqtgraph plot and view-box menus; when it is a QWidget, parentless menus are reparented to it before deletion.

Returns:

number of distinct menu roots retired. 0 also covers an environment without pyqtgraph or an owner whose C++ object is gone.

Nested helpers

retire_pyqtgraph_menus.retire(menu) → None

Retire one menu, once. Already-seen menus are skipped.

spacr/qt/widget_cleanup.py:49