diff --git a/nw/core/document.py b/nw/core/document.py index e158cf87..c645a840 100644 --- a/nw/core/document.py +++ b/nw/core/document.py @@ -38,10 +38,10 @@ logger = logging.getLogger(__name__) class NWDoc(): - def __init__(self, theProject, theParent): + def __init__(self, theProject): self.theProject = theProject - self.theParent = theParent + self.theParent = theProject.theParent # Internal Variables self._theItem = None # The currently open item diff --git a/nw/core/index.py b/nw/core/index.py index 8d6f04c3..d7b09ec4 100644 --- a/nw/core/index.py +++ b/nw/core/index.py @@ -32,7 +32,7 @@ import os from time import time -from nw.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert +from nw.enum import nwItemType, nwItemClass, nwItemLayout from nw.common import isHandle, isTitleTag, isItemClass, isItemLayout from nw.constants import nwFiles, nwKeyWords, nwUnicode from nw.core.document import NWDoc @@ -44,12 +44,11 @@ class NWIndex(): H_VALID = ("H0", "H1", "H2", "H3", "H4") H_LEVEL = {"H0": 0, "H1": 1, "H2": 2, "H3": 3, "H4": 4} - def __init__(self, theProject, theParent): + def __init__(self, theProject): # Internal self.mainConf = nw.CONFIG self.theProject = theProject - self.theParent = theParent self.indexBroken = False # Indices @@ -116,7 +115,7 @@ class NWIndex(): if tItem.itemType != nwItemType.FILE: return False - theDoc = NWDoc(self.theProject, self.theParent) + theDoc = NWDoc(self.theProject) theText = theDoc.readDocument(tHandle) if theText: self.scanText(tHandle, theText) @@ -157,10 +156,6 @@ class NWIndex(): logger.error("Failed to load index file") nw.logException() self.indexBroken = True - self.theParent.makeAlert( - "Could not load cached index file. Rebuilding index.", - nwAlert.WARN - ) return False self._tagIndex = theData.get("tagIndex", {}) diff --git a/nw/core/project.py b/nw/core/project.py index 75aaafa9..e0e978ee 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -266,7 +266,7 @@ class NWProject(): titlePage = "%s%s %s\n" % (titlePage, self.tr("By"), self.getAuthors()) # Document object for writing files - aDoc = NWDoc(self, self.theParent) + aDoc = NWDoc(self) if popMinimal: # Creating a minimal project with a few root folders and a @@ -1393,7 +1393,7 @@ class NWProject(): return # Handle orphans - aDoc = NWDoc(self, self.theParent) + aDoc = NWDoc(self) nOrph = 0 noWhere = False oPrefix = self.tr("Recovered") diff --git a/nw/core/tohtml.py b/nw/core/tohtml.py index 412efe4f..180c2da8 100644 --- a/nw/core/tohtml.py +++ b/nw/core/tohtml.py @@ -37,8 +37,8 @@ class ToHtml(Tokenizer): M_EXPORT = 1 # Tweak output for saving to HTML or printing M_EBOOK = 2 # Tweak output for converting to epub - def __init__(self, theProject, theParent): - Tokenizer.__init__(self, theProject, theParent) + def __init__(self, theProject): + Tokenizer.__init__(self, theProject) self.genMode = self.M_EXPORT self.cssStyles = True diff --git a/nw/core/tokenizer.py b/nw/core/tokenizer.py index 713d2dd5..d04ffe47 100644 --- a/nw/core/tokenizer.py +++ b/nw/core/tokenizer.py @@ -76,10 +76,10 @@ class Tokenizer(): A_Z_TOPMRG = 0x0100 # Zero top margin A_Z_BTMMRG = 0x0200 # Zero bottom margin - def __init__(self, theProject, theParent): + def __init__(self, theProject): self.theProject = theProject - self.theParent = theParent + self.theParent = theProject.theParent # Data Variables self.theText = "" # The raw text to be tokenized @@ -284,7 +284,7 @@ class Tokenizer(): self.theText = theText else: # Otherwise, load it from file - theDoc = NWDoc(self.theProject, self.theParent) + theDoc = NWDoc(self.theProject) theText = theDoc.readDocument(theHandle) if theText: self.theText = theText diff --git a/nw/core/tomd.py b/nw/core/tomd.py index 53e3ab80..684a23fb 100644 --- a/nw/core/tomd.py +++ b/nw/core/tomd.py @@ -36,8 +36,8 @@ class ToMarkdown(Tokenizer): M_STD = 0 # Standard Markdown M_GH = 1 # GitHub Markdown - def __init__(self, theProject, theParent): - Tokenizer.__init__(self, theProject, theParent) + def __init__(self, theProject): + Tokenizer.__init__(self, theProject) self.genMode = self.M_STD self.fullMD = [] diff --git a/nw/core/toodt.py b/nw/core/toodt.py index 89b74148..ca06cacf 100644 --- a/nw/core/toodt.py +++ b/nw/core/toodt.py @@ -65,8 +65,8 @@ class ToOdt(Tokenizer): X_BRK = 0x08 # Line break X_TAB = 0x10 # Tab - def __init__(self, theProject, theParent, isFlat): - Tokenizer.__init__(self, theProject, theParent) + def __init__(self, theProject, isFlat): + Tokenizer.__init__(self, theProject) self.mainConf = nw.CONFIG diff --git a/nw/dialogs/docmerge.py b/nw/dialogs/docmerge.py index 8dbaaa98..a609e63d 100644 --- a/nw/dialogs/docmerge.py +++ b/nw/dialogs/docmerge.py @@ -107,7 +107,7 @@ class GuiDocMerge(QDialog): ) return - theDoc = NWDoc(self.theProject, self.theParent) + theDoc = NWDoc(self.theProject) theText = "" for tHandle in finalOrder: docText = theDoc.readDocument(tHandle).rstrip("\n") diff --git a/nw/dialogs/docsplit.py b/nw/dialogs/docsplit.py index bf5f2d1f..74fbedfa 100644 --- a/nw/dialogs/docsplit.py +++ b/nw/dialogs/docsplit.py @@ -127,7 +127,7 @@ class GuiDocSplit(QDialog): ) return - theDoc = NWDoc(self.theProject, self.theParent) + theDoc = NWDoc(self.theProject) theText = theDoc.readDocument(self.sourceItem) if theText is None: theText = "" @@ -259,7 +259,7 @@ class GuiDocSplit(QDialog): return self.listBox.clear() - theDoc = NWDoc(self.theProject, self.theParent) + theDoc = NWDoc(self.theProject) theText = theDoc.readDocument(self.sourceItem) if theText is None: theText = "" diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 7cbb761e..759c0053 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -75,7 +75,7 @@ class GuiDocEditor(QTextEdit): self.theTheme = theParent.theTheme self.theIndex = theParent.theIndex self.theProject = theParent.theProject - self.nwDocument = NWDoc(self.theProject, self.theParent) + self.nwDocument = NWDoc(self.theProject) self.docChanged = False # Flag for changed status of document self.spellCheck = False # Flag for spell checking enabled diff --git a/nw/gui/docviewer.py b/nw/gui/docviewer.py index 0feaa101..8ba3fbef 100644 --- a/nw/gui/docviewer.py +++ b/nw/gui/docviewer.py @@ -168,7 +168,7 @@ class GuiDocViewer(QTextBrowser): qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) sPos = self.verticalScrollBar().value() - aDoc = ToHtml(self.theProject, self.theParent) + aDoc = ToHtml(self.theProject) aDoc.setPreview(self.mainConf.viewComments, self.mainConf.viewSynopsis) aDoc.setLinkHeaders(True) diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index 005e4d2f..84415f80 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -286,7 +286,7 @@ class GuiProjectTree(QTreeWidget): return True # This is a new files, so let's add some content - newDoc = NWDoc(self.theProject, self.theParent) + newDoc = NWDoc(self.theProject) curTxt = newDoc.readDocument(tHandle) if curTxt is None: curTxt = "" @@ -527,7 +527,7 @@ class GuiProjectTree(QTreeWidget): if self.theParent.docEditor.theHandle == tHandle: self.theParent.closeDocument() - theDoc = NWDoc(self.theProject, self.theParent) + theDoc = NWDoc(self.theProject) theDoc.deleteDocument(tHandle) self.theIndex.deleteHandle(tHandle) self._deleteTreeItem(tHandle) diff --git a/nw/guimain.py b/nw/guimain.py index aff3bea0..8c97d6d5 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -88,7 +88,7 @@ class GuiMain(QMainWindow): # Core Classes and Settings self.theTheme = GuiTheme(self) self.theProject = NWProject(self) - self.theIndex = NWIndex(self.theProject, self) + self.theIndex = NWIndex(self.theProject) self.hasProject = False self.isFocusMode = False self.idleRefTime = time() diff --git a/nw/tools/build.py b/nw/tools/build.py index 58526af5..a3093cea 100644 --- a/nw/tools/build.py +++ b/nw/tools/build.py @@ -608,7 +608,7 @@ class GuiBuildNovel(QDialog): # Build Preview # ============= - makeHtml = ToHtml(self.theProject, self.theParent) + makeHtml = ToHtml(self.theProject) self._doBuild(makeHtml, isPreview=True) if replaceTabs: makeHtml.replaceTabs() @@ -875,7 +875,7 @@ class GuiBuildNovel(QDialog): wSuccess = False if theFmt == self.FMT_ODT: - makeOdt = ToOdt(self.theProject, self.theParent, isFlat=False) + makeOdt = ToOdt(self.theProject, isFlat=False) self._doBuild(makeOdt) try: makeOdt.saveOpenDocText(savePath) @@ -884,7 +884,7 @@ class GuiBuildNovel(QDialog): errMsg = str(e) elif theFmt == self.FMT_FODT: - makeOdt = ToOdt(self.theProject, self.theParent, isFlat=True) + makeOdt = ToOdt(self.theProject, isFlat=True) self._doBuild(makeOdt) try: makeOdt.saveFlatXML(savePath) @@ -893,7 +893,7 @@ class GuiBuildNovel(QDialog): errMsg = str(e) elif theFmt == self.FMT_HTM: - makeHtml = ToHtml(self.theProject, self.theParent) + makeHtml = ToHtml(self.theProject) self._doBuild(makeHtml) if replaceTabs: makeHtml.replaceTabs() @@ -905,7 +905,7 @@ class GuiBuildNovel(QDialog): errMsg = str(e) elif theFmt == self.FMT_NWD: - makeNwd = ToMarkdown(self.theProject, self.theParent) + makeNwd = ToMarkdown(self.theProject) makeNwd.setKeepMarkdown(True) self._doBuild(makeNwd, doConvert=False) if replaceTabs: @@ -918,7 +918,7 @@ class GuiBuildNovel(QDialog): errMsg = str(e) elif theFmt in (self.FMT_MD, self.FMT_GH): - makeMd = ToMarkdown(self.theProject, self.theParent) + makeMd = ToMarkdown(self.theProject) if theFmt == self.FMT_GH: makeMd.setGitHubMarkdown() else: @@ -945,7 +945,7 @@ class GuiBuildNovel(QDialog): } if theFmt == self.FMT_JSON_H: - makeHtml = ToHtml(self.theProject, self.theParent) + makeHtml = ToHtml(self.theProject) self._doBuild(makeHtml) if replaceTabs: makeHtml.replaceTabs() @@ -959,7 +959,7 @@ class GuiBuildNovel(QDialog): } elif theFmt == self.FMT_JSON_M: - makeMd = ToHtml(self.theProject, self.theParent) + makeMd = ToHtml(self.theProject) makeMd.setKeepMarkdown(True) self._doBuild(makeMd, doConvert=False) if replaceTabs: diff --git a/tests/test_core/test_core_document.py b/tests/test_core/test_core_document.py index df02ea1b..056b212e 100644 --- a/tests/test_core/test_core_document.py +++ b/tests/test_core/test_core_document.py @@ -37,7 +37,7 @@ def testCoreDocument_LoadSave(monkeypatch, dummyGUI, nwMinimal): assert theProject.openProject(nwMinimal) assert theProject.projPath == nwMinimal - theDoc = NWDoc(theProject, dummyGUI) + theDoc = NWDoc(theProject) sHandle = "8c659a11cd429" # Not a valid handle @@ -126,7 +126,7 @@ def testCoreDocument_Methods(monkeypatch, dummyGUI, nwMinimal): assert theProject.openProject(nwMinimal) assert theProject.projPath == nwMinimal - theDoc = NWDoc(theProject, dummyGUI) + theDoc = NWDoc(theProject) sHandle = "8c659a11cd429" docPath = os.path.join(nwMinimal, "content", sHandle+".nwd") diff --git a/tests/test_core/test_core_index.py b/tests/test_core/test_core_index.py index 95b83a81..7dc5c9f8 100644 --- a/tests/test_core/test_core_index.py +++ b/tests/test_core/test_core_index.py @@ -48,7 +48,7 @@ def testCoreIndex_LoadSave(monkeypatch, nwLipsum, dummyGUI, outDir, refDir): monkeypatch.setattr("nw.core.index.time", lambda: 123.4) - theIndex = NWIndex(theProject, dummyGUI) + theIndex = NWIndex(theProject) notIndexable = { "b3643d0f92e32": False, # Novel ROOT "45e6b01ca35c1": False, # Chapter One FOLDER @@ -132,7 +132,7 @@ def testCoreIndex_ScanThis(nwMinimal, dummyGUI): theProject.projTree.setSeed(42) assert theProject.openProject(nwMinimal) - theIndex = NWIndex(theProject, dummyGUI) + theIndex = NWIndex(theProject) isValid, theBits, thePos = theIndex.scanThis("tag: this, and this") assert not isValid @@ -183,7 +183,7 @@ def testCoreIndex_CheckThese(nwMinimal, dummyGUI): theProject.projTree.setSeed(42) assert theProject.openProject(nwMinimal) - theIndex = NWIndex(theProject, dummyGUI) + theIndex = NWIndex(theProject) nHandle = theProject.newFile("Hello", nwItemClass.NOVEL, "a508bb932959c") cHandle = theProject.newFile("Jane", nwItemClass.CHARACTER, "afb3043c7b2b3") nItem = theProject.projTree[nHandle] @@ -244,7 +244,7 @@ def testCoreIndex_ScanText(nwMinimal, dummyGUI): theProject.projTree.setSeed(42) assert theProject.openProject(nwMinimal) - theIndex = NWIndex(theProject, dummyGUI) + theIndex = NWIndex(theProject) # Some items for fail to scan tests dHandle = theProject.newFolder("Folder", nwItemClass.NOVEL, "a508bb932959c") @@ -449,7 +449,7 @@ def testCoreIndex_ExtractData(nwMinimal, dummyGUI): theProject.projTree.setSeed(42) assert theProject.openProject(nwMinimal) - theIndex = NWIndex(theProject, dummyGUI) + theIndex = NWIndex(theProject) nHandle = theProject.newFile("Hello", nwItemClass.NOVEL, "a508bb932959c") cHandle = theProject.newFile("Jane", nwItemClass.CHARACTER, "afb3043c7b2b3") @@ -678,7 +678,7 @@ def testCoreIndex_CheckTagIndex(dummyGUI): """Test the tag index checker. """ theProject = NWProject(dummyGUI) - theIndex = NWIndex(theProject, dummyGUI) + theIndex = NWIndex(theProject) # Valid Index theIndex._tagIndex = { @@ -742,7 +742,7 @@ def testCoreIndex_CheckRefIndex(dummyGUI): """Test the reference index checker. """ theProject = NWProject(dummyGUI) - theIndex = NWIndex(theProject, dummyGUI) + theIndex = NWIndex(theProject) # Valid Index theIndex._refIndex = { @@ -864,7 +864,7 @@ def testCoreIndex_CheckNovelNoteIndex(dummyGUI): """Test the novel and note index checkers. """ theProject = NWProject(dummyGUI) - theIndex = NWIndex(theProject, dummyGUI) + theIndex = NWIndex(theProject) # Valid Index theIndex._novelIndex = { @@ -1122,7 +1122,7 @@ def testCoreIndex_CheckTextCounts(dummyGUI): """Test the text counts checker. """ theProject = NWProject(dummyGUI) - theIndex = NWIndex(theProject, dummyGUI) + theIndex = NWIndex(theProject) # Valid Index theIndex._textCounts = { diff --git a/tests/test_core/test_core_tohtml.py b/tests/test_core/test_core_tohtml.py index 8e25b432..8706c0c9 100644 --- a/tests/test_core/test_core_tohtml.py +++ b/tests/test_core/test_core_tohtml.py @@ -32,8 +32,8 @@ def testCoreToHtml_Format(dummyGUI): """Test all the formatters for the ToHtml class. """ theProject = NWProject(dummyGUI) - dummyGUI.theIndex = NWIndex(theProject, dummyGUI) - theHtml = ToHtml(theProject, dummyGUI) + dummyGUI.theIndex = NWIndex(theProject) + theHtml = ToHtml(theProject) # Export Mode # =========== @@ -84,8 +84,8 @@ def testCoreToHtml_Convert(dummyGUI): """Test the converter of the ToHtml class. """ theProject = NWProject(dummyGUI) - dummyGUI.theIndex = NWIndex(theProject, dummyGUI) - theHtml = ToHtml(theProject, dummyGUI) + dummyGUI.theIndex = NWIndex(theProject) + theHtml = ToHtml(theProject) # Export Mode # =========== @@ -348,7 +348,7 @@ def testCoreToHtml_Complex(dummyGUI, fncDir): """Test the ave method of the ToHtml class. """ theProject = NWProject(dummyGUI) - theHtml = ToHtml(theProject, dummyGUI) + theHtml = ToHtml(theProject) # Build Project # ============= @@ -421,7 +421,7 @@ def testCoreToHtml_Methods(dummyGUI): """Test all the other methods of the ToHtml class. """ theProject = NWProject(dummyGUI) - theHtml = ToHtml(theProject, dummyGUI) + theHtml = ToHtml(theProject) theHtml.setKeepMarkdown(True) # Auto-Replace, keep Unicode diff --git a/tests/test_core/test_core_tokenizer.py b/tests/test_core/test_core_tokenizer.py index 743c45f5..6d13faee 100644 --- a/tests/test_core/test_core_tokenizer.py +++ b/tests/test_core/test_core_tokenizer.py @@ -33,7 +33,7 @@ def testCoreToken_Setters(dummyGUI): """Test all the setters for the Tokenizer class. """ theProject = NWProject(dummyGUI) - theToken = Tokenizer(theProject, dummyGUI) + theToken = Tokenizer(theProject) # Verify defaults assert theToken.fmtTitle == "%title%" @@ -120,7 +120,7 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, dummyGUI): theProject.projLang = "en" theProject._loadProjectLocalisation() - theToken = Tokenizer(theProject, dummyGUI) + theToken = Tokenizer(theProject) theToken.setKeepMarkdown(True) assert theProject.openProject(nwMinimal) @@ -137,7 +137,7 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, dummyGUI): ) docTextR = docText.replace("", "this").replace("", "that") - nDoc = NWDoc(theProject, dummyGUI) + nDoc = NWDoc(theProject) nDoc.readDocument(sHandle) nDoc.writeDocument(docText) nDoc.clearDocument() @@ -200,7 +200,7 @@ def testCoreToken_Tokenize(dummyGUI): """Test the tokenization of the Tokenizer class. """ theProject = NWProject(dummyGUI) - theToken = Tokenizer(theProject, dummyGUI) + theToken = Tokenizer(theProject) theToken.setKeepMarkdown(True) # Header 1 @@ -417,7 +417,7 @@ def testCoreToken_Headers(dummyGUI): theProject = NWProject(dummyGUI) theProject.projLang = "en" theProject._loadProjectLocalisation() - theToken = Tokenizer(theProject, dummyGUI) + theToken = Tokenizer(theProject) # Nothing theToken.theText = "Some text ...\n" diff --git a/tests/test_core/test_core_toodt.py b/tests/test_core/test_core_toodt.py index 9cad2f7d..955963e7 100644 --- a/tests/test_core/test_core_toodt.py +++ b/tests/test_core/test_core_toodt.py @@ -48,8 +48,8 @@ def testCoreToOdt_Convert(dummyGUI): """Test the converter of the ToHtml class. """ theProject = NWProject(dummyGUI) - dummyGUI.theIndex = NWIndex(theProject, dummyGUI) - theDoc = ToOdt(theProject, dummyGUI, isFlat=True) + dummyGUI.theIndex = NWIndex(theProject) + theDoc = ToOdt(theProject, isFlat=True) # Export Mode # ===========