23 |
23 |
24 |
24 |
25 def _stylesheet(): |
25 def _stylesheet(): |
26 """ |
26 """ |
27 Function to get the stylesheet matching the desktop environment. |
27 Function to get the stylesheet matching the desktop environment. |
28 |
28 |
29 @return stylesheet |
29 @return stylesheet |
30 @rtype str |
30 @rtype str |
31 """ |
31 """ |
32 stylesheetType = "dark" if ericApp().usesDarkPalette() else "light" |
32 stylesheetType = "dark" if ericApp().usesDarkPalette() else "light" |
33 if not _stylesheetsCache[stylesheetType]: |
33 if not _stylesheetsCache[stylesheetType]: |
34 # load the stylesheet from file |
34 # load the stylesheet from file |
35 stylesheetFilePath = os.path.join( |
35 stylesheetFilePath = os.path.join( |
36 os.path.dirname(__file__), "data", |
36 os.path.dirname(__file__), |
37 "documentViewerStyle-{0}.css".format(stylesheetType)) |
37 "data", |
|
38 "documentViewerStyle-{0}.css".format(stylesheetType), |
|
39 ) |
38 with open(stylesheetFilePath, "r") as f: |
40 with open(stylesheetFilePath, "r") as f: |
39 _stylesheetsCache[stylesheetType] = f.read() |
41 _stylesheetsCache[stylesheetType] = f.read() |
40 |
42 |
41 return _stylesheetsCache[stylesheetType] |
43 return _stylesheetsCache[stylesheetType] |
42 |
44 |
43 |
45 |
44 def prepareDocumentationViewerHtmlDocument(documentationInfo): |
46 def prepareDocumentationViewerHtmlDocument(documentationInfo): |
45 """ |
47 """ |
46 Public function to prepare the HTML document. |
48 Public function to prepare the HTML document. |
47 |
49 |
48 @param documentationInfo dictionary containing the various documentation |
50 @param documentationInfo dictionary containing the various documentation |
49 parts |
51 parts |
50 @type dict |
52 @type dict |
51 @return prepared HTML document |
53 @return prepared HTML document |
52 @rtype str |
54 @rtype str |
62 @HEADER@ |
64 @HEADER@ |
63 @DOCSTRING@ |
65 @DOCSTRING@ |
64 </body> |
66 </body> |
65 </html> |
67 </html> |
66 """ |
68 """ |
67 |
69 |
68 headerTemplate = """ |
70 headerTemplate = """ |
69 @TITLE@ |
71 @TITLE@ |
70 @METADATA@ |
72 @METADATA@ |
71 """ |
73 """ |
72 |
74 |
73 titleTemplate = """ |
75 titleTemplate = """ |
74 <div class="title"><h1>@NAME@</h1></div> |
76 <div class="title"><h1>@NAME@</h1></div> |
75 """ |
77 """ |
76 |
78 |
77 metadataTemplate = """ |
79 metadataTemplate = """ |
78 <div class="metadata"> |
80 <div class="metadata"> |
79 @ARGSPEC@ |
81 @ARGSPEC@ |
80 @TYPE@ |
82 @TYPE@ |
81 @NOTE@ |
83 @NOTE@ |
82 </div> |
84 </div> |
83 """ |
85 """ |
84 |
86 |
85 argspecTemplate = QCoreApplication.translate( |
87 argspecTemplate = QCoreApplication.translate( |
86 "CodeDocumentationViewer", |
88 "CodeDocumentationViewer", |
87 '<p><b>Definition:</b> <span class="def">@NAME@@ARGSPEC@</span></p>', |
89 '<p><b>Definition:</b> <span class="def">@NAME@@ARGSPEC@</span></p>', |
88 "Just translate 'Definition:' and leave the rest intact.") |
90 "Just translate 'Definition:' and leave the rest intact.", |
89 |
91 ) |
|
92 |
90 typeTemplate = QCoreApplication.translate( |
93 typeTemplate = QCoreApplication.translate( |
91 "CodeDocumentationViewer", |
94 "CodeDocumentationViewer", |
92 "<p><b>Type:</b> @TYPE@</p>", |
95 "<p><b>Type:</b> @TYPE@</p>", |
93 "Just translate 'Type:' and leave the rest intact.") |
96 "Just translate 'Type:' and leave the rest intact.", |
94 |
97 ) |
|
98 |
95 noteTemplate = QCoreApplication.translate( |
99 noteTemplate = QCoreApplication.translate( |
96 "CodeDocumentationViewer", |
100 "CodeDocumentationViewer", |
97 "<p><b>Note:</b> @NOTE@</p>", |
101 "<p><b>Note:</b> @NOTE@</p>", |
98 "Just translate 'Note:' and leave the rest intact.") |
102 "Just translate 'Note:' and leave the rest intact.", |
99 |
103 ) |
|
104 |
100 docstringTemplate = """ |
105 docstringTemplate = """ |
101 <div class="docstring"> |
106 <div class="docstring"> |
102 @DOCSTRING@ |
107 @DOCSTRING@ |
103 </div> |
108 </div> |
104 """ |
109 """ |
105 |
110 |
106 name = documentationInfo["name"] |
111 name = documentationInfo["name"] |
107 if name: |
112 if name: |
108 title = titleTemplate.replace("@NAME@", name) |
113 title = titleTemplate.replace("@NAME@", name) |
109 if "argspec" in documentationInfo and documentationInfo["argspec"]: |
114 if "argspec" in documentationInfo and documentationInfo["argspec"]: |
110 argspec = Utilities.html_encode(documentationInfo["argspec"]) |
115 argspec = Utilities.html_encode(documentationInfo["argspec"]) |
111 for char in ['=', ',', '(', ')', '*', '**']: |
116 for char in ["=", ",", "(", ")", "*", "**"]: |
112 argspec = argspec.replace( |
117 argspec = argspec.replace( |
113 char, |
118 char, '<span class="argspec-highlight">{0}</span>'.format(char) |
114 '<span class="argspec-highlight">{0}</span>'.format( |
119 ) |
115 char)) |
120 argspec = argspecTemplate.replace("@NAME@", name).replace( |
116 argspec = ( |
121 "@ARGSPEC@", argspec |
117 argspecTemplate |
|
118 .replace("@NAME@", name) |
|
119 .replace("@ARGSPEC@", argspec) |
|
120 ) |
122 ) |
121 else: |
123 else: |
122 argspec = ( |
124 argspec = argspecTemplate.replace("@NAME@", name).replace("@ARGSPEC@", "") |
123 argspecTemplate |
125 |
124 .replace("@NAME@", name) |
|
125 .replace("@ARGSPEC@", "") |
|
126 ) |
|
127 |
|
128 if "typ" in documentationInfo and documentationInfo["typ"]: |
126 if "typ" in documentationInfo and documentationInfo["typ"]: |
129 typeInfo = typeTemplate.replace("@TYPE@", |
127 typeInfo = typeTemplate.replace("@TYPE@", documentationInfo["typ"]) |
130 documentationInfo["typ"]) |
|
131 else: |
128 else: |
132 typeInfo = "" |
129 typeInfo = "" |
133 |
130 |
134 if "note" in documentationInfo and documentationInfo["note"]: |
131 if "note" in documentationInfo and documentationInfo["note"]: |
135 note = noteTemplate.replace("@NOTE@", |
132 note = noteTemplate.replace("@NOTE@", documentationInfo["note"]) |
136 documentationInfo["note"]) |
|
137 else: |
133 else: |
138 note = "" |
134 note = "" |
139 |
135 |
140 metaData = ( |
136 metaData = ( |
141 metadataTemplate |
137 metadataTemplate.replace("@ARGSPEC@", argspec) |
142 .replace("@ARGSPEC@", argspec) |
|
143 .replace("@TYPE@", typeInfo) |
138 .replace("@TYPE@", typeInfo) |
144 .replace("@NOTE@", note) |
139 .replace("@NOTE@", note) |
145 ) |
140 ) |
146 |
141 |
147 header = ( |
142 header = headerTemplate.replace("@TITLE@", title).replace( |
148 headerTemplate |
143 "@METADATA@", metaData |
149 .replace("@TITLE@", title) |
|
150 .replace("@METADATA@", metaData) |
|
151 ) |
144 ) |
152 else: |
145 else: |
153 header = "" |
146 header = "" |
154 |
147 |
155 if "docstring" in documentationInfo and documentationInfo["docstring"]: |
148 if "docstring" in documentationInfo and documentationInfo["docstring"]: |
156 docstring = ( |
149 docstring = ( |
157 documentationInfo["docstring"] |
150 documentationInfo["docstring"] |
158 .replace("\r\n", "<br/>") |
151 .replace("\r\n", "<br/>") |
159 .replace("\n", "<br/>") |
152 .replace("\n", "<br/>") |
160 .replace("\r", "<br/>") |
153 .replace("\r", "<br/>") |
161 ) |
154 ) |
162 docstring = docstringTemplate.replace("@DOCSTRING@", docstring) |
155 docstring = docstringTemplate.replace("@DOCSTRING@", docstring) |
163 else: |
156 else: |
164 docstring = ( |
157 docstring = """<div class="hr"></div><div id="doc-warning">{0}</div>""".format( |
165 """<div class="hr"></div><div id="doc-warning">{0}</div>""" |
158 QCoreApplication.translate( |
166 .format(QCoreApplication.translate( |
159 "CodeDocumentationViewer", "No further documentation available" |
167 "CodeDocumentationViewer", |
160 ) |
168 "No further documentation available")) |
161 ) |
169 ) |
162 |
170 |
|
171 return ( |
163 return ( |
172 mainTemplate.format(_stylesheet()) |
164 mainTemplate.format(_stylesheet()) |
173 .replace("@HEADER@", header) |
165 .replace("@HEADER@", header) |
174 .replace("@DOCSTRING@", docstring) |
166 .replace("@DOCSTRING@", docstring) |
175 ) |
167 ) |
176 |
168 |
177 |
169 |
178 def prepareDocumentationViewerHtmlDocWarningDocument(text): |
170 def prepareDocumentationViewerHtmlDocWarningDocument(text): |
179 """ |
171 """ |
180 Public function to prepare a HTML warning document. |
172 Public function to prepare a HTML warning document. |
181 |
173 |
182 @param text warning text to be shown |
174 @param text warning text to be shown |
183 @type str |
175 @type str |
184 @return prepared HTML document |
176 @return prepared HTML document |
185 @rtype str |
177 @rtype str |
186 """ |
178 """ |