Make project instance private to main GUI class

This commit is contained in:
Veronica Berglyd Olsen
2023-08-08 17:21:00 +02:00
parent 94c95d6f67
commit 12897ff2e1
37 changed files with 445 additions and 465 deletions
+2 -3
View File
@@ -49,8 +49,7 @@ class GuiDocMerge(QDialog):
logger.debug("Create: GuiDocMerge")
self.setObjectName("GuiDocMerge")
self.mainGui = mainGui
self.theProject = mainGui.theProject
self.mainGui = mainGui
self._data = {}
@@ -156,7 +155,7 @@ class GuiDocMerge(QDialog):
self.listBox.clear()
for tHandle in itemList:
nwItem = self.theProject.tree[tHandle]
nwItem = self.mainGui.project.tree[tHandle]
if nwItem is None or not nwItem.isFileType():
continue
+5 -6
View File
@@ -51,8 +51,7 @@ class GuiDocSplit(QDialog):
logger.debug("Create: GuiDocSplit")
self.setObjectName("GuiDocSplit")
self.mainGui = mainGui
self.theProject = mainGui.theProject
self.mainGui = mainGui
self._data = {}
self._text = []
@@ -71,7 +70,7 @@ class GuiDocSplit(QDialog):
vSp = CONFIG.pxInt(8)
bSp = CONFIG.pxInt(12)
pOptions = self.theProject.options
pOptions = self.mainGui.project.options
spLevel = pOptions.getInt("GuiDocSplit", "spLevel", 3)
intoFolder = pOptions.getBool("GuiDocSplit", "intoFolder", True)
docHierarchy = pOptions.getBool("GuiDocSplit", "docHierarchy", True)
@@ -170,7 +169,7 @@ class GuiDocSplit(QDialog):
self._data["docHierarchy"] = docHierarchy
self._data["moveToTrash"] = moveToTrash
pOptions = self.theProject.options
pOptions = self.mainGui.project.options
pOptions.setValue("GuiDocSplit", "spLevel", spLevel)
pOptions.setValue("GuiDocSplit", "intoFolder", intoFolder)
pOptions.setValue("GuiDocSplit", "docHierarchy", docHierarchy)
@@ -200,13 +199,13 @@ class GuiDocSplit(QDialog):
self.listBox.clear()
nwItem = self.theProject.tree[sHandle]
nwItem = self.mainGui.project.tree[sHandle]
if nwItem is None or not nwItem.isFileType():
return
spLevel = self.splitLevel.currentData()
if not self._text:
inDoc = self.theProject.storage.getDocument(sHandle)
inDoc = self.mainGui.project.storage.getDocument(sHandle)
self._text = (inDoc.readDocument() or "").splitlines()
for lineNo, aLine in enumerate(self._text):
+1 -2
View File
@@ -49,8 +49,7 @@ class GuiPreferences(NPagedDialog):
logger.debug("Create: GuiPreferences")
self.setObjectName("GuiPreferences")
self.mainGui = mainGui
self.theProject = mainGui.theProject
self.mainGui = mainGui
self.setWindowTitle(self.tr("Preferences"))
+20 -22
View File
@@ -51,14 +51,13 @@ class GuiProjectDetails(NPagedDialog):
logger.debug("Create: GuiProjectDetails")
self.setObjectName("GuiProjectDetails")
self.mainGui = mainGui
self.theProject = mainGui.theProject
self.mainGui = mainGui
self.setWindowTitle(self.tr("Project Details"))
wW = CONFIG.pxInt(600)
wH = CONFIG.pxInt(400)
pOptions = self.theProject.options
pOptions = self.mainGui.project.options
self.setMinimumWidth(wW)
self.setMinimumHeight(wH)
@@ -67,8 +66,8 @@ class GuiProjectDetails(NPagedDialog):
CONFIG.pxInt(pOptions.getInt("GuiProjectDetails", "winHeight", wH))
)
self.tabMain = GuiProjectDetailsMain(self.mainGui, self.theProject)
self.tabContents = GuiProjectDetailsContents(self.mainGui, self.theProject)
self.tabMain = GuiProjectDetailsMain(self.mainGui)
self.tabContents = GuiProjectDetailsContents(self.mainGui)
self.addTab(self.tabMain, self.tr("Overview"))
self.addTab(self.tabContents, self.tr("Contents"))
@@ -125,7 +124,7 @@ class GuiProjectDetails(NPagedDialog):
countFrom = self.tabContents.poValue.value()
clearDouble = self.tabContents.dblValue.isChecked()
pOptions = self.theProject.options
pOptions = self.mainGui.project.options
pOptions.setValue("GuiProjectDetails", "winWidth", winWidth)
pOptions.setValue("GuiProjectDetails", "winHeight", winHeight)
pOptions.setValue("GuiProjectDetails", "widthCol0", widthCol0)
@@ -144,11 +143,10 @@ class GuiProjectDetails(NPagedDialog):
class GuiProjectDetailsMain(QWidget):
def __init__(self, mainGui, theProject):
def __init__(self, mainGui):
super().__init__(parent=mainGui)
self.theProject = theProject
self.mainGui = mainGui
self.mainGui = mainGui
fPx = CONFIG.theme.fontPixelSize
fPt = CONFIG.theme.fontPointSize
@@ -246,22 +244,23 @@ class GuiProjectDetailsMain(QWidget):
def updateValues(self):
"""Set all the values.
"""
pIndex = self.theProject.index
project = self.mainGui.project
pIndex = project.index
hCounts = pIndex.getNovelTitleCounts()
nwCount = pIndex.getNovelWordCount()
edTime = self.theProject.getCurrentEditTime()
edTime = project.getCurrentEditTime()
self.bookTitle.setText(self.theProject.data.title or self.theProject.data.name)
self.projName.setText(self.tr("Project: {0}").format(self.theProject.data.name))
self.bookAuthors.setText(self.tr("By {0}").format(self.theProject.data.author))
self.bookTitle.setText(project.data.title or project.data.name)
self.projName.setText(self.tr("Project: {0}").format(project.data.name))
self.bookAuthors.setText(self.tr("By {0}").format(project.data.author))
self.wordCountVal.setText(f"{nwCount:n}")
self.chapCountVal.setText(f"{hCounts[2]:n}")
self.sceneCountVal.setText(f"{hCounts[3]:n}")
self.revCountVal.setText(f"{self.theProject.data.saveCount:n}")
self.revCountVal.setText(f"{project.data.saveCount:n}")
self.editTimeVal.setText(formatTime(edTime))
self.projPathVal.setText(str(self.theProject.storage.storagePath))
self.projPathVal.setText(str(project.storage.storagePath))
return
@@ -276,11 +275,10 @@ class GuiProjectDetailsContents(QWidget):
C_PAGE = 3
C_PROG = 4
def __init__(self, mainGui, theProject):
def __init__(self, mainGui):
super().__init__(parent=mainGui)
self.theProject = theProject
self.mainGui = mainGui
self.mainGui = mainGui
# Internal
self._theToC = []
@@ -289,14 +287,14 @@ class GuiProjectDetailsContents(QWidget):
iPx = CONFIG.theme.baseIconSize
hPx = CONFIG.pxInt(12)
vPx = CONFIG.pxInt(4)
pOptions = self.theProject.options
pOptions = self.mainGui.project.options
# Header
# ======
self.tocLabel = QLabel("<b>%s</b>" % self.tr("Table of Contents"))
self.novelValue = NovelSelector(self, self.theProject, self.mainGui)
self.novelValue = NovelSelector(self, self.mainGui)
self.novelValue.setMinimumWidth(CONFIG.pxInt(200))
self.novelValue.novelSelectionChanged.connect(self._novelValueChanged)
@@ -445,7 +443,7 @@ class GuiProjectDetailsContents(QWidget):
"""Extract the information from the project index.
"""
logger.debug("Populating ToC from handle '%s'", rootHandle)
self._theToC = self.theProject.index.getTableOfContents(rootHandle, 2)
self._theToC = self.mainGui.project.index.getTableOfContents(rootHandle, 2)
self._theToC.append(("", 0, self.tr("END"), 0))
return
+29 -32
View File
@@ -60,15 +60,13 @@ class GuiProjectSettings(NPagedDialog):
logger.debug("Create: GuiProjectSettings")
self.setObjectName("GuiProjectSettings")
self.mainGui = mainGui
self.theProject = mainGui.theProject
self.theProject.countStatus()
self.mainGui = mainGui
self.mainGui.project.countStatus()
self.setWindowTitle(self.tr("Project Settings"))
wW = CONFIG.pxInt(570)
wH = CONFIG.pxInt(375)
pOptions = self.theProject.options
pOptions = self.mainGui.project.options
self.setMinimumWidth(wW)
self.setMinimumHeight(wH)
@@ -117,34 +115,35 @@ class GuiProjectSettings(NPagedDialog):
def _doSave(self):
"""Save settings and close dialog.
"""
project = self.mainGui.project
projName = self.tabMain.editName.text()
bookTitle = self.tabMain.editTitle.text()
bookAuthor = self.tabMain.editAuthor.text()
spellLang = self.tabMain.spellLang.currentData()
doBackup = not self.tabMain.doBackup.isChecked()
self.theProject.data.setName(projName)
self.theProject.data.setTitle(bookTitle)
self.theProject.data.setAuthor(bookAuthor)
self.theProject.data.setDoBackup(doBackup)
project.data.setName(projName)
project.data.setTitle(bookTitle)
project.data.setAuthor(bookAuthor)
project.data.setDoBackup(doBackup)
# Remember this as updating spell dictionary can be expensive
self._spellChanged = self.theProject.data.setSpellLang(spellLang)
self._spellChanged = project.data.setSpellLang(spellLang)
if self.tabStatus.colChanged:
newList, delList = self.tabStatus.getNewList()
self.theProject.setStatusColours(newList, delList)
project.setStatusColours(newList, delList)
if self.tabImport.colChanged:
newList, delList = self.tabImport.getNewList()
self.theProject.setImportColours(newList, delList)
project.setImportColours(newList, delList)
if self.tabStatus.colChanged or self.tabImport.colChanged:
self.mainGui.rebuildTrees()
if self.tabReplace.arChanged:
newList = self.tabReplace.getNewList()
self.theProject.data.setAutoReplace(newList)
project.data.setAutoReplace(newList)
self._saveGuiSettings()
self.accept()
@@ -184,7 +183,7 @@ class GuiProjectSettings(NPagedDialog):
statusColW = CONFIG.rpxInt(self.tabStatus.listBox.columnWidth(0))
importColW = CONFIG.rpxInt(self.tabImport.listBox.columnWidth(0))
pOptions = self.theProject.options
pOptions = self.mainGui.project.options
pOptions.setValue("GuiProjectSettings", "winWidth", winWidth)
pOptions.setValue("GuiProjectSettings", "winHeight", winHeight)
pOptions.setValue("GuiProjectSettings", "replaceColW", replaceColW)
@@ -201,8 +200,7 @@ class GuiProjectEditMain(QWidget):
def __init__(self, projGui):
super().__init__(parent=projGui)
self.mainGui = projGui.mainGui
self.theProject = projGui.theProject
self.mainGui = projGui.mainGui
# The Form
self.mainForm = NConfigLayout()
@@ -212,11 +210,12 @@ class GuiProjectEditMain(QWidget):
self.mainForm.addGroupLabel(self.tr("Project Settings"))
xW = CONFIG.pxInt(250)
pData = self.mainGui.project.data
self.editName = QLineEdit()
self.editName.setMaxLength(200)
self.editName.setMaximumWidth(xW)
self.editName.setText(self.theProject.data.name)
self.editName.setText(pData.name)
self.mainForm.addRow(
self.tr("Project name"),
self.editName,
@@ -226,7 +225,7 @@ class GuiProjectEditMain(QWidget):
self.editTitle = QLineEdit()
self.editTitle.setMaxLength(200)
self.editTitle.setMaximumWidth(xW)
self.editTitle.setText(self.theProject.data.title)
self.editTitle.setText(pData.title)
self.mainForm.addRow(
self.tr("Novel title"),
self.editTitle,
@@ -236,7 +235,7 @@ class GuiProjectEditMain(QWidget):
self.editAuthor = QLineEdit()
self.editAuthor.setMaxLength(200)
self.editAuthor.setMaximumWidth(xW)
self.editAuthor.setText(self.theProject.data.author)
self.editAuthor.setText(pData.author)
self.mainForm.addRow(
self.tr("Author(s)"),
self.editAuthor,
@@ -259,13 +258,13 @@ class GuiProjectEditMain(QWidget):
)
spellIdx = 0
if self.theProject.data.spellLang is not None:
spellIdx = self.spellLang.findData(self.theProject.data.spellLang)
if pData.spellLang is not None:
spellIdx = self.spellLang.findData(pData.spellLang)
if spellIdx != -1:
self.spellLang.setCurrentIndex(spellIdx)
self.doBackup = NSwitch(self)
self.doBackup.setChecked(not self.theProject.data.doBackup)
self.doBackup.setChecked(not pData.doBackup)
self.mainForm.addRow(
self.tr("No backup on close"),
self.doBackup,
@@ -289,20 +288,19 @@ class GuiProjectEditStatus(QWidget):
def __init__(self, projGui, isStatus):
super().__init__(parent=projGui)
self.mainGui = projGui.mainGui
self.theProject = projGui.theProject
self.mainGui = projGui.mainGui
if isStatus:
self.theStatus = self.theProject.data.itemStatus
self.theStatus = self.mainGui.project.data.itemStatus
pageLabel = self.tr("Novel File Status Levels")
colSetting = "statusColW"
else:
self.theStatus = self.theProject.data.itemImport
self.theStatus = self.mainGui.project.data.itemImport
pageLabel = self.tr("Note File Importance Levels")
colSetting = "importColW"
wCol0 = CONFIG.pxInt(
self.theProject.options.getInt("GuiProjectSettings", colSetting, 130)
self.mainGui.project.options.getInt("GuiProjectSettings", colSetting, 130)
)
self.colDeleted = []
@@ -576,12 +574,11 @@ class GuiProjectEditReplace(QWidget):
def __init__(self, projGui):
super().__init__(parent=projGui)
self.mainGui = projGui.mainGui
self.theProject = projGui.theProject
self.arChanged = False
self.mainGui = projGui.mainGui
self.arChanged = False
wCol0 = CONFIG.pxInt(
self.theProject.options.getInt("GuiProjectSettings", "replaceColW", 130)
self.mainGui.project.options.getInt("GuiProjectSettings", "replaceColW", 130)
)
pageLabel = self.tr("Text Replace List for Preview and Export")
@@ -597,7 +594,7 @@ class GuiProjectEditReplace(QWidget):
self.listBox.setColumnWidth(self.COL_KEY, wCol0)
self.listBox.setIndentation(0)
for aKey, aVal in self.theProject.data.autoReplace.items():
for aKey, aVal in self.mainGui.project.data.autoReplace.items():
newItem = QTreeWidgetItem(["<%s>" % aKey, aVal])
self.listBox.addTopLevelItem(newItem)
+6 -8
View File
@@ -50,16 +50,14 @@ class GuiWordList(QDialog):
logger.debug("Create: GuiWordList")
self.setObjectName("GuiWordList")
self.mainGui = mainGui
self.theProject = mainGui.theProject
self.setWindowTitle(self.tr("Project Word List"))
self.mainGui = mainGui
mS = CONFIG.pxInt(250)
wW = CONFIG.pxInt(320)
wH = CONFIG.pxInt(340)
pOptions = self.theProject.options
pOptions = self.mainGui.project.options
self.setMinimumWidth(mS)
self.setMinimumHeight(mS)
@@ -151,7 +149,7 @@ class GuiWordList(QDialog):
def _doSave(self):
"""Save the new word list and close."""
self._saveGuiSettings()
userDict = UserDictionary(self.theProject)
userDict = UserDictionary(self.mainGui.project)
for i in range(self.listBox.count()):
item = self.listBox.item(i)
if isinstance(item, QListWidgetItem):
@@ -174,7 +172,7 @@ class GuiWordList(QDialog):
def _loadWordList(self):
"""Load the project's word list, if it exists."""
userDict = UserDictionary(self.theProject)
userDict = UserDictionary(self.mainGui.project)
userDict.load()
self.listBox.clear()
for word in userDict:
@@ -187,7 +185,7 @@ class GuiWordList(QDialog):
winWidth = CONFIG.rpxInt(self.width())
winHeight = CONFIG.rpxInt(self.height())
pOptions = self.theProject.options
pOptions = self.mainGui.project.options
pOptions.setValue("GuiWordList", "winWidth", winWidth)
pOptions.setValue("GuiWordList", "winHeight", winHeight)