From 49e3403d69e75cf1171bb9818235cc3ddd1954d1 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 22 Jan 2025 00:35:53 +0100 Subject: [PATCH] Remove deleteLater calls that can be replaced by setParent(None) --- novelwriter/gui/docviewer.py | 3 ++- novelwriter/gui/projtree.py | 3 ++- novelwriter/guimain.py | 2 +- novelwriter/tools/welcome.py | 2 +- tests/test_gui/test_gui_doceditor.py | 2 ++ tests/test_tools/test_tools_welcome.py | 1 + 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/novelwriter/gui/docviewer.py b/novelwriter/gui/docviewer.py index 0be61bf4..7a0b8d7a 100644 --- a/novelwriter/gui/docviewer.py +++ b/novelwriter/gui/docviewer.py @@ -424,7 +424,8 @@ class GuiDocViewer(QTextBrowser): # Open the context menu if viewport := self.viewport(): ctxMenu.exec(viewport.mapToGlobal(point)) - ctxMenu.deleteLater() + + ctxMenu.setParent(None) return diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index 181f6f31..20878bc4 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -969,7 +969,8 @@ class GuiProjectTree(QTreeView): if viewport := self.viewport(): ctxMenu.exec(viewport.mapToGlobal(point)) - ctxMenu.deleteLater() + + ctxMenu.setParent(None) return diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index 47d85a4a..4dfcbf07 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -1064,7 +1064,7 @@ class GuiMain(QMainWindow): if syntax: SHARED.theme.loadSyntax() - self.docEditor.updateSyntaxColours() + self.docEditor.updateSyntaxColors() self.docEditor.initEditor() self.docViewer.initViewer() diff --git a/novelwriter/tools/welcome.py b/novelwriter/tools/welcome.py index 354b206d..287fd416 100644 --- a/novelwriter/tools/welcome.py +++ b/novelwriter/tools/welcome.py @@ -366,7 +366,7 @@ class _OpenProjectPage(QWidget): action = qtAddAction(ctxMenu, self.tr("Remove Project")) action.triggered.connect(self._deleteSelectedItem) ctxMenu.exec(self.mapToGlobal(pos)) - ctxMenu.deleteLater() + ctxMenu.setParent(None) return ## diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index 428807f3..2546a9c2 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -333,6 +333,7 @@ def testGuiEditor_MetaData(qtbot, nwGUI, projPath, mockRnd): def testGuiEditor_ContextMenu(monkeypatch, qtbot, nwGUI, projPath, mockRnd): """Test the editor context menu.""" monkeypatch.setattr(QMenu, "exec", lambda *a: None) + monkeypatch.setattr(QMenu, "setParent", lambda *a: None) buildTestProject(nwGUI, projPath) assert nwGUI.openDocument(C.hSceneDoc) is True @@ -475,6 +476,7 @@ def testGuiEditor_ContextMenu(monkeypatch, qtbot, nwGUI, projPath, mockRnd): def testGuiEditor_SpellChecking(qtbot, monkeypatch, nwGUI, projPath, ipsumText, mockRnd): """Test the document spell checker.""" monkeypatch.setattr(QMenu, "exec", lambda *a: None) + monkeypatch.setattr(QMenu, "setParent", lambda *a: None) buildTestProject(nwGUI, projPath) assert nwGUI.openDocument(C.hSceneDoc) is True diff --git a/tests/test_tools/test_tools_welcome.py b/tests/test_tools/test_tools_welcome.py index 228b162f..a999f2ee 100644 --- a/tests/test_tools/test_tools_welcome.py +++ b/tests/test_tools/test_tools_welcome.py @@ -70,6 +70,7 @@ def testToolWelcome_Main(qtbot, monkeypatch, nwGUI, fncPath): def testToolWelcome_Open(qtbot, monkeypatch, nwGUI, fncPath): """Test the open tab in the Welcome window.""" monkeypatch.setattr(QMenu, "exec", lambda *a: None) + monkeypatch.setattr(QMenu, "setParent", lambda *a: None) CONFIG.recentProjects.update("/stuff/project_one", "Project One", 12345, 1690000000) CONFIG.recentProjects.update("/stuff/project_two", "Project Two", 54321, 1700000000)