Core classes should only init with project class and if needed access main gui via project

This commit is contained in:
Veronica K. B. Olsen
2021-04-25 17:39:52 +02:00
parent 45f726669e
commit 48695651e1
19 changed files with 56 additions and 61 deletions
+2 -2
View File
@@ -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
+3 -8
View File
@@ -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", {})
+2 -2
View File
@@ -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")
+2 -2
View File
@@ -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
+3 -3
View File
@@ -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
+2 -2
View File
@@ -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 = []
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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")
+2 -2
View File
@@ -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 = ""
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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()
+8 -8
View File
@@ -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: