--- a/UI/CodeDocumentationViewer.py Wed Oct 18 19:16:28 2017 +0200 +++ b/UI/CodeDocumentationViewer.py Thu Oct 19 19:39:59 2017 +0200 @@ -22,6 +22,12 @@ import Preferences import UI.PixmapCache +from .CodeDocumentationViewerTemplate import \ + prepareDocumentationViewerHtmlDocument, \ + prepareDocumentationViewerHtmlWarningDocument + +from .data import codeDocumentationViewer_rc # __IGNORE_WARNING__ + class PlainTextDocumentationViewer(QWidget): """ @@ -44,6 +50,7 @@ self.__contents = QTextEdit(self) self.__contents.setTabChangesFocus(True) self.__contents.setReadOnly(True) + self.__contents.setLineWrapMode(QTextEdit.NoWrap) self.__contents.setObjectName("contents") self.__verticalLayout.addWidget(self.__contents) @@ -99,9 +106,16 @@ self.__verticalLayout.setContentsMargins(0, 0, 0, 0) try: - from PyQt5.QtWebEngineWidgets import QWebEngineView + from PyQt5.QtWebEngineWidgets import QWebEngineView, \ + QWebEngineSettings self.__contents = QWebEngineView(self) self.__contents.page().linkHovered.connect(self.__showLink) + try: + self.__contents.settings().setAttribute( + QWebEngineSettings.FocusOnNavigationEnabled, False) + except AttributeError: + # pre Qt 5.8 + pass self.__usesWebKit = False except ImportError: from PyQt5.QtWebKitWidgets import QWebPage, QWebView @@ -147,7 +161,9 @@ @param html HTML text to be shown @type str """ + self.__contents.setEnabled(False) self.__contents.setHtml(html) + self.__contents.setEnabled(True) def clear(self): """ @@ -188,6 +204,7 @@ self.__startingUp = True self.__lastDocumentation = None + self.__requestingEditor = None self.__noDocumentationString = self.tr("No documentation available") self.__disabledString = self.tr( @@ -390,7 +407,7 @@ self.__providers[self.__selectedProvider][0](editor) # TODO: document this hook in the plug-in document - def documentationReady(self, documentationInfo): + def documentationReady(self, documentationInfo, isWarning=False): """ Public method to provide the documentation info to the viewer. @@ -405,6 +422,8 @@ @param documentationInfo dictionary containing the source docu data @type dict or str + @param isWarning flag indicating a warning page + @type bool """ self.__ui.activateCodeDocumentationViewer(switchFocus=False) @@ -413,13 +432,29 @@ if documentationInfo is not None: if not documentationInfo: if self.__selectedProvider == self.__disabledProvider: - fullText = self.__disabledString + self.documentationReady(self.__disabledString, + isWarning=True) else: - fullText = self.__noDocumentationString - elif isinstance(documentationInfo, str): + self.documentationReady(self.__noDocumentationString, + isWarning=True) + return + + if self.__showMarkdown: + if isWarning: + html = prepareDocumentationViewerHtmlWarningDocument( + documentationInfo) + elif isinstance(documentationInfo, dict): + html = prepareDocumentationViewerHtmlDocument( + documentationInfo) + else: + html = "" + if html: + self.__setHtml(html) + return + + if isinstance(documentationInfo, str): fullText = documentationInfo elif isinstance(documentationInfo, dict): - # format the text with markdown syntax name = documentationInfo["name"] if name: title = "".join([name, "\n", @@ -428,30 +463,14 @@ title = "" if documentationInfo["argspec"]: - if self.__showMarkdown: - definition = self.tr( - "**Definition**: {0}{1}\n", - "string with markdown syntax").format( - name, documentationInfo["argspec"]) - else: - definition = self.tr( - "Definition: {0}{1}\n", - "string as plain text").format( - name, documentationInfo["argspec"]) + definition = self.tr("Definition: {0}{1}\n").format( + name, documentationInfo["argspec"]) else: definition = '' if documentationInfo["note"]: - if self.__showMarkdown: - note = self.tr( - "**Info**: {0}\n\n----\n\n", - "string with markdown syntax").format( - documentationInfo["note"]) - else: - note = self.tr( - "Info: {0}\n\n----\n\n", - "string as plain text").format( - documentationInfo["note"]) + note = self.tr("Info: {0}\n\n----\n\n").format( + documentationInfo["note"]) else: note = "" @@ -491,7 +510,7 @@ provider = self.providerComboBox.itemData(index) if provider == self.__disabledProvider: - self.documentationReady(self.__disabledString) + self.documentationReady(self.__disabledString, isWarning=True) else: self.__lastDocumentation = None