styles module
Gather GUI style-related objects.
In particular, define functions to display math equations.
- MATH_LABEL_DPI = 150
DPI used when rasterising mathtext labels.
- MATH_LABEL_FONTSIZE = 6
Font size (pt) passed to matplotlib.
- MATH_LABEL_DEFAULT_WIDTH_PX = 300
Fallback width (px) used for the first render, before the widget has been laid out and its real width is known.
- _normalize_key(key)
Convert all RST
:math:`...`spans to$...$.This allows keys written in either notation to go through the same rendering pipeline.
- _parse_key(key)
Split key into
(text, units).
- _render_to_pixmap(text, width_px, fontsize=6, dpi=150)
Render text as a matplotlib mathtext pixmap of width_px pixels.
- Parameters:
text (
str) – Fully composed mathtext string (output ofcompose_mathtext()).width_px (
int) – Available horizontal space in pixels. The figure is sized to this width so that matplotlib’swrap=Truebreaks lines at the correct point.fontsize (
int, default:6) – Font size in points.dpi (
int, default:150) – Rasterisation resolution.
- Returns:
Rendered pixmap, or
Noneif rendering failed.- Return type:
QPixmap or None
- _compose_mathtext(body, units)
Assemble body and units into a single matplotlib mathtext string.
- class MathTextLabel(body, units, fontsize=6, dpi=150, parent=None)
Bases:
QLabelA
QLabelthat renders mixed plain/math text as a pixmap.Re-renders automatically whenever the widget is resized, so the text always wraps to fit the available column width.
- Parameters:
- math_text_label_from_key(key, fontsize=6, dpi=150)
Convenience wrapper: parse key then render it.
- Parameters:
- Return type:
- Returns:
QLabel – Rendered label ready to be passed to
QTableWidget.setCellWidget.QLabel – Rendered unit ready to be passed to
QTableWidget.setCellWidget.