Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give main GUI objects better names #1081

Merged
merged 4 commits into from Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
78 changes: 39 additions & 39 deletions novelwriter/core/project.py
Expand Up @@ -56,11 +56,11 @@ class NWProject():

FILE_VERSION = "1.4" # The current project file format version

def __init__(self, theParent):
def __init__(self, mainGui):

# Internal
self.theParent = theParent
self.mainConf = novelwriter.CONFIG
self.mainConf = novelwriter.CONFIG
self.mainGui = mainGui

# Core Elements
self._optState = OptionState(self) # Project-specific GUI options
Expand Down Expand Up @@ -414,7 +414,7 @@ def openProject(self, fileName, overrideLock=False):
if not os.path.isfile(fileName):
fileName = os.path.join(fileName, nwFiles.PROJ_FILE)
if not os.path.isfile(fileName):
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"File not found: {0}"
).format(fileName), nwAlert.ERROR)
return False
Expand Down Expand Up @@ -465,20 +465,20 @@ def openProject(self, fileName, overrideLock=False):
try:
nwXML = etree.parse(fileName)
except Exception as exc:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Failed to parse project xml."
), nwAlert.ERROR, exception=exc)

# Trying to open backup file instead
backFile = fileName[:-3]+"bak"
if os.path.isfile(backFile):
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Attempting to open backup project file instead."
), nwAlert.INFO)
try:
nwXML = etree.parse(backFile)
except Exception as exc:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Failed to parse project xml."
), nwAlert.ERROR, exception=exc)
self.clearProject()
Expand All @@ -501,7 +501,7 @@ def openProject(self, fileName, overrideLock=False):
# ===============

if not nwxRoot == "novelWriterXML":
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Project file does not appear to be a novelWriterXML file."
), nwAlert.ERROR)
self.clearProject()
Expand All @@ -527,7 +527,7 @@ def openProject(self, fileName, overrideLock=False):
# stored and handled. Introduced in version 1.7.

if fileVersion not in ("1.0", "1.1", "1.2", "1.3", "1.4"):
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Unknown or unsupported novelWriter project file format. "
"The project cannot be opened by this version of novelWriter. "
"The file was saved with novelWriter version {0}."
Expand All @@ -536,7 +536,7 @@ def openProject(self, fileName, overrideLock=False):
return False

if fileVersion != self.FILE_VERSION:
msgYes = self.theParent.askQuestion(
msgYes = self.mainGui.askQuestion(
self.tr("File Version"),
self.tr(
"The file format of your project is about to be updated. "
Expand All @@ -552,7 +552,7 @@ def openProject(self, fileName, overrideLock=False):
# =========================

if hexToInt(hexVersion) > hexToInt(novelwriter.__hexversion__):
msgYes = self.theParent.askQuestion(
msgYes = self.mainGui.askQuestion(
self.tr("Version Conflict"),
self.tr(
"This project was saved by a newer version of "
Expand Down Expand Up @@ -646,7 +646,7 @@ def openProject(self, fileName, overrideLock=False):
for projItem in legacyList:
errList = self._legacyDataFolder(projItem, errList)
if errList:
self.theParent.makeAlert(errList, nwAlert.ERROR)
self.mainGui.makeAlert(errList, nwAlert.ERROR)

# Clean up no longer used files
self._deprecatedFiles()
Expand All @@ -672,7 +672,7 @@ def openProject(self, fileName, overrideLock=False):

self._writeLockFile()
self.setProjectChanged(False)
self.theParent.setStatus(self.tr("Opened Project: {0}").format(self.projName))
self.mainGui.setStatus(self.tr("Opened Project: {0}").format(self.projName))

return True

Expand All @@ -683,7 +683,7 @@ def saveProject(self, autoSave=False):
file.
"""
if self.projPath is None:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Project path not set, cannot save project."
), nwAlert.ERROR)
return False
Expand Down Expand Up @@ -763,7 +763,7 @@ def saveProject(self, autoSave=False):
xml_declaration=True
))
except Exception as exc:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Failed to save project."
), nwAlert.ERROR, exception=exc)
return False
Expand All @@ -775,7 +775,7 @@ def saveProject(self, autoSave=False):
os.replace(saveFile, backFile)
os.replace(tempFile, saveFile)
except OSError as exc:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Failed to save project."
), nwAlert.ERROR, exception=exc)
return False
Expand All @@ -788,7 +788,7 @@ def saveProject(self, autoSave=False):
self.mainConf.saveRecentCache()

self._writeLockFile()
self.theParent.setStatus(self.tr("Saved Project: {0}").format(self.projName))
self.mainGui.setStatus(self.tr("Saved Project: {0}").format(self.projName))
self.setProjectChanged(False)

return True
Expand Down Expand Up @@ -836,22 +836,22 @@ def ensureFolderStructure(self):
def zipIt(self, doNotify):
"""Create a zip file of the entire project.
"""
if not self.theParent.hasProject:
if not self.mainGui.hasProject:
logger.error("No project open")
return False

logger.info("Backing up project")
self.theParent.setStatus(self.tr("Backing up project ..."))
self.mainGui.setStatus(self.tr("Backing up project ..."))

if not (self.mainConf.backupPath and os.path.isdir(self.mainConf.backupPath)):
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Cannot backup project because no valid backup path is set. "
"Please set a valid backup location in Preferences."
), nwAlert.ERROR)
return False

if not self.projName:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Cannot backup project because no project name is set. "
"Please set a Working Title in Project Settings."
), nwAlert.ERROR)
Expand All @@ -864,13 +864,13 @@ def zipIt(self, doNotify):
os.mkdir(baseDir)
logger.debug("Created folder: %s", baseDir)
except Exception as exc:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Could not create backup folder."
), nwAlert.ERROR, exception=exc)
return False

if baseDir and baseDir.startswith(self.projPath):
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Cannot backup project because the backup path is within the "
"project folder to be backed up. Please choose a different "
"backup path in Preferences."
Expand All @@ -886,17 +886,17 @@ def zipIt(self, doNotify):
self._writeLockFile()
logger.info("Backup written to: %s", archName)
if doNotify:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Backup archive file written to: {0}"
).format(f"{os.path.join(cleanName, archName)}.zip"), nwAlert.INFO)

except Exception as exc:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Could not write backup archive."
), nwAlert.ERROR, exception=exc)
return False

self.theParent.setStatus(self.tr(
self.mainGui.setStatus(self.tr(
"Project backed up to '{0}'"
).format(f"{baseName}.zip"))

Expand Down Expand Up @@ -924,7 +924,7 @@ def extractSampleProject(self, projData):
shutil.unpack_archive(pkgSample, projPath)
isSuccess = True
except Exception as exc:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Failed to create a new example project."
), nwAlert.ERROR, exception=exc)

Expand All @@ -946,21 +946,21 @@ def extractSampleProject(self, projData):
isSuccess = True

except Exception as exc:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Failed to create a new example project."
), nwAlert.ERROR, exception=exc)

else:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Failed to create a new example project. "
"Could not find the necessary files. "
"They seem to be missing from this installation."
), nwAlert.ERROR)

if isSuccess:
self.clearProject()
self.theParent.openProject(projPath)
self.theParent.rebuildIndex()
self.mainGui.openProject(projPath)
self.mainGui.rebuildIndex()

return isSuccess

Expand All @@ -985,14 +985,14 @@ def setProjectPath(self, projPath, newProject=False):
os.mkdir(projPath)
logger.debug("Created folder: %s", projPath)
except Exception as exc:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Could not create new project folder."
), nwAlert.ERROR, exception=exc)
return False

if os.path.isdir(projPath):
if os.listdir(self.projPath):
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"New project folder is not empty. "
"Each project requires a dedicated project folder."
), nwAlert.ERROR)
Expand Down Expand Up @@ -1042,14 +1042,14 @@ def setProjBackup(self, doBackup):
self.doBackup = doBackup
if doBackup:
if not os.path.isdir(self.mainConf.backupPath):
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"You must set a valid backup path in Preferences to use "
"the automatic project backup feature."
), nwAlert.WARN)
return False

if self.projName == "":
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"You must set a valid project name in Project Settings to "
"use the automatic project backup feature."
), nwAlert.WARN)
Expand Down Expand Up @@ -1154,7 +1154,7 @@ def setProjectChanged(self, bValue):
information to the GUI statusbar.
"""
self.projChanged = bValue
self.theParent.statusBar.doUpdateProjectStatus(bValue)
self.mainGui.statusBar.doUpdateProjectStatus(bValue)
if bValue:
# If we've changed the project at all, this should be True
self.projAltered = True
Expand Down Expand Up @@ -1384,7 +1384,7 @@ def _checkFolder(self, thePath):
os.mkdir(thePath)
logger.debug("Created folder: %s", thePath)
except Exception as exc:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Could not create folder."
), nwAlert.ERROR, exception=exc)
return False
Expand Down Expand Up @@ -1447,7 +1447,7 @@ def _scanProjectFolder(self):

# Report status
if len(orphanFiles) > 0:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"Found {0} orphaned file(s) in project folder."
).format(len(orphanFiles)), nwAlert.WARN)
else:
Expand Down Expand Up @@ -1504,7 +1504,7 @@ def _scanProjectFolder(self):
self._projTree.updateItemData(orphItem.itemHandle)

if noWhere:
self.theParent.makeAlert(self.tr(
self.mainGui.makeAlert(self.tr(
"One or more orphaned files could not be added back into the project. "
"Make sure at least a Novel root folder exists."
), nwAlert.WARN)
Expand Down
1 change: 0 additions & 1 deletion novelwriter/core/tokenizer.py
Expand Up @@ -82,7 +82,6 @@ class Tokenizer(ABC):
def __init__(self, theProject):

self.theProject = theProject
self.theParent = theProject.theParent
self.mainConf = novelwriter.CONFIG

# Data Variables
Expand Down