spacr.qt.widgets.ai_toggle_label¶
AiToggleLabel — a clickable text label used in place of a QCheckBox for the “AI” switch that sits at the bottom-right of every AppScreen.
Reads “AI” in the current theme’s foreground colour when off — white on the dark themes, near-black on light.
Reads “AI” in the accent blue when on.
Emits
toggled(bool)on click; also exposes a QCheckBox-compatibleisChecked()/setChecked()API so the AppScreen doesn’t care which widget it’s talking to.
Note
The OFF colour is resolved through spacr.qt.theme.active_palette()
(i.e. palette_for(resolve_effective_theme())) every time the style
is rebuilt, never imported from theme.PALETTE. That module-level
name is the dark palette and nothing updates it, so importing it
painted #ffffff “AI” text onto the light theme’s #fafafa page:
1.04:1 measured, white on near-white, invisible. It is 18.50:1
now. See tests.qt.test_theme_blind_console_widgets.
Classes¶
Clickable text label that behaves like a QCheckBox toggle. |
Module Contents¶
- class spacr.qt.widgets.ai_toggle_label.AiToggleLabel(parent=None, text: str = 'AI', tooltip: str | None = None)[source]¶
Bases:
PySide6.QtWidgets.QLabelClickable text label that behaves like a QCheckBox toggle.
Originally the “AI” switch, now also used for the “Live” preview toggle. Every consumer gets the same on-blue / off-white visual so the row of toggles reads consistently.
- Parameters:
text – label text (default
"AI"for back-compat).tooltip – hover tooltip; falls back to a sensible AI-flavoured message when omitted.
parent – parent widget; ownership only.
- Variables:
toggled – emitted with the new on/off state whenever the user clicks or
setChecked()flips the state.
Build the AI toggle label, off.
The English source text and tooltip are kept as properties, so a runtime language switch translates the original rather than translating a translation, and the toggle’s state survives it.
- Parameters:
parent – parent widget, or
None.text – the label;
"AI"by default.tooltip – hover text;
Noneuses the standard explanation of what the toggle does.
- changeEvent(event)[source]¶
Re-style when the application sheet or palette is replaced.
Saving Preferences calls
app.setStyleSheet(...), which sends every widget aStyleChange. Widgets styled by the application sheet pick the new Zoom up for free; this one is not, so without this hook “Live” and “AI” would keep the size and the colour they were built with until the app was restarted.- Parameters:
event – the change event; passed to the base class, and a style, palette, application-palette or application-font change re-styles the label.
- displayed_text() str[source]¶
What the label is actually painting, elided or not.
Distinct from
text(), which is the logical label. Tests need both to tell “the toggle says X” from “the toggle currently fits this much of X”.
- minimumSizeHint() PySide6.QtCore.QSize[source]¶
Cap how much width this toggle can demand of its row.
QLabel reports the full width of its text here, which makes the text a hard floor for every ancestor layout. See
ELIDE_ABOVE_PXfor what that cost.
- mousePressEvent(event)[source]¶
Flip the toggle on left-click; forward other buttons to Qt.
- Parameters:
event – the mouse press; only its button is read, and a left-button press is consumed.
- resizeEvent(event)[source]¶
Re-elide for the width just granted.
- Parameters:
event – the resize event; passed to the base class, and the new width is read back from the widget itself.
- setChecked(on: bool) None[source]¶
Set the toggle state; emits
toggledonly on a real change.- Parameters:
on – the new state, coerced to
bool;Trueis ON.
- setText(text) None[source]¶
Remember the full text, then show as much of it as fits.
The language switch calls this with a fresh translation, so the stored text has to follow it rather than be captured once.
- Parameters:
text – the full label text; stored as
text()and elided to the current width when it does not fit.