UI/CodeDocumentationViewerTemplate.py

changeset 5961
2a5232311a65
parent 5960
be837f440186
child 6048
82ad8ec9548c
diff -r be837f440186 -r 2a5232311a65 UI/CodeDocumentationViewerTemplate.py
--- a/UI/CodeDocumentationViewerTemplate.py	Sun Nov 05 13:24:07 2017 +0100
+++ b/UI/CodeDocumentationViewerTemplate.py	Sun Nov 05 17:16:40 2017 +0100
@@ -51,6 +51,7 @@
     metadataTemplate = """
         <div class="metadata">
         @ARGSPEC@
+        @TYPE@
         @NOTE@
         </div>
     """
@@ -60,6 +61,11 @@
         '<p><b>Definition:</b> <span class="def">@NAME@@ARGSPEC@</span></p>',
         "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.")
+    
     noteTemplate = QCoreApplication.translate(
         "CodeDocumentationViewer",
         "<p><b>Note:</b> @NOTE@</p>",
@@ -74,31 +80,37 @@
     name = documentationInfo["name"]
     if name:
         title = titleTemplate.replace("@NAME@", name)
-        if documentationInfo["argspec"] or documentationInfo["note"]:
-            if documentationInfo["argspec"]:
-                argspec = Utilities.html_encode(documentationInfo["argspec"])
-                for char in ['=', ',', '(', ')', '*', '**']:
-                    argspec = argspec.replace(
-                        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@", "")
-            if documentationInfo["note"]:
-                note = noteTemplate.replace("@NOTE@",
-                                            documentationInfo["note"])
-            else:
-                note = ""
-            metaData = metadataTemplate\
-                .replace("@ARGSPEC@", argspec)\
-                .replace("@NOTE@", note)
+        if "argspec" in documentationInfo and documentationInfo["argspec"]:
+            argspec = Utilities.html_encode(documentationInfo["argspec"])
+            for char in ['=', ',', '(', ')', '*', '**']:
+                argspec = argspec.replace(
+                    char,
+                    '<span class="argspec-highlight">{0}</span>'.format(
+                        char))
+            argspec = argspecTemplate\
+                .replace("@NAME@", name)\
+                .replace("@ARGSPEC@", argspec)
         else:
-            metaData = ""
+            argspec = argspecTemplate\
+                .replace("@NAME@", name)\
+                .replace("@ARGSPEC@", "")
+        
+        if "typ" in documentationInfo and documentationInfo["typ"]:
+            typeInfo = typeTemplate.replace("@TYPE@",
+                                            documentationInfo["typ"])
+        else:
+            typeInfo = ""
+        
+        if "note" in documentationInfo and documentationInfo["note"]:
+            note = noteTemplate.replace("@NOTE@",
+                                        documentationInfo["note"])
+        else:
+            note = ""
+        
+        metaData = metadataTemplate\
+            .replace("@ARGSPEC@", argspec)\
+            .replace("@TYPE@", typeInfo)\
+            .replace("@NOTE@", note)
         
         header = headerTemplate\
             .replace("@TITLE@", title)\
@@ -106,7 +118,7 @@
     else:
         header = ""
     
-    if documentationInfo["docstring"]:
+    if "docstring" in documentationInfo and documentationInfo["docstring"]:
         docstring = documentationInfo["docstring"]\
             .replace("\r\n", "<br/>")\
             .replace("\n", "<br/>")\

eric ide

mercurial