diff --git a/orangecanvas/application/canvasmain.py b/orangecanvas/application/canvasmain.py index 1269127e..13c2bd4c 100644 --- a/orangecanvas/application/canvasmain.py +++ b/orangecanvas/application/canvasmain.py @@ -1549,13 +1549,15 @@ def save_scheme_as(self): acceptMode=QFileDialog.AcceptSave, windowModality=Qt.WindowModal, objectName="save-as-ows-filedialog", + defaultSuffix=".ows" ) dialog.setNameFilter(self.tr("Orange Workflow (*.ows)")) - dialog.exec() - files = dialog.selectedFiles() + # `deleteLater` can be ivoked before `exec` as PyQt 6.9 doc says, that + # it is activated after `exec`, and work on PyQt 5 version well (here) dialog.deleteLater() - if files: - filename = files[0] + # dialog.exec waits for user action + if dialog.exec(): + filename = dialog.selectedFiles()[0] settings.setValue("last-scheme-dir", os.path.dirname(filename)) if self.save_scheme_to(curr_scheme, filename): document.setPath(filename) @@ -1591,7 +1593,7 @@ def save_scheme_to(self, scheme, filename): exc_info=True, parent=self ) - return False + return False # return False here because there is second part try: with open(filename, "wb") as f: @@ -1608,7 +1610,6 @@ def save_scheme_to(self, scheme, filename): informative_text=self.tr("Choose another location."), parent=self ) - return False except PermissionError as ex: log.error("%s saving '%s'", type(ex).__name__, filename, exc_info=True) @@ -1621,7 +1622,6 @@ def save_scheme_to(self, scheme, filename): "another location."), parent=self ) - return False except OSError as ex: log.error("%s saving '%s'", type(ex).__name__, filename, exc_info=True) @@ -1632,8 +1632,6 @@ def save_scheme_to(self, scheme, filename): exc_info=True, parent=self ) - return False - except Exception: # pylint: disable=broad-except log.error("Error saving %r to %r", scheme, filename, exc_info=True) message_critical( @@ -1643,7 +1641,7 @@ def save_scheme_to(self, scheme, filename): exc_info=True, parent=self ) - return False + return False # default behaviour def save_swp(self): """ diff --git a/orangecanvas/application/tests/test_mainwindow.py b/orangecanvas/application/tests/test_mainwindow.py index 927257c4..ff06a095 100644 --- a/orangecanvas/application/tests/test_mainwindow.py +++ b/orangecanvas/application/tests/test_mainwindow.py @@ -1,7 +1,7 @@ import io import os import tempfile -from unittest.mock import patch +from unittest.mock import patch, Mock from AnyQt.QtGui import QWhatsThisClickedEvent from AnyQt.QtWidgets import ( @@ -149,7 +149,7 @@ class TestMainWindowLoad(TestMainWindowBase): def setUp(self): super().setUp() - fd, filename = tempfile.mkstemp() + fd, filename = tempfile.mkstemp(suffix=".ows") self.file = os.fdopen(fd, "w+b") self.filename = filename @@ -182,8 +182,11 @@ def exec(myself): myself.setOption(QFileDialog.DontConfirmOverwrite) myself.selectFile(self.filename) myself.accept() + return True - with patch("AnyQt.QtWidgets.QFileDialog.exec", exec): + with (patch("AnyQt.QtWidgets.QFileDialog.exec", exec), + patch("AnyQt.QtWidgets.QMessageBox.question", + new=Mock(return_value=QMessageBox.Yes))): w.save_scheme() self.assertTrue(os.path.samefile(w.current_document().path(), self.filename))