UI/CodeDocumentationViewerTemplate.py

Thu, 19 Oct 2017 19:39:59 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 19 Oct 2017 19:39:59 +0200
changeset 5914
e44c04a89dbc
child 5919
d0de2b378b24
permissions
-rw-r--r--

Improved and beautified the rich text display of the documentation viewer.

5914
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2017 Detlev Offenbach <detlev@die-offenbachs.de>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing functions to prepare an HTML documentation view.
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 def prepareDocumentationViewerHtmlDocument(documentationInfo):
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 Public function to prepare the HTML document.
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 @param documentationInfo dictionary containing the various documentation
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 parts
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 @type dict
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 @return prepared HTML document
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 @rtype str
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 mainTemplate = """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 <!DOCTYPE html>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 <html>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 <head>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 <meta http-equiv="content-type" content="text/html; charset=utf-8">
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 <link rel="stylesheet" href="qrc:documentViewerStyle.css"
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 type="text/css" />
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 </head>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 <body>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @HEADER@
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @DOCSTRING@
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 </body>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 </html>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 headerTemplate = """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @TITLE@
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @METADATA@
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 titleTemplate = """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 <div class="title"><h1>@NAME@</h1></div>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 metadataTemplate = """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 <div class="metadata">
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 @ARGSPEC@
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @NOTE@
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 </div>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 argspecTemplate = """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 <p><b>Definition:</b> <span class="def">@NAME@@ARGSPEC@</span></p>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 noteTemplate = """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 <p><b>Type:</b> @NOTE@</p>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 docstringTemplate = """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 <div class="docstring">
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 @DOCSTRING@
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 </div>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 name = documentationInfo["name"]
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 if name:
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 title = titleTemplate.replace("@NAME@", name)
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 if documentationInfo["argspec"] or documentationInfo["note"]:
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 if documentationInfo["argspec"]:
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 argspec = argspecTemplate\
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 .replace("@NAME@", name)\
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 .replace("@ARGSPEC@", documentationInfo["argspec"])
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 else:
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 argspec = ""
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 if documentationInfo["note"]:
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 note = noteTemplate.replace("@NOTE@",
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 documentationInfo["note"])
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 else:
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 note = ""
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 metaData = metadataTemplate\
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 .replace("@ARGSPEC@", argspec)\
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 .replace("@NOTE@", note)
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 else:
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 metaData = ""
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 header = headerTemplate\
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 .replace("@TITLE@", title)\
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 .replace("@METADATA@", metaData)
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 else:
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 header = ""
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 if documentationInfo["docstring"]:
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 docstring = documentationInfo["docstring"]\
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 .replace("\r\n", "<br/>")\
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 .replace("\n", "<br/>")\
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 .replace("\r", "<br/>")
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 docstring = docstringTemplate.replace("@DOCSTRING@", docstring)
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 else:
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 docstring = ""
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 return mainTemplate\
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 .replace("@HEADER@", header)\
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 .replace("@DOCSTRING@", docstring)
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 def prepareDocumentationViewerHtmlWarningDocument(text):
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 Public function to prepare a HTML warning document.
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 @param text warning text to be shown
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 @type str
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @return prepared HTML document
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @rtype str
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 mainTemplate = """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 <!DOCTYPE html>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 <html>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 <head>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 <meta http-equiv="content-type" content="text/html; charset=utf-8">
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 <link rel="stylesheet" href="qrc:documentViewerStyle.css"
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 type="text/css" />
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 </head>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 <body>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 <div id="doc-warning">@TEXT@</div>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 </body>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 </html>
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 """
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
e44c04a89dbc Improved and beautified the rich text display of the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 return mainTemplate.replace("@TEXT@", text)

eric ide

mercurial