Skip to content

visualdynamics.gui.levels_readout

levels_readout

What the sine view's readouts of extracted levels share.

The distortion readout (gui.distortion_panel) and the frequency readout (gui.frequency_panel) are one shape: a rule and a title under the extraction's settings, the tone and the control channel to check, the check's own settings, the numbers it found, its notes, and a small plot. Each reads the levels already extracted and never extracts them, hides beside a record with none (principle 3), says so and checks nothing beside levels the project marks stale, and reads again at once on an edit, keeping the expensive part of the check when only its judgement moved. That behavior lives here once; each readout says what it checks, what its settings are and how its numbers are worded.

Classes:

Name Description
CheckPlot

A check against frequency, small: frequency on the log axis every

LevelsReadout

The tone, the channel and the check's settings, then what it

Classes

CheckPlot

CheckPlot(parent: QWidget | None = None)

Bases: PreviewPlot

A check against frequency, small: frequency on the log axis every sine level is read on, the check's own reading linear up the side. A readout's plot says how the check is drawn (draw) and how far up the side it reaches (span).

Methods:

Name Description
draw

Draw check on channel dof and return the items drawn.

span

The range up the side, (bottom, top).

show_check

Draw channel dof of check, or clear the plot when the

Source code in src/visualdynamics/gui/levels_readout.py
def __init__(self, parent: QWidget | None = None) -> None:
    super().__init__(parent)
    self.items: list[Any] = []
Methods:
draw
draw(check: Any, dof: str | None) -> list[Any]

Draw check on channel dof and return the items drawn.

Source code in src/visualdynamics/gui/levels_readout.py
def draw(self, check: Any, dof: str | None) -> list[Any]:
    """Draw `check` on channel `dof` and return the items drawn."""
    raise NotImplementedError
span
span(check: Any, dof: str | None) -> tuple[float, float]

The range up the side, (bottom, top).

Source code in src/visualdynamics/gui/levels_readout.py
def span(self, check: Any, dof: str | None) -> tuple[float, float]:
    """The range up the side, (bottom, top)."""
    raise NotImplementedError
show_check
show_check(check: Any, dof: str | None) -> None

Draw channel dof of check, or clear the plot when the check is None.

Source code in src/visualdynamics/gui/levels_readout.py
def show_check(self, check: Any, dof: str | None) -> None:
    """Draw channel `dof` of `check`, or clear the plot when the
    check is None."""
    for item in self.items:
        self.plot.removeItem(item)
    self.items = []
    if check is None:
        return
    self.items = self.draw(check, dof)
    self.plot.setYRange(*self.span(check, dof), padding=0.0)

LevelsReadout

LevelsReadout(parent: QWidget | None = None)

Bases: QWidget

The tone, the channel and the check's settings, then what it found. A readout names its TITLE, its plot class PLOT, its derived rows DERIVED as (key, label), and fills in the methods below the line.

Methods:

Name Description
show_levels

Check the extracted levels of history against

settings

The check's arguments as its plot function takes them: 'tone',

apply_theme

Redraw the small plot in a new theme's colors.

Source code in src/visualdynamics/gui/levels_readout.py
def __init__(self, parent: QWidget | None = None) -> None:
    super().__init__(parent)
    grid = QGridLayout(self)
    grid.setContentsMargins(0, 4, 0, 0)
    grid.setHorizontalSpacing(8)
    grid.setVerticalSpacing(4)
    rule = QFrame()
    rule.setFrameShape(QFrame.Shape.HLine)
    rule.setFrameShadow(QFrame.Shadow.Sunken)
    grid.addWidget(rule, 0, 0, 1, 2)
    self.title: QLabel = QLabel(self.TITLE)
    font = self.title.font()
    font.setBold(True)
    self.title.setFont(font)
    grid.addWidget(self.title, 1, 0, 1, 2)
    #: what is being read, and the check last made of it
    self._history: Any = None
    self._specification: Any = None
    self._levels: Any = None
    self._key: tuple | None = None
    self.check: Any = None
    #: why the levels shown are stale, when they are: nothing is
    #: checked against them until they are extracted again
    self._stale: str | None = None
    self._loading = False

    self.tone_box: QComboBox = QComboBox()
    self.tone_box.setToolTip('The tone checked, of those extracted')
    self.channel_box: QComboBox = QComboBox()
    self.channel_box.setToolTip(
        'The control channel checked: the extraction reads the '
        'channels the specification controls')
    rows = ([('tone', 'Tone', self.tone_box),
             ('channel', 'Channel', self.channel_box)]
            + self._setting_rows())
    self.names, self.editors = add_keyed_settings(grid, rows,
                                                  first_row=2)
    first = 2 + len(rows)
    made = add_derived(grid, self.DERIVED, first)
    self.derived: dict[str, QLabel] = {key: value for key, (_name, value)
                                       in made.items()}
    self.notes: QLabel = QLabel('')
    self.notes.setWordWrap(True)
    self.notes.setAlignment(Qt.AlignmentFlag.AlignLeft)
    grid.addWidget(self.notes, first + len(self.DERIVED), 0, 1, 2)
    self.preview: CheckPlot = self.PLOT()
    grid.addWidget(self.preview, first + len(self.DERIVED) + 1, 0, 1, 2)
    self.tone_box.currentIndexChanged.connect(self._edited)
    self.channel_box.currentIndexChanged.connect(self._edited)
Methods:
show_levels
show_levels(history: Any, specification: Any, levels: Any, stale: str | None = None) -> Any

Check the extracted levels of history against specification and show it; hide, and return None, when there are no levels to check (principle 3). The tone and channel boxes list what the levels hold and keep the ones chosen while the levels keep them; the tone row shows only when there is more than one. stale is the project's reason the levels are stale, if they are: then nothing is checked and the reason is shown, since the levels describe the record as it was. Returns the check, or None when there is none or it was refused (the refusal is shown).

Source code in src/visualdynamics/gui/levels_readout.py
def show_levels(self, history: Any, specification: Any, levels: Any,
                stale: str | None = None) -> Any:
    """Check the extracted `levels` of `history` against
    `specification` and show it; hide, and return None, when there are
    no levels to check (principle 3). The tone and channel boxes list
    what the levels hold and keep the ones chosen while the levels
    keep them; the tone row shows only when there is more than one.
    `stale` is the project's reason the levels are stale, if they
    are: then nothing is checked and the reason is shown, since the
    levels describe the record as it was. Returns the check, or None
    when there is none or it was refused (the refusal is shown)."""
    if levels is None or not len(levels):
        self.hide()
        self.check = None
        self._stale = None
        return None
    self._loading = True
    try:
        self._fill(self.tone_box, list(levels.tone_names))
        self._fill(self.channel_box,
                   [str(dof) for dof in levels.response_dof])
    finally:
        self._loading = False
    several = self.tone_box.count() > 1
    self.names['tone'].setVisible(several)
    self.tone_box.setVisible(several)
    self._history, self._specification = history, specification
    self._levels = levels
    self._stale = stale or None
    self.show()
    if stale:
        self._refused(f'These levels are stale ({stale}); extract them '
                      'again to check the record against them.')
        return None
    self._read()
    return self.check
settings
settings() -> dict[str, Any]

The check's arguments as its plot function takes them: 'tone', 'channel' and the readout's own (_own_settings).

Source code in src/visualdynamics/gui/levels_readout.py
def settings(self) -> dict[str, Any]:
    """The check's arguments as its plot function takes them: 'tone',
    'channel' and the readout's own (`_own_settings`)."""
    return {'tone': self.tone_box.currentText() or None,
            'channel': self.channel_box.currentText() or None,
            **self._own_settings()}
apply_theme
apply_theme(colors: Mapping[str, str]) -> None

Redraw the small plot in a new theme's colors.

Source code in src/visualdynamics/gui/levels_readout.py
def apply_theme(self, colors: Mapping[str, str]) -> None:
    """Redraw the small plot in a new theme's colors."""
    self.preview.apply_theme(colors)
    if self.check is not None:
        self.preview.show_check(self.check, self.settings()['channel'])

Functions: