Rename showGUI variable to blockGUI and added some comments in Config class

This commit is contained in:
Veronica K. B. Olsen
2020-09-22 21:37:00 +02:00
parent 7a9124ca58
commit 9a9cfe1ce5
12 changed files with 49 additions and 51 deletions
+1 -1
View File
@@ -195,7 +195,7 @@ def main(sysArgs=None):
testMode = True testMode = True
# Set Config Options # Set Config Options
CONFIG.showGUI = not testMode CONFIG.blockGUI = not testMode
CONFIG.debugInfo = debugLevel < logging.INFO CONFIG.debugInfo = debugLevel < logging.INFO
CONFIG.cmdOpen = cmdOpen CONFIG.cmdOpen = cmdOpen
+19 -21
View File
@@ -57,32 +57,31 @@ class Config:
self.cmdOpen = None self.cmdOpen = None
# Debug Settings # Debug Settings
self.showGUI = True self.blockGUI = True # Allow blocking the GUI (disabled for testing)
self.debugInfo = False self.debugInfo = False # True if log level is DEBUG or VERBOSE
# Config Error Handling # Config Error Handling
self.hasError = False self.hasError = False # True if the config class encountered an error
self.errData = [] self.errData = [] # List of error messages
# Set Paths # Set Paths
self.confPath = None self.confPath = None # Folder where the config is saved
self.confFile = None self.confFile = None # The config file name
self.dataPath = None self.dataPath = None # Folder where app data is stored
self.homePath = None self.homePath = None # The user's home folder
self.lastPath = None self.lastPath = None # The last user-selected folder (browse dialogs)
self.appPath = None self.appPath = None # The full path to the novelwriter package folder
self.appRoot = None self.appRoot = None # The full path to the novelwriter root folder
self.appIcon = None self.appIcon = None # The full path to the novelwriter icon file
self.assetPath = None self.assetPath = None # The full path to the nw/assets folder
self.themeRoot = None self.themeRoot = None # The full path to the nw/assets/themes folder
self.graphPath = None self.dictPath = None # The full path to the nw/assets/dict folder
self.dictPath = None self.iconPath = None # The full path to the nw/assets/icons folder
self.iconPath = None self.helpPath = None # The full path to the novelwriter .qhc help file
self.helpPath = None
# Runtime Settings and Variables # Runtime Settings and Variables
self.confChanged = False self.confChanged = False # True whenever the config has chenged, false after save
self.hasHelp = False self.hasHelp = False # True if the Qt help files are present in the assets folder
## General ## General
self.guiTheme = "default" self.guiTheme = "default"
@@ -264,7 +263,6 @@ class Config:
self.appRoot = path.join(self.appPath, path.pardir) self.appRoot = path.join(self.appPath, path.pardir)
self.assetPath = path.join(self.appPath, "assets") self.assetPath = path.join(self.appPath, "assets")
self.themeRoot = path.join(self.assetPath, "themes") self.themeRoot = path.join(self.assetPath, "themes")
self.graphPath = path.join(self.assetPath, "graphics")
self.dictPath = path.join(self.assetPath, "dict") self.dictPath = path.join(self.assetPath, "dict")
self.iconPath = path.join(self.assetPath, "icons") self.iconPath = path.join(self.assetPath, "icons")
self.appIcon = path.join(self.iconPath, "novelwriter.svg") self.appIcon = path.join(self.iconPath, "novelwriter.svg")
+2 -2
View File
@@ -513,7 +513,7 @@ class NWProject():
# Check novelWriter Version # Check novelWriter Version
# ========================= # =========================
if int(hexVersion, 16) > int(nw.__hexversion__, 16) and self.mainConf.showGUI: if int(hexVersion, 16) > int(nw.__hexversion__, 16) and self.mainConf.blockGUI:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question(self.theParent, "Version Conflict", ( msgRes = msgBox.question(self.theParent, "Version Conflict", (
"This project was saved by a newer version of novelWriter, version %s. " "This project was saved by a newer version of novelWriter, version %s. "
@@ -926,7 +926,7 @@ class NWProject():
return False return False
if path.isdir(projPath): if path.isdir(projPath):
if self.mainConf.showGUI and listdir(self.projPath): if self.mainConf.blockGUI and listdir(self.projPath):
self.theParent.makeAlert(( self.theParent.makeAlert((
"New project folder is not empty. " "New project folder is not empty. "
"Each project requires a dedicated project folder." "Each project requires a dedicated project folder."
+1 -1
View File
@@ -160,7 +160,7 @@ def exceptionHandler(exType, exValue, exTrace, testMode=False):
errMsg = NWErrorMessage(nwGUI) errMsg = NWErrorMessage(nwGUI)
errMsg.setMessage(exType, exValue, exTrace) errMsg.setMessage(exType, exValue, exTrace)
if nw.CONFIG.showGUI: if nw.CONFIG.blockGUI:
errMsg.exec_() errMsg.exec_()
try: try:
+2 -2
View File
@@ -633,7 +633,7 @@ class GuiBuildNovel(QDialog):
if not path.isdir(saveDir): if not path.isdir(saveDir):
saveDir = self.mainConf.homePath saveDir = self.mainConf.homePath
if self.mainConf.showGUI: if self.mainConf.blockGUI:
dlgOpt = QFileDialog.Options() dlgOpt = QFileDialog.Options()
dlgOpt |= QFileDialog.DontUseNativeDialog dlgOpt |= QFileDialog.DontUseNativeDialog
saveTo = QFileDialog.getSaveFileName( saveTo = QFileDialog.getSaveFileName(
@@ -745,7 +745,7 @@ class GuiBuildNovel(QDialog):
errMsg = "Unknown format" errMsg = "Unknown format"
# Report to user # Report to user
if self.mainConf.showGUI: if self.mainConf.blockGUI:
if wSuccess: if wSuccess:
self.theParent.makeAlert( self.theParent.makeAlert(
"%s file successfully written to:<br> %s" % ( "%s file successfully written to:<br> %s" % (
+1 -1
View File
@@ -160,7 +160,7 @@ class GuiDocSplit(QDialog):
), nwAlert.ERROR) ), nwAlert.ERROR)
return return
if self.mainConf.showGUI: if self.mainConf.blockGUI:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Split Document", ( self, "Split Document", (
+1 -1
View File
@@ -103,7 +103,7 @@ class GuiPreferences(PagedDialog):
validEntries &= retA validEntries &= retA
needsRestart |= retB needsRestart |= retB
if needsRestart and self.mainConf.showGUI: if needsRestart and self.mainConf.blockGUI:
msgBox = QMessageBox() msgBox = QMessageBox()
msgBox.information( msgBox.information(
self, "Preferences", self, "Preferences",
+2 -2
View File
@@ -177,7 +177,7 @@ class GuiProjectLoad(QDialog):
"""Browse for a folder path. """Browse for a folder path.
""" """
logger.verbose("GuiProjectLoad browse button clicked") logger.verbose("GuiProjectLoad browse button clicked")
if self.mainConf.showGUI: if self.mainConf.blockGUI:
dlgOpt = QFileDialog.Options() dlgOpt = QFileDialog.Options()
dlgOpt |= QFileDialog.DontUseNativeDialog dlgOpt |= QFileDialog.DontUseNativeDialog
projFile, _ = QFileDialog.getOpenFileName( projFile, _ = QFileDialog.getOpenFileName(
@@ -218,7 +218,7 @@ class GuiProjectLoad(QDialog):
selList = self.listBox.selectedItems() selList = self.listBox.selectedItems()
if selList: if selList:
doRemove = False doRemove = False
if self.mainConf.showGUI: if self.mainConf.blockGUI:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Remove Entry", self, "Remove Entry",
+2 -2
View File
@@ -410,7 +410,7 @@ class GuiProjectTree(QTreeWidget):
# If the file is in the trash folder already, as the # If the file is in the trash folder already, as the
# user if they want to permanently delete the file. # user if they want to permanently delete the file.
doPermanent = False doPermanent = False
if self.mainConf.showGUI and not alreadyAsked: if self.mainConf.blockGUI and not alreadyAsked:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Delete File", "Permanently delete file '%s'?" % nwItemS.itemName self, "Delete File", "Permanently delete file '%s'?" % nwItemS.itemName
@@ -439,7 +439,7 @@ class GuiProjectTree(QTreeWidget):
# The file is not already in the trash folder, so we # The file is not already in the trash folder, so we
# move it there. # move it there.
doTrash = False doTrash = False
if self.mainConf.showGUI and askForTrash: if self.mainConf.blockGUI and askForTrash:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Delete File", "Move file '%s' to Trash?" % nwItemS.itemName self, "Delete File", "Move file '%s' to Trash?" % nwItemS.itemName
+2 -2
View File
@@ -325,7 +325,7 @@ class GuiWritingStats(QDialog):
if not path.isdir(saveDir): if not path.isdir(saveDir):
saveDir = self.mainConf.homePath saveDir = self.mainConf.homePath
if self.mainConf.showGUI: if self.mainConf.blockGUI:
dlgOpt = QFileDialog.Options() dlgOpt = QFileDialog.Options()
dlgOpt |= QFileDialog.DontUseNativeDialog dlgOpt |= QFileDialog.DontUseNativeDialog
saveTo = QFileDialog.getSaveFileName( saveTo = QFileDialog.getSaveFileName(
@@ -379,7 +379,7 @@ class GuiWritingStats(QDialog):
errMsg = str(e) errMsg = str(e)
# Report to user # Report to user
if self.mainConf.showGUI: if self.mainConf.blockGUI:
if wSuccess: if wSuccess:
self.theParent.makeAlert( self.theParent.makeAlert(
"%s file successfully written to:<br> %s" % ( "%s file successfully written to:<br> %s" % (
+15 -15
View File
@@ -195,7 +195,7 @@ class GuiMain(QMainWindow):
self.setStatus = self.statusBar.setStatus self.setStatus = self.statusBar.setStatus
self.setProjectStatus = self.statusBar.setProjectStatus self.setProjectStatus = self.statusBar.setProjectStatus
if self.mainConf.showGUI: if self.mainConf.blockGUI:
self.show() self.show()
# Check that config loaded fine # Check that config loaded fine
@@ -250,7 +250,7 @@ class GuiMain(QMainWindow):
projects from a cache of recently opened projects, or provide a projects from a cache of recently opened projects, or provide a
browse button for projects not yet cached. browse button for projects not yet cached.
""" """
if not self.mainConf.showGUI: if not self.mainConf.blockGUI:
return False return False
dlgProj = GuiProjectLoad(self) dlgProj = GuiProjectLoad(self)
@@ -275,7 +275,7 @@ class GuiMain(QMainWindow):
) )
return False return False
if projData is None and self.mainConf.showGUI: if projData is None and self.mainConf.blockGUI:
projData = self.newProjectDialog() projData = self.newProjectDialog()
if projData is None: if projData is None:
@@ -316,7 +316,7 @@ class GuiMain(QMainWindow):
# There is no project loaded, everything OK # There is no project loaded, everything OK
return True return True
if self.mainConf.showGUI and not isYes: if self.mainConf.blockGUI and not isYes:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Close Project", "Save changes and close current project?" self, "Close Project", "Save changes and close current project?"
@@ -332,7 +332,7 @@ class GuiMain(QMainWindow):
doBackup = False doBackup = False
if self.theProject.doBackup and self.mainConf.backupOnClose: if self.theProject.doBackup and self.mainConf.backupOnClose:
doBackup = True doBackup = True
if self.mainConf.showGUI and self.mainConf.askBeforeBackup: if self.mainConf.blockGUI and self.mainConf.askBeforeBackup:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Backup Project", "Backup current project?" self, "Backup Project", "Backup current project?"
@@ -379,7 +379,7 @@ class GuiMain(QMainWindow):
# reason handled by the project class. # reason handled by the project class.
return False return False
if self.mainConf.showGUI: if self.mainConf.blockGUI:
try: try:
lockDetails = ( lockDetails = (
"<br><br>The project was locked by the computer " "<br><br>The project was locked by the computer "
@@ -611,7 +611,7 @@ class GuiMain(QMainWindow):
return False return False
if not self.docEditor.isEmpty(): if not self.docEditor.isEmpty():
if self.mainConf.showGUI: if self.mainConf.blockGUI:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question(self, "Import Document", ( msgRes = msgBox.question(self, "Import Document", (
"Importing the file will overwrite the current content of the document. " "Importing the file will overwrite the current content of the document. "
@@ -629,7 +629,7 @@ class GuiMain(QMainWindow):
def mergeDocuments(self): def mergeDocuments(self):
"""Merge multiple documents to one single new document. """Merge multiple documents to one single new document.
""" """
if self.mainConf.showGUI: if self.mainConf.blockGUI:
dlgMerge = GuiDocMerge(self, self.theProject) dlgMerge = GuiDocMerge(self, self.theProject)
dlgMerge.exec_() dlgMerge.exec_()
return True return True
@@ -637,7 +637,7 @@ class GuiMain(QMainWindow):
def splitDocument(self): def splitDocument(self):
"""Split a single document into multiple documents. """Split a single document into multiple documents.
""" """
if self.mainConf.showGUI: if self.mainConf.blockGUI:
dlgSplit = GuiDocSplit(self, self.theProject) dlgSplit = GuiDocSplit(self, self.theProject)
dlgSplit.exec_() dlgSplit.exec_()
return True return True
@@ -684,7 +684,7 @@ class GuiMain(QMainWindow):
return return
logger.verbose("Requesting change to item %s" % tHandle) logger.verbose("Requesting change to item %s" % tHandle)
if self.mainConf.showGUI: if self.mainConf.blockGUI:
dlgProj = GuiItemEditor(self, self.theProject, tHandle) dlgProj = GuiItemEditor(self, self.theProject, tHandle)
if dlgProj.exec_(): if dlgProj.exec_():
self.treeView.setTreeItemValues(tHandle) self.treeView.setTreeItemValues(tHandle)
@@ -745,7 +745,7 @@ class GuiMain(QMainWindow):
qApp.restoreOverrideCursor() qApp.restoreOverrideCursor()
if self.mainConf.showGUI and not beQuiet: if self.mainConf.blockGUI and not beQuiet:
self.makeAlert("The project index has been successfully rebuilt.", nwAlert.INFO) self.makeAlert("The project index has been successfully rebuilt.", nwAlert.INFO)
return True return True
@@ -830,7 +830,7 @@ class GuiMain(QMainWindow):
def showAboutNWDialog(self): def showAboutNWDialog(self):
"""Show the about dialog for novelWriter. """Show the about dialog for novelWriter.
""" """
if self.mainConf.showGUI: if self.mainConf.blockGUI:
dlgAbout = GuiAbout(self) dlgAbout = GuiAbout(self)
dlgAbout.exec_() dlgAbout.exec_()
return True return True
@@ -838,7 +838,7 @@ class GuiMain(QMainWindow):
def showAboutQtDialog(self): def showAboutQtDialog(self):
"""Show the about dialog for Qt. """Show the about dialog for Qt.
""" """
if self.mainConf.showGUI: if self.mainConf.blockGUI:
msgBox = QMessageBox() msgBox = QMessageBox()
msgBox.aboutQt(self, "About Qt") msgBox.aboutQt(self, "About Qt")
return True return True
@@ -870,7 +870,7 @@ class GuiMain(QMainWindow):
logger.error(msgLine) logger.error(msgLine)
# Popup # Popup
if self.mainConf.showGUI: if self.mainConf.blockGUI:
msgBox = QMessageBox() msgBox = QMessageBox()
if theLevel == nwAlert.INFO: if theLevel == nwAlert.INFO:
msgBox.information(self, "Information", popMsg) msgBox.information(self, "Information", popMsg)
@@ -901,7 +901,7 @@ class GuiMain(QMainWindow):
def closeMain(self): def closeMain(self):
"""Save everything, and close novelWriter. """Save everything, and close novelWriter.
""" """
if self.mainConf.showGUI and self.hasProject: if self.mainConf.blockGUI and self.hasProject:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(
self, "Exit", "Do you want to save changes and exit?" self, "Exit", "Do you want to save changes and exit?"
+1 -1
View File
@@ -779,7 +779,7 @@ def testPreferences(qtbot, nwMinimal, nwTemp, nwRef, tmpConf):
nwPrefs.show() nwPrefs.show()
# Override Config # Override Config
tmpConf.showGUI = False tmpConf.blockGUI = False
tmpConf.confPath = nwMinimal tmpConf.confPath = nwMinimal
nwGUI.mainConf = tmpConf nwGUI.mainConf = tmpConf
nwPrefs.mainConf = tmpConf nwPrefs.mainConf = tmpConf