Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion negpy/desktop/view/widgets/export_settings_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
_LABEL_WIDTH = 90


def _coerce_output_mode(mode: Any) -> ExportPresetOutputMode:
"""Persisted configs come back from JSON as plain strings. The destination
combo holds StrEnum members as item data, and findData() compares across the
QVariant boundary — a plain string never matches, so the row must be
normalized to the enum before lookup."""
try:
return ExportPresetOutputMode(mode)
except ValueError:
return ExportPresetOutputMode.ABSOLUTE


def constrain_combo(combo: QComboBox, min_chars: int = 6) -> None:
"""Stop long item text from stretching the panel: size the combo to a small
minimum and elide overflow, filling its row via the layout's spare space."""
Expand Down Expand Up @@ -509,7 +520,7 @@ def load(self, v: Dict[str, Any]) -> None:
out_path = v.get("icc_output_path")
self.icc_output_combo.setCurrentText(os.path.basename(out_path) if out_path else "None")

mode = v.get("output_mode", ExportPresetOutputMode.ABSOLUTE)
mode = _coerce_output_mode(v.get("output_mode"))
idx = self.output_mode_combo.findData(mode)
if idx >= 0:
self.output_mode_combo.setCurrentIndex(idx)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_export_settings_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ def test_destination_subfields_track_output_mode(qapp):
assert form._abspath_container.isHidden()


def test_destination_mode_restored_from_persisted_plain_string(qapp):
"""Saved settings come back from JSON as plain strings, not StrEnum members —
the combo must still land on the saved destination mode."""
form = ExportSettingsForm()
for mode in ExportPresetOutputMode:
form.load(_values(output_mode=str(mode.value)))
assert form.output_mode_combo.currentData() == mode, mode
assert form.values()["output_mode"] == mode, mode


def test_destination_mode_falls_back_to_absolute_when_unknown(qapp):
form = ExportSettingsForm()
form.load(_values(output_mode="not_a_mode"))
assert form.values()["output_mode"] == ExportPresetOutputMode.ABSOLUTE


def test_load_does_not_emit_changed(qapp):
form = ExportSettingsForm()
fired = []
Expand Down
Loading