--- a/eric6/UI/CodeDocumentationViewerTemplate.py Thu Sep 24 19:51:19 2020 +0200 +++ b/eric6/UI/CodeDocumentationViewerTemplate.py Sat Sep 26 10:58:18 2020 +0200 @@ -7,6 +7,7 @@ Module implementing functions to prepare an HTML documentation view. """ +import os from PyQt5.QtCore import QCoreApplication @@ -15,7 +16,31 @@ import Utilities -# TODO: convert style sheet files to Python source file and embed style in mainTemplate. +_stylesheetsCache = { + "dark": "", + "light": "", +} + + +def _stylesheet(): + """ + Function to get the stylesheet matching the desktop environment. + + @return stylesheet + @rtype str + """ + stylesheetType = "dark" if e5App().usesDarkPalette() else "light" + if not _stylesheetsCache[stylesheetType]: + # load the stylesheet from file + stylesheetFilePath = os.path.join( + 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. @@ -31,8 +56,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> - <link rel="stylesheet" href="qrc:documentViewerStyle-{0}.css" - type="text/css" /> + <style>{0}</style> </head> <body> @HEADER@ @@ -145,7 +169,7 @@ ) return ( - mainTemplate.format("dark" if e5App().usesDarkPalette() else "light") + mainTemplate.format(_stylesheet()) .replace("@HEADER@", header) .replace("@DOCSTRING@", docstring) ) @@ -165,8 +189,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> - <link rel="stylesheet" href="qrc:documentViewerStyle-{0}.css" - type="text/css" /> + <style>{0}</style> </head> <body> <div id="doc-warning">@TEXT@</div> @@ -175,7 +198,7 @@ """ return ( - mainTemplate.format("dark" if e5App().usesDarkPalette() else "light") + mainTemplate.format(_stylesheet()) .replace("@TEXT@", text) ) @@ -194,8 +217,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> - <link rel="stylesheet" href="qrc:documentViewerStyle-{0}.css" - type="text/css" /> + <style>{0}</style> </head> <body> <div id="warning">@TEXT@</div> @@ -204,6 +226,6 @@ """ return ( - mainTemplate.format("dark" if e5App().usesDarkPalette() else "light") + mainTemplate.format(_stylesheet()) .replace("@TEXT@", text) )