Replace exec_ with exec

This commit is contained in:
Veronica Berglyd Olsen
2024-04-03 18:41:39 +02:00
parent c8fe5e6620
commit f95bbb8760
28 changed files with 49 additions and 49 deletions
+2 -2
View File
@@ -187,7 +187,7 @@ def main(sysArgs: list | None = None):
))
for errLine in errorData:
logger.critical(errLine)
errApp.exec_()
errApp.exec()
sys.exit(errorCode)
# Finish initialising config
@@ -237,6 +237,6 @@ def main(sysArgs: list | None = None):
nwGUI = GuiMain()
nwGUI.postLaunchTasks(cmdOpen)
sys.exit(nwApp.exec_())
sys.exit(nwApp.exec())
# END Function main
+1 -1
View File
@@ -88,7 +88,7 @@ class GuiEditLabel(QDialog):
def getLabel(cls, parent: QWidget, text: str) -> tuple[str, bool]:
"""Pop the dialog and return the result."""
cls = GuiEditLabel(parent, text=text)
cls.exec_()
cls.exec()
label = cls.itemLabel
accepted = cls.result() == QDialog.Accepted
cls.deleteLater()
+1 -1
View File
@@ -123,7 +123,7 @@ class GuiQuoteSelect(QDialog):
def getQuote(cls, parent: QWidget, current: str = "") -> tuple[str, bool]:
"""Pop the dialog and return the result."""
cls = GuiQuoteSelect(parent, current=current)
cls.exec_()
cls.exec()
quote = cls._selected
accepted = cls.result() == QDialog.DialogCode.Accepted
cls.deleteLater()
+1 -1
View File
@@ -197,7 +197,7 @@ def exceptionHandler(exType: type, exValue: BaseException, exTrace: TracebackTyp
errMsg = NWErrorMessage(nwGUI)
errMsg.setMessage(exType, exValue, exTrace)
errMsg.exec_()
errMsg.exec()
try:
# Try a controlled shutdown
+1 -1
View File
@@ -1171,7 +1171,7 @@ class GuiDocEditor(QPlainTextEdit):
action.triggered.connect(lambda: self._addWord(word, block))
# Execute the context menu
ctxMenu.exec_(self.viewport().mapToGlobal(pos))
ctxMenu.exec(self.viewport().mapToGlobal(pos))
ctxMenu.deleteLater()
return
+1 -1
View File
@@ -410,7 +410,7 @@ class GuiDocViewer(QTextBrowser):
ctxMenu.addAction(mnuSelPara)
# Open the context menu
ctxMenu.exec_(self.viewport().mapToGlobal(point))
ctxMenu.exec(self.viewport().mapToGlobal(point))
ctxMenu.deleteLater()
return
+3 -3
View File
@@ -1230,7 +1230,7 @@ class GuiProjectTree(QTreeWidget):
else:
ctxMenu.buildSingleSelectMenu(hasChild)
ctxMenu.exec_(self.viewport().mapToGlobal(clickPos))
ctxMenu.exec(self.viewport().mapToGlobal(clickPos))
ctxMenu.deleteLater()
return True
@@ -1410,7 +1410,7 @@ class GuiProjectTree(QTreeWidget):
itemList.remove(tHandle)
dlgMerge = GuiDocMerge(self.mainGui, tHandle, itemList)
dlgMerge.exec_()
dlgMerge.exec()
if dlgMerge.result() == QDialog.DialogCode.Accepted:
@@ -1480,7 +1480,7 @@ class GuiProjectTree(QTreeWidget):
return False
dlgSplit = GuiDocSplit(self.mainGui, tHandle)
dlgSplit.exec_()
dlgSplit.exec()
if dlgSplit.result() == QDialog.DialogCode.Accepted:
+4 -4
View File
@@ -768,7 +768,7 @@ class GuiMain(QMainWindow):
"""Open the welcome dialog."""
dialog = GuiWelcome(self)
dialog.openProjectRequest.connect(self._openProjectFromWelcome)
dialog.exec_()
dialog.exec()
return
@pyqtSlot()
@@ -776,7 +776,7 @@ class GuiMain(QMainWindow):
"""Open the preferences dialog."""
dialog = GuiPreferences(self)
dialog.newPreferencesReady.connect(self._processConfigChanges)
dialog.exec_()
dialog.exec()
return
@pyqtSlot()
@@ -786,7 +786,7 @@ class GuiMain(QMainWindow):
if SHARED.hasProject:
dialog = GuiProjectSettings(self, gotoPage=focusTab)
dialog.newProjectSettingsReady.connect(self._processProjectSettingsChanges)
dialog.exec_()
dialog.exec()
return
@pyqtSlot()
@@ -820,7 +820,7 @@ class GuiMain(QMainWindow):
if SHARED.hasProject:
dialog = GuiWordList(self)
dialog.newWordListReady.connect(self._processWordListChanges)
dialog.exec_()
dialog.exec()
return
@pyqtSlot()
+4 -4
View File
@@ -292,7 +292,7 @@ class SharedData(QObject):
self._lastAlert = alert.logMessage
if log:
logger.info(self._lastAlert, stacklevel=2)
alert.exec_()
alert.exec()
alert.deleteLater()
return
@@ -304,7 +304,7 @@ class SharedData(QObject):
self._lastAlert = alert.logMessage
if log:
logger.warning(self._lastAlert, stacklevel=2)
alert.exec_()
alert.exec()
alert.deleteLater()
return
@@ -319,7 +319,7 @@ class SharedData(QObject):
self._lastAlert = alert.logMessage
if log:
logger.error(self._lastAlert, stacklevel=2)
alert.exec_()
alert.exec()
alert.deleteLater()
return
@@ -329,7 +329,7 @@ class SharedData(QObject):
alert.setMessage(text, info, details)
alert.setAlertType(_GuiAlert.WARN if warn else _GuiAlert.ASK, True)
self._lastAlert = alert.logMessage
alert.exec_()
alert.exec()
isYes = alert.result() == QMessageBox.StandardButton.Yes
alert.deleteLater()
return isYes
+1 -1
View File
@@ -129,7 +129,7 @@ class GuiLipsum(QDialog):
def getLipsum(cls, parent: QWidget) -> str:
"""Pop the dialog and return the lipsum text."""
cls = GuiLipsum(parent)
cls.exec_()
cls.exec()
text = cls.lipsumText
cls.deleteLater()
return text
+2 -2
View File
@@ -385,7 +385,7 @@ class GuiManuscript(QDialog):
build = self._getSelectedBuild()
if isinstance(build, BuildSettings):
dlgBuild = GuiManuscriptBuild(self, build)
dlgBuild.exec_()
dlgBuild.exec()
# After the build is done, save build settings changes
if build.changed:
@@ -398,7 +398,7 @@ class GuiManuscript(QDialog):
"""Open the print preview dialog."""
preview = QPrintPreviewDialog(self)
preview.paintRequested.connect(self.docPreview.printPreview)
preview.exec_()
preview.exec()
return
##
+1 -1
View File
@@ -377,7 +377,7 @@ class _OpenProjectPage(QWidget):
action.triggered.connect(self.openSelectedItem)
action = ctxMenu.addAction(self.tr("Remove Project"))
action.triggered.connect(self._deleteSelectedItem)
ctxMenu.exec_(self.mapToGlobal(pos))
ctxMenu.exec(self.mapToGlobal(pos))
ctxMenu.deleteLater()
return
+2 -2
View File
@@ -142,7 +142,7 @@ def projPath(fncPath):
@pytest.fixture(scope="function")
def mockGUI(qtbot, monkeypatch):
"""Create a mock instance of novelWriter's main GUI class."""
monkeypatch.setattr(QMessageBox, "exec_", lambda *a: None)
monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes)
gui = MockGuiMain()
theme = MockTheme()
@@ -154,7 +154,7 @@ def mockGUI(qtbot, monkeypatch):
@pytest.fixture(scope="function")
def nwGUI(qtbot, monkeypatch, functionFixture):
"""Create an instance of the novelWriter GUI."""
monkeypatch.setattr(QMessageBox, "exec_", lambda *a: None)
monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes)
nwGUI = main(["--testmode", f"--config={_TMP_CONF}", f"--data={_TMP_CONF}"])
+4 -4
View File
@@ -72,27 +72,27 @@ def testBaseError_Handler(qtbot, monkeypatch, nwGUI):
"""
# Normal shutdown
with monkeypatch.context() as mp:
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
mp.setattr(NWErrorMessage, "exec", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
exceptionHandler(Exception, "Error Message", None) # type: ignore
# Should not crash when no GUI is found
with monkeypatch.context() as mp:
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
mp.setattr(NWErrorMessage, "exec", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.topLevelWidgets", lambda: [])
exceptionHandler(Exception, "Error Message", None) # type: ignore
# Should handle QApplication failing
with monkeypatch.context() as mp:
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
mp.setattr(NWErrorMessage, "exec", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.topLevelWidgets", causeException)
exceptionHandler(Exception, "Error Message", None) # type: ignore
# Should handle failing to close main GUI
with monkeypatch.context() as mp:
mp.setattr(NWErrorMessage, "exec_", lambda *a: None)
mp.setattr(NWErrorMessage, "exec", lambda *a: None)
mp.setattr("PyQt5.QtWidgets.QApplication.exit", lambda *a: None)
mp.setattr(nwGUI, "closeMain", causeException)
exceptionHandler(Exception, "Error Message", None) # type: ignore
+2 -2
View File
@@ -70,7 +70,7 @@ def testBaseInit_Launch(caplog, monkeypatch, fncPath):
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setApplicationVersion", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setWindowIcon", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.setOrganizationDomain", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec_", lambda *a: 0)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec", lambda *a: 0)
with pytest.raises(SystemExit) as ex:
main([f"--config={fncPath}", f"--data={fncPath}"])
assert ex.value.code == 0
@@ -148,7 +148,7 @@ def testBaseInit_Imports(caplog, monkeypatch, fncPath):
"""Check import error handling."""
monkeypatch.setattr("novelwriter.guimain.GuiMain", MockGuiMain)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.__init__", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec_", lambda *a: 0)
monkeypatch.setattr("PyQt5.QtWidgets.QApplication.exec", lambda *a: 0)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.__init__", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.resize", lambda *a: None)
monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.showMessage", lambda *a: None)
+1 -1
View File
@@ -129,7 +129,7 @@ def testBaseSharedData_Projects(monkeypatch, caplog, fncPath):
@pytest.mark.base
def testBaseSharedData_Alerts(qtbot, monkeypatch, caplog):
"""Test SharedData class alert helper functions."""
monkeypatch.setattr(QMessageBox, "exec_", lambda *a: None)
monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes)
shared = SharedData()
+2 -2
View File
@@ -32,7 +32,7 @@ from novelwriter.dialogs.editlabel import GuiEditLabel
@pytest.mark.gui
def testDlgOther_QuoteSelect(qtbot, monkeypatch, nwGUI):
"""Test the quote symbols dialog."""
monkeypatch.setattr(GuiQuoteSelect, "exec_", lambda *a: None)
monkeypatch.setattr(GuiQuoteSelect, "exec", lambda *a: None)
nwQuot = GuiQuoteSelect(nwGUI)
nwQuot.show()
@@ -68,7 +68,7 @@ def testDlgOther_QuoteSelect(qtbot, monkeypatch, nwGUI):
@pytest.mark.gui
def testDlgOther_EditLabel(qtbot, monkeypatch):
"""Test the label editor dialog."""
monkeypatch.setattr(GuiEditLabel, "exec_", lambda *a: None)
monkeypatch.setattr(GuiEditLabel, "exec", lambda *a: None)
with monkeypatch.context() as mp:
mp.setattr(GuiEditLabel, "result", lambda *a: QDialog.Accepted)
+1 -1
View File
@@ -38,7 +38,7 @@ KEY_DELAY = 1
def testDlgPreferences_Main(qtbot, monkeypatch, nwGUI, tstPaths):
"""Test the preferences dialog loading."""
monkeypatch.setattr(SHARED._spelling, "listDictionaries", lambda: [("en", "English [en]")])
monkeypatch.setattr(GuiPreferences, "exec_", lambda *a: None)
monkeypatch.setattr(GuiPreferences, "exec", lambda *a: None)
# Load GUI with standard values
nwGUI.mainMenu.aPreferences.activate(QAction.ActionEvent.Trigger)
@@ -42,7 +42,7 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI):
test, but are instead tested in the individual tab tests.
"""
# Block the GUI blocking thread
monkeypatch.setattr(GuiProjectSettings, "exec_", lambda *a: None)
monkeypatch.setattr(GuiProjectSettings, "exec", lambda *a: None)
monkeypatch.setattr(GuiProjectSettings, "result", lambda *a: QDialog.Accepted)
# Check that we cannot open when there is no project
+1 -1
View File
@@ -38,7 +38,7 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, fncPath, projPath):
"""test the word list editor."""
buildTestProject(nwGUI, projPath)
monkeypatch.setattr(GuiWordList, "exec_", lambda *a: None)
monkeypatch.setattr(GuiWordList, "exec", lambda *a: None)
monkeypatch.setattr(GuiWordList, "result", lambda *a: QDialog.Accepted)
monkeypatch.setattr(GuiWordList, "accept", lambda *a: None)
+1 -1
View File
@@ -244,7 +244,7 @@ def testGuiEditor_MetaData(qtbot, nwGUI, projPath, mockRnd):
@pytest.mark.gui
def testGuiEditor_ContextMenu(monkeypatch, qtbot, nwGUI, projPath, mockRnd):
"""Test the editor context menu."""
monkeypatch.setattr(QMenu, "exec_", lambda *a: None)
monkeypatch.setattr(QMenu, "exec", lambda *a: None)
buildTestProject(nwGUI, projPath)
assert nwGUI.openDocument(C.hSceneDoc) is True
+1 -1
View File
@@ -146,7 +146,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
docViewer.setTextCursor(cursor)
docViewer._makeSelection(QTextCursor.WordUnderCursor)
with monkeypatch.context() as mp:
mp.setattr(QMenu, "exec_", mockExec)
mp.setattr(QMenu, "exec", mockExec)
docViewer._openContextMenu(docViewer.cursorRect().center())
assert menuOpened
+2 -2
View File
@@ -60,7 +60,7 @@ def testGuiMain_ProjectBlocker(nwGUI):
@pytest.mark.gui
def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, projPath):
"""Test the handling of launch tasks."""
monkeypatch.setattr(GuiWelcome, "exec_", lambda *a: None)
monkeypatch.setattr(GuiWelcome, "exec", lambda *a: None)
CONFIG.lastNotes = "0x0"
buildTestProject(nwGUI, projPath)
@@ -511,7 +511,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
assert "test" in suggest
with monkeypatch.context() as mp:
mp.setattr(QMenu, "exec_", lambda *a: None)
mp.setattr(QMenu, "exec", lambda *a: None)
docEditor.setCursorPosition(errPos)
docEditor._openContextFromCursor()
+2 -2
View File
@@ -47,8 +47,8 @@ LANG_DATA = CONFIG.listLanguages(CONFIG.LANG_NW)
@pytest.mark.parametrize("language", [a for a, b in LANG_DATA])
def testGuiI18n_Localisation(qtbot, monkeypatch, language, nwGUI, projPath):
"""Test loading the gui with a specific language."""
monkeypatch.setattr(QDialog, "exec_", lambda *a: None)
monkeypatch.setattr(QMessageBox, "exec_", lambda *a: None)
monkeypatch.setattr(QDialog, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes)
# Set the test language
+3 -3
View File
@@ -539,7 +539,7 @@ def testGuiProjTree_MergeDocuments(qtbot, monkeypatch, nwGUI, projPath, mockRnd,
mergeData = {}
monkeypatch.setattr(GuiDocMerge, "__init__", lambda *a: None)
monkeypatch.setattr(GuiDocMerge, "exec_", lambda *a: None)
monkeypatch.setattr(GuiDocMerge, "exec", lambda *a: None)
monkeypatch.setattr(GuiDocMerge, "result", lambda *a: QDialog.Accepted)
monkeypatch.setattr(GuiDocMerge, "getData", lambda *a: mergeData)
@@ -640,7 +640,7 @@ def testGuiProjTree_SplitDocument(qtbot, monkeypatch, nwGUI, projPath, mockRnd,
splitText = []
monkeypatch.setattr(GuiDocSplit, "__init__", lambda *a: None)
monkeypatch.setattr(GuiDocSplit, "exec_", lambda *a: None)
monkeypatch.setattr(GuiDocSplit, "exec", lambda *a: None)
monkeypatch.setattr(GuiDocSplit, "result", lambda *a: QDialog.Accepted)
monkeypatch.setattr(GuiDocSplit, "getData", lambda *a: (splitData, splitText))
@@ -1162,7 +1162,7 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
# Pop the menu
with monkeypatch.context() as mp:
mp.setattr(QMenu, "exec_", lambda *a: None)
mp.setattr(QMenu, "exec", lambda *a: None)
projTree.clearSelection()
# No item under menu
+1 -1
View File
@@ -60,7 +60,7 @@ def testToolLipsum_Main(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
assert nwGUI.openDocument(C.hSceneDoc) is True
nwGUI.docEditor.setCursorLine(3)
with monkeypatch.context() as mp:
mp.setattr(GuiLipsum, "exec_", lambda *a: None)
mp.setattr(GuiLipsum, "exec", lambda *a: None)
mp.setattr(GuiLipsum, "lipsumText", "FooBar")
nwGUI.mainMenu.aLipsumText.activate(QAction.Trigger)
assert nwGUI.docEditor.getText() == "### New Scene\n\nFooBar"
+2 -2
View File
@@ -278,7 +278,7 @@ def testManuscript_Features(monkeypatch, qtbot, nwGUI, projPath, mockRnd):
build._changed = True
manus.buildList.clearSelection()
with monkeypatch.context() as mp:
mp.setattr("novelwriter.tools.manusbuild.GuiManuscriptBuild.exec_", lambda *a: None)
mp.setattr("novelwriter.tools.manusbuild.GuiManuscriptBuild.exec", lambda *a: None)
manus.buildList.setCurrentRow(0)
manus.btnBuild.click()
@@ -313,7 +313,7 @@ def testManuscript_Print(monkeypatch, qtbot: QtBot, nwGUI: GuiMain, projPath: Pa
assert manus.docPreview.toPlainText().strip() != ""
with monkeypatch.context() as mp:
mp.setattr(QPrintPreviewDialog, "exec_", lambda *a: None)
mp.setattr(QPrintPreviewDialog, "exec", lambda *a: None)
manus.btnPrint.click()
for obj in manus.children():
if isinstance(obj, QPrintPreviewDialog):
+1 -1
View File
@@ -70,7 +70,7 @@ def testToolWelcome_Main(qtbot: QtBot, monkeypatch, nwGUI, fncPath):
@pytest.mark.gui
def testToolWelcome_Open(qtbot: QtBot, monkeypatch, nwGUI, fncPath):
"""Test the open tab in the Welcome window."""
monkeypatch.setattr(QMenu, "exec_", lambda *a: None)
monkeypatch.setattr(QMenu, "exec", lambda *a: None)
monkeypatch.setattr(QMenu, "deleteLater", lambda *a: None)
CONFIG.recentProjects.update("/stuff/project_one", "Project One", 12345, 1690000000)