Skip to content
Open
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
18 changes: 8 additions & 10 deletions orangecanvas/application/canvasmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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):
"""
Expand Down
9 changes: 6 additions & 3 deletions orangecanvas/application/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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))

Expand Down
Loading