From 1953399f9bf0cf18ba54961583632d703eeaa07e Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 30 Oct 2026 19:46:12 +0100 Subject: Add Ctrl+Q and ask before quitting with an unsaved upscale Quit and window close share closeEvent, so both ask. The unsaved check moves into discard_ok, used by Clear as well. Co-Authored-By: Claude Opus 5.5 --- test_upscale_qt.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test_upscale_qt.py') diff --git a/test_upscale_qt.py b/test_upscale_qt.py index 66423e8..7175e92 100644 --- a/test_upscale_qt.py +++ b/test_upscale_qt.py @@ -114,6 +114,25 @@ def test_main_window(): assert not w.a_clear.isEnabled() and not w.a_up.isEnabled() +def test_quit_asks_when_unsaved(): + from PyQt6.QtWidgets import QMessageBox + w = uq.Main() + assert w.a_quit.shortcut().toString() == 'Ctrl+Q' + path = os.path.join(TMP, 'q.png') + QImage(4, 4, QImage.Format.Format_RGB32).save(path) + w.load(path) + w.jobs[0].result = QImage(16, 16, QImage.Format.Format_RGB32) + answers = [] + real = QMessageBox.question + try: + QMessageBox.question = lambda *a: answers.append(a) or QMessageBox.StandardButton.No + assert not w.close() and len(answers) == 1 # declined, stays open + w.jobs[0].saved = True + assert w.close() and len(answers) == 1 # saved, no question + finally: + QMessageBox.question = real + + if __name__ == '__main__': for name, fn in list(globals().items()): if name.startswith('test_'): -- cgit v1.2.3