Documentation and ODT exporter updates (#859)

* Clean up a few things in the ODT exporter
* Remove local HTML docs and instead add PDF docs
* Update documentation
This commit is contained in:
Veronica Berglyd Olsen
2021-08-20 17:16:14 +02:00
committed by GitHub
parent eee0f5e4c9
commit 95c79e1c23
13 changed files with 255 additions and 138 deletions
+11
View File
@@ -71,6 +71,7 @@ class Config:
self.themeRoot = None # The full path to the nw/assets/themes folder
self.dictPath = None # The full path to the nw/assets/dict folder
self.iconPath = None # The full path to the nw/assets/icons folder
self.pdfDocs = None # The location of the PDF manual, if it exists
# Runtime Settings and Variables
self.confChanged = False # True whenever the config has chenged, false after save
@@ -356,6 +357,16 @@ class Config:
if self.spellLanguage is None:
self.spellLanguage = "en"
# Look for a PDF version of the manual
lookIn = [
os.path.join(self.assetPath, "help", "manual.pdf"),
os.path.join(self.appRoot, "UserManual.pdf"),
]
for pdfDocs in lookIn:
if os.path.isfile(pdfDocs):
self.pdfDocs = pdfDocs
break
logger.debug("Config initialisation complete")
return True
+22 -14
View File
@@ -107,7 +107,7 @@ class ToOdt(Tokenizer):
self.headerText = ""
# Internal
self._fontFamily = "'Liberation Sans'"
self._fontFamily = "'Liberation Serif'"
self._fontPitch = "variable"
self._fSizeTitle = "30pt"
self._fSizeHead1 = "24pt"
@@ -239,6 +239,9 @@ class ToOdt(Tokenizer):
self._blockIndent = self._emToCm(self.blockIndent)
self._textAlign = "justify" if self.doJustify else "left"
# Clear Errors
self._errData = []
# Document Header
# ===============
@@ -546,8 +549,8 @@ class ToOdt(Tokenizer):
rFmt += "_B%s b_ " % (" "*len(tText))
if len(theBits) > 1:
if theBits[0] == nwKeyWords.TAG_KEY:
rTxt += "%s" % theBits[1]
rFmt += "%s" % (" "*len(theBits[1]))
rTxt += theBits[1]
rFmt += " "*len(theBits[1])
else:
tTags = ", ".join(theBits[1:])
rTxt += tTags
@@ -585,12 +588,15 @@ class ToOdt(Tokenizer):
tTemp = ""
xFmt = 0x00
pFmt = 0x00
pErr = 0
parProc = XMLParagraph(xElem)
for i, c in enumerate(theText):
if theFmt[i] == "_":
if theFmt[i] == " ":
tTemp += c
elif theFmt[i] == "_":
continue
elif theFmt[i] == "B":
xFmt |= X_BLD
@@ -604,9 +610,8 @@ class ToOdt(Tokenizer):
xFmt |= X_DEL
elif theFmt[i] == "s":
xFmt &= M_DEL
if theFmt[i] == " ":
tTemp += c
else:
pErr += 1
if xFmt != pFmt:
if pFmt == 0x00:
@@ -624,6 +629,9 @@ class ToOdt(Tokenizer):
else:
parProc.appendSpan(tTemp, self._textStyle(pFmt))
if pErr > 0:
self._errData.append("Unknown format tag encountered")
nErr, errMsg = parProc.checkError()
if nErr > 0: # pragma: no cover
# This one should only capture bugs
@@ -652,23 +660,23 @@ class ToOdt(Tokenizer):
return newName
def _textStyle(self, styleCode):
def _textStyle(self, tFmt):
"""Return a text style for a given style code.
"""
if styleCode in self._autoText:
return self._autoText[styleCode][0]
if tFmt in self._autoText:
return self._autoText[tFmt][0]
newName = "T%d" % (len(self._autoText) + 1)
newStyle = ODTTextStyle()
if styleCode & X_BLD:
if tFmt & X_BLD:
newStyle.setFontWeight("bold")
if styleCode & X_ITA:
if tFmt & X_ITA:
newStyle.setFontStyle("italic")
if styleCode & X_DEL:
if tFmt & X_DEL:
newStyle.setStrikeStyle("solid")
newStyle.setStrikeType("single")
self._autoText[styleCode] = (newName, newStyle)
self._autoText[tFmt] = (newName, newStyle)
return newName
+17 -29
View File
@@ -23,11 +23,9 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import os
import nw
import logging
from http.client import HTTPSConnection
from urllib.parse import urljoin
from urllib.request import pathname2url
@@ -137,31 +135,13 @@ class GuiMainMenu(QMenuBar):
QDesktopServices.openUrl(QUrl(theUrl))
return True
def _openDocumentation(self):
"""Open the documentation, and select whether it should be the
stable or latest version. If no internet connection, open
local.
def _openUserManualFile(self):
"""Open the documentation in PDF format.
"""
if nw.__hexversion__[-2] == "f":
docsPath = "/en/stable/"
else:
docsPath = "/en/latest/"
try:
conn = HTTPSConnection(nw.__docurl__.replace("https://", ""))
conn.request("HEAD", docsPath)
resp = conn.getresponse()
hasAccess = resp.code == 200
except Exception:
hasAccess = False
docsFile = os.path.join(self.mainConf.assetPath, "help", "html", "index.html")
if hasAccess or not os.path.isfile(docsFile):
self._openWebsite(nw.__docurl__ + docsPath)
else:
self._openWebsite(urljoin("file:", pathname2url(docsFile)))
return
if self.mainConf.pdfDocs is None:
return False
QDesktopServices.openUrl(QUrl(urljoin("file:", pathname2url(self.mainConf.pdfDocs))))
return True
##
# Menu Builders
@@ -1106,13 +1086,21 @@ class GuiMainMenu(QMenuBar):
# Help > Separator
self.helpMenu.addSeparator()
# Help > Documentation
self.aHelpDocs = QAction(self.tr("Documentation"), self)
# Help > User Manual (Online)
self.aHelpDocs = QAction(self.tr("User Manual (Online)"), self)
self.aHelpDocs.setStatusTip(self.tr("Open documentation in browser"))
self.aHelpDocs.triggered.connect(self._openDocumentation)
self.aHelpDocs.setShortcut("F1")
self.aHelpDocs.triggered.connect(lambda: self._openWebsite(nw.__docurl__))
self.helpMenu.addAction(self.aHelpDocs)
# Help > User Manual (PDF)
if self.mainConf.pdfDocs is not None:
self.aPdfDocs = QAction(self.tr("User Manual (PDF)"), self)
self.aPdfDocs.setStatusTip(self.tr("Open PDF documentation"))
self.aPdfDocs.setShortcut("Shift+F1")
self.aPdfDocs.triggered.connect(self._openUserManualFile)
self.helpMenu.addAction(self.aPdfDocs)
# Help > Separator
self.helpMenu.addSeparator()
+2
View File
@@ -1373,6 +1373,8 @@ class GuiMain(QMainWindow):
# Help
self.addAction(self.mainMenu.aHelpDocs)
if self.mainConf.pdfDocs is not None:
self.addAction(self.mainMenu.aPdfDocs)
return True