spacr.qt.widgets.usage_bar

UsageBar — labeled slim progress bar for RAM/GPU/CPU indicators.

Classes

UsageBar

Labeled thin progress bar with a right-aligned percent readout.

Module Contents

class spacr.qt.widgets.usage_bar.UsageBar(label: str, parent=None)[source]

Bases: PySide6.QtWidgets.QWidget

Labeled thin progress bar with a right-aligned percent readout.

Both text columns have fixed widths. The caption column is wider than “RAM” needs so the four bars of the System card line up; the readout column is fixed so the bar does not shift sideways as 9 % becomes 10 %. The widths are measured from the font rather than written as constants, so they hold at a large font scale: see _size_the_columns().

Parameters:
  • label – text shown to the left of the bar (e.g. “RAM”, “GPU”).

  • parent – parent widget; ownership only.

Build one labelled resource meter.

The row itself must paint nothing: the application sheet’s blanket background rule would otherwise put an opaque rectangle behind the bar, whatever is behind the page. The theme sheet’s UsageBarRow rule says so for every row at once, so a row carries no sheet of its own.

Parameters:
  • label – what is being measured.

  • parent – parent widget, or None.

changeEvent(event) → None[source]

Re-measure when the font under this row changes.

The stylesheet is what carries the font scale, and it is installed on the application after these widgets are built – a preferences save re-installs it on a live window. Both arrive as a font change on the widgets whose resolved font moved, so the columns are re-measured there rather than being right only for the sheet that happened to be current at construction.

Parameters:

event – the change event, passed to the base class; a font, application-font or style change re-measures the columns.

set_value(pct: float) → None[source]

Set the bar value, clamped to 0-100, and re-color at 75/90 %.

The new value is scheduled for the next paint rather than painted now. QProgressBar.setValue repaints synchronously whenever the change moves a pixel, and the bar is translucent over the window’s field, so each call painted the field under it and flushed the window there and then: four synchronous flushes every two seconds on every module screen, which on a composited GPU desktop each wait for the display. With updates held off for the call, the bar is marked dirty instead and is drawn with the next field frame.

The bar is re-polished only when the reading crosses into another band. A polish re-resolves the application style sheet for the bar, and the usage poll calls this for every bar every two seconds, almost always with the colour unchanged.

Parameters:

pct – value in 0.0-100.0; out-of-range values clamp.

showEvent(event) → None[source]

Re-measure on the way to being seen.

A widget’s QSS font is resolved when it is polished, which for a screen built into a stacked page happens on the way to the first show. Measuring here as well as on the font change is what keeps a row that was never sent a font change – because its own font was inherited whole – from being sized by the default metrics.

Parameters:

event – the show event, passed to the base class after the columns are re-measured.