diff --git a/novelwriter/constants.py b/novelwriter/constants.py index 016a30e9..3e7d0bb6 100644 --- a/novelwriter/constants.py +++ b/novelwriter/constants.py @@ -25,7 +25,7 @@ from __future__ import annotations from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP -from novelwriter.enum import nwAlert, nwBuildFmt, nwItemClass, nwItemLayout, nwOutline +from novelwriter.enum import nwBuildFmt, nwItemClass, nwItemLayout, nwOutline def trConst(text: str) -> str: @@ -165,12 +165,6 @@ class nwLabels: nwItemLayout.DOCUMENT: QT_TRANSLATE_NOOP("Constant", "Novel Document"), nwItemLayout.NOTE: QT_TRANSLATE_NOOP("Constant", "Project Note"), } - ALERT_NAME = { - nwAlert.INFO: QT_TRANSLATE_NOOP("Constant", "Information"), - nwAlert.WARN: QT_TRANSLATE_NOOP("Constant", "Warning"), - nwAlert.ERROR: QT_TRANSLATE_NOOP("Constant", "Error"), - nwAlert.ASK: QT_TRANSLATE_NOOP("Constant", "Question"), - } ITEM_DESCRIPTION = { "none": QT_TRANSLATE_NOOP("Constant", "None"), "root": QT_TRANSLATE_NOOP("Constant", "Root Folder"), diff --git a/novelwriter/enum.py b/novelwriter/enum.py index 1abc29c7..36546778 100644 --- a/novelwriter/enum.py +++ b/novelwriter/enum.py @@ -119,16 +119,6 @@ class nwDocInsert(Enum): # END Enum nwDocInsert -class nwAlert(Enum): - - INFO = 0 - WARN = 1 - ERROR = 2 - ASK = 3 - -# END Enum nwAlert - - class nwView(Enum): EDITOR = 0 diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index 3b7f7e8a..d303491c 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -59,7 +59,6 @@ from novelwriter.tools.lipsum import GuiLipsum from novelwriter.tools.manuscript import GuiManuscript from novelwriter.tools.projwizard import GuiProjectWizard from novelwriter.tools.writingstats import GuiWritingStats -from novelwriter.core.project import NWProject from novelwriter.core.coretools import ProjectBuilder from novelwriter.enum import ( @@ -333,9 +332,7 @@ class GuiMain(QMainWindow): return def postLaunchTasks(self, cmdOpen: str | None) -> None: - """This function is called after the main window is created to - determine what to open or show after initialisation. - """ + """Process tasks after the main window has been created.""" if cmdOpen: logger.info("Command line path: %s", cmdOpen) self.openProject(cmdOpen) @@ -350,15 +347,6 @@ class GuiMain(QMainWindow): return - ## - # Properties - ## - - @property - def project(self) -> NWProject: - """The project instance.""" - return SHARED.project - ## # Project Actions ## diff --git a/tests/test_dialogs/test_dlg_docsplit.py b/tests/test_dialogs/test_dlg_docsplit.py index fc6ceccf..0de88a72 100644 --- a/tests/test_dialogs/test_dlg_docsplit.py +++ b/tests/test_dialogs/test_dlg_docsplit.py @@ -23,6 +23,7 @@ import pytest from tools import C, buildTestProject +from novelwriter import SHARED from novelwriter.dialogs.docsplit import GuiDocSplit from novelwriter.dialogs.editlabel import GuiEditLabel @@ -35,7 +36,7 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, projPath, mockRnd): # Create a new project buildTestProject(nwGUI, projPath) - theProject = nwGUI.project + theProject = SHARED.project projTree = nwGUI.projView.projTree docText = ( diff --git a/tests/test_dialogs/test_dlg_projdetails.py b/tests/test_dialogs/test_dlg_projdetails.py index af234423..88fd9a92 100644 --- a/tests/test_dialogs/test_dlg_projdetails.py +++ b/tests/test_dialogs/test_dlg_projdetails.py @@ -25,6 +25,7 @@ from tools import getGuiItem from PyQt5.QtWidgets import QAction +from novelwriter import SHARED from novelwriter.dialogs.projdetails import GuiProjectDetails @@ -54,7 +55,7 @@ def testDlgProjDetails_Dialog(qtbot, nwGUI, prjLipsum): assert projDet.tabMain.wordCountVal.text() == f"{3000:n}" assert projDet.tabMain.chapCountVal.text() == f"{3:n}" assert projDet.tabMain.sceneCountVal.text() == f"{5:n}" - assert projDet.tabMain.revCountVal.text() == f"{nwGUI.project.data.saveCount:n}" + assert projDet.tabMain.revCountVal.text() == f"{SHARED.project.data.saveCount:n}" assert projDet.tabMain.projPathVal.text() == str(prjLipsum) diff --git a/tests/test_dialogs/test_dlg_projsettings.py b/tests/test_dialogs/test_dlg_projsettings.py index 0eeb9f6e..bafdadc7 100644 --- a/tests/test_dialogs/test_dlg_projsettings.py +++ b/tests/test_dialogs/test_dlg_projsettings.py @@ -95,7 +95,7 @@ def testDlgProjSettings_Main(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockR CONFIG.setBackupPath(fncPath) # Set some values - theProject = nwGUI.project + theProject = SHARED.project theProject.data.setSpellLang("en") theProject.data.setAuthor("Jane Smith") theProject.data.setAutoReplace({"A": "B", "C": "D"}) @@ -160,7 +160,7 @@ def testDlgProjSettings_StatusImport(qtbot, monkeypatch, nwGUI, fncPath, projPat CONFIG.setBackupPath(fncPath) # Set some values - theProject = nwGUI.project + theProject = SHARED.project theProject.tree[C.hTitlePage].setStatus(C.sFinished) theProject.tree[C.hChapterDoc].setStatus(C.sDraft) theProject.tree[C.hSceneDoc].setStatus(C.sDraft) @@ -361,7 +361,7 @@ def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, fncPath, projPath, mo CONFIG.setBackupPath(fncPath) # Set some values - theProject = nwGUI.project + theProject = SHARED.project theProject.data.setAutoReplace({ "A": "B", "C": "D" }) diff --git a/tests/test_dialogs/test_dlg_wordlist.py b/tests/test_dialogs/test_dlg_wordlist.py index 35b1b1cf..6012cf8e 100644 --- a/tests/test_dialogs/test_dlg_wordlist.py +++ b/tests/test_dialogs/test_dlg_wordlist.py @@ -26,6 +26,7 @@ from PyQt5.QtWidgets import QDialog, QAction from tools import buildTestProject, getGuiItem +from novelwriter import SHARED from novelwriter.core.spellcheck import UserDictionary from novelwriter.dialogs.wordlist import GuiWordList @@ -55,7 +56,7 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, projPath): assert wList.listBox.count() == 0 # Add words - userDict = UserDictionary(nwGUI.project) + userDict = UserDictionary(SHARED.project) userDict.add("word_a") userDict.add("word_c") userDict.add("word_g") diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index ea8a9f4f..ef05fd2a 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -28,7 +28,7 @@ from PyQt5.QtCore import Qt from PyQt5.QtGui import QTextBlock, QTextCursor, QTextOption from PyQt5.QtWidgets import QAction, qApp -from novelwriter import CONFIG +from novelwriter import CONFIG, SHARED from novelwriter.enum import nwDocAction, nwDocInsert, nwItemLayout from novelwriter.constants import nwKeyWords, nwUnicode from novelwriter.core.index import countWords @@ -163,10 +163,10 @@ def testGuiEditor_SaveText(qtbot, monkeypatch, caplog, nwGUI, projPath, ipsumTex assert "Could not save document." in caplog.text # Change header level - assert nwGUI.project.tree[C.hSceneDoc].itemLayout == nwItemLayout.DOCUMENT + assert SHARED.project.tree[C.hSceneDoc].itemLayout == nwItemLayout.DOCUMENT nwGUI.docEditor.replaceText(longText[1:]) assert nwGUI.docEditor.saveText() is True - assert nwGUI.project.tree[C.hSceneDoc].itemLayout == nwItemLayout.DOCUMENT + assert SHARED.project.tree[C.hSceneDoc].itemLayout == nwItemLayout.DOCUMENT # Regular save assert nwGUI.docEditor.saveText() is True @@ -203,9 +203,9 @@ def testGuiEditor_MetaData(qtbot, nwGUI, projPath, mockRnd): assert nwGUI.docEditor.setCursorPosition(None) is False assert nwGUI.docEditor.setCursorPosition(10) is True assert nwGUI.docEditor.getCursorPosition() == 10 - assert nwGUI.project.tree[C.hSceneDoc].cursorPos != 10 + assert SHARED.project.tree[C.hSceneDoc].cursorPos != 10 nwGUI.docEditor.saveCursorPosition() - assert nwGUI.project.tree[C.hSceneDoc].cursorPos == 10 + assert SHARED.project.tree[C.hSceneDoc].cursorPos == 10 assert nwGUI.docEditor.setCursorLine(None) is False assert nwGUI.docEditor.setCursorLine(3) is True @@ -1067,7 +1067,7 @@ def testGuiEditor_Tags(qtbot, nwGUI, projPath, ipsumText, mockRnd): # Create Character theText = "### Jane Doe\n\n@tag: Jane\n\n" + ipsumText[1] + "\n\n" - cHandle = nwGUI.project.newFile("Jane Doe", C.hCharRoot) + cHandle = SHARED.project.newFile("Jane Doe", C.hCharRoot) assert nwGUI.openDocument(cHandle) is True assert nwGUI.docEditor.replaceText(theText) is True assert nwGUI.saveDocument() is True @@ -1145,8 +1145,8 @@ def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, projPath, ipsumText, m assert nwGUI.docEditor.docFooter.wordsText.text() == "Words: 0 (+0)" # Open a document and populate it - nwGUI.project.tree[C.hSceneDoc]._initCount = 0 # Clear item's count - nwGUI.project.tree[C.hSceneDoc]._wordCount = 0 # Clear item's count + SHARED.project.tree[C.hSceneDoc]._initCount = 0 # Clear item's count + SHARED.project.tree[C.hSceneDoc]._wordCount = 0 # Clear item's count assert nwGUI.openDocument(C.hSceneDoc) is True theText = "\n\n".join(ipsumText) @@ -1170,9 +1170,9 @@ def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, projPath, ipsumText, m nwGUI.docEditor.wCounterDoc.run() # nwGUI.docEditor._updateDocCounts(cC, wC, pC) - assert nwGUI.project.tree[C.hSceneDoc]._charCount == cC - assert nwGUI.project.tree[C.hSceneDoc]._wordCount == wC - assert nwGUI.project.tree[C.hSceneDoc]._paraCount == pC + assert SHARED.project.tree[C.hSceneDoc]._charCount == cC + assert SHARED.project.tree[C.hSceneDoc]._wordCount == wC + assert SHARED.project.tree[C.hSceneDoc]._paraCount == pC assert nwGUI.docEditor.docFooter.wordsText.text() == f"Words: {wC} (+{wC})" # Select all text diff --git a/tests/test_gui/test_gui_docviewer.py b/tests/test_gui/test_gui_docviewer.py index de21171f..cc8bc995 100644 --- a/tests/test_gui/test_gui_docviewer.py +++ b/tests/test_gui/test_gui_docviewer.py @@ -27,7 +27,7 @@ from PyQt5.QtCore import Qt, QUrl from PyQt5.QtGui import QTextCursor from PyQt5.QtWidgets import qApp, QAction -from novelwriter import CONFIG +from novelwriter import CONFIG, SHARED from novelwriter.enum import nwDocAction from novelwriter.core.tohtml import ToHtml @@ -40,8 +40,8 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum): # Rebuild the index nwGUI.mainMenu.aRebuildIndex.activate(QAction.Trigger) - assert nwGUI.project.index._tagsIndex._tags != {} - assert nwGUI.project.index._itemIndex._items != {} + assert SHARED.project.index._tagsIndex._tags != {} + assert SHARED.project.index._itemIndex._items != {} # Select a document in the project tree nwGUI.projView.setSelectedHandle("88243afbe5ed8") @@ -128,7 +128,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum): nwGUI.docViewer.reloadText() # Change document title - nwItem = nwGUI.project.tree["4c4f28287af27"] + nwItem = SHARED.project.tree["4c4f28287af27"] nwItem.setName("Test Title") assert nwItem.itemName == "Test Title" nwGUI.docViewer.updateDocInfo("4c4f28287af27") diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index 5ca394cd..4f45367c 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -202,14 +202,14 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd): assert nwGUI.saveProject() assert nwGUI.closeProject() - assert len(nwGUI.project.tree) == 0 - assert len(nwGUI.project.tree._treeOrder) == 0 - assert len(nwGUI.project.tree._treeRoots) == 0 - assert nwGUI.project.tree.trashRoot() is None - assert nwGUI.project.data.name == "" - assert nwGUI.project.data.title == "" - assert nwGUI.project.data.author == "" - assert nwGUI.project.data.spellCheck is False + assert len(SHARED.project.tree) == 0 + assert len(SHARED.project.tree._treeOrder) == 0 + assert len(SHARED.project.tree._treeRoots) == 0 + assert SHARED.project.tree.trashRoot() is None + assert SHARED.project.data.name == "" + assert SHARED.project.data.title == "" + assert SHARED.project.data.author == "" + assert SHARED.project.data.spellCheck is False # Check the files projFile = projPath / "nwProject.nwx" @@ -222,14 +222,14 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd): assert nwGUI.openProject(projPath) # Check that we loaded the data - assert len(nwGUI.project.tree) == 8 - assert len(nwGUI.project.tree._treeOrder) == 8 - assert len(nwGUI.project.tree._treeRoots) == 4 - assert nwGUI.project.tree.trashRoot() is None - assert nwGUI.project.data.name == "New Project" - assert nwGUI.project.data.title == "New Novel" - assert nwGUI.project.data.author == "Jane Doe" - assert nwGUI.project.data.spellCheck is False + assert len(SHARED.project.tree) == 8 + assert len(SHARED.project.tree._treeOrder) == 8 + assert len(SHARED.project.tree._treeRoots) == 4 + assert SHARED.project.tree.trashRoot() is None + assert SHARED.project.data.name == "New Project" + assert SHARED.project.data.title == "New Novel" + assert SHARED.project.data.author == "Jane Doe" + assert SHARED.project.data.spellCheck is False # Check that tree items have been created assert nwGUI.projView.projTree._getTreeItem(C.hNovelRoot) is not None diff --git a/tests/test_gui/test_gui_noveltree.py b/tests/test_gui/test_gui_noveltree.py index ab2812ad..4ada522b 100644 --- a/tests/test_gui/test_gui_noveltree.py +++ b/tests/test_gui/test_gui_noveltree.py @@ -29,7 +29,7 @@ from PyQt5.QtGui import QFocusEvent from PyQt5.QtCore import Qt, QEvent from PyQt5.QtWidgets import QInputDialog, QToolTip -from novelwriter import CONFIG +from novelwriter import CONFIG, SHARED from novelwriter.enum import nwWidget, nwItemType from novelwriter.gui.noveltree import NovelTreeColumn from novelwriter.dialogs.editlabel import GuiEditLabel @@ -48,7 +48,7 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd): nwGUI.projView.projTree._getTreeItem(C.hCharRoot).setSelected(True) nwGUI.projView.projTree.newTreeItem(nwItemType.FILE) - contentPath = nwGUI.project.storage.contentPath + contentPath = SHARED.project.storage.contentPath assert isinstance(contentPath, Path) (contentPath / "0000000000010.nwd").write_text( diff --git a/tests/test_gui/test_gui_outline.py b/tests/test_gui/test_gui_outline.py index 4d617b28..85ea4640 100644 --- a/tests/test_gui/test_gui_outline.py +++ b/tests/test_gui/test_gui_outline.py @@ -27,7 +27,7 @@ from tools import buildTestProject, writeFile from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QWidget, QAction -from novelwriter import CONFIG +from novelwriter import CONFIG, SHARED from novelwriter.enum import nwItemClass, nwOutline, nwView @@ -71,7 +71,7 @@ def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, projPath): # Option State # ============ - pOptions = nwGUI.project.options + pOptions = SHARED.project.options colNames = [h.name for h in nwOutline] colItems = [h for h in nwOutline] colWidth = {h: outlineTree.DEF_WIDTH[h] for h in nwOutline} @@ -181,7 +181,7 @@ def testGuiOutline_Content(qtbot, nwGUI, prjLipsum): assert outlineBar.novelValue.itemData(2) == "" # All novels # Add a second novel folder - newHandle = nwGUI.project.newRoot(nwItemClass.NOVEL) + newHandle = SHARED.project.newRoot(nwItemClass.NOVEL) nwGUI.projView.projTree.revealNewTreeItem(newHandle) # Check new values in dropdown list @@ -198,7 +198,7 @@ def testGuiOutline_Content(qtbot, nwGUI, prjLipsum): ("Section 4", 4), ] for dTitle, hLevel in docList: - aHandle = nwGUI.project.newFile(dTitle, newHandle) + aHandle = SHARED.project.newFile(dTitle, newHandle) hHash = "#"*hLevel writeFile(prjLipsum / "content" / f"{aHandle}.nwd", f"{hHash} {dTitle}\n\n") nwGUI.projView.projTree.revealNewTreeItem(aHandle) diff --git a/tests/test_gui/test_gui_projtree.py b/tests/test_gui/test_gui_projtree.py index 83705388..f96ad4e3 100644 --- a/tests/test_gui/test_gui_projtree.py +++ b/tests/test_gui/test_gui_projtree.py @@ -30,7 +30,7 @@ from mocked import causeOSError from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QMessageBox, QMenu, QTreeWidgetItem, QDialog -from novelwriter import CONFIG +from novelwriter import CONFIG, SHARED from novelwriter.enum import nwItemLayout, nwItemType, nwItemClass from novelwriter.guimain import GuiMain from novelwriter.gui.projtree import GuiProjectTree, GuiProjectView @@ -46,7 +46,7 @@ def testGuiProjTree_NewItems(qtbot, caplog, monkeypatch, nwGUI, projPath, mockRn projView = nwGUI.projView projTree = nwGUI.projView.projTree - theProject = nwGUI.project + theProject = SHARED.project # Try to add item with no project assert projView.projTree.newTreeItem(nwItemType.FILE) is False @@ -260,19 +260,19 @@ def testGuiProjTree_MoveItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd): # =========== projView.setSelectedHandle(C.hNovelRoot) - assert nwGUI.project.tree._treeOrder.index(C.hNovelRoot) == 0 + assert SHARED.project.tree._treeOrder.index(C.hNovelRoot) == 0 # Move novel folder up assert projTree.moveTreeItem(-1) is False - assert nwGUI.project.tree._treeOrder.index(C.hNovelRoot) == 0 + assert SHARED.project.tree._treeOrder.index(C.hNovelRoot) == 0 # Move novel folder down assert projTree.moveTreeItem(1) is True - assert nwGUI.project.tree._treeOrder.index(C.hNovelRoot) == 1 + assert SHARED.project.tree._treeOrder.index(C.hNovelRoot) == 1 # Move novel folder up again assert projTree.moveTreeItem(-1) is True - assert nwGUI.project.tree._treeOrder.index(C.hNovelRoot) == 0 + assert SHARED.project.tree._treeOrder.index(C.hNovelRoot) == 0 # Clean up # qtbot.stop() @@ -348,7 +348,7 @@ def testGuiProjTree_RequestDeleteItem(qtbot, caplog, monkeypatch, nwGUI, projPat C.hChapterDir, C.hChapterDoc, C.hSceneDoc, "0000000000010" ] - trashHandle = nwGUI.project.tree.trashRoot() + trashHandle = SHARED.project.tree.trashRoot() assert projTree.getTreeFromHandle(trashHandle) == [ trashHandle, "0000000000012", "0000000000011" ] @@ -368,7 +368,7 @@ def testGuiProjTree_MoveItemToTrash(qtbot, caplog, monkeypatch, nwGUI, projPath, """Test moving items to Trash.""" monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True)) - theProject = nwGUI.project + theProject = SHARED.project projTree = nwGUI.projView.projTree # Create a project @@ -420,7 +420,7 @@ def testGuiProjTree_PermanentlyDeleteItem(qtbot, caplog, monkeypatch, nwGUI, pro """Test permanently deleting items.""" monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True)) - theProject = nwGUI.project + theProject = SHARED.project projTree = nwGUI.projView.projTree # Create a project @@ -471,7 +471,7 @@ def testGuiProjTree_EmptyTrash(qtbot, caplog, monkeypatch, nwGUI, projPath, mock """Test emptying Trash.""" monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True)) - theProject = nwGUI.project + theProject = SHARED.project projTree = nwGUI.projView.projTree # No project open @@ -541,16 +541,16 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): projTree.setExpandedFromHandle(None, True) projTree._addTrashRoot() - hTrashRoot = nwGUI.project.tree.trashRoot() + hTrashRoot = SHARED.project.tree.trashRoot() projTree.setSelectedHandle(C.hCharRoot) projTree.newTreeItem(nwItemType.FILE) projTree.setSelectedHandle(C.hNovelRoot) projTree.newTreeItem(nwItemType.FILE, isNote=True) - nwGUI.project.newFile("SubNote", hNovelNote) + SHARED.project.newFile("SubNote", hNovelNote) projTree.revealNewTreeItem(hSubNote) - assert nwGUI.project.tree[hSubNote].itemParent == hNovelNote + assert SHARED.project.tree[hSubNote].itemParent == hNovelNote def itemPos(tHandle): return projTree.visualItemRect(projTree._getTreeItem(tHandle)).center() @@ -578,7 +578,7 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): # Direct Edit Functions # ===================== # Trigger the dedicated functions the menu entries connect to - nwItem = nwGUI.project.tree[hNovelNote] + nwItem = SHARED.project.tree[hNovelNote] # Toggle active flag assert nwItem.isActive is True @@ -619,17 +619,17 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): with monkeypatch.context() as mp: mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No) projTree._covertFolderToFile(hNewFolderOne, nwItemLayout.DOCUMENT) - assert nwGUI.project.tree[hNewFolderOne].isFolderType() + assert SHARED.project.tree[hNewFolderOne].isFolderType() # Convert the first folder to a document projTree._covertFolderToFile(hNewFolderOne, nwItemLayout.DOCUMENT) - assert nwGUI.project.tree[hNewFolderOne].isFileType() - assert nwGUI.project.tree[hNewFolderOne].isDocumentLayout() + assert SHARED.project.tree[hNewFolderOne].isFileType() + assert SHARED.project.tree[hNewFolderOne].isDocumentLayout() # Convert the second folder to a note projTree._covertFolderToFile(hNewFolderTwo, nwItemLayout.NOTE) - assert nwGUI.project.tree[hNewFolderTwo].isFileType() - assert nwGUI.project.tree[hNewFolderTwo].isNoteLayout() + assert SHARED.project.tree[hNewFolderTwo].isFileType() + assert SHARED.project.tree[hNewFolderTwo].isNoteLayout() # qtbot.stop() @@ -649,7 +649,7 @@ def testGuiProjTree_MergeDocuments(qtbot, monkeypatch, nwGUI, projPath, mockRnd, # Create a project buildTestProject(nwGUI, projPath) - theProject = nwGUI.project + theProject = SHARED.project projTree = nwGUI.projView.projTree mergedDoc1 = "0000000000014" @@ -751,7 +751,7 @@ def testGuiProjTree_SplitDocument(qtbot, monkeypatch, nwGUI, projPath, mockRnd, # Create a project buildTestProject(nwGUI, projPath) - theProject = nwGUI.project + theProject = SHARED.project projTree = nwGUI.projView.projTree docText = ( @@ -852,7 +852,7 @@ def testGuiProjTree_Duplicate(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mock """Test the duplicate items function.""" # Create a project buildTestProject(nwGUI, projPath) - assert len(nwGUI.project.tree) == 8 + assert len(SHARED.project.tree) == 8 projTree = nwGUI.projView.projTree projTree._getTreeItem(C.hNovelRoot).setExpanded(True) # type: ignore @@ -860,28 +860,28 @@ def testGuiProjTree_Duplicate(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mock # Nothing to do assert projTree._duplicateFromHandle(C.hInvalid) is False - assert len(nwGUI.project.tree) == 8 + assert len(SHARED.project.tree) == 8 # Duplicate title page, but select no with monkeypatch.context() as mp: mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No) assert projTree._duplicateFromHandle(C.hTitlePage) is False - assert len(nwGUI.project.tree) == 8 + assert len(SHARED.project.tree) == 8 # Duplicate title page assert projTree._duplicateFromHandle(C.hTitlePage) is True - assert len(nwGUI.project.tree) == 9 + assert len(SHARED.project.tree) == 9 # Duplicate folder assert projTree._duplicateFromHandle(C.hChapterDir) is True - assert len(nwGUI.project.tree) == 12 + assert len(SHARED.project.tree) == 12 # Duplicate novel root assert projTree._duplicateFromHandle(C.hNovelRoot) is True - assert len(nwGUI.project.tree) == 21 + assert len(SHARED.project.tree) == 21 # Check tree order that all items are next to eachother - assert nwGUI.project.tree._treeOrder == [ + assert SHARED.project.tree._treeOrder == [ C.hNovelRoot, C.hTitlePage, "0000000000010", C.hChapterDir, C.hChapterDoc, C.hSceneDoc, "0000000000011", "0000000000012", "0000000000013", "0000000000014", "0000000000015", "0000000000016", "0000000000017", "0000000000018", "0000000000019", "000000000001a", @@ -889,7 +889,7 @@ def testGuiProjTree_Duplicate(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mock ] # Make the duplicator stop early - content = nwGUI.project.storage.contentPath + content = SHARED.project.storage.contentPath assert isinstance(content, Path) (content / "000000000001e.nwd").touch() assert (content / "000000000001e.nwd").exists() @@ -897,7 +897,7 @@ def testGuiProjTree_Duplicate(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mock # Should only create the folder, and skip the two files because the # next handle is already a file assert projTree._duplicateFromHandle(C.hChapterDir) is True - assert len(nwGUI.project.tree) == 22 + assert len(SHARED.project.tree) == 22 # qtbot.stop() @@ -938,13 +938,13 @@ def testGuiProjTree_Other(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mockRnd) assert projTree.revealNewTreeItem(C.hInvalid) is False # Try to add an orphaned file to the tree - nHandle = nwGUI.project.newFile("Test", C.hNovelRoot) - nwGUI.project.tree[nHandle].setParent(None) # type: ignore + nHandle = SHARED.project.newFile("Test", C.hNovelRoot) + SHARED.project.tree[nHandle].setParent(None) # type: ignore assert projTree.revealNewTreeItem(nHandle) is False # Try to add an item with unknown parent to the tree - nHandle = nwGUI.project.newFile("Test", C.hNovelRoot) - nwGUI.project.tree[nHandle].setParent(C.hInvalid) # type: ignore + nHandle = SHARED.project.newFile("Test", C.hNovelRoot) + SHARED.project.tree[nHandle].setParent(C.hInvalid) # type: ignore assert projTree.revealNewTreeItem(nHandle) is False # Method: undoLastMove diff --git a/tests/test_gui/test_gui_statusbar.py b/tests/test_gui/test_gui_statusbar.py index 701a2d07..2a024f8a 100644 --- a/tests/test_gui/test_gui_statusbar.py +++ b/tests/test_gui/test_gui_statusbar.py @@ -24,7 +24,7 @@ import pytest from tools import C, buildTestProject -from novelwriter import CONFIG +from novelwriter import CONFIG, SHARED from novelwriter.extensions.statusled import StatusLED @@ -32,8 +32,8 @@ from novelwriter.extensions.statusled import StatusLED def testGuiStatusBar_Main(qtbot, nwGUI, projPath, mockRnd): """Test the the various features of the status bar.""" buildTestProject(nwGUI, projPath) - cHandle = nwGUI.project.newFile("A Note", C.hCharRoot) - newDoc = nwGUI.project.storage.getDocument(cHandle) + cHandle = SHARED.project.newFile("A Note", C.hCharRoot) + newDoc = SHARED.project.storage.getDocument(cHandle) newDoc.writeDocument("# A Note\n\n") nwGUI.projView.projTree.revealNewTreeItem(cHandle) nwGUI.rebuildIndex(beQuiet=True) diff --git a/tests/test_tools/test_tools_manuscript.py b/tests/test_tools/test_tools_manuscript.py index 9d58554d..af8a8146 100644 --- a/tests/test_tools/test_tools_manuscript.py +++ b/tests/test_tools/test_tools_manuscript.py @@ -32,7 +32,7 @@ from PyQt5.QtCore import Qt, pyqtSlot from PyQt5.QtWidgets import QDialogButtonBox from PyQt5.QtPrintSupport import QPrintPreviewDialog -from novelwriter import CONFIG +from novelwriter import CONFIG, SHARED from novelwriter.guimain import GuiMain from novelwriter.core.buildsettings import BuildSettings from novelwriter.tools.manuscript import GuiManuscript @@ -45,7 +45,7 @@ def testManuscript_Init(monkeypatch, qtbot: QtBot, nwGUI: GuiMain, projPath: Pat """Test the init/main functionality of the GuiManuscript dialog.""" buildTestProject(nwGUI, projPath) nwGUI.openProject(projPath) - nwGUI.project.storage.getDocument(C.hChapterDoc).writeDocument("## A Chapter\n\n\t\tHi") + SHARED.project.storage.getDocument(C.hChapterDoc).writeDocument("## A Chapter\n\n\t\tHi") allText = "New Novel\nBy Jane Doe\nA Chapter\n\t\tHi\n* * *" manus = GuiManuscript(nwGUI) @@ -159,7 +159,7 @@ def testManuscript_Features(monkeypatch, qtbot: QtBot, nwGUI: GuiMain, projPath: manus.show() manus.loadContent() - cacheFile = CONFIG.dataPath("cache") / f"build_{nwGUI.project.data.uuid}.json" + cacheFile = CONFIG.dataPath("cache") / f"build_{SHARED.project.data.uuid}.json" manus.buildList.setCurrentRow(0) build = manus._getSelectedBuild() assert isinstance(build, BuildSettings) diff --git a/tests/test_tools/test_tools_manussettings.py b/tests/test_tools/test_tools_manussettings.py index deccca1c..1371caf0 100644 --- a/tests/test_tools/test_tools_manussettings.py +++ b/tests/test_tools/test_tools_manussettings.py @@ -21,16 +21,16 @@ along with this program. If not, see . import pytest -from tools import C, buildTestProject - from pathlib import Path from pytestqt.qtbot import QtBot +from tools import C, buildTestProject + from PyQt5.QtGui import QFont from PyQt5.QtCore import pyqtSlot from PyQt5.QtWidgets import QDialogButtonBox, QFontDialog -from novelwriter import CONFIG +from novelwriter import CONFIG, SHARED from novelwriter.guimain import GuiMain from novelwriter.constants import nwHeadFmt from novelwriter.core.buildsettings import BuildSettings, FilterMode @@ -128,11 +128,11 @@ def testBuildSettings_Filter(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockR "worldRoot": 9, } - hPlotDoc = nwGUI.project.newFile("Main Plot", C.hPlotRoot) - hCharDoc = nwGUI.project.newFile("Jane Doe", C.hCharRoot) + hPlotDoc = SHARED.project.newFile("Main Plot", C.hPlotRoot) + hCharDoc = SHARED.project.newFile("Jane Doe", C.hCharRoot) nwGUI.projView.projTree.revealNewTreeItem(hPlotDoc) nwGUI.projView.projTree.revealNewTreeItem(hCharDoc) - nwGUI.project.tree[hPlotDoc].setActive(False) # type: ignore + SHARED.project.tree[hPlotDoc].setActive(False) # type: ignore # Create the dialog and populate it bSettings = GuiBuildSettings(nwGUI, build) @@ -167,7 +167,7 @@ def testBuildSettings_Filter(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockR # Switch off novel docs filterTab.filterOpt._widgets[switchMap["incNovel"]].setChecked(False) - assert build.buildItemFilter(nwGUI.project) == { + assert build.buildItemFilter(SHARED.project) == { C.hNovelRoot: (False, FilterMode.SKIPPED), C.hTitlePage: (False, FilterMode.FILTERED), C.hChapterDir: (False, FilterMode.SKIPPED), @@ -182,7 +182,7 @@ def testBuildSettings_Filter(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockR # Switch on note docs filterTab.filterOpt._widgets[switchMap["incNotes"]].setChecked(True) - assert build.buildItemFilter(nwGUI.project) == { + assert build.buildItemFilter(SHARED.project) == { C.hNovelRoot: (False, FilterMode.SKIPPED), C.hTitlePage: (False, FilterMode.FILTERED), C.hChapterDir: (False, FilterMode.SKIPPED), @@ -197,7 +197,7 @@ def testBuildSettings_Filter(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockR # Switch on inactive docs filterTab.filterOpt._widgets[switchMap["incInactive"]].setChecked(True) - assert build.buildItemFilter(nwGUI.project) == { + assert build.buildItemFilter(SHARED.project) == { C.hNovelRoot: (False, FilterMode.SKIPPED), C.hTitlePage: (False, FilterMode.FILTERED), C.hChapterDir: (False, FilterMode.SKIPPED), @@ -214,7 +214,7 @@ def testBuildSettings_Filter(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockR filterTab._treeMap[C.hChapterDoc].setSelected(True) filterTab._treeMap[C.hSceneDoc].setSelected(True) filterTab.includedButton.click() - assert build.buildItemFilter(nwGUI.project) == { + assert build.buildItemFilter(SHARED.project) == { C.hNovelRoot: (False, FilterMode.SKIPPED), C.hTitlePage: (False, FilterMode.FILTERED), C.hChapterDir: (False, FilterMode.SKIPPED), @@ -232,7 +232,7 @@ def testBuildSettings_Filter(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockR filterTab._treeMap[hPlotDoc].setSelected(True) # type: ignore filterTab._treeMap[hCharDoc].setSelected(True) # type: ignore filterTab.excludedButton.click() - assert build.buildItemFilter(nwGUI.project) == { + assert build.buildItemFilter(SHARED.project) == { C.hNovelRoot: (False, FilterMode.SKIPPED), C.hTitlePage: (False, FilterMode.FILTERED), C.hChapterDir: (False, FilterMode.SKIPPED), @@ -247,7 +247,7 @@ def testBuildSettings_Filter(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockR # Switch on novel docs filterTab.filterOpt._widgets[switchMap["incNovel"]].setChecked(True) - assert build.buildItemFilter(nwGUI.project) == { + assert build.buildItemFilter(SHARED.project) == { C.hNovelRoot: (False, FilterMode.SKIPPED), C.hTitlePage: (True, FilterMode.FILTERED), # Now enabled C.hChapterDir: (False, FilterMode.SKIPPED), @@ -264,7 +264,7 @@ def testBuildSettings_Filter(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockR filterTab.optTree.clearSelection() filterTab._treeMap[C.hNovelRoot].setSelected(True) filterTab.resetButton.click() - assert build.buildItemFilter(nwGUI.project) == { + assert build.buildItemFilter(SHARED.project) == { C.hNovelRoot: (False, FilterMode.SKIPPED), C.hTitlePage: (True, FilterMode.FILTERED), C.hChapterDir: (False, FilterMode.SKIPPED), @@ -284,7 +284,7 @@ def testBuildSettings_Filter(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockR filterTab._treeMap[hPlotDoc].setSelected(True) # type: ignore filterTab._treeMap[hCharDoc].setSelected(True) # type: ignore filterTab.resetButton.click() - assert build.buildItemFilter(nwGUI.project) == { + assert build.buildItemFilter(SHARED.project) == { C.hNovelRoot: (False, FilterMode.SKIPPED), C.hTitlePage: (True, FilterMode.FILTERED), C.hChapterDir: (False, FilterMode.SKIPPED), @@ -302,8 +302,8 @@ def testBuildSettings_Filter(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockR C.hNovelRoot, C.hTitlePage, C.hChapterDir, C.hChapterDoc, C.hSceneDoc, C.hPlotRoot, hPlotDoc, C.hCharRoot, hCharDoc, ] - nwGUI.project.tree[hCharDoc].setRoot(None) # type: ignore - nwGUI.project.tree[hPlotDoc].setParent(None) # type: ignore + SHARED.project.tree[hCharDoc].setRoot(None) # type: ignore + SHARED.project.tree[hPlotDoc].setParent(None) # type: ignore filterTab._populateTree() assert list(filterTab._treeMap.keys()) == [ C.hNovelRoot, C.hTitlePage, C.hChapterDir, C.hChapterDoc, C.hSceneDoc, diff --git a/tests/test_tools/test_tools_writingstats.py b/tests/test_tools/test_tools_writingstats.py index 50d78f2a..64de8775 100644 --- a/tests/test_tools/test_tools_writingstats.py +++ b/tests/test_tools/test_tools_writingstats.py @@ -20,15 +20,17 @@ along with this program. If not, see . """ import json -from pathlib import Path import pytest +from pathlib import Path + from tools import getGuiItem, buildTestProject from mocked import causeOSError from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QAction, QFileDialog +from novelwriter import SHARED from novelwriter.constants import nwFiles from novelwriter.tools.writingstats import GuiWritingStats @@ -39,7 +41,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, projPath, tstPaths): """ # Create a project to work on buildTestProject(nwGUI, projPath) - project = nwGUI.project + project = SHARED.project qtbot.wait(100) assert nwGUI.saveProject() diff --git a/tests/tools.py b/tests/tools.py index f96b5259..6230d1a2 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -165,8 +165,9 @@ def buildTestProject(obj, projPath): nwGUI = None project = obj else: + from novelwriter import SHARED nwGUI = obj - project = obj.project + project = SHARED.project project.storage.openProjectInPlace(projPath) project.setDefaultStatusImport()