|
9 | 9 | from types import SimpleNamespace |
10 | 10 |
|
11 | 11 | import numpy as np |
| 12 | +from guidata import qthelpers as guidata_qth |
| 13 | +from plotpy import config as plotpy_config |
12 | 14 | from qtpy import QtCore as QC |
13 | 15 | from qtpy import QtGui as QG |
14 | 16 | from qtpy import QtWidgets as QW |
@@ -120,6 +122,38 @@ def create_gaussian(menu: QW.QMenu, *_args) -> None: |
120 | 122 | Conf.welcome_on_startup.set(initial) |
121 | 123 |
|
122 | 124 |
|
| 125 | +def test_welcome_page_follows_color_mode(monkeypatch) -> None: |
| 126 | + """Subdued texts remain legible when the color mode is switched at runtime""" |
| 127 | + # Switching the color mode changes these globals: restore them at teardown |
| 128 | + monkeypatch.setenv(guidata_qth.ENV_COLOR_MODE, guidata_qth.get_color_mode()) |
| 129 | + monkeypatch.setattr(guidata_qth, "CURRENT_THEME", guidata_qth.CURRENT_THEME) |
| 130 | + initial_mode = Conf.color_mode.get() |
| 131 | + description = _("Generate a 1D signal or 2D image from a template.") |
| 132 | + with datalab_test_app_context(console=False) as win: |
| 133 | + page = win.welcomepanel |
| 134 | + labels = [page.start_title] + [ |
| 135 | + label |
| 136 | + for label in page.entries["create"].findChildren(QW.QLabel) |
| 137 | + if label.text() == description |
| 138 | + ] |
| 139 | + assert len(labels) == 2 |
| 140 | + try: |
| 141 | + # Light to dark, then dark to light |
| 142 | + for mode in ("light", "dark", "light"): |
| 143 | + Conf.color_mode.set(mode) |
| 144 | + win._update_color_mode() # pylint: disable=protected-access |
| 145 | + palette = QW.QApplication.instance().palette() |
| 146 | + window = palette.color(QG.QPalette.Window).lightness() |
| 147 | + for label in labels: |
| 148 | + text = label.palette().color(QG.QPalette.WindowText) |
| 149 | + alpha = text.alphaF() |
| 150 | + lightness = alpha * text.lightness() + (1 - alpha) * window |
| 151 | + assert abs(lightness - window) > 64, (mode, label.text()) |
| 152 | + finally: |
| 153 | + Conf.color_mode.set(initial_mode) |
| 154 | + plotpy_config.set_plotpy_color_mode(guidata_qth.LIGHT) |
| 155 | + |
| 156 | + |
123 | 157 | def _application_plugin( |
124 | 158 | plugin_id: str, |
125 | 159 | tiles: tuple[WelcomeTile, ...] | Exception, |
|
0 commit comments