From 3708b3486bb419832842bcf439b592852470530b Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 4 Aug 2020 21:23:25 +0200 Subject: [PATCH] Make sure the assistant executable also exists --- nw/config.py | 21 ++++++++++++++++++--- nw/gui/mainmenu.py | 25 +++++++++++++++---------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/nw/config.py b/nw/config.py index ec397aea..ac5e9fca 100644 --- a/nw/config.py +++ b/nw/config.py @@ -33,6 +33,7 @@ import nw from os import path, mkdir, unlink, rename from time import time +from distutils import spawn from PyQt5.Qt import PYQT_VERSION_STR from PyQt5.QtCore import QT_VERSION_STR, QStandardPaths, QSysInfo @@ -76,9 +77,11 @@ class Config: self.graphPath = None self.dictPath = None self.iconPath = None + self.helpPath = None - # Set default values + # Runtime Settings and Variables self.confChanged = False + self.hasHelp = False ## General self.guiTheme = "default" @@ -200,8 +203,9 @@ class Config: self.kernelVer = "Unknown" # Packages - self.hasEnchant = False - self.hasSymSpell = False + self.hasEnchant = False + self.hasSymSpell = False + self.hasAssistant = False # The Qt Assistant # Recent Cache self.recentProj = {} @@ -315,6 +319,10 @@ class Config: if self.spellLanguage is None: self.spellLanguage = "en" + # Check if local help files exist + self.helpPath = path.join(self.assetPath, "help", "novelWriter.qhc") + self.hasHelp = path.isfile(self.helpPath) + logger.debug("Config initialisation complete") return True @@ -893,6 +901,13 @@ class Config: self.hasEnchant = False logger.debug("Checking package pyenchant: Missing") + try: + self.hasAssistant = spawn.find_executable("assistant") + logger.debug("Checking executable assistant: Ok") + except: + self.hasAssistant = False + logger.debug("Checking executable assistant: Missing") + return # End Class Config diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index c21629b3..ed42c2ba 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -49,10 +49,10 @@ class GuiMainMenu(QMenuBar): self.theParent = theParent self.theProject = theParent.theProject + # Internals self.assistProc = None - self.helpPath = path.join(self.mainConf.assetPath, "help", "novelWriter.qhc") - self.hasHelp = path.isfile(self.helpPath) + # Build Menu self._buildProjectMenu() self._buildDocumentMenu() self._buildEditMenu() @@ -79,8 +79,10 @@ class GuiMainMenu(QMenuBar): def setAvailableRoot(self): for itemClass in nwItemClass: - if itemClass == nwItemClass.NO_CLASS: continue - if itemClass == nwItemClass.TRASH: continue + if itemClass == nwItemClass.NO_CLASS: + continue + if itemClass == nwItemClass.TRASH: + continue self.rootItems[itemClass].setEnabled( self.theProject.projTree.checkRootUnique(itemClass) ) @@ -166,12 +168,15 @@ class GuiMainMenu(QMenuBar): def _openAssistant(self): """Open the documentation in Qt Assistant. """ - self.assistProc = QProcess(self) - self.assistProc.start("assistant", [ - "-collectionFile", self.helpPath, "-enableRemoteControl" - ]) - if not self.assistProc.waitForStarted(20000): + if not self.mainConf.hasHelp: return False + + self.assistProc = QProcess(self) + self.assistProc.start("assistant", ["-collectionFile", self.mainConf.helpPath]) + + if not self.assistProc.waitForStarted(10000): + return False + return True def _openWebsite(self, theUrl): @@ -860,7 +865,7 @@ class GuiMainMenu(QMenuBar): # Document > Documentation self.aHelp = QAction("Documentation", self) - if self.hasHelp: + if self.mainConf.hasHelp and self.mainConf.hasAssistant: self.aHelp.setStatusTip("View local documentation with Qt Assistant") self.aHelp.triggered.connect(self._openAssistant) else: