daplis_rtp.gui.theme module
Where every colour, font size and plot style in the application comes from.
One object holds the lot - the window palette, the accent, the colours the traces are drawn in, the two font sizes - and one signal says it has changed. Nothing else in the package hard-codes a colour.
The reason is that the old application chose its colours in a dozen
places: plt.style.use("dark_background") in three canvas modules,
#f48383 and teal written into the plotting calls, qdarkstyle
on the application, and a setPointSize on very nearly every widget
built. Changing the look meant finding all of them, and a user who
wanted a lighter background, or a colour they could actually
distinguish, had nowhere to say so.
Two rules keep it that way:
Widgets do not set their own font. The application font is set here and inherited; a widget that needs a different one gets an object name and a rule in the stylesheet below. A per-widget
setFontpins that widget at the size it was built with and ignores every later change.Canvases ask for their colours when they draw. They hold no copies, so a theme change is a redraw, not a rebuild.
Settings are stored per user through QSettings - on Windows in the
registry under HKCU\Software\DAPLIS\daplis-rtp - so two people
sharing a machine keep their own.
- class daplis_rtp.gui.theme.Theme(key: str, name: str, base: str, window: str, surface: str, text: str, muted: str, accent: str, ok: str, warn: str, error: str, figure_bg: str, axes_bg: str, axes_fg: str, axes_edge: str, grid: str, series: Tuple[str, ...], marker: str, glow: bool, grid_on: bool, panel: str = '', button: str = '', border: str = '', text_dim: str = '')[source]
Bases:
objectA complete look: window, controls and plots together.
Frozen because a theme is a value, not a thing that is edited. The user’s changes are kept separately, as overrides, and applied with
dataclasses.replacewhen the effective theme is built - so “reset to preset” is throwing the overrides away rather than reconstructing anything.- __init__(key: str, name: str, base: str, window: str, surface: str, text: str, muted: str, accent: str, ok: str, warn: str, error: str, figure_bg: str, axes_bg: str, axes_fg: str, axes_edge: str, grid: str, series: Tuple[str, ...], marker: str, glow: bool, grid_on: bool, panel: str = '', button: str = '', border: str = '', text_dim: str = '') None
- accent: str
- axes_bg: str
- axes_edge: str
- axes_fg: str
- base: str
- border: str = ''
- button: str = ''
- error: str
- figure_bg: str
- glow: bool
- grid: str
- grid_on: bool
- key: str
- marker: str
- muted: str
- name: str
- ok: str
- panel: str = ''
- series: Tuple[str, ...]
- surface: str
- text: str
- text_dim: str = ''
- warn: str
- window: str
- class daplis_rtp.gui.theme.ThemeManager(parent=None)[source]
Bases:
QObjectThe live theme, the user’s changes to it, and who to tell.
One of these exists per process - see
theme_manager(). It is aQObjectfor one reason: it emits a signal. Everything that draws connects tochangedand redraws itself, which is what makes a colour picked in the Preferences dialog show up on the plot while the dialog is still open.- apply_to_app(app=None)[source]
Put the current theme on the application.
The font goes on the
QApplicationrather than on the widgets, so that every widget built before or after this call picks it up. That is the whole reason nothing in the package callssetFontany more.
- changed
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- load()[source]
Read the stored settings, ignoring anything unrecognised.
A stored value that no longer names a field - a preset that was renamed, a colour written by a newer version - is skipped rather than raising. A settings file is not something the user can easily repair, so it must never be able to stop the application opening.
- property marker_size
- mpl_rc(fontsize=None)[source]
The theme as matplotlib rcParams.
Handed to
rc_contextaround a draw rather than pushed into the globalrcParams. The old code calledplt.style.useat import time andplt.rcParams.updatefrom inside draws, which meant the last canvas to be built decided how all of them looked.
- property plot_font_size
- property preset_key
- set_preset(key, keep_overrides=False)[source]
Switch preset.
The overrides are dropped by default, and that is deliberate: picking a new preset and getting the last one’s accent back is the surprising behaviour, not the helpful one.
- stylesheet()[source]
qdarkstyle for the controls, our own rules on top.
qdarkstyle is kept because it styles the sixty-odd widget classes Qt ships and nobody wants to write that. Its colours are swapped for the theme’s (see
retint()), so the window background, the text and the selection follow the theme. What it does not know about is the handful of named widgets - the tab title, the hint line, the log - that need to look different from their neighbours.
- property theme
The preset with the user’s overrides laid over it.
- property ui_font_size
- daplis_rtp.gui.theme.chrome_colours(palette, theme)[source]
{qdarkstyle colour: theme colour}for every palette colour.Backgrounds, borders and the greyed-out text of a disabled control run from the theme’s window background to its text; the softer text shades from its text to its dim text; the accent shades from the window background to its accent, so a selection is a deep tint of the accent on a dark theme and a pale one on a light theme.
Disabled is placed between background and text, as qdarkstyle has it, rather than taken from the dim text: on the light themes the dim text is dark enough to read, and a disabled button drawn in it looked like one that worked.
- daplis_rtp.gui.theme.preset_names()[source]
(key, display name)for every preset, in the order defined.
- daplis_rtp.gui.theme.retint(qss, palette, theme)[source]
qdarkstyle’s stylesheet with its palette swapped for the theme’s.
One pass over the text, so that a colour already swapped can never be swapped again by a later rule - two palette shades can land on each other’s old values. A colour the palette does not name is left as it is.