spacr.qt.widgets.foldable¶
Shared click-to-fold behavior for titled Qt panels.
Folding hides the panel body so it no longer contributes to the layout size hint; adjacent stretchable content can then occupy the released space. The heading remains visible and provides the control for restoring the body.
Classes¶
The fold state of one panel, and the two widgets it moves. |
Functions¶
|
Make clicking |
Module Contents¶
- class spacr.qt.widgets.foldable.Folder(heading: PySide6.QtWidgets.QLabel, body: PySide6.QtWidgets.QWidget, name: str = '', on_change: Callable[[bool], None] | None = None)[source]¶
The fold state of one panel, and the two widgets it moves.
Not a QWidget. The panels this serves are already built and already in their layouts, and a wrapper would mean re-parenting them – which changes what their stylesheets match and what their splitters remember.
- Parameters:
heading – the label that folds the panel when clicked. It is rewritten to carry the arrow, so it must be a label this owns.
body – the widget shown and hidden.
name – what the panel is called, for the tooltip and for anything remembering fold state. Defaults to the heading’s own text.
on_change – called with the new shut/open state after each fold.
Make one heading fold the panel under it.
The heading is composed – an arrow, the panel name, and sometimes an alert – so asking the catalogue for the finished line asks for a key that cannot exist. The generic language pass is kept off it and the line is rebuilt from its translated parts.
- Parameters:
heading – the label that becomes the fold control.
body – the widget it folds away.
name – the panel’s name; defaults to the heading’s own text.
on_change – called with the new folded state after each toggle.
- add_listener(callback: Callable[[bool, bool], None]) None[source]¶
Call
callback(shut, by_user)after every fold from now on.A second audience beside
on_change: the splitter that gives the released room away, and the bookkeeping that keeps an automatic fold from undoing a fold the user chose, both need to hear about it without taking the callback the panel’s owner already holds.- Parameters:
callback – called with the new shut state and whether the user asked for it.
- alert(note: str = '!') None[source]¶
Mark the folded strip as having something to say.
A FOLDED CONSOLE THAT RECEIVES AN ERROR SAYS SO. Silence from a panel the user folded is indistinguishable from silence from a panel with nothing in it, and the first is the one that matters.
- set_shut(shut: bool, *, by_user: bool = True) bool[source]¶
Open or close the fold, reporting whether anything moved.
- Parameters:
shut – True to close it.
by_user – False when the program folds it on the user’s behalf (for example, a live preview opening). Such a fold is not remembered across a restart, and the listeners are told so.
- Returns:
the new shut state.
- toggle(*, by_user: bool = True) bool[source]¶
Fold if open, unfold if shut. Returns the new shut state.
- Parameters:
by_user – whether a person asked for it; see
set_shut().
- spacr.qt.widgets.foldable.make_foldable(heading: PySide6.QtWidgets.QLabel, body: PySide6.QtWidgets.QWidget, name: str = '', on_change: Callable[[bool], None] | None = None, *, persist_key: str = '', shut_by_default: bool = False) Folder[source]¶
Make clicking
headingfoldbodyaway. Returns the Folder.The Folder is returned so the caller can hold it: it owns the event filter, and a Folder nobody keeps stops working silently.
- Parameters:
heading – label that receives the click event filter and displays the open or shut marker.
body – panel whose visibility the heading toggles.
persist_key –
"<module>/<panel>". Given, the fold survives a restart. Empty means it does not, which is what a bare panel in a test wants – a test that wrote to the real preferences would fold a panel on the user’s next launch.shut_by_default – start folded unless the user opened this panel before (advanced rows that most people never change).