diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/UI/CodeDocumentationViewerTemplate.py --- a/src/eric7/UI/CodeDocumentationViewerTemplate.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/UI/CodeDocumentationViewerTemplate.py Wed Jul 13 14:55:47 2022 +0200 @@ -25,7 +25,7 @@ def _stylesheet(): """ Function to get the stylesheet matching the desktop environment. - + @return stylesheet @rtype str """ @@ -33,18 +33,20 @@ if not _stylesheetsCache[stylesheetType]: # load the stylesheet from file stylesheetFilePath = os.path.join( - os.path.dirname(__file__), "data", - "documentViewerStyle-{0}.css".format(stylesheetType)) + os.path.dirname(__file__), + "data", + "documentViewerStyle-{0}.css".format(stylesheetType), + ) with open(stylesheetFilePath, "r") as f: _stylesheetsCache[stylesheetType] = f.read() - + return _stylesheetsCache[stylesheetType] def prepareDocumentationViewerHtmlDocument(documentationInfo): """ Public function to prepare the HTML document. - + @param documentationInfo dictionary containing the various documentation parts @type dict @@ -64,16 +66,16 @@ </body> </html> """ - + headerTemplate = """ @TITLE@ @METADATA@ """ - + titleTemplate = """ <div class="title"><h1>@NAME@</h1></div> """ - + metadataTemplate = """ <div class="metadata"> @ARGSPEC@ @@ -81,77 +83,68 @@ @NOTE@ </div> """ - + argspecTemplate = QCoreApplication.translate( "CodeDocumentationViewer", '<p><b>Definition:</b> <span class="def">@NAME@@ARGSPEC@</span></p>', - "Just translate 'Definition:' and leave the rest intact.") - + "Just translate 'Definition:' and leave the rest intact.", + ) + typeTemplate = QCoreApplication.translate( "CodeDocumentationViewer", "<p><b>Type:</b> @TYPE@</p>", - "Just translate 'Type:' and leave the rest intact.") - + "Just translate 'Type:' and leave the rest intact.", + ) + noteTemplate = QCoreApplication.translate( "CodeDocumentationViewer", "<p><b>Note:</b> @NOTE@</p>", - "Just translate 'Note:' and leave the rest intact.") - + "Just translate 'Note:' and leave the rest intact.", + ) + docstringTemplate = """ <div class="docstring"> @DOCSTRING@ </div> """ - + name = documentationInfo["name"] if name: title = titleTemplate.replace("@NAME@", name) if "argspec" in documentationInfo and documentationInfo["argspec"]: argspec = Utilities.html_encode(documentationInfo["argspec"]) - for char in ['=', ',', '(', ')', '*', '**']: + for char in ["=", ",", "(", ")", "*", "**"]: argspec = argspec.replace( - char, - '<span class="argspec-highlight">{0}</span>'.format( - char)) - argspec = ( - argspecTemplate - .replace("@NAME@", name) - .replace("@ARGSPEC@", argspec) + char, '<span class="argspec-highlight">{0}</span>'.format(char) + ) + argspec = argspecTemplate.replace("@NAME@", name).replace( + "@ARGSPEC@", argspec ) else: - argspec = ( - argspecTemplate - .replace("@NAME@", name) - .replace("@ARGSPEC@", "") - ) - + argspec = argspecTemplate.replace("@NAME@", name).replace("@ARGSPEC@", "") + if "typ" in documentationInfo and documentationInfo["typ"]: - typeInfo = typeTemplate.replace("@TYPE@", - documentationInfo["typ"]) + typeInfo = typeTemplate.replace("@TYPE@", documentationInfo["typ"]) else: typeInfo = "" - + if "note" in documentationInfo and documentationInfo["note"]: - note = noteTemplate.replace("@NOTE@", - documentationInfo["note"]) + note = noteTemplate.replace("@NOTE@", documentationInfo["note"]) else: note = "" - + metaData = ( - metadataTemplate - .replace("@ARGSPEC@", argspec) + metadataTemplate.replace("@ARGSPEC@", argspec) .replace("@TYPE@", typeInfo) .replace("@NOTE@", note) ) - - header = ( - headerTemplate - .replace("@TITLE@", title) - .replace("@METADATA@", metaData) + + header = headerTemplate.replace("@TITLE@", title).replace( + "@METADATA@", metaData ) else: header = "" - + if "docstring" in documentationInfo and documentationInfo["docstring"]: docstring = ( documentationInfo["docstring"] @@ -161,13 +154,12 @@ ) docstring = docstringTemplate.replace("@DOCSTRING@", docstring) else: - docstring = ( - """<div class="hr"></div><div id="doc-warning">{0}</div>""" - .format(QCoreApplication.translate( - "CodeDocumentationViewer", - "No further documentation available")) + docstring = """<div class="hr"></div><div id="doc-warning">{0}</div>""".format( + QCoreApplication.translate( + "CodeDocumentationViewer", "No further documentation available" + ) ) - + return ( mainTemplate.format(_stylesheet()) .replace("@HEADER@", header) @@ -178,7 +170,7 @@ def prepareDocumentationViewerHtmlDocWarningDocument(text): """ Public function to prepare a HTML warning document. - + @param text warning text to be shown @type str @return prepared HTML document @@ -196,17 +188,14 @@ </body> </html> """ - - return ( - mainTemplate.format(_stylesheet()) - .replace("@TEXT@", text) - ) + + return mainTemplate.format(_stylesheet()).replace("@TEXT@", text) def prepareDocumentationViewerHtmlWarningDocument(text): """ Public function to prepare a HTML warning document. - + @param text warning text to be shown @type str @return prepared HTML document @@ -224,8 +213,5 @@ </body> </html> """ - - return ( - mainTemplate.format(_stylesheet()) - .replace("@TEXT@", text) - ) + + return mainTemplate.format(_stylesheet()).replace("@TEXT@", text)