Skip to content

Commit 8ffe507

Browse files
author
Bryan Lawrence
committed
Font defaults, dialog behaviour, field properties in a fixed width font
1 parent 8730835 commit 8ffe507

File tree

7 files changed

+333
-88
lines changed

7 files changed

+333
-88
lines changed

tests/test_cf_interface.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def __init__(self) -> None:
142142
self.lineplot_calls: list[dict[str, object]] = []
143143
self.cscale_calls: list[dict[str, object]] = []
144144
self.gopen_calls: list[dict[str, object]] = []
145+
self.setvars_calls: list[dict[str, object]] = []
145146
self.gclose_calls = 0
146147

147148
def levs(self, **kwargs: object) -> None:
@@ -161,17 +162,24 @@ def gopen(self, file: str = "cfplot.png", **kwargs: object) -> None:
161162
payload.update(kwargs)
162163
self.gopen_calls.append(payload)
163164

165+
def setvars(self, **kwargs: object) -> None:
166+
self.setvars_calls.append(kwargs)
167+
164168
def gclose(self) -> None:
165169
self.gclose_calls += 1
166170

167171

168172
class _FakeFigure:
169173
def __init__(self) -> None:
170174
self.text_calls: list[tuple[tuple[object, ...], dict[str, object]]] = []
175+
self.suptitle_calls: list[tuple[tuple[object, ...], dict[str, object]]] = []
171176

172177
def text(self, *args: object, **kwargs: object) -> None:
173178
self.text_calls.append((args, kwargs))
174179

180+
def suptitle(self, *args: object, **kwargs: object) -> None:
181+
self.suptitle_calls.append((args, kwargs))
182+
175183

176184
class _FakePlt:
177185
def __init__(self) -> None:
@@ -205,9 +213,43 @@ def test_run_contour_plot_applies_levels_annotations_and_save(
205213
assert cfp.cscale_calls == [{"scale": "magma"}]
206214
assert cfp.gopen_calls == [{"file": "/tmp/mock.png"}]
207215
assert cfp.levs_calls == [{"manual": [-1.0, 0.0, 1.0]}]
216+
assert cfp.setvars_calls == [{"title_fontsize": 10.5}]
208217
assert cfp.con_calls
209218
assert cfp.gclose_calls == 1
210219
assert plt_obj.figure.text_calls
220+
assert plt_obj.figure.text_calls[-1][1]["fontsize"] == 8.0
221+
222+
223+
def test_run_contour_plot_uses_configured_title_font_sizes(
224+
monkeypatch: pytest.MonkeyPatch,
225+
) -> None:
226+
cfp = _FakeCFPlot()
227+
plt_obj = _FakePlt()
228+
229+
monkeypatch.setattr(cf_interface, "cfp", cfp)
230+
monkeypatch.setattr(cf_interface, "plt", plt_obj)
231+
232+
run_contour_plot(
233+
pfld=object(),
234+
options={
235+
"mode": "default",
236+
"page_title": "Overview",
237+
"page_title_display": True,
238+
"annotation_display": True,
239+
"annotation_properties": [("units", "K")],
240+
"contour_title_fontsize": 12.5,
241+
"page_title_fontsize": 14.0,
242+
"annotation_fontsize": 9.5,
243+
},
244+
)
245+
246+
assert cfp.setvars_calls == [{"title_fontsize": 12.5}]
247+
assert plt_obj.figure.suptitle_calls == [
248+
(("Overview",), {"y": 0.995, "fontsize": 14.0})
249+
]
250+
assert plt_obj.figure.text_calls == [
251+
((0.5, 0.02, "units: K"), {"ha": "center", "va": "bottom", "fontsize": 9.5})
252+
]
211253

212254

213255
def test_run_contour_plot_sets_title_from_singleton_selection(

xconv2/core_window.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
QComboBox,
2525
QDialog,
2626
QDialogButtonBox,
27+
QDoubleSpinBox,
2728
QFileDialog,
2829
QGroupBox,
2930
QHBoxLayout,
@@ -386,6 +387,30 @@ def _visible_coordinate_rows(self, settings: dict[str, object] | None = None) ->
386387
return raw
387388
return 4
388389

390+
def _contour_title_fontsize(self, settings: dict[str, object] | None = None) -> float:
391+
"""Return validated default contour title font size."""
392+
source = settings if settings is not None else self._settings
393+
raw = source.get("contour_title_fontsize", 10.5)
394+
if isinstance(raw, (int, float)) and float(raw) > 0:
395+
return float(raw)
396+
return 10.5
397+
398+
def _page_title_fontsize(self, settings: dict[str, object] | None = None) -> float:
399+
"""Return validated default page title font size."""
400+
source = settings if settings is not None else self._settings
401+
raw = source.get("page_title_fontsize", 10.0)
402+
if isinstance(raw, (int, float)) and float(raw) > 0:
403+
return float(raw)
404+
return 10.0
405+
406+
def _annotation_fontsize(self, settings: dict[str, object] | None = None) -> float:
407+
"""Return validated default annotation font size."""
408+
source = settings if settings is not None else self._settings
409+
raw = source.get("annotation_fontsize", 8.0)
410+
if isinstance(raw, (int, float)) and float(raw) > 0:
411+
return float(raw)
412+
return 8.0
413+
389414
@staticmethod
390415
def _timestamp_plot_filename() -> str:
391416
"""Return default timestamp-based plot filename stem."""
@@ -466,6 +491,39 @@ def _show_settings_dialog(self) -> None:
466491
coord_rows_row.addStretch(1)
467492
coord_rows_row.addWidget(coord_rows_spin)
468493

494+
contour_title_fontsize_row = QHBoxLayout()
495+
contour_title_fontsize_label = QLabel("Default contour title font size")
496+
contour_title_fontsize_spin = QDoubleSpinBox()
497+
contour_title_fontsize_spin.setRange(1.0, 48.0)
498+
contour_title_fontsize_spin.setDecimals(1)
499+
contour_title_fontsize_spin.setSingleStep(0.5)
500+
contour_title_fontsize_spin.setValue(self._contour_title_fontsize())
501+
contour_title_fontsize_row.addWidget(contour_title_fontsize_label)
502+
contour_title_fontsize_row.addStretch(1)
503+
contour_title_fontsize_row.addWidget(contour_title_fontsize_spin)
504+
505+
page_title_fontsize_row = QHBoxLayout()
506+
page_title_fontsize_label = QLabel("Default page title font size")
507+
page_title_fontsize_spin = QDoubleSpinBox()
508+
page_title_fontsize_spin.setRange(1.0, 48.0)
509+
page_title_fontsize_spin.setDecimals(1)
510+
page_title_fontsize_spin.setSingleStep(0.5)
511+
page_title_fontsize_spin.setValue(self._page_title_fontsize())
512+
page_title_fontsize_row.addWidget(page_title_fontsize_label)
513+
page_title_fontsize_row.addStretch(1)
514+
page_title_fontsize_row.addWidget(page_title_fontsize_spin)
515+
516+
annotation_fontsize_row = QHBoxLayout()
517+
annotation_fontsize_label = QLabel("Default annotation font size")
518+
annotation_fontsize_spin = QDoubleSpinBox()
519+
annotation_fontsize_spin.setRange(1.0, 48.0)
520+
annotation_fontsize_spin.setDecimals(1)
521+
annotation_fontsize_spin.setSingleStep(0.5)
522+
annotation_fontsize_spin.setValue(self._annotation_fontsize())
523+
annotation_fontsize_row.addWidget(annotation_fontsize_label)
524+
annotation_fontsize_row.addStretch(1)
525+
annotation_fontsize_row.addWidget(annotation_fontsize_spin)
526+
469527
plot_filename_row = QHBoxLayout()
470528
plot_filename_label = QLabel("Default plot filename")
471529
plot_filename_edit = QLineEdit(self._plot_filename_template())
@@ -537,6 +595,9 @@ def _choose_plot_dir() -> None:
537595
gui_defaults_layout.addLayout(recent_row)
538596
gui_defaults_layout.addLayout(field_rows_row)
539597
gui_defaults_layout.addLayout(coord_rows_row)
598+
gui_defaults_layout.addLayout(contour_title_fontsize_row)
599+
gui_defaults_layout.addLayout(page_title_fontsize_row)
600+
gui_defaults_layout.addLayout(annotation_fontsize_row)
540601

541602
output_frame = QGroupBox("Output")
542603
output_layout = QVBoxLayout(output_frame)
@@ -556,6 +617,9 @@ def _choose_plot_dir() -> None:
556617
self._settings["max_recent_files"] = int(recent_spin.value())
557618
self._settings["field_list_rows"] = int(field_rows_spin.value())
558619
self._settings["visible_coordinate_rows"] = int(coord_rows_spin.value())
620+
self._settings["contour_title_fontsize"] = float(contour_title_fontsize_spin.value())
621+
self._settings["page_title_fontsize"] = float(page_title_fontsize_spin.value())
622+
self._settings["annotation_fontsize"] = float(annotation_fontsize_spin.value())
559623
self._settings["default_plot_filename"] = self._sanitize_plot_filename_stem(
560624
plot_filename_edit.text()
561625
)

xconv2/main_window.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ def _request_plot_task(self, save_code_path: str | None, save_plot_path: str | N
391391
return
392392

393393
plot_options = dict(self.plot_options_by_kind.get(plot_kind, {}))
394+
if plot_kind == "contour":
395+
plot_options.setdefault("contour_title_fontsize", self._contour_title_fontsize())
396+
plot_options.setdefault("page_title_fontsize", self._page_title_fontsize())
397+
plot_options.setdefault("annotation_fontsize", self._annotation_fontsize())
398+
394399
if save_plot_path:
395400
plot_options["filename"] = str(Path(save_plot_path).expanduser())
396401
elif not plot_options:

0 commit comments

Comments
 (0)