5 |
5 |
6 """ |
6 """ |
7 Module implementing functions to prepare an HTML documentation view. |
7 Module implementing functions to prepare an HTML documentation view. |
8 """ |
8 """ |
9 |
9 |
|
10 import os |
10 |
11 |
11 from PyQt5.QtCore import QCoreApplication |
12 from PyQt5.QtCore import QCoreApplication |
12 |
13 |
13 from E5Gui.E5Application import e5App |
14 from E5Gui.E5Application import e5App |
14 |
15 |
15 import Utilities |
16 import Utilities |
16 |
17 |
17 |
18 |
18 # TODO: convert style sheet files to Python source file and embed style in mainTemplate. |
19 _stylesheetsCache = { |
|
20 "dark": "", |
|
21 "light": "", |
|
22 } |
|
23 |
|
24 |
|
25 def _stylesheet(): |
|
26 """ |
|
27 Function to get the stylesheet matching the desktop environment. |
|
28 |
|
29 @return stylesheet |
|
30 @rtype str |
|
31 """ |
|
32 stylesheetType = "dark" if e5App().usesDarkPalette() else "light" |
|
33 if not _stylesheetsCache[stylesheetType]: |
|
34 # load the stylesheet from file |
|
35 stylesheetFilePath = os.path.join( |
|
36 os.path.dirname(__file__), "data", |
|
37 "documentViewerStyle-{0}.css".format(stylesheetType)) |
|
38 with open(stylesheetFilePath, "r") as f: |
|
39 _stylesheetsCache[stylesheetType] = f.read() |
|
40 |
|
41 return _stylesheetsCache[stylesheetType] |
|
42 |
|
43 |
19 def prepareDocumentationViewerHtmlDocument(documentationInfo): |
44 def prepareDocumentationViewerHtmlDocument(documentationInfo): |
20 """ |
45 """ |
21 Public function to prepare the HTML document. |
46 Public function to prepare the HTML document. |
22 |
47 |
23 @param documentationInfo dictionary containing the various documentation |
48 @param documentationInfo dictionary containing the various documentation |
143 "CodeDocumentationViewer", |
167 "CodeDocumentationViewer", |
144 "No further documentation available")) |
168 "No further documentation available")) |
145 ) |
169 ) |
146 |
170 |
147 return ( |
171 return ( |
148 mainTemplate.format("dark" if e5App().usesDarkPalette() else "light") |
172 mainTemplate.format(_stylesheet()) |
149 .replace("@HEADER@", header) |
173 .replace("@HEADER@", header) |
150 .replace("@DOCSTRING@", docstring) |
174 .replace("@DOCSTRING@", docstring) |
151 ) |
175 ) |
152 |
176 |
153 |
177 |
163 mainTemplate = """ |
187 mainTemplate = """ |
164 <!DOCTYPE html> |
188 <!DOCTYPE html> |
165 <html> |
189 <html> |
166 <head> |
190 <head> |
167 <meta http-equiv="content-type" content="text/html; charset=utf-8"> |
191 <meta http-equiv="content-type" content="text/html; charset=utf-8"> |
168 <link rel="stylesheet" href="qrc:documentViewerStyle-{0}.css" |
192 <style>{0}</style> |
169 type="text/css" /> |
|
170 </head> |
193 </head> |
171 <body> |
194 <body> |
172 <div id="doc-warning">@TEXT@</div> |
195 <div id="doc-warning">@TEXT@</div> |
173 </body> |
196 </body> |
174 </html> |
197 </html> |
175 """ |
198 """ |
176 |
199 |
177 return ( |
200 return ( |
178 mainTemplate.format("dark" if e5App().usesDarkPalette() else "light") |
201 mainTemplate.format(_stylesheet()) |
179 .replace("@TEXT@", text) |
202 .replace("@TEXT@", text) |
180 ) |
203 ) |
181 |
204 |
182 |
205 |
183 def prepareDocumentationViewerHtmlWarningDocument(text): |
206 def prepareDocumentationViewerHtmlWarningDocument(text): |
192 mainTemplate = """ |
215 mainTemplate = """ |
193 <!DOCTYPE html> |
216 <!DOCTYPE html> |
194 <html> |
217 <html> |
195 <head> |
218 <head> |
196 <meta http-equiv="content-type" content="text/html; charset=utf-8"> |
219 <meta http-equiv="content-type" content="text/html; charset=utf-8"> |
197 <link rel="stylesheet" href="qrc:documentViewerStyle-{0}.css" |
220 <style>{0}</style> |
198 type="text/css" /> |
|
199 </head> |
221 </head> |
200 <body> |
222 <body> |
201 <div id="warning">@TEXT@</div> |
223 <div id="warning">@TEXT@</div> |
202 </body> |
224 </body> |
203 </html> |
225 </html> |
204 """ |
226 """ |
205 |
227 |
206 return ( |
228 return ( |
207 mainTemplate.format("dark" if e5App().usesDarkPalette() else "light") |
229 mainTemplate.format(_stylesheet()) |
208 .replace("@TEXT@", text) |
230 .replace("@TEXT@", text) |
209 ) |
231 ) |