handle tuple returns from file dialog properly

This commit is contained in:
Veronica K. B. Olsen
2020-10-07 19:19:36 +02:00
parent 48742ceb0e
commit e22f99cffb
5 changed files with 12 additions and 17 deletions
+2 -4
View File
@@ -762,12 +762,10 @@ class GuiBuildNovel(QDialog):
if self.mainConf.showGUI: if self.mainConf.showGUI:
dlgOpt = QFileDialog.Options() dlgOpt = QFileDialog.Options()
dlgOpt |= QFileDialog.DontUseNativeDialog dlgOpt |= QFileDialog.DontUseNativeDialog
saveTo = QFileDialog.getSaveFileName( savePath, _ = QFileDialog.getSaveFileName(
self, "Save Document As", savePath, options=dlgOpt self, "Save Document As", savePath, options=dlgOpt
) )
if saveTo[0]: if not savePath:
savePath = saveTo[0]
else:
return False return False
self.mainConf.setLastPath(savePath) self.mainConf.setLastPath(savePath)
+3 -4
View File
@@ -334,12 +334,11 @@ class GuiWritingStats(QDialog):
dlgOpt = QFileDialog.Options() dlgOpt = QFileDialog.Options()
dlgOpt |= QFileDialog.DontUseNativeDialog dlgOpt |= QFileDialog.DontUseNativeDialog
saveTo = QFileDialog.getSaveFileName( savePath, _ = QFileDialog.getSaveFileName(
self, "Save Document As", savePath, options=dlgOpt self, "Save Document As", savePath, options=dlgOpt
) )
if saveTo[0]:
savePath = saveTo[0] if not savePath:
else:
return False return False
self.mainConf.setLastPath(savePath) self.mainConf.setLastPath(savePath)
+2 -4
View File
@@ -562,12 +562,10 @@ class GuiMain(QMainWindow):
] ]
dlgOpt = QFileDialog.Options() dlgOpt = QFileDialog.Options()
dlgOpt |= QFileDialog.DontUseNativeDialog dlgOpt |= QFileDialog.DontUseNativeDialog
inPath = QFileDialog.getOpenFileName( loadFile, _ = QFileDialog.getOpenFileName(
self, "Import File", lastPath, options=dlgOpt, filter=";;".join(extFilter) self, "Import File", lastPath, options=dlgOpt, filter=";;".join(extFilter)
) )
if inPath: if not loadFile:
loadFile = inPath[0]
else:
return False return False
if loadFile.strip() == "": if loadFile.strip() == "":
+2 -2
View File
@@ -283,10 +283,10 @@ def testWritingStatsExport(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTemp):
assert isinstance(sessLog, GuiWritingStats) assert isinstance(sessLog, GuiWritingStats)
qtbot.wait(stepDelay) qtbot.wait(stepDelay)
monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda *args, **kwargs: []) monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda *args, **kwargs: ("", ""))
assert not sessLog._saveData(sessLog.FMT_CSV) assert not sessLog._saveData(sessLog.FMT_CSV)
monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda ss, tt, pp, options: [pp]) monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda ss, tt, pp, options: (pp, ""))
assert sessLog._saveData(sessLog.FMT_CSV) assert sessLog._saveData(sessLog.FMT_CSV)
qtbot.wait(stepDelay) qtbot.wait(stepDelay)
assert sessLog._saveData(sessLog.FMT_JSON) assert sessLog._saveData(sessLog.FMT_JSON)
+3 -3
View File
@@ -1107,16 +1107,16 @@ def testInsertMenu(qtbot, monkeypatch, nwFuncTemp, nwTemp):
nwGUI.closeDocument() nwGUI.closeDocument()
# First, with no path # First, with no path
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwards: []) monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwards: ("", ""))
assert not nwGUI.importDocument() assert not nwGUI.importDocument()
# Then with a path, but an invalid one # Then with a path, but an invalid one
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwards: [" "]) monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwards: (" ", ""))
assert not nwGUI.importDocument() assert not nwGUI.importDocument()
# Then a valid path, but bot a file that exists # Then a valid path, but bot a file that exists
theFile = os.path.join(nwTemp, "import.txt") theFile = os.path.join(nwTemp, "import.txt")
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwards: [theFile]) monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args, **kwards: (theFile, ""))
assert not nwGUI.importDocument() assert not nwGUI.importDocument()
# Create the file and try again, but with no target document open # Create the file and try again, but with no target document open